:root {
  color-scheme: dark;
  font: 15px system-ui, sans-serif;
  color: #eee6d4;
  background: #101b1b;
  --surface: #162724;
  --control: #20332c;
  --border: #43574b;
  --muted: #b7c6b8;
  --gold: #f1d58b;
  --heading: Georgia, serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select { font: inherit; }

button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--control);
  color: inherit;
  cursor: pointer;
  line-height: 1.3;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  button:not(:disabled):hover { background: #2c463a; border-color: #708778; }
}

button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -3px;
}

button:disabled { opacity: .55; cursor: default; }
button.selected { border-color: var(--gold); background: #37412e; }

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid #3b4e43;
  background: linear-gradient(115deg, #21342c, #101b1b 64%);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand img { border-radius: 7px; flex: none; }
.brand strong { font: 700 21px/1.05 var(--heading); color: #fff0d2; }
.brand strong span { color: var(--gold); font-family: system-ui, sans-serif; font-size: .58em; }

#wallet {
  flex: none;
  margin-left: auto;
  padding: 5px 9px;
  border: 1px solid #635637;
  border-radius: 999px;
  background: #2c2b21;
  color: var(--gold);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#wallet:empty { display: none; }
#header-toggle, .help-label { display: none; }
#header-actions, .utilities, .game-actions { display: flex; gap: 5px; }
.utilities { margin-left: 3px; padding-left: 8px; border-left: 1px solid var(--border); }
header button { min-height: 38px; font-size: 13px; font-weight: 600; }
.utilities button { background: #172522; }
#help { min-width: 38px; padding-inline: 8px; }

main { flex: 1; min-height: 0; position: relative; overflow: hidden; }
#stage { position: absolute; inset: 0; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; touch-action: none; }
#scene { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; outline: none; }

#hud {
  position: absolute;
  top: 12px;
  left: max(12px, env(safe-area-inset-left));
  max-width: calc(100% - 28px);
  padding: 6px 10px;
  border: 1px solid #71826a;
  border-radius: 8px;
  color: #fff0ce;
  background: #101f1eee;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

#hud:empty { display: none; }
#stations { position: absolute; inset: 0; pointer-events: none; }
#stations span {
  position: absolute;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(26%, 156px);
  padding: 4px 8px;
  border: 1px solid #9c986a;
  border-radius: 6px;
  background: #0d1c15ed;
  box-shadow: 0 2px 8px #0a150f80;
  text-align: center;
  color: #f4ecd8;
  font-size: clamp(11px, 1vw, 14px);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

#interact, #camp-gate {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(88%, 360px);
}
#interact {
  background: #1a2d24;
  border-color: #8b9a74;
}
#camp-gate:not([hidden]) + #interact {
  bottom: calc(66px + env(safe-area-inset-bottom));
}

#camp-gate {
  min-height: 44px;
  padding-inline: 20px;
  background: #a9ae81;
  border-color: #d8d4a8;
  color: #17201a;
  font-size: 14px;
  font-weight: 750;
  box-shadow: 0 4px 18px #0710088c;
}

@media (hover: hover) {
  #camp-gate:hover { background: #bdc097; border-color: #ece3bc; }
}

#camp-gate:focus-visible { outline-color: #263424; }

#sheet {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: #091611a8;
}

#menu {
  width: min(620px, 100%);
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  background: linear-gradient(155deg, #21332c, var(--surface) 56%);
  border: 1px solid #687c6a;
  border-top-color: #a18e61;
  border-radius: 14px;
  box-shadow: 0 12px 36px #080e0bb3;
  padding: 22px;
  scroll-padding: 16px;
}

#menu h1 { margin: 0 0 14px; padding-inline-end: 52px; color: #fff0d2; font: 700 29px/1.13 var(--heading); }
.dialog-tools {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  height: 0;
  pointer-events: none;
}
#menu .window-close, #error .window-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  flex: none;
  background: #182923;
  color: #f4ead2;
  font: 24px/1 system-ui, sans-serif;
  pointer-events: auto;
}
@media (hover: hover) {
  #menu .window-close:hover, #error .window-close:hover {
    background: #2c463a;
    border-color: #708778;
  }
}
#menu h2 { margin: 18px 0 8px; color: var(--gold); font-size: 17px; }
#menu p { color: var(--muted); line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
#menu button { display: block; width: 100%; min-height: 42px; margin: 8px 0; }
#menu input[type=text], #menu input[type=password], #menu select {
  max-width: 100%;
  padding: 9px 11px;
  border: 1px solid #6e8271;
  border-radius: 7px;
  background: #101e1b;
  color: inherit;
}
#menu input[type=text], #menu input[type=password] { display: block; width: min(350px, 100%); margin: 12px auto; }
#menu .row { display: flex; align-items: center; gap: 16px; margin: 12px 0; }
#menu .row > div { flex: 1; min-width: 0; }
#menu .row button { width: 155px; flex-shrink: 0; margin: 0; }
#menu .row small { display: block; color: var(--muted); margin-top: 4px; }
#menu .roles, #menu .frame-rates { display: flex; gap: 8px; }
#menu .roles button, #menu .frame-rates button { flex: 1; min-width: 0; width: auto; overflow-wrap: anywhere; }
#menu .frame-rates button { margin: 0; }
#menu canvas[data-training-model] { width: 128px; height: 100px; max-width: 100%; margin: 0 auto; pointer-events: none; }

.appearance, .inventory-summary { display: flex; gap: 20px; align-items: center; }
.appearance { justify-content: center; }
.appearance canvas { width: 96px; height: 160px; flex-shrink: 0; }
.appearance div { flex: 1; max-width: 270px; }
.inventory-summary canvas { width: 120px; height: 200px; flex-shrink: 0; }
.inventory-summary > div { flex: 1; }
.equipment-slots, .item-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
#menu .equipment-slots button, #menu .item-grid button { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.equipment-slots button { font-size: 14px; }
.item-detail { border: 1px solid var(--border); border-radius: 8px; background: var(--control); padding: 12px; margin: 16px 0; }
details { margin: 20px 0; }
summary { cursor: pointer; padding: 8px 0; color: var(--gold); }
code { display: block; overflow-wrap: anywhere; font-size: 12px; color: var(--muted); }
.hint { font-size: 13px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

.leaderboard-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.leaderboard-table th, .leaderboard-table td { padding: 8px 5px; border-bottom: 1px solid var(--border); text-align: right; }
.leaderboard-table th:nth-child(2), .leaderboard-table td:nth-child(2) { text-align: left; overflow-wrap: anywhere; }
.leaderboard-filters { display: flex; gap: 8px; flex-wrap: wrap; }
#menu .leaderboard-filters button { width: auto; flex: 1; }
.player-id { unicode-bidi: isolate; direction: ltr; display: block; font: 10px monospace; color: var(--muted); overflow-wrap: anywhere; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px max(12px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid #3b4e43;
  color: var(--muted);
  font-size: 12px;
}

#connection::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  vertical-align: 1px;
  border-radius: 50%;
  background: #e5c27a;
}

#connection[data-status=live]::before { background: #96d69a; }
#connection[data-status=offline]::before { background: #eea188; }
#connection[data-status=replay]::before { background: #aac1de; }
#error { position: fixed; bottom: 35px; left: 10px; right: 10px; padding: 14px; background: #4a2e29; border: 1px solid #bc795d; border-radius: 8px; z-index: 10; }
#error:not([hidden]) { display: flex; align-items: flex-start; gap: 12px; }
#error span { flex: 1; overflow-wrap: anywhere; }
[hidden] { display: none !important; }

body.immersive > header, body.immersive > footer,
body.mobile-playing > header, body.mobile-playing > footer { display: none; }
body.immersive > main, body.mobile-playing > main { position: fixed; inset: 0; }
body.immersive #hud, body.mobile-playing #hud { top: calc(12px + env(safe-area-inset-top)); }
body.immersive #hud { max-width: calc(100% - 140px); }

#leave-fullscreen {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 80;
  padding: 6px 10px;
  min-height: 36px;
  background: #152720f5;
}

#touch-controls {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: end;
  pointer-events: none;
  z-index: 5;
}

#touch-controls button {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  min-height: 64px;
  min-width: 64px;
  padding: 8px;
  border: 2px solid #849977;
  border-radius: 12px;
  background: #162a23f0;
  font-size: 14px;
}

#touch-controls #touch-jump { width: 96px; font-weight: 750; border-color: #dec78a; }
#touch-controls button.pressed { background: #45624b; border-color: #ffe6a0; }
body.immersive #touch-controls, body.mobile-playing #touch-controls { bottom: calc(12px + env(safe-area-inset-bottom)); }

.compact-navigation header {
  position: relative;
  z-index: 6;
  gap: 8px;
  padding-block: calc(4px + env(safe-area-inset-top)) 4px;
  background: #14221e;
}
.compact-navigation #header-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 6px 10px;
  background: #1d3027;
  font-size: 12px;
}
.compact-navigation #header-toggle::before {
  content: '';
  width: 12px;
  height: 7px;
  border-block: 1px solid currentColor;
}
.compact-navigation #header-toggle[aria-expanded=true] { border-color: #a18e61; color: var(--gold); }
.compact-navigation #header-actions {
  display: none;
  position: absolute;
  top: 100%;
  right: max(8px, env(safe-area-inset-right));
  width: min(232px, calc(100% - 24px - env(safe-area-inset-right)));
  max-height: calc(var(--app-height, 100dvh) - 60px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px;
  border: 1px solid #687c6a;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 9px 24px #080e0bb3;
}
.compact-navigation #header-toggle[aria-expanded=true] + #header-actions { display: block; }
.compact-navigation #header-actions .game-actions, .compact-navigation #header-actions .utilities { display: grid; }
.compact-navigation #header-actions .utilities {
  margin: 8px 0 0;
  padding: 8px 0 0;
  border: 0;
  border-top: 1px solid var(--border);
}
.compact-navigation #header-actions button { min-height: 44px; text-align: left; }
.compact-navigation #help [aria-hidden] { display: none; }
.compact-navigation .help-label { display: inline; }

.camp-view #scene { image-rendering: auto; }
.camp-view #scene.scaled-pixels { image-rendering: pixelated; }
.camp-view #hud {
  color: #fff0d1;
  background: #0b1b14e8;
  border-color: #9c986a;
}
.camp-view .brand strong span { display: none; }

@media (max-width: 760px) {
  .brand { gap: 6px; }
  .brand img { width: 25px; height: 25px; }
  .brand strong {
    overflow: hidden;
    font-size: clamp(15px, 4vw, 19px);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .brand strong span { display: none; }
  #wallet { font-size: 12px; padding-inline: 7px; }
  #keys { display: none; }
  #hud { font-size: 13px; }
  #menu { padding: 16px; }
  #menu h1 { font-size: 25px; }
  #menu .opening-brand img { width: 44px; height: 44px; }
  #menu .row { gap: 8px; }
  #menu .row button { width: 125px; }
  .appearance, .inventory-summary { gap: 12px; }
}

@media (max-width: 380px) {
  header { padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); }
  .brand img { width: 22px; height: 22px; }
}

@media (max-width: 580px) {
  .inventory-summary canvas { width: 72px; height: 120px; }
  .equipment-slots, .item-grid { grid-template-columns: 1fr; }
}

@media (pointer: coarse) {
  header button, #menu button { min-height: 44px; }
  #help { min-width: 44px; }
}

.gear-layout { display: grid; grid-template-columns: minmax(88px, 1fr) 2fr; gap: 12px; align-items: center; }
.gear-portrait { display: grid; justify-items: center; padding: 10px; text-align: center; background: #101e1a; border-radius: 10px; }
.gear-portrait canvas { width: 72px; height: 120px; }
.gear-portrait h2 { margin: 8px 0 0; overflow-wrap: anywhere; }
.gear-slots, .gear-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; }
.gear-slot { min-width: 0; }
.gear-slot small { color: var(--muted); }
#menu .gear-slots button, #menu .gear-grid button, .empty-gear { min-height: 46px; margin: 0; padding: 5px; overflow-wrap: anywhere; }
.gear-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
.empty-gear { border: 1px solid #354940; border-radius: 8px; background: #11201b; }
#menu [data-rarity=rare] button { border-color: #a479b9; color: #e8c5ff; }
#menu [data-rarity=legendary] button { border-color: #c28c42; color: #ffdc95; }
@media (max-width: 480px) {
  .gear-layout { gap: 8px; }
  .gear-slots { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .gear-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  #menu .gear-grid button, #menu .gear-slots button { font-size: 12px; }
}

.opening-brand { display:flex; align-items:center; gap:12px; margin-bottom:12px; }
.opening-brand h1 { margin:0; }
.opening-brand img { border-radius:12px; }

.skill-choices { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; margin:0 0 14px; }
#menu .skill-choice {
  display:flex; flex-direction:column; align-items:flex-start; gap:10px;
  min-width:0; min-height:128px; margin:0; padding:12px; text-align:left;
  border-color:#50675a; background:#1d3029;
}
.skill-icon {
  display:grid; place-items:center; width:46px; height:46px; flex:0 0 46px;
  border:1px solid #4e6258; border-radius:8px; background:#111f1b;
}
.skill-icon canvas { display:block; width:32px; height:32px; image-rendering:pixelated; }
.skill-copy { display:grid; gap:4px; min-width:0; overflow-wrap:anywhere; }
.skill-copy strong { color:#f4ead2; font-size:15px; line-height:1.25; }
.skill-copy small { color:#dec18a; font-size:11px; }
.skill-copy > span { color:var(--muted); font-size:13px; line-height:1.42; }
.skill-entry { display:grid; grid-template-columns:auto minmax(0,1fr); gap:12px; padding:14px 0; border-top:1px solid #40564b; }
#menu .skill-entry h2 { margin:0 0 8px; }
.skill-entry dl { display:grid; gap:6px; margin:0; font-size:13px; }
.skill-entry dl div { display:grid; grid-template-columns:minmax(52px,auto) 1fr; gap:10px; }
.skill-entry dt { color:#dec18a; }
.skill-entry dd { margin:0; color:var(--muted); }
@media (max-width:560px) {
  .skill-choices { grid-template-columns:1fr; }
  #menu .skill-choice { flex-direction:row; align-items:center; min-height:76px; }
}

#menu .login-panel { max-width:420px; margin:0 auto; padding:8px 0; }
#menu .login-panel p { margin:8px 0 18px; }
#menu .login-panel label { display:block; color:#d9c5a1; font-size:13px; }
#menu .login-panel #nsec-key { width:100%; min-height:44px; margin:6px 0 16px; font-family:monospace; font-size:17px; }
#menu .login-panel .login-error {
  margin:0 0 12px; padding:10px 12px; border:1px solid #946453; border-radius:7px;
  background:#3a2926; color:#f0d4cb; font-size:14px;
}
#menu [data-action=account-login], #menu [data-action=nsec-sign] {
  background:#e4c789; color:#21271d; border-color:#e9d29b; font-weight:700;
}
#menu [data-action=nsec-open] { background:transparent; color:#c4cdbd; border-color:transparent; }
#menu [data-action=opening-guest] { background:#20332b; }
@media (hover:hover) {
  #menu .skill-choice:not(:disabled):hover { background:#273d32; border-color:#819280; }
  #menu [data-action=account-login]:hover, #menu [data-action=nsec-sign]:hover { background:#f1dba8; }
  #menu [data-action=nsec-open]:hover { background:#20332b; border-color:#50675a; }
}

@media (pointer:coarse) {
  #menu .keyboard-hint { display:none; }
}
