:root {
  --ink: #e8f1ec;
  --ink-dim: #9db3ac;
  --bg: #0b1618;
  --panel: rgba(12, 26, 28, 0.86);
  --line: rgba(190, 225, 210, 0.16);
  --accent: #7fe0b0;
  --warn: #e8b56a;
  --bad: #e07a6a;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: "Atkinson Hyperlegible", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }

/* ---------- top HUD ---------- */
#hud-top {
  position: fixed; top: calc(var(--safe-top) + 10px); left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none; z-index: 10;
}
.clock {
  display: flex; align-items: center; gap: 8px;
  font-family: "Pixelify Sans", monospace; font-size: 15px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 7px 11px; border-radius: 999px;
  backdrop-filter: blur(10px);
}
.clock .pill {
  font-family: "Atkinson Hyperlegible", sans-serif; font-size: 11px;
  letter-spacing: .04em; text-transform: uppercase; color: var(--ink-dim);
}
.identity { text-align: right; max-width: 55%; }
.identity .title {
  display: block; font-family: "Pixelify Sans", monospace;
  font-size: 17px; letter-spacing: .01em;
}
.identity .doing {
  display: block; font-size: 12px; color: var(--ink-dim);
  margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- needs ---------- */
#needs {
  position: fixed; top: calc(var(--safe-top) + 62px); left: 12px; z-index: 10;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.need { display: flex; align-items: center; gap: 6px; }
.need .ico { font-size: 12px; width: 16px; text-align: center; filter: saturate(.8); }
.need .bar {
  width: 66px; height: 5px; border-radius: 3px;
  background: rgba(255,255,255,.14); overflow: hidden;
}
.need .bar b {
  display: block; height: 100%; width: 50%;
  background: var(--accent); border-radius: 3px;
  transition: width .4s ease, background .4s ease;
}
.need .bar b.low { background: var(--warn); }
.need .bar b.crit { background: var(--bad); }

/* ---------- tabs + panel ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 8px);
  display: flex; gap: 4px; padding: 0 10px; z-index: 12;
}
#tabs button {
  flex: 1; padding: 9px 4px 8px; font-size: 11.5px; font-weight: 700;
  letter-spacing: .02em; color: var(--ink-dim); background: var(--panel);
  border: 1px solid var(--line); border-radius: 11px;
  backdrop-filter: blur(10px); font-family: inherit;
}
#tabs button.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }
#tabs button em {
  font-style: normal; background: rgba(0,0,0,.25); border-radius: 6px;
  padding: 0 4px; margin-left: 2px; font-size: 10px;
}
#tabs button.active em { background: rgba(0,0,0,.18); }

#panel {
  position: fixed; left: 8px; right: 8px; bottom: calc(var(--safe-bottom) + 56px);
  max-height: 46vh; overflow-y: auto; z-index: 11;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); backdrop-filter: blur(14px);
  transform: translateY(0); transition: transform .25s ease;
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
}
#panel.hidden { transform: translateY(calc(100% + 70px)); }
.panel-body { padding: 12px 13px 14px; }

.card {
  border: 1px solid var(--line); border-radius: 11px;
  padding: 10px 11px; margin-bottom: 8px; background: rgba(255,255,255,.03);
}
.card h3 { margin: 0 0 4px; font-size: 13.5px; font-weight: 700; }
.card p { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--ink-dim); }
.card .why { font-size: 11.5px; margin-top: 6px; color: var(--ink-dim); opacity: .8; }
.card .alt { font-size: 11.5px; margin-top: 6px; font-style: italic; opacity: .75; }
.card .row { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.card .row button {
  flex: 1; min-width: 96px; padding: 9px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: rgba(127,224,176,.12);
  color: var(--ink); font-family: inherit; font-size: 12px; font-weight: 700;
}
.card .row button:active { background: rgba(127,224,176,.3); }
.card .row button.ghost { background: transparent; color: var(--ink-dim); }

.empty { text-align: center; padding: 18px 8px; color: var(--ink-dim); font-size: 12.5px; line-height: 1.5; }

.skill { display: flex; justify-content: space-between; font-size: 12px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
.skill span:last-child { color: var(--accent); font-family: "Pixelify Sans", monospace; }

.event { display: flex; gap: 8px; padding: 6px 0; font-size: 12px; border-bottom: 1px solid rgba(255,255,255,.05); }
.event time { color: var(--ink-dim); font-family: "Pixelify Sans", monospace; font-size: 10.5px; min-width: 52px; }

.token-row { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.token { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--accent); }
.token.spent { border-color: var(--line); background: rgba(255,255,255,.06); }
.crate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.crate-grid button {
  padding: 11px 9px; border-radius: 10px; text-align: left;
  border: 1px solid var(--line); background: rgba(255,255,255,.04);
  color: var(--ink); font-family: inherit; font-size: 12px; line-height: 1.3;
}
.crate-grid button b { display: block; font-size: 12.5px; margin-bottom: 2px; }
.crate-grid button small { color: var(--ink-dim); font-size: 10.5px; }
.crate-grid button:disabled { opacity: .4; }

/* ---------- toast + recentre ---------- */
#toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 96px); transform: translate(-50%, -8px);
  background: rgba(20, 40, 38, .95); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; font-size: 12.5px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 30;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#recenter {
  position: fixed; right: 12px; bottom: calc(var(--safe-bottom) + 120px);
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--ink); font-size: 19px; z-index: 12; backdrop-filter: blur(10px);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
