/* Game page UI. The game keeps one look in light and dark mode: it is a lit pixel world. */

body.game {
  --paper: #fff8e1;
  --paper-ink: #1c1a2a;
  --panel: #151a31;
  --panel-line: #070913;
  --gold: #f5bf48;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #1f5230;
  color: #eef0fa;
  -webkit-user-select: none;
  user-select: none;
}
.stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
.stage canvas { position: absolute; left: 0; top: 0; image-rendering: pixelated; cursor: pointer; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; z-index: 5; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-panel {
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px;
  background: var(--panel); border: 2px solid var(--panel-line); box-shadow: inset 0 0 0 2px #2b3154;
  font-family: var(--pixel); font-size: 18px; font-weight: 600;
}
.hud-me canvas { width: 28px; height: 28px; image-rendering: pixelated; }
.hud-quest .label { color: #a6adca; font-weight: 500; }
.gems { display: flex; gap: 5px; }
.gems i { width: 12px; height: 12px; background: #2b3154; transform: rotate(45deg); box-shadow: 0 0 0 2px #070913; }
.gems i.on { background: var(--gold); }
.gems i.on[data-gem="vouch"] { background: #7d77f0; }
.gems i.on[data-gem="mizan"] { background: #2fa396; }
.gems i.on[data-gem="flows"] { background: #4cc28a; }
.hud-actions { display: flex; gap: 8px; margin-left: auto; }
.hud-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  background: var(--panel); color: #eef0fa; border: 2px solid var(--panel-line); box-shadow: inset 0 0 0 2px #2b3154;
  cursor: pointer; text-decoration: none;
}
.hud-btn svg { width: 22px; height: 22px; }
.hud-btn:hover { background: #1f2544; }
.hud-btn:active { transform: translateY(2px); }
@media (max-width: 520px) { .hud-quest .label { display: none; } .hud-panel { font-size: 16px; padding: 0 10px; } }
@media (max-width: 420px) {
  .hud { gap: 6px; flex-wrap: nowrap; }
  #hud-name { display: none; }
  .hud-panel, .hud-actions .hud-btn { height: 40px; }
  .hud-actions { gap: 6px; }
  .hud-actions .hud-btn { width: 40px; }
}

/* ---------- Title and character select ---------- */
.screen {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at center, rgba(10, 12, 28, 0.35), rgba(10, 12, 28, 0.78));
}
.title-card, .select-card { display: grid; justify-items: center; gap: 18px; text-align: center; max-width: 720px; }
.title-kicker { font-family: var(--mono); font-size: 14px; letter-spacing: 0.1em; text-transform: uppercase; color: #fff1c9; text-shadow: 0 2px 0 #070913; }
.title-logo {
  font-family: var(--pixel); font-weight: 700; font-size: clamp(54px, 11vw, 116px); line-height: 0.95; color: #fff1c9;
  text-shadow: 4px 0 #070913, -4px 0 #070913, 0 4px #070913, 0 -4px #070913, 4px 4px #070913, -4px 4px #070913, 4px -4px #070913, -4px -4px #070913, 0 10px #070913;
}
.title-logo span { color: var(--gold); }
.title-sub { max-width: 36ch; font-size: 19px; color: #fff; text-shadow: 0 2px 0 #070913; }
.title-help { font-family: var(--mono); font-size: 14px; color: #dfe3f7; text-shadow: 0 2px 0 #070913; }
.title-link { color: #fff; text-shadow: 0 2px 0 #070913; }
@media (prefers-reduced-motion: no-preference) {
  #btn-start .face { animation: nudge 1.4s steps(2, jump-none) infinite; }
}
@keyframes nudge { 50% { transform: translateY(-3px); } }

.select-title { font-family: var(--pixel); font-weight: 700; font-size: clamp(34px, 6vw, 52px); color: #fff1c9; text-shadow: 3px 0 #070913, -3px 0 #070913, 0 3px #070913, 0 -3px #070913, 0 7px #070913; }
.select-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; width: min(560px, 90vw); }
.pick {
  display: grid; justify-items: center; gap: 6px; padding: 22px 12px 18px; cursor: pointer;
  background: var(--paper); color: var(--paper-ink); border: 0; box-shadow: 0 0 0 4px #070913, 8px 8px 0 4px rgba(7, 9, 19, 0.6);
  transition: transform 90ms steps(2);
}
.pick canvas { width: 96px; height: 150px; image-rendering: pixelated; }
.pick-name { font-family: var(--pixel); font-weight: 700; font-size: 28px; }
.pick-person { font-size: 15px; color: #4f5874; }
.pick:hover, .pick:focus-visible { transform: translateY(-4px); box-shadow: 0 0 0 4px #070913, 0 0 0 8px var(--gold), 8px 12px 0 4px rgba(7, 9, 19, 0.6); outline: none; }
.select-note { color: #fff; text-shadow: 0 2px 0 #070913; }
@media (max-width: 420px) { .pick canvas { width: 80px; height: 125px; } .pick-name { font-size: 24px; } }

/* ---------- Dialog box ---------- */
.dialog {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: grid; justify-items: center;
  padding: 0 12px calc(env(safe-area-inset-bottom, 0px) + 14px);
}
.dialog-box {
  position: relative; width: min(780px, 100%); padding: 22px 24px 20px; cursor: pointer;
  background: var(--paper); color: var(--paper-ink);
  box-shadow: 0 0 0 4px #070913, 0 0 0 7px var(--paper), 0 0 0 11px #070913, 0 14px 0 11px rgba(7, 9, 19, 0.45);
}
.dialog-name {
  position: absolute; left: 18px; top: -22px; padding: 4px 12px;
  background: #1c1a2a; color: #fff1c9; font-family: var(--pixel); font-weight: 600; font-size: 17px;
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px #070913;
}
.dialog-name:empty { display: none; }
.dialog-text { min-height: 3.2em; font-family: var(--pixel); font-size: clamp(18px, 2.2vw, 21px); line-height: 1.45; white-space: pre-line; }
.dialog-choices { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; }
.dialog-choices li button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px 8px 30px; position: relative;
  background: transparent; border: 0; color: var(--paper-ink); text-align: left; cursor: pointer;
  font-family: var(--pixel); font-size: clamp(17px, 2vw, 19px); font-weight: 600;
}
.dialog-choices li button[aria-selected="true"] { background: #f3e4b8; }
.dialog-choices li button[aria-selected="true"]::before {
  content: ""; position: absolute; left: 10px; top: 50%; margin-top: -6px;
  border-left: 9px solid #1c1a2a; border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}
.dialog-choices svg { width: 18px; height: 18px; flex: none; }
.dialog-next {
  position: absolute; right: 18px; bottom: 12px; width: 0; height: 0;
  border-top: 9px solid #1c1a2a; border-left: 7px solid transparent; border-right: 7px solid transparent;
}
.dialog-next[hidden] { display: none; }
@media (prefers-reduced-motion: no-preference) { .dialog-next { animation: bob 0.8s steps(2, jump-none) infinite; } }
@keyframes bob { 50% { transform: translateY(3px); } }

/* ---------- Gallery ---------- */
.gallery {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: rgba(7, 9, 19, 0.82);
}
.gallery-panel {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto auto; width: min(1040px, 100%); max-height: 100%;
  background: var(--panel); border: 2px solid var(--panel-line); box-shadow: inset 0 0 0 2px #2b3154, 0 0 0 4px #070913;
  user-select: text; -webkit-user-select: text;
}
.gallery-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 10px 10px 18px; }
.gallery-head h2 { font-family: var(--pixel); font-weight: 700; font-size: 26px; color: #fff1c9; }
.gallery-stage { position: relative; min-height: 0; display: grid; place-items: center; background: #0b0d1a; border-block: 2px solid #070913; }
.gallery-stage img, .gallery-stage video { max-width: 100%; max-height: min(62vh, 620px); width: auto; height: auto; object-fit: contain; }
.gallery-stage video { width: 100%; aspect-ratio: 16 / 9; background: #000; }
.gallery-bar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px; }
.gallery-caption { color: #dfe3f7; font-size: 15.5px; }
.gallery-count { font-family: var(--mono); font-size: 13px; color: #a6adca; }
.gallery-thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 0 10px 10px; scrollbar-width: thin; }
.gallery-thumbs button { flex: none; width: 92px; height: 58px; padding: 0; border: 2px solid #070913; background: #0b0d1a; cursor: pointer; opacity: 0.6; position: relative; }
.gallery-thumbs button[aria-current="true"] { opacity: 1; box-shadow: 0 0 0 2px var(--gold); }
.gallery-thumbs img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.gallery-thumbs .vid::after { content: ""; position: absolute; left: 50%; top: 50%; margin: -8px 0 0 -5px; border-left: 12px solid #fff; border-top: 8px solid transparent; border-bottom: 8px solid transparent; filter: drop-shadow(0 1px 0 #000); }
.gallery-links { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; padding: 12px 14px 16px; border-top: 2px solid #070913; }
.gallery-links a { color: #fff1c9; font-weight: 600; display: inline-flex; gap: 8px; align-items: center; }
.gallery-links svg { width: 18px; height: 18px; flex: none; }
.gallery-panel:focus { outline: none; }
@media (max-width: 600px) {
  .gallery-bar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .gallery-count { display: none; }
  .gallery-head h2 { font-size: 22px; }
}

/* ---------- Touch controls ---------- */
.touch {
  position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 18px) max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.touch.off { display: none; }
.dpad {
  pointer-events: auto; position: relative; width: 150px; height: 150px; touch-action: none;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
}
.dpad span { background: rgba(21, 26, 49, 0.78); border: 2px solid #070913; }
.dpad .dpad-up { grid-area: 1 / 2; border-bottom: 0; }
.dpad .dpad-left { grid-area: 2 / 1; border-right: 0; }
.dpad .dpad-mid { grid-area: 2 / 2; border: 0; border-block: 2px solid transparent; }
.dpad .dpad-right { grid-area: 2 / 3; border-left: 0; }
.dpad .dpad-down { grid-area: 3 / 2; border-top: 0; }
.dpad span.on { background: rgba(245, 191, 72, 0.85); }
.dpad-up::after, .dpad-down::after, .dpad-left::after, .dpad-right::after { content: ""; display: block; width: 0; height: 0; margin: 14px auto 0; }
.dpad-up::after { border-bottom: 10px solid #dfe3f7; border-left: 8px solid transparent; border-right: 8px solid transparent; }
.dpad-down::after { border-top: 10px solid #dfe3f7; border-left: 8px solid transparent; border-right: 8px solid transparent; }
.dpad-left::after { margin: 14px 0 0 16px; border-right: 10px solid #dfe3f7; border-top: 8px solid transparent; border-bottom: 8px solid transparent; }
.dpad-right::after { margin: 14px 0 0 20px; border-left: 10px solid #dfe3f7; border-top: 8px solid transparent; border-bottom: 8px solid transparent; }
.ab { pointer-events: auto; display: flex; gap: 14px; align-items: flex-end; }
.ab-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 3px solid #070913; cursor: pointer; touch-action: none;
  font-family: var(--pixel); font-weight: 700; font-size: 26px; color: #1c1a2a; box-shadow: 0 5px 0 #070913;
}
.ab-btn.a { background: var(--gold); margin-bottom: 26px; }
.ab-btn.b { background: #dfe3f7; width: 54px; height: 54px; font-size: 22px; }
.ab-btn:active, .ab-btn.on { transform: translateY(4px); box-shadow: 0 1px 0 #070913; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 25; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 70px); transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 24px)); padding: 12px 16px; text-align: center;
  background: var(--paper); color: var(--paper-ink); font-family: var(--pixel); font-size: 18px; font-weight: 600;
  box-shadow: 0 0 0 4px #070913, 0 8px 0 4px rgba(7, 9, 19, 0.45);
}
.noscript { position: fixed; inset: auto 16px 16px; padding: 16px; background: var(--paper); color: var(--paper-ink); }
