/* Layout: select screen = poster header + three skin cards with scene thumbnails;
   game = HUD bar, 16:9 pixel scene with hotspots, dialogue box under it;
   in-world computer = full-screen monitor overlay (briefing | gdb terminal | registers + code).
   Single committed dark look per skin, so no light-mode blocks. */
:root {
  color-scheme: dark;
  --bg: #111418;
  --panel: #181c21;
  --line: #2b313a;
  --fg: #e5e8ec;
  --muted: #8c95a2;
  --accent: #f2b33d;
  --danger: #ff5247;
  --ok: #4fd18b;
  --term-bg: #0c0e11;
  --term-fg: #d7dde4;
  --f-display: 'Black Han Sans', 'Noto Sans KR', system-ui, sans-serif;
  --f-body: 'Noto Sans KR', system-ui, -apple-system, 'Malgun Gothic', sans-serif;
  --f-story: var(--f-body);
  --f-mono: 'JetBrains Mono', 'Nanum Gothic Coding', ui-monospace, Consolas, monospace;
  --term-size: 14px;
  --radius: 6px;
}

/* ---------- skins ---------- */
[data-skin="defuse"] {
  --bg: #121110; --panel: #1b1916; --line: #3a342b; --fg: #f3eee5; --muted: #a39a8b;
  --accent: #ff6a1f; --term-bg: #0b0a09; --term-fg: #f0e6d6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.6 var(--f-body); }
#app { min-height: 100%; background: var(--bg); color: var(--fg); }
h1, h2, h3 { text-wrap: balance; margin: 0; }
code { font-family: var(--f-mono); font-size: .92em; color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---------- select screen ---------- */
.select { max-width: 1120px; margin: 0 auto; padding: 48px 16px 32px; display: grid; gap: 32px; }
.select-head { display: grid; gap: 14px; max-width: 720px; }
.eyebrow { margin: 0; color: var(--accent); font: 700 12px/1 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; }
.select-head h1 { font: 400 clamp(40px, 8vw, 76px)/1 var(--f-display); letter-spacing: -.01em; }
.lede { margin: 0; color: var(--muted); font-size: 17px; max-width: 62ch; }
.foot { margin: 0; color: var(--muted); font-size: 13px; }
.theme-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.skin-card {
  display: grid; align-content: start; gap: 10px;
  padding: 0 0 18px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--fg); text-align: left; overflow: hidden;
  transition: transform .18s ease, border-color .18s ease;
}
.skin-card:hover, .skin-card:focus-visible { transform: translateY(-3px); border-color: var(--accent); }
.skin-card canvas { width: 100%; aspect-ratio: 16 / 9; max-width: 100%; display: block; border-bottom: 1px solid var(--line); }
.skin-card > :not(canvas) { margin-inline: 18px; }
.skin-card .kicker { margin-top: 6px; font: 700 11px/1 var(--f-mono); letter-spacing: .14em; color: var(--accent); text-transform: uppercase; }
.skin-card h2 { font: 400 32px/1.1 var(--f-display); }
.skin-card p { margin-block: 0; color: var(--muted); font-family: var(--f-story); }
.skin-card .go { font: 700 13px/1 var(--f-mono); color: var(--accent); }

/* ---------- HUD ---------- */
.game { min-height: 100%; display: flex; flex-direction: column; }
.hud {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
[data-skin="defuse"] .hud { border-bottom: 4px solid transparent; border-image: repeating-linear-gradient(-45deg, var(--accent) 0 10px, #111 10px 20px) 4; }
.btn-ghost { background: none; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; font-size: 13px; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); border-color: var(--muted); }
.btn-ghost .n { color: var(--accent); font-weight: 700; margin-left: 4px; }
.hud-title { display: grid; line-height: 1.2; }
.hud-title .kicker { font: 700 10px/1.4 var(--f-mono); letter-spacing: .14em; color: var(--accent); text-transform: uppercase; }
.hud-title strong { font: 400 22px/1.1 var(--f-display); }
.stage-list { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.stage-list li { font: 12px/1 var(--f-mono); padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }
.stage-list li.done { color: var(--ok); border-color: var(--ok); }
.hud-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.stat { display: grid; text-align: right; line-height: 1.2; }
.stat span { font-size: 11px; color: var(--muted); }
.stat b { font: 700 20px/1.1 var(--f-mono); font-variant-numeric: tabular-nums; }
.stat b.low { color: var(--danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* ---------- scene + dialogue ---------- */
.stage-wrap {
  flex: 1;
  width: min(100%, calc((100dvh - 230px) * 16 / 9), 1180px);
  margin: 0 auto;
  padding-block: 14px 18px;
  padding-inline: 16px;
  display: grid;
  align-content: start;
  gap: 10px;
  box-sizing: content-box;
  max-width: calc(100% - 32px);
}
.scene {
  position: relative;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  border: 2px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  background: #000;
}
.scene canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.place-tag {
  position: absolute; left: 10px; top: 10px;
  padding: 4px 9px; font: 700 12px/1.3 var(--f-mono);
  background: rgba(0,0,0,.65); color: var(--fg); border-left: 3px solid var(--accent);
}
.objective {
  position: absolute; right: 10px; top: 10px; max-width: 55%;
  padding: 5px 10px; font-size: 12.5px; line-height: 1.4;
  background: rgba(0,0,0,.7); color: var(--accent); border: 1px solid var(--accent); border-radius: 3px;
}
.title-card {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: #000; color: #fff; animation: card 1.6s ease forwards;
}
.title-card span { font: 400 clamp(22px, 4vw, 40px)/1.2 var(--f-display); color: var(--accent); letter-spacing: .02em; }
@keyframes card { 0% { opacity: 1; } 65% { opacity: 1; } 100% { opacity: 0; } }

.spots { position: absolute; inset: 0; }
.spot {
  position: absolute; padding: 0; background: transparent;
  border: 2px dashed color-mix(in srgb, var(--accent) 70%, transparent);
  border-radius: 3px;
  animation: pulse 2.2s ease-in-out infinite;
}
.spot.seen { border-color: color-mix(in srgb, var(--fg) 25%, transparent); border-style: dotted; animation: none; }
.spot.lockedspot { border-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.spot .lbl {
  position: absolute; left: 50%; bottom: calc(100% + 4px); transform: translateX(-50%);
  white-space: nowrap; padding: 3px 7px; font: 700 11.5px/1.2 var(--f-body);
  background: rgba(0,0,0,.85); color: var(--fg); border: 1px solid var(--accent); border-radius: 3px;
  opacity: 0; pointer-events: none; transition: opacity .12s;
}
.spot.term .lbl::before { content: '▶ '; color: var(--accent); }
.spot:hover .lbl, .spot:focus-visible .lbl { opacity: 1; }
.spot:hover, .spot:focus-visible { background: color-mix(in srgb, var(--accent) 14%, transparent); border-style: solid; }
@media (hover: none) { .spot .lbl { opacity: 1; } }
@keyframes pulse { 50% { border-color: color-mix(in srgb, var(--accent) 25%, transparent); } }

.dialog {
  position: relative;
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; align-items: start;
  min-height: 118px; padding: 14px 16px 16px;
  background: var(--panel); border: 2px solid var(--line); border-radius: 4px;
  cursor: pointer; user-select: none;
}
.dialog.idle { cursor: default; }
[data-skin="defuse"] .dialog { border-color: #3a342b; box-shadow: inset 0 3px 0 var(--accent); }
.portrait { width: 88px; height: 88px; border: 2px solid var(--line); background: var(--term-bg); border-radius: 3px; }
.portrait.sm { width: 52px; height: 52px; }
.portrait.none { visibility: hidden; width: 0; border: 0; }
.dialog.narration .portrait { display: none; }
.dialog.narration { grid-template-columns: minmax(0, 1fr); }
.dialog.shake .portrait { animation: shake .45s; }
.dlg-name { margin: 0 0 2px; font: 700 13px/1.3 var(--f-mono); color: var(--accent); }
.dlg-text { margin: 0; font: 17px/1.65 var(--f-story); min-height: 3.3em; max-width: 70ch; }
.dialog.narration .dlg-text { color: var(--muted); font-style: italic; }
.dlg-next { position: absolute; right: 14px; bottom: 8px; color: var(--accent); font-size: 12px; animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
.choices { display: grid; gap: 6px; margin-top: 10px; }
.choices:empty { display: none; }
.choice {
  text-align: left; padding: 9px 12px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg); font: 15px/1.4 var(--f-body);
}
.choice:hover, .choice:focus-visible { border-color: var(--accent); }
.choice code { color: inherit; }

/* ---------- monitor overlay ---------- */
.monitor { position: fixed; inset: 0; z-index: 15; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.78); }
.monitor-frame {
  width: min(1240px, 100%); height: min(760px, calc(100dvh - 32px));
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 10px solid #2b2d30; border-radius: 10px;
  box-shadow: 0 0 0 2px #0b0c0d, 0 0 0 4px #444, 0 20px 60px rgba(0,0,0,.6);
  overflow: hidden;
  animation: pop .22s ease-out;
}
.mon-top { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.mon-say { flex: 1; min-width: 0; }
.mon-line { margin: 0; font: 14.5px/1.5 var(--f-story); }
.mon-actions { display: flex; align-items: center; gap: 8px; }
.mon-board { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr) minmax(240px, 290px); }
.brief, .inspect { min-width: 0; overflow-y: auto; padding: 14px; display: grid; align-content: start; gap: 18px; background: var(--panel); }
.brief { border-right: 1px solid var(--line); }
.inspect { border-left: 1px solid var(--line); }
.brief h3, .inspect h3 { font: 700 11px/1.3 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.brief h3 small { letter-spacing: 0; text-transform: none; font-weight: 400; }
.goal p { margin: 0; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12.5px/1 var(--f-mono); padding: 7px 9px; border-radius: 4px; border: 1px dashed var(--line); background: transparent; color: var(--term-fg); }
.chip:hover { border-style: solid; border-color: var(--accent); }
.chip.used { opacity: .45; }

.terminal { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--term-bg); color: var(--term-fg); position: relative; }
.term-bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font: 12px/1 var(--f-mono); color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dots { display: inline-flex; gap: 5px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.term-out { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 4px; font: var(--term-size)/1.5 var(--f-mono); white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 4; }
.term-out div { min-height: 1.5em; }
.l-cmd .p { color: var(--accent); }
.l-err { color: var(--danger); }
.l-boom { color: var(--danger); font-weight: 700; }
.l-ok { color: var(--ok); font-weight: 700; }
.l-story { font-family: var(--f-story); font-size: 14.5px; color: var(--accent); border-left: 2px solid var(--accent); padding: 2px 0 2px 10px; margin: 6px 0; white-space: normal; }
.l-sys { color: var(--muted); }
.term-form { display: flex; align-items: center; gap: 8px; padding: 10px 16px 14px; font: var(--term-size)/1.5 var(--f-mono); }
.term-form label { color: var(--accent); white-space: nowrap; }
.term-form input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; color: var(--term-fg); font: inherit; caret-color: var(--accent); }
.term-form.waiting label { color: var(--fg); }

.regs { width: 100%; border-collapse: collapse; font: 13px/1.5 var(--f-mono); font-variant-numeric: tabular-nums; }
.regs td { padding: 1px 0; }
.regs td:first-child { color: var(--muted); width: 3.5em; }
.regs td:last-child { text-align: right; color: var(--muted); }
.regs tr.changed td { color: var(--accent); }
.regs tr.changed td:first-child::after { content: ' ●'; font-size: 9px; vertical-align: middle; }
.flags { margin-top: 8px; display: flex; gap: 6px; font: 12px/1 var(--f-mono); }
.flags span { padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); }
.flags span.on { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.code { margin: 0; font: 12px/1.6 var(--f-mono); color: var(--term-fg); overflow-x: auto; white-space: pre; }
.code .cur { display: block; background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--fg); }
.code .bp::before { content: '●'; color: var(--danger); margin-right: 2px; }
.code .dim { color: var(--muted); white-space: normal; font-family: var(--f-body); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.72); }
.modal-box {
  width: min(560px, 100%); max-height: 90vh; overflow-y: auto;
  padding: 26px 24px 22px; background: var(--panel);
  border: 1px solid var(--accent); border-radius: var(--radius);
  display: grid; gap: 12px; position: relative; animation: pop .28s ease-out;
}
@keyframes pop { from { transform: scale(.94); opacity: .4; } }
.modal-kicker { margin: 0; font: 700 11px/1 var(--f-mono); letter-spacing: .14em; color: var(--accent); text-transform: uppercase; }
.modal-box h2 { font: 400 28px/1.2 var(--f-display); }
.modal-story { margin: 0; font: 15px/1.65 var(--f-story); color: var(--muted); }
.modal-body { font-size: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.modal-body ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.modal-body .clue { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.modal-body .clue b { display: block; color: var(--accent); font-size: 13px; }
.modal-body .empty { color: var(--muted); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.btn { padding: 9px 16px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--accent); color: var(--bg); font-weight: 700; }
.btn.secondary { background: transparent; color: var(--fg); border-color: var(--line); }

/* ---------- tutorial ---------- */
.skin-card .badge {
  justify-self: start; margin-top: 6px; padding: 3px 8px; border-radius: 999px;
  font: 700 11px/1.3 var(--f-body); border: 1px solid currentColor;
}
.skin-card .badge.on { color: var(--accent); }
.skin-card .badge.off { color: var(--muted); }
.mon-say .choices { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.mon-say .choice { padding: 7px 11px; font-size: 14px; }
.mon-say .choice:first-child:last-child { border-color: var(--accent); color: var(--accent); }
.mon-board.no-inspect { grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); }
.tools { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tools li { display: grid; gap: 1px; font-size: 13px; line-height: 1.35; }
.tools li code { font-size: 12.5px; }
.tools li span { color: var(--muted); }
.tools li.empty { color: var(--muted); }
.term-form input::placeholder { color: color-mix(in srgb, var(--term-fg) 35%, transparent); }
.regs-note { color: var(--muted); font-family: var(--f-body); font-size: 12px; padding-top: 6px !important; text-align: left !important; }
.term { color: inherit; background: none; border: 0; padding: 0; font: inherit; cursor: help;
  text-decoration: underline dotted var(--accent); text-underline-offset: 3px; text-decoration-thickness: 2px; }
.term:hover { color: var(--accent); }
.gloss {
  position: fixed; z-index: 40; max-width: min(320px, calc(100vw - 32px));
  padding: 10px 12px; background: var(--panel); color: var(--fg);
  border: 1px solid var(--accent); border-radius: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-size: 14px; line-height: 1.5;
}
.gloss b { display: block; color: var(--accent); margin-bottom: 2px; }
.gloss p { margin: 0; }
.decoder { display: grid; gap: 10px; }
.dec-meter { height: 8px; background: var(--term-bg); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.dec-meter i { display: block; height: 100%; background: var(--accent); transition: width .8s ease; }
.decoder-code {
  margin: 0; padding: 12px; overflow-x: auto;
  background: var(--term-bg); color: var(--term-fg); border: 1px solid var(--line); border-radius: 4px;
  font: 13px/1.7 var(--f-mono); tab-size: 2;
}
.dec-mask {
  display: inline-block; height: 1.05em; vertical-align: -0.15em; border-radius: 2px;
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--muted) 55%, transparent) 0 3px, color-mix(in srgb, var(--muted) 20%, transparent) 3px 6px);
}
.modal-box > *, .decoder > * { min-width: 0; }
.dec-tok { background: none; border: 0; padding: 0; font: inherit; color: var(--term-fg); cursor: pointer; border-radius: 2px; }
.dec-tok:hover, .dec-tok:focus-visible { background: color-mix(in srgb, var(--accent) 25%, transparent); }
.dec-tok.fresh { color: var(--accent); animation: fresh 1.6s ease 2; }
@keyframes fresh { 50% { background: color-mix(in srgb, var(--accent) 35%, transparent); } }
.dec-note { min-height: 3em; margin: 0; font-size: 14px; color: var(--muted); }
.dec-note b { color: var(--accent); font-family: var(--f-mono); }
.dec-learned { display: flex; flex-wrap: wrap; gap: 6px; }
.dec-learned span { font-size: 12px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }
.dec-learned span.new { color: var(--accent); border-color: var(--accent); }
.modal-box.wide { width: min(640px, 100%); }

/* attention highlight in lessons: character line vs. command line */
.mon-top, .mon-board, .term-form { transition: background-color .25s ease, box-shadow .25s ease, opacity .25s ease; }
.term-form { position: relative; }
.focus-say .mon-top {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  box-shadow: inset 0 0 0 2px var(--accent);
  animation: attend 1.4s ease-in-out 2;
}
.focus-say .mon-top .mon-line { color: var(--fg); }
.focus-say .mon-board { opacity: .7; }
.focus-say .mon-top::after {
  content: '▲ 먼저 읽어 보세요'; align-self: flex-end;
  font: 700 11px/1 var(--f-body); color: var(--accent); white-space: nowrap;
}
.focus-input .term-form {
  background: color-mix(in srgb, var(--accent) 10%, var(--term-bg));
  box-shadow: inset 0 0 0 2px var(--accent);
  animation: attend 1.4s ease-in-out infinite;
}
.focus-input .term-form::after {
  content: '⌨ 여기에 명령을 입력';
  position: absolute; right: 12px; top: -11px; padding: 2px 8px;
  font: 700 11px/1.4 var(--f-body); color: var(--bg); background: var(--accent); border-radius: 3px;
  pointer-events: none;
}
@keyframes attend { 50% { box-shadow: inset 0 0 0 2px var(--accent), 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent); } }

/* ---------- effects ---------- */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 30; opacity: 0; }
.fx.boom { animation: boom .9s ease-out; background: radial-gradient(circle, #fff 0%, var(--danger) 30%, rgba(0,0,0,0) 75%); }
.fx.win { animation: win 1s ease-out; background: radial-gradient(circle, color-mix(in srgb, var(--ok) 45%, transparent), transparent 70%); }
@keyframes boom { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes win { 0% { opacity: .9; } 100% { opacity: 0; } }
.shake { animation: shake .45s; }
@keyframes shake { 20% { transform: translate(-8px, 4px); } 40% { transform: translate(7px, -5px); } 60% { transform: translate(-5px, 3px); } 80% { transform: translate(4px, -2px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .title-card { display: none !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .mon-board { grid-template-columns: minmax(0, 1fr) minmax(220px, 260px); grid-template-rows: auto minmax(0, 1fr); }
  .mon-board.no-inspect { grid-template-columns: minmax(0, 1fr); }
  .brief { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); border-right: 0; border-bottom: 1px solid var(--line); max-height: 30vh; }
}
@media (max-width: 760px) {
  .theme-cards { grid-template-columns: minmax(0, 1fr); }
  .select { padding-top: 32px; }
  .stage-wrap { width: auto; }
  .hud-right { margin-left: 0; }
  .portrait { width: 64px; height: 64px; }
  .dlg-text { font-size: 15.5px; }
  .objective { max-width: 62%; font-size: 11px; padding: 3px 7px; }
  .place-tag { font-size: 10.5px; }
  .monitor { padding: 0; }
  .monitor-frame { height: 100dvh; border-width: 4px; border-radius: 0; }
  .mon-top { flex-wrap: wrap; }
  .mon-board { display: flex; flex-direction: column; overflow-y: auto; }
  .mon-board > * { flex-shrink: 0; }
  .brief { grid-template-columns: minmax(0, 1fr); max-height: none; }
  .terminal { min-height: 60vh; }
  .inspect { border-left: 0; border-top: 1px solid var(--line); }
}
