/* Press Start 2P: SIL Open Font License 1.1 (see assets/fonts/OFL.txt). */
@font-face {
  font-family: 'Press Start 2P';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/assets/fonts/press-start-2p-latin.woff2) format('woff2');
}

:root {
  --bg: #1b1d2b;
  --ink: #2a2238;
  --muted: #6b6075;
  --paper: #fffaf0;
  --paper-2: #f3e9d2;
  --line: #2a2238;
  --accent: #d8483f;
  --accent-2: #b8352e;
  --gold: #f8c840;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#game { position: fixed; inset: 0; }
#game canvas { display: block; image-rendering: pixelated; touch-action: none; }

a { color: inherit; }
h2, h3 { margin: 0; line-height: 1.3; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 10px 14px;
  border: 3px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font: 10px/1.2 var(--pixel);
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 var(--paper-2), 0 3px 0 rgba(0, 0, 0, .35);
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 var(--paper-2), 0 1px 0 rgba(0, 0, 0, .35); }
.btn:focus-visible, .slot:focus-visible, .prompt:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-sm { min-height: 34px; padding: 8px 10px; font-size: 9px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: inset 0 -3px 0 var(--accent-2), 0 3px 0 rgba(0, 0, 0, .35); }
.btn-primary:hover { background: #e55a50; }

.key {
  display: inline-block;
  min-width: 1.9em;
  padding: 3px 5px;
  border: 2px solid currentColor;
  font: 9px/1 var(--pixel);
  text-align: center;
}

/* -------------------------------------------------------------------- HUD */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 0;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-town {
  margin: 0;
  padding: 9px 10px;
  background: rgba(27, 29, 43, .82);
  color: #fff;
  font: 9px/1.4 var(--pixel);
  border: 2px solid rgba(255, 255, 255, .2);
}
button.hud-town { cursor: pointer; text-align: left; }
button.hud-town:hover { border-color: var(--gold); }
button.hud-town:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.hud-count { color: var(--gold); margin-left: 6px; white-space: nowrap; }
/* Press Start 2P has no star glyph: draw it with the system font at a readable size. */
.hud-star { font: 13px/0 var(--sans); vertical-align: -1px; }
.hud-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.is-touch .hint { display: none; }
.is-touch .hud .btn-sm { min-height: 40px; min-width: 40px; }
.is-touch button.hud-town { min-height: 40px; }

/* ------------------------------------------------------------ title screen */
.title {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 22, 34, .72);
  overflow: auto;
}
.title-card {
  width: 100%;
  max-width: 560px;
  padding: 28px 24px 22px;
  background: var(--paper);
  border: 4px solid var(--line);
  box-shadow: inset 0 0 0 3px var(--paper-2), 0 8px 0 rgba(0, 0, 0, .4);
  text-align: center;
}
.title-kicker { margin: 0 0 14px; font: 9px/1.4 var(--pixel); color: var(--accent); letter-spacing: .04em; }
.title h1 { margin: 0 0 10px; font: 22px/1.3 var(--pixel); }
.title-role { margin: 0 0 14px; font-weight: 600; }
.title-summary { margin: 0 0 22px; color: var(--muted); font-size: 15px; }
.title-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.title-actions .btn { min-width: 150px; }
.title-help { margin: 18px 0 0; color: var(--muted); font-size: 13px; }
.title-error { margin: 14px 0 0; padding: 10px 12px; background: #fde8e6; border: 2px solid var(--accent); font-size: 14px; }

/* ----------------------------------------------------------------- prompt */
.prompt {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  z-index: 15;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
  border: 3px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.3 var(--sans);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  animation: pop .15s steps(3);
}
.prompt .key { margin-right: 6px; color: var(--accent); }
.is-touch .prompt { bottom: calc(150px + var(--safe-b)); }
@keyframes pop { from { transform: translate(-50%, 6px); } }

/* ----------------------------------------------------------------- dialog */
.dialog {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  z-index: 20;
  width: min(720px, calc(100vw - 24px));
  min-height: 116px;
  transform: translateX(-50%);
  padding: 16px 20px 18px;
  background: var(--paper);
  border: 4px solid var(--line);
  box-shadow: inset 0 0 0 3px var(--paper-2), 0 6px 0 rgba(0, 0, 0, .35);
  cursor: pointer;
}
.dialog-name { margin: 0 0 8px; font: 10px/1 var(--pixel); color: var(--accent); }
.dialog-text { margin: 0; font-size: 17px; white-space: pre-line; }
.dialog-links { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 0; }
.dialog-next { position: absolute; right: 14px; bottom: 8px; font-size: 12px; animation: blink 1s steps(2) infinite; }
.is-touch .dialog { bottom: calc(150px + var(--safe-b)); }
@keyframes blink { 50% { opacity: 0; } }

/* ------------------------------------------------------------------ panel */
.panel {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 10, 20, .6);
}
.panel-box {
  position: relative;
  width: 100%;
  max-width: 680px;
  max-height: calc(100dvh - 32px);
  display: flex;
  background: var(--paper);
  border: 4px solid var(--line);
  box-shadow: inset 0 0 0 3px var(--paper-2), 0 8px 0 rgba(0, 0, 0, .4);
}
/* The pixel font draws ✕ as a speck: use the system font so the close target reads clearly. */
.panel-close { position: absolute; top: 10px; right: 10px; z-index: 1; min-width: 38px; font: 700 16px/1 var(--sans); }
.panel-body { overflow: auto; padding: 24px 24px 26px; width: 100%; }
.panel-head { padding-right: 44px; margin-bottom: 18px; }
.panel-head h2 { font: 15px/1.5 var(--pixel); }
.kicker { margin: 0 0 8px; font: 9px/1.4 var(--pixel); color: var(--accent); }
.intro { margin: 10px 0 0; color: var(--muted); font-style: italic; }
.meta { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.track { margin: 6px 0 0; font-size: 14px; font-weight: 600; }

.entry { padding: 16px 0 0; margin-top: 16px; border-top: 3px dashed var(--paper-2); }
.panel-head + .entry { margin-top: 0; border-top: 0; padding-top: 0; }
.entry h2, .entry h3 { font-size: 18px; }
.entry h2 { font-size: 20px; }
.entry p { margin: 8px 0 0; }
.entry ul { margin: 10px 0 0; padding-left: 20px; }
.entry li { margin: 4px 0; }
.entry li::marker { color: var(--accent); }
.results li { font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { padding: 2px 8px; background: var(--paper-2); font-size: 13px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.cta { margin-top: 22px; }

.home-head { display: flex; gap: 16px; align-items: center; }
.avatar { width: 96px; height: 96px; object-fit: cover; border: 3px solid var(--line); flex: none; }
.stats { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stats li { padding: 10px 12px; background: var(--paper-2); }
.stats strong { display: block; font: 700 19px/1.3 var(--sans); color: var(--accent-2); }
.stats span { font-size: 13px; color: var(--muted); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------------------------------------------------------------- journal */
.quest-bar { display: block; width: 100%; height: 14px; margin-top: 12px; appearance: none; border: 3px solid var(--line); background: var(--paper-2); }
.quest-bar::-webkit-progress-bar { background: var(--paper-2); }
.quest-bar::-webkit-progress-value { background: var(--gold); }
.quest-bar::-moz-progress-bar { background: var(--gold); }
.quest-n { margin-left: 6px; font: 9px/1 var(--pixel); color: var(--muted); }
.entry ul.quests { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 16px; }
.quests li { display: flex; align-items: center; gap: 8px; margin: 2px 0; }
.quests li.done { color: var(--muted); }
.quest-box { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border: 3px solid var(--line); background: #fff; font: 700 13px/1 var(--sans); color: var(--accent-2); }
.quests li.done .quest-box { background: var(--gold); color: var(--ink); }

.controls { padding-left: 0; list-style: none; }
.controls li { margin: 10px 0; }

/* -------------------------------------------------------------- inventory */
.icon {
  display: inline-block;
  width: 48px;
  height: 48px;
  background: url(/game/sprites/items.png) no-repeat;
  background-size: auto 48px;
  background-position: calc(var(--i, 0) * -48px) 0;
  image-rendering: pixelated;
}
.icon-lg { width: 64px; height: 64px; background-size: auto 64px; background-position: calc(var(--i, 0) * -64px) 0; }
.bag { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.bag-grid { display: grid; grid-template-columns: repeat(auto-fill, 60px); gap: 6px; }
.slot {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 3px solid var(--paper-2);
  background: #fff;
  cursor: pointer;
}
.slot[aria-selected="true"] { border-color: var(--accent); background: #fff3e6; }
.bag-detail { padding: 14px; background: var(--paper-2); min-height: 200px; }
.bag-detail h3 { font-size: 18px; }
.bag-detail p { margin: 8px 0 0; }
.bag-list { margin-top: 18px; font-size: 14px; color: var(--muted); }
.bag-list p { margin: 4px 0; }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  z-index: 18;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 24px);
  margin: 0;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  border: 2px solid var(--gold);
}

/* ------------------------------------------------------------------ touch */
.touch { display: none; }
.is-touch.playing .touch { display: block; }
.stick {
  position: fixed;
  left: 20px;
  bottom: calc(24px + var(--safe-b));
  z-index: 12;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  border: 3px solid rgba(255, 255, 255, .45);
  touch-action: none;
}
.stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .85);
  border: 3px solid var(--line);
  pointer-events: none;
}
.btn-a {
  position: fixed;
  right: 24px;
  bottom: calc(44px + var(--safe-b));
  z-index: 12;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 4px solid var(--line);
  background: var(--accent);
  color: #fff;
  font: 16px/1 var(--pixel);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .4);
  touch-action: manipulation;
}
.btn-a:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .4); }

@media (max-width: 560px) {
  .hud-town { font-size: 8px; }
  .hud-name { display: none; }
  .hud-count { margin-left: 0; }
  .title h1 { font-size: 17px; }
  .panel { padding: 8px; }
  .panel-box { max-height: calc(100dvh - 16px); }
  .panel-body { padding: 18px 16px 20px; }
  .bag { grid-template-columns: 1fr; }
  .entry ul.quests { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .home-head { align-items: flex-start; }
  .avatar { width: 72px; height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  .prompt, .dialog-next { animation: none; }
}
