:root {
  --ink: #1d1a14;
  --paper: #f3eee2;
  --panel: rgba(28, 24, 18, 0.62);
  --panel-line: rgba(255, 245, 225, 0.14);
  --text: #f6f0e2;
  --muted: rgba(246, 240, 226, 0.66);
  --accent: #d9862b;
  --hunger: #c9a227;
  --stamina: #7fb069;
  --alert: #d0453a;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9c3d6; color: var(--text); }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud[hidden] { display: none; }

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 10px 14px;
}
.stats { top: 14px; left: 14px; min-width: 150px; }
.score { font-size: 30px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.score small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.row { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 13px; }
.row span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.row.wx { justify-content: flex-start; gap: 8px; }
.row.wx #clock { font-weight: 600; font-size: 12px; color: var(--muted); }
.lives { margin-top: 6px; font-size: 18px; letter-spacing: 3px; }
.lives .lost { opacity: 0.25; filter: grayscale(1); }

.bars { top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 16px; padding: 9px 14px; }
.bar { display: flex; flex-direction: column; gap: 4px; width: 120px; }
.track { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.16); overflow: hidden; }
.fill { height: 100%; width: 100%; border-radius: 4px; transform-origin: left center; transition: width 0.12s linear; }
.fill.hunger { background: var(--hunger); }
.fill.stamina { background: var(--stamina); }
.fill.alert { background: var(--alert); width: 0; }
.fill.low { animation: blink 0.5s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

#minimap {
  position: absolute; top: 14px; right: 14px;
  width: 168px; height: 168px;
  border-radius: 50%;
  border: 2px solid var(--panel-line);
  background: rgba(28, 24, 18, 0.5);
}

#minimap { pointer-events: auto; cursor: zoom-in; }
.mapHint { position: absolute; top: 186px; right: 14px; width: 168px; text-align: center; font-size: 11px; color: rgba(255,255,255,0.85); text-shadow: 0 1px 2px rgba(0,0,0,0.6); }
.mission { top: 136px; left: 14px; max-width: min(340px, calc(100% - 210px)); display: flex; flex-direction: column; gap: 3px; padding: 8px 12px; border-color: rgba(255, 176, 58, 0.55); }
.mission #missionText { font-size: 14px; font-weight: 600; line-height: 1.3; }
.mission #missionDist { font-size: 13px; color: #ffb03a; font-weight: 700; font-variant-numeric: tabular-nums; }
.mapview { background: rgba(20, 17, 12, 0.72); z-index: 5; }
.mapbox { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; }
#bigmap { width: min(calc(100vh - 110px), calc(100vw - 32px)); height: min(calc(100vh - 110px), calc(100vw - 32px)); border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); background: #b9b39a; touch-action: none; }
.mapbar { display: flex; gap: 10px; width: min(520px, 100%); }
.mapbar button { margin: 0; flex: 1; }
.mapbar .secondary { background: var(--paper); }

#toasts { position: absolute; top: 96px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 999px;
  padding: 6px 14px; font-size: 14px; font-weight: 600;
  animation: toast 2.4s ease forwards;
}
.toast.warn { background: rgba(140, 32, 24, 0.82); }
@keyframes toast {
  0% { opacity: 0; transform: translateY(-6px); }
  10%, 75% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-6px); }
}

#popups { position: absolute; inset: 0; overflow: hidden; }
.pop {
  position: absolute; transform: translate(-50%, -50%);
  font-weight: 800; font-size: 18px; color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45), 0 0 12px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  animation: pop 1.1s ease-out forwards;
}
@keyframes pop {
  0% { opacity: 0; margin-top: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; margin-top: -48px; }
}

.hint {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

#touch { position: absolute; inset: 0; }
#touch[hidden] { display: none; }
.stick {
  position: absolute; left: 22px; bottom: 26px; width: 128px; height: 128px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.14); border: 2px solid rgba(255, 255, 255, 0.3);
  pointer-events: auto; touch-action: none;
}
.knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.55);
}
.btns { position: absolute; right: 16px; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 12px; }
.btns button {
  pointer-events: auto; touch-action: none;
  width: 78px; height: 78px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(28, 24, 18, 0.55); color: #fff;
  font: 700 14px/1 inherit; font-family: inherit;
}
.btns button.on { background: rgba(217, 134, 43, 0.85); }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(20, 17, 12, 0.45);
}
.overlay[hidden] { display: none; }
.card {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--paper); color: var(--ink);
  border-radius: 16px; padding: 28px 28px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.card.small { width: min(300px, 100%); text-align: center; }
.kicker { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: #8a6a3c; font-weight: 600; }
h1 { margin: 0 0 10px; font-size: 34px; line-height: 1.05; }
h2 { margin: 0 0 10px; font-size: 26px; }
.lead { margin: 0 0 14px; line-height: 1.5; color: #3d362a; }
.keys { list-style: none; padding: 12px 14px; margin: 0 0 12px; background: rgba(0, 0, 0, 0.05); border-radius: 10px; font-size: 14px; line-height: 1.9; }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; margin-right: 3px;
  border: 1px solid rgba(0, 0, 0, 0.2); border-bottom-width: 2px; border-radius: 5px;
  background: #fff; font: 600 12px/1.5 inherit; font-family: inherit; text-align: center;
}
.goal { font-size: 14px; color: #5a4e3a; margin: 0 0 18px; }
.primary {
  width: 100%; padding: 14px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font: 700 16px/1 inherit; font-family: inherit;
  cursor: pointer;
}
.primary:hover { filter: brightness(1.06); }
.primary[disabled] { opacity: 0.6; cursor: progress; }
.secondary {
  width: 100%; margin-top: 10px; padding: 12px; border: 1px solid rgba(0, 0, 0, 0.18); border-radius: 10px;
  background: transparent; color: var(--ink); font: 600 15px/1 inherit; font-family: inherit; cursor: pointer;
}
.secondary:hover { background: rgba(0, 0, 0, 0.05); }
.primary:focus-visible, .secondary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.summary { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 0 0 18px; font-size: 15px; }
.summary dt { color: #5a4e3a; }
.summary dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.error .card { border-top: 4px solid #a33; }

@media (max-width: 720px) {
  .bars { top: auto; bottom: 170px; left: 14px; transform: none; flex-direction: column; gap: 6px; }
  .bar { width: 110px; }
  #minimap { width: 112px; height: 112px; }
  .mapHint { top: 128px; width: 112px; }
  .mission { top: 136px; max-width: calc(100% - 150px); }
  .mission #missionText { font-size: 12px; }
  .score { font-size: 24px; }
  .hint { display: none; }
  #toasts { top: 200px; width: calc(100% - 32px); }
  .toast { text-align: center; }
  h1 { font-size: 28px; }
  .card { padding: 22px 18px 18px; }
}
#errorText { white-space: pre-line; overflow-wrap: anywhere; }

/* ---- cover ---- */
#cover { position: fixed; inset: 0; z-index: 20; background: #1d2b55; overflow: hidden; }
#cover[hidden] { display: none; }
.coverArt { position: absolute; inset: 0; width: 100%; height: 100%; }
.coverUI { position: absolute; left: 0; right: 0; bottom: 0; top: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: max(6vh, 28px) 20px 24px; text-align: center; }
.coverKicker { margin: 0; color: #ffe2b0; letter-spacing: 0.4em; text-transform: uppercase; font-size: clamp(11px, 1.6vw, 15px); font-weight: 700; text-shadow: 0 2px 10px rgba(0,0,0,0.5); }
.coverTitle { margin: 6px 0 0; font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif; font-weight: 900; line-height: 0.92; color: #fff1d6; font-size: clamp(46px, 9vw, 118px); letter-spacing: 0.01em; text-shadow: 0 4px 0 #6a2a14, 0 10px 30px rgba(0,0,0,0.55); }
.coverTitle span { color: #ffb347; font-style: italic; }
.loadBar { margin-top: auto; width: min(360px, 80vw); height: 6px; border-radius: 3px; background: rgba(255,255,255,0.22); overflow: hidden; }
#loadFill { height: 100%; width: 100%; background: linear-gradient(90deg, #ffb347, #ffe7a6); transform-origin: left center; transform: scaleX(0.04); transition: transform 0.4s ease; }
.loadText { margin: 8px 0 14px; color: #ffe8c8; font-size: 13px; text-shadow: 0 1px 4px rgba(0,0,0,0.7); min-height: 1.2em; }
.coverPlay { width: min(320px, 80vw); font-size: 20px; padding: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
#cover.ready .loadBar, #cover.ready .loadText { display: none; }
#cover.ready .coverPlay { margin-top: auto; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.coverHow { margin-top: 10px; background: none; border: 0; color: #ffe8c8; text-decoration: underline; font: 600 15px/1.2 inherit; font-family: inherit; cursor: pointer; padding: 8px; }
#intro { z-index: 21; }

/* ---- HUD extras ---- */
.hudBtn { position: absolute; top: 206px; right: 14px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--panel-line); background: var(--panel); color: #fff; font-size: 18px; pointer-events: auto; cursor: pointer; }
.mission .timer { margin-left: 6px; color: #ffd27a; font-weight: 700; font-variant-numeric: tabular-nums; }
.mission .timer.hurry { color: #ff7a6a; }
.btns button.gold { background: rgba(214, 160, 30, 0.9); color: #2a1a00; font-size: 12px; }
body.quiet #toasts .toast:not(.warn), body.quiet #popups, body.quiet .hint { display: none; }
body.quiet .mission { padding: 5px 9px; max-width: min(260px, calc(100% - 150px)); }
body.quiet .mission .label { display: none; }
body.quiet .mission #missionText { font-size: 11px; font-weight: 500; line-height: 1.25; }
@media (max-width: 720px) {
  .hudBtn { top: 150px; right: 14px; width: 36px; height: 36px; font-size: 16px; }
}
