/* Emberwood — interface styles */
:root {
  --ink: #14131c;
  --ink-2: #1e1c29;
  --ink-3: #2a2738;
  --line: rgba(255, 220, 170, .16);
  --text: #f3e6cf;
  --dim: #a99c88;
  --ember: #ff8a3a;
  --ember-dark: #c9591a;
  --gold: #ffd166;
  --moss: #7fb069;
  --blood: #e2574c;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", "Varela Round", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b1020;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

[hidden] { display: none !important; }

.vignette, .hurt { position: fixed; inset: 0; pointer-events: none; opacity: 0; }
.vignette {
  background: radial-gradient(ellipse at center, rgba(5, 6, 14, 0) 28%, rgba(5, 6, 14, .88) 100%);
  transition: opacity 1.2s;
}
.hurt {
  background: radial-gradient(ellipse at center, rgba(226, 60, 50, 0) 45%, rgba(226, 60, 50, .6) 100%);
  transition: opacity .6s;
}
.hurt.on { opacity: 1; transition: opacity .05s; }

/* ── Shared pieces ─────────────────────────────────────────── */
.panel {
  background: rgba(20, 19, 28, .86);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
}
.panel-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 6px;
}
.panel-label b { color: var(--gold); margin-left: 4px; }

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 1px 6px;
  margin: 0 1px;
  border-radius: 7px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  font: 700 12px var(--font);
  text-align: center;
  color: var(--text);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  font: 800 16px var(--font);
  color: var(--text);
  background: var(--ink-3);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .4);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .4); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { width: 100%; color: #1a0f06; background: var(--ember); box-shadow: 0 4px 0 var(--ember-dark); }
.btn:focus-visible, .chip-btn:focus-visible, input:focus-visible, .swatch:focus-visible, .round-btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.bar { height: 10px; border-radius: 999px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 100%; border-radius: 999px; transition: width .3s; }

/* ── Lobby ─────────────────────────────────────────────────── */
.lobby {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  background: radial-gradient(ellipse at center, rgba(5, 6, 14, .1) 20%, rgba(5, 6, 14, .75) 100%);
}
.card {
  width: min(430px, 100%);
  background: rgba(20, 19, 28, .9);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 28px 28px 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
  animation: rise .5s cubic-bezier(.2, .9, .3, 1.2) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.97); } }

.eyebrow {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ember);
}
.card h1 {
  margin: 0;
  font-size: 48px;
  line-height: 1;
  letter-spacing: -.02em;
  color: var(--text);
  text-shadow: 0 0 34px rgba(255, 138, 58, .45);
}
.lede { margin: 10px 0 18px; line-height: 1.45; color: var(--dim); }
.lede b { color: var(--gold); }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: var(--dim);
}
input[type="text"] {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--ink);
  padding: 11px 13px;
  font: 700 16px var(--font);
  color: var(--text);
}
input[type="text"]::placeholder { color: #6f6659; font-weight: 600; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  box-shadow: 0 0 0 2px var(--line);
  cursor: pointer;
  padding: 0;
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.1); }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--text); transform: scale(1.12); }

.or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dim);
}
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .25em; text-align: center; }
.join-row .btn { white-space: nowrap; }

.error {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(226, 87, 76, .18);
  border: 1px solid rgba(226, 87, 76, .5);
  color: #ffb3ab;
  font-weight: 700;
}
.keys { margin: 16px 0 0; font-size: 12.5px; line-height: 2; text-align: center; color: var(--dim); }

/* ── HUD layout ────────────────────────────────────────────── */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud > * { pointer-events: auto; position: absolute; }

.top-left { top: 14px; left: 14px; width: 214px; }
.camp-code { font-size: 14px; margin-bottom: 6px; color: var(--dim); }
.camp-code strong { font-size: 20px; letter-spacing: .14em; margin-left: 4px; color: var(--text); }
.chip-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--ink-3);
  border-radius: 999px;
  padding: 4px 10px;
  margin: 0 4px 4px 0;
  font: 700 12px var(--font);
  color: var(--text);
  cursor: pointer;
}
.chip-btn:hover { filter: brightness(1.2); }
.players { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; font-weight: 700; font-size: 13px; }
.player { display: grid; grid-template-columns: 11px 1fr; gap: 2px 7px; align-items: center; }
.player i { width: 11px; height: 11px; border-radius: 50%; }
.player small { font-weight: 600; color: var(--dim); margin-left: 4px; }
.player .bar { grid-column: 2; height: 4px; margin-bottom: 2px; }
.player .bar > i { background: var(--blood); }
.player.down { opacity: .55; }

.top-center { top: 14px; left: 50%; transform: translateX(-50%); width: 300px; pointer-events: none; }
.clock { text-align: center; }
.phase { font-size: 20px; font-weight: 800; letter-spacing: .01em; }
.phase small { font-size: 13px; font-weight: 700; color: var(--dim); margin-left: 6px; }
.clock.night .phase { color: #b9c6ff; }
.bar-cycle { height: 6px; margin: 6px 0 9px; }
.bar-cycle > i { background: var(--gold); transition: none; }
.clock.night .bar-cycle > i { background: #8ea6ff; }
.fire-row { display: grid; grid-template-columns: auto 1fr; gap: 9px; align-items: center; }
.fire-lv { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--ember); }
.bar-fuel > i { background: linear-gradient(90deg, #ff6a1a, #ffd166); }
.bar-fuel.low > i { animation: pulse .7s infinite alternate; }
@keyframes pulse { to { opacity: .35; } }
.hint {
  margin: 8px auto 0;
  width: fit-content;
  max-width: 100%;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(20, 19, 28, .7);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}
.hint.warn { background: rgba(160, 40, 30, .85); }
.hint:empty { display: none; }

.top-right { top: 14px; right: 14px; width: 214px; display: flex; flex-direction: column; gap: 8px; }
.stock { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 4px; }
.stock-item { display: flex; align-items: center; justify-content: center; gap: 4px; font-weight: 800; font-size: 14px; }
.stock-item svg { width: 22px; height: 22px; }
.stock-item.bump { animation: bump .35s; }
@keyframes bump { 40% { transform: scale(1.3); } }
.map-panel canvas { display: block; width: 100%; aspect-ratio: 1; border-radius: 50%; cursor: pointer; }

.cost { display: inline-flex; align-items: center; gap: 3px; font-weight: 800; font-size: 12.5px; color: var(--dim); }
.cost svg { width: 15px; height: 15px; }
.cost.ok { color: var(--moss); }
.cost.short { color: #ff8f85; }

.prompt {
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: rgba(20, 19, 28, .9);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 9px 16px;
  box-shadow: var(--shadow);
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  max-width: 94vw;
}
.prompt.muted { font-weight: 700; color: var(--dim); }
.prompt.nope { animation: nope .3s; }
@keyframes nope { 25% { transform: translateX(calc(-50% - 7px)); } 75% { transform: translateX(calc(-50% + 7px)); } }

/* Bottom-left: chat + vitals */
.bottom-left { left: 14px; bottom: 14px; width: 290px; display: flex; flex-direction: column; gap: 8px; }
.chat-log { display: flex; flex-direction: column; gap: 4px; max-height: 150px; overflow: hidden; justify-content: flex-end; pointer-events: none; }
.chat-line {
  align-self: flex-start;
  max-width: 100%;
  background: rgba(20, 19, 28, .8);
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 13.5px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  animation: rise .25s both;
  transition: opacity .8s;
}
.chat-line b { margin-right: 5px; }
.chat-line.sys { font-style: italic; color: var(--gold); }
.chat-line.old { opacity: 0; }
.chat-input {
  border-radius: 999px !important;
  padding: 7px 14px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  background: rgba(20, 19, 28, .7) !important;
}
.vitals { display: flex; flex-direction: column; gap: 7px; }
.vital { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 8px; }
.vital span { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.bar-hp > i { background: var(--blood); }
.bar-food > i { background: #e0a44a; }
.bar-run { height: 6px; }
.bar-run > i { background: #7fd0e0; transition: none; }
.bar.low > i { animation: pulse .7s infinite alternate; }
.bag-row .panel-label { margin: 2px 0 4px; }
.bag { display: flex; gap: 10px; flex-wrap: wrap; min-height: 24px; align-items: center; }
.bag-item { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 14px; }
.bag-item svg { width: 20px; height: 20px; }
.bag-item.band { appearance: none; border: 1px solid var(--line); background: var(--ink-3); color: #ff9d94; border-radius: 999px; padding: 2px 10px; font-family: var(--font); cursor: pointer; }
.bag-empty { color: var(--dim); font-size: 13px; font-weight: 600; }
.bag.full .bag-item { color: var(--ember); }

/* Bottom-right: touch buttons */
.bottom-right { right: 14px; bottom: 14px; display: flex; align-items: flex-end; gap: 10px; }
.round-btn {
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(42, 39, 56, .92);
  color: var(--text);
  font: 800 14px var(--font);
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
.btn-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.round-btn.on { background: #2f6f7d; }
.round-btn.hit { width: 74px; height: 74px; background: #8f2f28; }
.round-btn.act { width: 88px; height: 88px; background: var(--ember); color: #1a0f06; font-size: 16px; }
.round-btn.act.idle { background: #5a5148; color: var(--dim); }
.round-btn:active { transform: scale(.94); }

.stick {
  left: 26px; bottom: 190px;
  width: 124px; height: 124px;
  border-radius: 50%;
  background: rgba(255, 240, 220, .12);
  border: 2px solid rgba(255, 240, 220, .35);
  touch-action: none;
}
.stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 54px; height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 240, 220, .8);
  box-shadow: var(--shadow);
}

/* Workbench */
.craft {
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, 94vw);
  max-height: 84vh;
  overflow: auto;
  padding: 18px 20px;
  background: rgba(20, 19, 28, .96);
}
.craft-head { display: flex; align-items: center; justify-content: space-between; }
.craft-head h2 { margin: 0; font-size: 24px; }
.craft-sub { margin: 2px 0 12px; color: var(--dim); font-size: 13px; }
.craft-list { display: flex; flex-direction: column; gap: 8px; }
.craft-list h4 { margin: 10px 0 0; font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ember); }
.recipe {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--ink-2);
  border: 1px solid transparent;
}
.recipe.ready { border-color: rgba(255, 138, 58, .55); }
.recipe.owned { opacity: .55; }
.recipe h3 { margin: 0; font-size: 15.5px; }
.recipe h3 small { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--dim); margin-left: 6px; }
.recipe p { margin: 0; grid-column: 1; font-size: 13px; color: var(--dim); }
.recipe .costs { grid-column: 1; display: flex; gap: 10px; margin-top: 3px; }
.recipe button {
  grid-column: 2; grid-row: 1 / span 3;
  appearance: none; border: 0; border-radius: 10px;
  padding: 9px 14px; min-width: 76px;
  font: 800 14px var(--font);
  background: var(--ember); color: #1a0f06; cursor: pointer;
}
.recipe button:disabled { background: var(--ink-3); color: var(--dim); cursor: default; }

/* Toasts + banner */
.toasts { top: 150px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  background: rgba(20, 19, 28, .92);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: rise .25s both;
  transition: opacity .5s, transform .5s;
  text-align: center;
}
.toast.out { opacity: 0; transform: translateY(-8px); }
.banner {
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  padding: 18px 34px;
  border-radius: 22px;
  background: rgba(20, 19, 28, .9);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
  animation: rise .6s cubic-bezier(.2, .9, .3, 1.3) both;
  pointer-events: none;
  max-width: 92vw;
}
.banner h2 { margin: 0 0 4px; font-size: 30px; }
.banner p { margin: 0; color: var(--dim); font-weight: 600; }
.banner.night h2 { color: #b9c6ff; }
.banner.bad h2 { color: #ff8f85; }
.banner.good h2 { color: var(--gold); }
.net {
  bottom: 14px; left: 50%; transform: translateX(-50%);
  background: #a2332b; color: #fff;
  padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: 13px;
}
.noscript { position: fixed; inset: auto 0 20px; text-align: center; font-weight: 700; }

/* ── Small screens / touch ─────────────────────────────────── */
@media (max-width: 900px) {
  .top-left { width: 170px; padding: 8px 10px; }
  .top-right { width: 150px; }
  .top-center { width: 230px; }
  .stock-item { font-size: 12px; }
  .stock-item svg { width: 17px; height: 17px; }
  .chat-input { display: none; }
}
@media (max-width: 620px) {
  .top-left { width: 112px; padding: 6px 8px; }
  .top-left .chip-btn, .players { display: none; }
  .camp-code { margin: 0; font-size: 11px; }
  .camp-code strong { display: block; margin: 0; font-size: 16px; }
  .top-center { top: 8px; width: 150px; left: 50%; }
  .clock { padding: 7px 9px; }
  .phase { font-size: 15px; }
  .phase small { display: block; margin: 0; font-size: 11px; }
  .fire-lv { font-size: 10px; }
  .hint { font-size: 11.5px; }
  .top-right { width: 104px; top: 8px; right: 8px; }
  .top-left { top: 8px; left: 8px; }
  .top-right .panel { padding: 6px 7px; }
  .top-right .panel-label { font-size: 9px; margin-bottom: 3px; }
  .stock { grid-template-columns: repeat(4, 1fr); gap: 2px 1px; }
  .stock-item { gap: 1px; }
  .vital { grid-template-columns: 44px 1fr; }
  .stock-item { font-size: 10.5px; }
  .stock-item svg { width: 14px; height: 14px; }
  .bottom-left { width: 190px; left: 8px; bottom: 8px; }
  .chat-log { max-height: 60px; }
  .vitals { padding: 8px 10px; }
  .bottom-right { right: 8px; bottom: 8px; gap: 6px; }
  .round-btn { width: 50px; height: 50px; font-size: 12px; }
  .btn-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.round-btn.on { background: #2f6f7d; }
.round-btn.hit { width: 58px; height: 58px; }
  .round-btn.act { width: 70px; height: 70px; font-size: 14px; }
  .prompt { top: 250px; bottom: auto; white-space: normal; text-align: center; justify-content: center; font-size: 13px; padding: 7px 12px; max-width: 86vw; }
  .toasts { top: 300px; width: 90vw; }
  .stick { bottom: 200px; left: 14px; }
  .card { padding: 22px 20px 16px; }
  .card h1 { font-size: 40px; }
  .recipe button { min-width: 62px; padding: 8px 10px; }
}
@media (pointer: coarse) {
  .prompt kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* the whole-forest map (Tab) */
.top-right.wide { width: min(460px, calc(100vw - 28px)); z-index: 5; }
.top-right.wide .map-panel canvas { cursor: zoom-out; }
.map-panel canvas { cursor: zoom-in; }

.vital.locked span { color: #7fd0e0; }
.vital.locked span::after { content: " ●"; }

/* touch controls: no text selection, long-press menus or double-tap zoom while playing */
.round-btn, .stick, .stick-knob, .bag-item, #scene, .hud {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.round-btn, .stick { touch-action: none; }

/* ghosts only watch: hide what they cannot use */
.hud.ghost .vitals, .hud.ghost #btn-hit, .hud.ghost #btn-shoot, .hud.ghost #btn-eat, .hud.ghost #btn-run, .hud.ghost #craft { display: none !important; }
.gameover {
  left: 50%; top: 34%; transform: translateX(-50%);
  width: min(400px, 90vw); text-align: center; padding: 22px 24px;
  background: rgba(20, 19, 28, .95);
}
.gameover h2 { margin: 0 0 6px; font-size: 26px; color: #ff8f85; }
.gameover p { margin: 0 0 14px; color: var(--dim); font-weight: 600; }
.gameover .gameover-sub { margin: 12px 0 0; }

/* key legend (desktop only) */
.keys-legend { right: 14px; bottom: 14px; padding: 8px 12px 10px; width: 262px; background: rgba(20, 19, 28, .72); }
.keys-legend .chip-btn { float: right; margin: -2px -4px 0 6px; padding: 2px 8px; font-size: 11px; }
.keys-legend .panel-label { margin-bottom: 5px; }
.keys-grid span { white-space: nowrap; }
.keys-grid { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 4px 6px; align-items: center; font-size: 12px; font-weight: 700; color: var(--dim); }
.keys-grid kbd { font-size: 11px; min-width: 1.6em; padding: 0 5px; border-bottom-width: 2px; justify-self: start; white-space: nowrap; }
.keys-legend.closed { width: auto; }
.keys-legend.closed .keys-grid, .keys-legend.closed .panel-label { display: none; }
.keys-legend.closed .chip-btn { float: none; margin: 0; }
@media (pointer: coarse), (max-width: 900px) { .keys-legend { display: none !important; } }
