:root {
  color-scheme: light;
  font-family: "Pretendard", "Malgun Gothic", "맑은 고딕", system-ui, sans-serif;
  color: #422d50;
  background: #90d9e8;
  --ink: #493250;
  --paper: #fff7df;
  --mint: #81dfc3;
  --shadow: 0 5px 0 #493250;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
button:focus-visible { outline: 3px solid #245cbb; outline-offset: 4px; }
[hidden] { display: none !important; }
#game { position: relative; width: 100%; height: 100dvh; min-height: 240px; overflow: hidden; isolation: isolate; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.intro {
  position: absolute; top: 50%; left: clamp(18px, 6.4vw, 112px); transform: translateY(-50%);
  width: min(440px, 54vw); max-height: calc(100% - 30px); overflow: auto;
  padding: clamp(19px, 3.35vw, 48px);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 26px;
  box-shadow: 8px 9px 0 #493250, 0 22px 40px #39596236;
}
.series { margin: 0 0 12px; font-weight: 900; font-size: clamp(12px, 1.35vw, 17px); color: #834d76; }
.series span { font-size: .64em; vertical-align: .14em; color: #c0648c; }
h1 { margin: 0; font-size: clamp(35px, min(5.6vw, 10vh), 74px); line-height: 1.03; letter-spacing: -.096em; font-weight: 1000; }
.lesson-line { display: flex; flex-wrap: wrap; gap: 7px; margin: 21px 0 15px; }
.lesson-line span { font-weight: 900; font-size: clamp(11px, 1.25vw, 15px); border-radius: 7px; padding: 5px 8px; background: #eaddfa; }
.lesson-line span:first-child { background: #ffdf84; }
.intro-copy { margin: 0 0 22px; font-size: clamp(12px, 1.45vw, 17px); line-height: 1.7; font-weight: 700; }
.primary, .board-button, .choice, .row-buttons button, .icon-button {
  border: 2px solid var(--ink); font-weight: 900; box-shadow: var(--shadow);
}
.primary { background: var(--mint); padding: 13px 17px; border-radius: 12px; font-size: clamp(16px, 1.9vw, 22px); display: inline-flex; align-items: center; gap: 22px; }
.primary span { font-size: 1.22em; line-height: .85; }
button:not(:disabled):active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.key-help { font-size: clamp(10px, 1.2vw, 13px); font-weight: 650; margin: 19px 0 0; color: #6b566b; }
kbd { font: inherit; font-weight: 900; }
.key-help span { padding: 0 3px; }
.hud {
  position: absolute; inset: max(13px, env(safe-area-inset-top)) max(15px, env(safe-area-inset-right)) auto max(15px, env(safe-area-inset-left));
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.stage-label, .collection { display: flex; align-items: center; background: #fff8e3; border: 2px solid var(--ink); box-shadow: 0 4px 0 var(--ink); border-radius: 13px; padding: 7px; min-height: 44px; font-size: clamp(11px, 1.58vw, 16px); font-weight: 900; }
.stage-label { gap: 9px; padding-right: 12px; white-space: nowrap; }
.stage-label b { background: #ffdb78; padding: 4px 6px; border-radius: 6px; }
.collection { justify-content: center; gap: 5px; flex-wrap: wrap; }
.ticket-chip { padding: 5px 8px; border-radius: 6px; white-space: nowrap; background: #eee3dd; color: #5e5461; }
.ticket-chip.collected { background: var(--event-color); color: #352538; }
.board-button { padding: 8px 11px; min-height: 44px; border-radius: 12px; background: #ffd978; font-size: clamp(11px, 1.55vw, 16px); white-space: nowrap; }
.board-button:disabled { background: #eee2d4; color: #675f66; }
.hint {
  position: absolute; left: 50%; top: max(73px, calc(env(safe-area-inset-top) + 60px)); transform: translateX(-50%); width: max-content; max-width: 84%;
  text-align: center; border-radius: 99px; padding: 7px 14px; color: #fff9e8; background: #47354eee;
  font-size: clamp(11px, 1.45vw, 15px); font-weight: 850; pointer-events: none;
}
.controls { position: absolute; inset: 0; pointer-events: none; user-select: none; }
.joystick, .jump {
  position: absolute; display: grid; place-items: center; border-radius: 50%; touch-action: none; pointer-events: auto;
  bottom: max(clamp(14px, 3.8vh, 34px), env(safe-area-inset-bottom));
}
.joystick {
  left: max(clamp(16px, 4vw, 58px), env(safe-area-inset-left)); width: clamp(84px, 17vh, 150px); aspect-ratio: 1;
  background: #fff5d9d9; border: 2px solid #50385c; box-shadow: 0 5px 0 #593b61bd; cursor: grab;
}
.joystick:active { cursor: grabbing; }
.joystick span { pointer-events: none; }
.direction { position: absolute; color: #76607c; font-weight: 900; }
.direction.up { top: 1%; } .direction.right { right: 6%; }
.direction.down { bottom: 1%; } .direction.left { left: 6%; }
.stick { display: block; width: 50%; height: 50%; border-radius: 50%; background: #aa86e7; border: 2px solid #4b3262; box-shadow: 0 4px 0 #6b4a9a; }
.jump {
  right: max(clamp(16px, 4vw, 58px), env(safe-area-inset-right)); width: clamp(78px, 14.5vh, 125px); aspect-ratio: 1;
  border: 2px solid #533655; background: #ffe184; box-shadow: 0 5px 0 #533655;
  align-content: center; font-size: clamp(14px, 2.5vh, 22px); font-weight: 1000; line-height: 1.12;
}
.jump span { font-size: 1.65em; }
.jump.held { transform: translateY(3px); box-shadow: 0 2px 0 #533655; }

dialog {
  width: min(95vw, 1120px); max-width: none; max-height: 94dvh; overflow: auto;
  border: 3px solid var(--ink); border-radius: 23px; padding: clamp(16px, 3.2vw, 38px);
  background: var(--paper); color: var(--ink); box-shadow: 0 8px 0 var(--ink), 0 22px 65px #24143472;
}
dialog::backdrop { background: #302544a6; }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.board-kicker { margin: 0 0 3px; font-weight: 900; font-size: clamp(12px, 1.15vw, 16px); color: #834d76; }
dialog h2 { margin: 0; font-size: clamp(25px, 4.4vw, 48px); letter-spacing: -.07em; line-height: 1.1; }
.icon-button { border-radius: 10px; width: 42px; height: 40px; padding: 0; background: #f4e6fb; font-size: 27px; line-height: 1; }
.board-instruction { font-weight: 800; margin: 13px 0; font-size: clamp(14px, 1.72vw, 19px); }
.graph-table { border: 2px solid var(--ink); background: #fffdf5; border-radius: 15px; overflow: hidden; }
.graph-legend { display: flex; align-items: center; gap: 6px; min-height: 37px; padding: 4px 11px; background: #f4ead9; font-weight: 900; font-size: clamp(13px, 1.75vw, 18px); }
.graph-legend .person { width: 21px; color: #8059af; }
.graph-row {
  display: grid; grid-template-columns: minmax(100px, 16%) minmax(0, 1fr) auto; align-items: center;
  gap: clamp(5px, 1.4vw, 16px); padding: 8px clamp(7px, 1.5vw, 16px); border-top: 1px solid #e7d7d7;
  min-height: clamp(56px, 11vh, 99px);
}
.graph-row strong { display: block; font-size: clamp(15px, 2.05vw, 23px); letter-spacing: -.06em; }
.target { display: inline-block; font-size: clamp(12px, 1.27vw, 15px); font-weight: 850; margin-top: 3px; color: #6d5570; }
.pictograms { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); align-items: center; gap: clamp(1px, .47vw, 6px); color: var(--event-color); }
.person { position: relative; display: inline-block; aspect-ratio: 0.85; width: 100%; max-width: 52px; color: inherit; }
.person::before, .person::after { content: ""; position: absolute; background: #f0e9e3; }
.person::before { top: 5%; left: 32%; width: 36%; aspect-ratio: 1; border-radius: 50%; }
.person::after { left: 18%; width: 64%; top: 45%; height: 46%; border-radius: 55% 55% 22% 22%; }
.person.filled::before, .person.filled::after { background: currentColor; }
.row-buttons { display: flex; align-items: center; gap: clamp(3px, .55vw, 7px); }
.row-buttons button { border-radius: 7px; padding: 0 3px; width: clamp(32px, 4.6vw, 54px); min-height: 38px; background: #f9ebff; box-shadow: 0 3px 0 var(--ink); font-size: clamp(12px, 1.65vw, 17px); }
.row-buttons button:first-child { background: #fff1d1; }
.row-buttons button:disabled { opacity: .46; }
.board-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 15px; }
.choice { border-radius: 9px; background: #f0dffb; padding: 9px 14px; font-size: clamp(14px, 1.8vw, 19px); }
.feedback { margin: 12px 0 0; min-height: 1.25em; font-weight: 850; font-size: clamp(12px, 1.6vw, 16px); color: #873c63; }
.finish { width: min(90vw, 510px); text-align: center; }
.finish > p:not(.series) { line-height: 1.7; font-weight: 750; }
@media (max-width: 590px) {
  .hud { gap: 5px; inset-inline: 7px; }
  .stage-label { gap: 4px; padding: 4px; }
  .collection { gap: 3px; padding: 4px; }
  .ticket-chip { padding: 4px; }
  .board-button { padding: 5px; }
  .intro { left: 7vw; width: min(86vw, 400px); top: 53%; }
  .graph-row { grid-template-columns: 1fr auto; row-gap: 9px; }
  .pictograms { grid-row: 2; grid-column: 1 / -1; }
  .row-buttons { grid-row: 1; grid-column: 2; }
}
@media (max-height: 520px) and (min-width: 591px) {
  .intro { padding: 13px 23px; width: min(43vw, 360px); }
  .series { margin-bottom: 6px; }
  .lesson-line { margin: 8px 0; }
  .intro-copy { margin-bottom: 10px; }
  .key-help { margin-top: 12px; }
  dialog { padding: 11px 15px; }
  .board-instruction { margin: 7px 0; }
  .graph-row { padding-block: 3px; }
  .graph-legend { min-height: 27px; }
  .graph-row .person { max-width: 36px; }
  .board-actions { margin-top: 8px; }
  .board-actions .primary { padding-block: 7px; }
  .feedback { margin-top: 7px; }
}
.touch-help { display: none; }
.pictograms.checked .person:not(.filled) { visibility: hidden; }
@media (pointer: coarse) {
  .keyboard-help { display: none; }
  .touch-help { display: block; }
}

.intro-actions, .finish-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.finish-actions { justify-content: center; }
.secondary, .stage-choice {
  border: 2px solid var(--ink); border-radius: 10px; padding: 8px 12px; min-height: 42px;
  background: #f1e1fb; box-shadow: 0 3px 0 var(--ink); font-weight: 900;
}
.stage-menu { width: min(90vw, 620px); }
.stage-list { display: grid; gap: 11px; margin-top: 18px; }
.stage-choice { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left; }
.stage-choice span { color: #65465e; font-weight: 800; font-size: .8em; white-space: nowrap; }
.stage-choice:disabled { background: #eee4d7; opacity: .52; }
.graph-legend { gap: clamp(9px, 2.8vw, 28px); flex-wrap: wrap; }
.legend-entry { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.graph-legend .person { width: 17px; }
.graph-legend .person.large { width: 22px; }
.pictograms { justify-items: center; min-height: 40px; }
.pictograms .person { width: 68%; }
.pictograms .person.large { width: 100%; max-width: 54px; }
.pictograms .slot { width: 80%; aspect-ratio: 1; max-width: 46px; border-radius: 8px; border: 1px dashed #c9b7bb; background: #f8f0e6; }
.row-buttons button { width: auto; min-width: clamp(34px, 4.5vw, 51px); min-height: 40px; padding: 0 4px; white-space: nowrap; }
.supply-count { min-width: 2.5em; text-align: center; font-weight: 900; color: #623d83; white-space: nowrap; }
.record-table { width: 100%; border-spacing: 0; border: 2px solid var(--ink); border-radius: 14px; overflow: hidden; font-size: clamp(14px, 1.85vw, 20px); text-align: center; }
.record-table caption { padding-bottom: 6px; text-align: left; font-weight: 900; }
.record-table th, .record-table td { padding: clamp(7px, 1.5vw, 18px) 4px; }
.record-table th { background: #e8d5fa; }
.record-table td { background: #fffdf5; font-weight: 800; }
.record-table td:last-child { background: #fff0c1; }
.ticket-chip.collected { color: #fff; }
@media (max-width: 750px) {
  .stage-label span { display: none; }
  .ticket-chip { padding-inline: 4px; }
  .collection { gap: 3px; }
}
@media (max-width: 590px) {
  .collection { align-self: stretch; }
  .pictograms { min-height: 30px; }
  .hud { align-items: center; }
  .hint { top: max(89px, calc(env(safe-area-inset-top) + 79px)); }
}

@media (max-height: 520px) {
  .pictograms .person.large { max-width: 36px; }
}

.hud-actions { display: flex; align-items: flex-start; gap: 7px; }
.ring-counter {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  min-width: 57px; padding: 6px 9px; border: 2px solid var(--ink); border-radius: 12px;
  background: #fff6dc; box-shadow: 0 5px 0 var(--ink); font-size: clamp(12px, 1.6vw, 17px); font-weight: 900;
}
.ring-emblem {
  flex: none; display: inline-block; width: 16px; aspect-ratio: 1;
  border: 3px solid #eab234; border-radius: 50%; box-shadow: 0 0 0 1px #a65c34;
}
.ring-counter.active { background: #ffe089; }
.finish-rings { display: flex; justify-content: center; align-items: center; gap: 8px; }
@media (max-width: 590px) {
  .hud-actions { flex-direction: column; align-items: flex-end; gap: 6px; }
  .ring-counter { min-height: 28px; min-width: 45px; padding: 2px 6px; box-shadow: 0 2px 0 var(--ink); }
  .ring-emblem { width: 12px; }
}

.sound-button {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; min-height: 44px; padding: 0; border: 2px solid var(--ink);
  border-radius: 11px; background: #fff4d0; color: var(--ink); box-shadow: 0 4px 0 var(--ink);
  font-family: "Segoe UI Emoji", "Apple Color Emoji", system-ui, sans-serif;
  font-size: 19px; line-height: 1;
}
.sound-button[aria-pressed="false"] { background: #eee3d8; }
.dialog-tools { display: flex; align-items: flex-start; gap: 8px; }
@media (max-width: 590px) {
  .hud-actions { display: grid; grid-template-columns: auto auto; }
  .hud-actions .sound-button { width: 42px; }
  .hud-actions .board-button { grid-column: 1 / -1; justify-self: end; }
}

.road-quiz { width: min(94vw, 880px); }
.road-quiz h2 { font-size: clamp(21px, 3.4vw, 37px); }
.road-graph { margin-top: clamp(9px, 2vh, 17px); }
.road-graph-row { grid-template-columns: minmax(88px, 19%) minmax(0, 1fr); }
.road-graph-row .pictograms { grid-row: auto; grid-column: auto; }
