:root {
  --bg: #0b1424;
  --panel: #111d33;
  --panel-2: #16243f;
  --line: #24365a;
  --text: #e8eef8;
  --muted: #93a6c4;
  --amber: #f2b450;
  --teal: #3fc1b0;
  --red: #ff7a7a;
  --green: #6fd08c;
  --radius: 12px;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --dialog-h: 168px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
.noscript { padding: 24px; text-align: center; }

#app {
  position: relative;
  max-width: 880px;
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#hud {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: rgba(11, 20, 36, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.hud-title { font-weight: 800; letter-spacing: -0.02em; }
#hud-goal { flex: 1; color: var(--amber); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-chapter { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

#art-wrap { position: relative; aspect-ratio: 16 / 9; max-height: 34vh; overflow: hidden; background: #08101d; }
#art { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .5s; }
#art.swap { opacity: 0; }
.art-fade { position: absolute; inset: auto 0 0 0; height: 45%; background: linear-gradient(transparent, var(--bg)); pointer-events: none; }

#board {
  flex: 1;
  padding: 4px 16px calc(var(--dialog-h) + 28px);
  display: flex; flex-direction: column; gap: 14px;
}

/* 대화창 */
#dialog {
  position: fixed; z-index: 10;
  left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(880px, 100%);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; align-items: flex-end;
  background: linear-gradient(transparent, rgba(11, 20, 36, 0.96) 22%);
}
#portrait { width: 92px; height: 92px; border-radius: 14px; object-fit: cover; background: var(--panel-2); border: 1px solid var(--line); flex: none; }
.bubble {
  flex: 1; position: relative;
  min-height: 112px;
  padding: 12px 14px 40px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
.speaker { font-size: 12.5px; color: var(--teal); font-weight: 700; margin-bottom: 4px; }
#line { margin: 0; font-size: 16px; line-height: 1.6; word-break: keep-all; }
#next {
  position: absolute; right: 10px; bottom: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: var(--amber); color: #1b1203; border: 0; font-weight: 800; cursor: pointer;
}
#next[hidden] { display: none; }
#dialog.waiting .bubble { border-color: var(--amber); }
#dialog.waiting.typed #line::after { content: "  ▴ 위에서 직접 해 보세요"; color: var(--amber); font-size: 13px; white-space: nowrap; }
/* 조작을 기다릴 때는 대화창을 작게 줄여 위의 칸을 덜 가린다 */
#dialog.waiting #portrait { width: 52px; height: 52px; border-radius: 10px; }
#dialog.waiting .bubble { min-height: 0; padding: 9px 12px 10px; }
#dialog.waiting .speaker { display: none; }
#dialog.waiting #line { font-size: 14.5px; }

/* 카드 공통 */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card h3 .tag { margin-left: auto; }
.tag { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-weight: 700; }
.tag.amber { color: var(--amber); border-color: rgba(242,180,80,.5); }
.tag.teal { color: var(--teal); border-color: rgba(63,193,176,.5); }
.tag.red { color: var(--red); border-color: rgba(255,122,122,.5); }
.tag.green { color: var(--green); border-color: rgba(111,208,140,.5); }

.mono { font-family: var(--mono); font-size: 13px; }
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; font-size: 14px; align-items: baseline; }
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; word-break: keep-all; overflow-wrap: anywhere; }
.none { color: var(--red); font-weight: 700; }

/* 탐색기 */
.explorer .bar { display: flex; align-items: center; gap: 8px; margin: -2px 0 12px; padding: 8px 10px; background: #0d182b; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font-size: 13px; }
.explorer .bar .mono { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow { display: grid; grid-template-columns: 1fr 24px 1fr; gap: 8px; align-items: center; margin-top: 10px; }
.flow .arrow { text-align: center; color: var(--muted); pointer-events: none; }
.io { display: flex; flex-direction: column; gap: 6px; }
.io .lbl { font-size: 11.5px; color: var(--muted); }
.coin {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 9px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 13.5px; text-align: left; width: 100%;
}
.coin b { font-variant-numeric: tabular-nums; white-space: nowrap; }
button.coin { cursor: pointer; }
button.coin.pulse { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(242,180,80,.2); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(242,180,80,.05); } }
.coin.spent { opacity: .55; text-decoration: line-through; }
.coin.change { border-color: rgba(63,193,176,.6); }
.coin.pay { border-color: rgba(242,180,80,.6); }
.fee { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* 선택지 */
.choices { display: flex; flex-direction: column; gap: 8px; animation: rise .3s ease both; }
.choice {
  text-align: left; padding: 13px 14px; border-radius: 10px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 15px; line-height: 1.45;
}
.choice:hover:not(:disabled) { border-color: var(--amber); }
.choice:disabled { cursor: default; }
.choice.wrong { border-color: var(--red); opacity: .6; }
.choice.right { border-color: var(--green); background: rgba(111,208,140,.1); }

.primary {
  align-self: flex-start;
  padding: 11px 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--amber); color: #1b1203; font-weight: 800; font-size: 15px;
}
.primary:disabled { opacity: .4; cursor: default; }
.ghost { padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-weight: 700; }

/* 꼬리표 */
.label-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-top: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { padding: 8px 12px; background: transparent; border: 0; cursor: pointer; font-size: 13.5px; font-weight: 700; color: var(--muted); }
.seg button.on { background: rgba(242,180,80,.18); color: var(--amber); }
.seg button.on[data-v="지불"] { background: rgba(242,180,80,.18); color: var(--amber); }
.seg button.on[data-v="체인지"] { background: rgba(63,193,176,.18); color: var(--teal); }

.memo table { width: 100%; border-collapse: collapse; font-size: 13px; }
.memo td { padding: 7px 4px; border-top: 1px dashed var(--line); }
.memo td:first-child { color: var(--amber); white-space: nowrap; }
.path b { color: var(--teal); }

.traits { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.traits div { padding: 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; line-height: 1.45; }
.traits b { display: block; color: var(--teal); margin-bottom: 2px; }

/* 흩어지기 */
.split-list { display: flex; flex-direction: column; gap: 4px; }
.split-row { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; font-size: 13px; padding: 6px 8px; border-radius: 7px; background: var(--panel-2); animation: rise .25s ease both; }
.split-row .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.split-sum { margin-top: 8px; font-size: 13.5px; color: var(--amber); font-weight: 700; }

/* 짝짓기 */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .col { display: flex; flex-direction: column; gap: 6px; }
.match .head { font-size: 12.5px; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.mi {
  text-align: left; padding: 9px 10px; border-radius: 9px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px; font-size: 13px;
}
.mi .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.mi b { font-variant-numeric: tabular-nums; font-size: 14px; }
.mi.sel { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(242,180,80,.2); }
.mi.shake { animation: shake .35s; border-color: var(--red); }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.mi.done { cursor: default; }
.mi[data-pair="1"] { border-color: #f2b450; } .mi[data-pair="2"] { border-color: #3fc1b0; }
.mi[data-pair="3"] { border-color: #b48cff; } .mi[data-pair="4"] { border-color: #ff9bc8; }
.mi .pair { font-size: 11px; font-weight: 800; }

.converge { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.converge .src { display: flex; flex-direction: column; gap: 5px; }
.converge .src div { font-size: 12.5px; padding: 6px 8px; border-radius: 7px; background: var(--panel-2); }
.converge .arrow { color: var(--amber); font-size: 22px; pointer-events: none; }

/* 시드, 복구, 컨펌 */
.seed { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seed span { padding: 7px 4px; text-align: center; border-radius: 7px; background: #f3ecd8; color: #2a2112; font-family: var(--mono); font-size: 12.5px; }
.seed span i { color: #9a8a66; font-style: normal; margin-right: 3px; font-size: 10.5px; }
.scan-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: 13px; padding: 6px 8px; border-radius: 7px; background: var(--panel-2); animation: rise .25s both; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 700; }
.field input { width: 100%; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: #0d182b; color: var(--text); font-family: var(--mono); font-size: 13.5px; }
.field small { color: var(--muted); font-size: 12px; }
.chain { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chain .blk { width: 44px; height: 34px; border-radius: 7px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; animation: rise .3s both; }
.chain .blk.mine { border-color: var(--green); color: var(--green); font-weight: 800; }
.confs { margin-top: 8px; font-size: 14px; font-weight: 800; color: var(--green); }
.tool-label { margin-top: 10px; padding: 10px 12px; border-radius: 9px; background: rgba(242,180,80,.08); border: 1px dashed var(--amber); color: var(--amber); font-size: 14px; line-height: 1.5; font-weight: 700; }
.tool-label small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.kv dd .sub { font-family: var(--sans); color: var(--muted); font-size: 12.5px; margin-left: 6px; }
.opret { margin-top: 10px; padding: 10px; border-radius: 9px; background: #0d182b; border: 1px dashed var(--teal); font-family: var(--mono); font-size: 13px; color: var(--teal); word-break: break-all; }

/* 겹창: 장 제목, 강의 노트 */
#overlay {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  padding: 18px;
  background: rgba(5, 10, 20, 0.78);
  backdrop-filter: blur(3px);
}
#overlay[hidden] { display: none; }
.chapter-card { text-align: center; animation: rise .4s both; }
.chapter-card .no { color: var(--amber); font-weight: 800; letter-spacing: .12em; font-size: 13px; }
.chapter-card h2 { margin: 8px 0 0; font-size: 28px; letter-spacing: -0.02em; }
.note {
  width: min(560px, 100%);
  max-height: 86vh; overflow: auto;
  background: #f6f1e4; color: #1f1a10;
  border-radius: 14px; padding: 18px 18px 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: rise .35s both;
}
.note .kicker { font-size: 12px; font-weight: 800; color: #8a5a00; letter-spacing: .06em; }
.note h4 { margin: 6px 0 2px; font-size: 18px; }
.note .lec { font-size: 13px; color: #6b5d40; margin-bottom: 10px; }
.note p { margin: 8px 0; line-height: 1.65; font-size: 15px; word-break: keep-all; }
.note .src { font-size: 12px; color: #7d6f52; }
.note .primary { margin-top: 10px; }

/* 시작, 끝 화면 */
.title-screen { text-align: center; padding-top: 6px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.title-screen h1 { margin: 0; font-size: 40px; letter-spacing: -0.03em; }
.title-screen .lead { margin: 0; font-size: 17px; line-height: 1.6; color: var(--text); word-break: keep-all; }
.title-screen .meta { color: var(--muted); font-size: 14px; }
.title-screen .promo { color: var(--teal); font-size: 13.5px; font-weight: 700; }
.fine { color: var(--muted); font-size: 12.5px; line-height: 1.6; word-break: keep-all; }
.title-screen .primary { align-self: center; font-size: 17px; padding: 14px 28px; }

.report .grade { font-size: 52px; font-weight: 900; color: var(--amber); line-height: 1; }
.report .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.report .stats div { background: var(--panel-2); border-radius: 10px; padding: 10px; font-size: 12.5px; color: var(--muted); }
.report .stats b { display: block; color: var(--text); font-size: 16px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.skills { display: flex; flex-wrap: wrap; gap: 6px; }
.skills span { font-size: 13px; padding: 6px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.skills span i { font-style: normal; color: var(--amber); font-weight: 800; margin-right: 4px; }
.cases { display: grid; gap: 8px; }
.cases div { background: var(--panel-2); border-radius: 10px; padding: 11px 12px; font-size: 14px; line-height: 1.55; word-break: keep-all; }
.cases b { display: block; margin-bottom: 2px; }
.cases small { color: var(--amber); font-weight: 700; }
.cta { background: linear-gradient(135deg, #17325a, #0f2340); border-color: rgba(242,180,80,.45); }
.cta h3 { color: var(--amber); }
.cta .course { font-size: 19px; font-weight: 800; margin: 2px 0 4px; }
.cta p { margin: 6px 0 12px; line-height: 1.6; font-size: 14.5px; color: #d5deec; word-break: keep-all; }
.cta .row { display: flex; gap: 8px; flex-wrap: wrap; }
.cta a.primary { text-decoration: none; }

@media (min-width: 700px) {
  :root { --dialog-h: 150px; }
  #portrait { width: 112px; height: 112px; }
  #line { font-size: 17px; }
}
@media (max-width: 420px) {
  .traits { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 78px 1fr; }
  .flow { grid-template-columns: 1fr; }
  .flow .arrow { justify-self: center; width: 24px; transform: rotate(90deg); }
  #portrait { width: 72px; height: 72px; }
  #line { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* HUD 버튼 */
.hud-btn { flex: none; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-size: 12.5px; font-weight: 700; cursor: pointer; position: relative; }
#hud-chapter { margin-left: auto; }
#hud-board.fresh::after { content: ""; position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 2px var(--bg); }

/* 시작 화면 추가 */
.title-screen .mission { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 12px; background: rgba(242,180,80,.08); border: 1px solid rgba(242,180,80,.4); max-width: 520px; font-size: 15px; line-height: 1.5; word-break: keep-all; }
.title-screen .mission b { color: var(--amber); font-size: 12.5px; letter-spacing: .04em; }
.title-screen .howto { color: var(--muted); font-size: 13.5px; word-break: keep-all; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.center { justify-content: center; }
a.ghost { text-decoration: none; display: inline-block; color: var(--text); }

/* 수사 보드 */
.casemap { width: 100%; max-width: 420px; display: block; margin: 4px auto 0; }
.casemap .edge { stroke: var(--line); stroke-width: 2; stroke-dasharray: 4 4; }
.casemap .edge.on { stroke: var(--amber); stroke-dasharray: none; }
.casemap .node rect { fill: #0d182b; stroke: var(--line); stroke-dasharray: 4 3; }
.casemap .node.on rect { fill: var(--panel-2); stroke: var(--teal); stroke-dasharray: none; }
.casemap .node text.t { fill: var(--muted); font-size: 12px; font-weight: 700; font-family: var(--sans); }
.casemap .node.on text.t { fill: var(--text); }
.casemap .node text.s { fill: var(--muted); font-size: 10.5px; font-family: var(--sans); }
.board-pop { width: min(520px, 100%); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; animation: rise .3s both; }
.board-pop .kicker { color: var(--amber); font-size: 12px; font-weight: 800; letter-spacing: .06em; }
.board-pop h4 { margin: 4px 0 6px; font-size: 18px; }
.board-pop h5 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.note-list { display: flex; flex-direction: column; gap: 6px; }
.note-item { text-align: left; padding: 9px 11px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.note-item b { color: var(--amber); font-size: 12px; }
.board-pop .primary { margin-top: 12px; }

/* 보고서 빈칸 */
.recall-line { margin: 10px 0 6px; font-size: 15.5px; line-height: 1.7; word-break: keep-all; }
.blank { display: inline-block; min-width: 90px; border-bottom: 2px solid var(--amber); color: var(--muted); padding: 0 4px; }
.blank.done { color: var(--amber); font-weight: 800; border-bottom-color: transparent; }
.report-lines { margin: 14px 0 0; padding-left: 20px; font-size: 14px; line-height: 1.65; color: #d5deec; word-break: keep-all; }
.course-kv { margin: 8px 0 6px; grid-template-columns: 74px 1fr; }
.course-kv dd { color: #d5deec; }
.cta p b { color: var(--amber); }

/* 심사 반영 v3 */
.hook { max-width: 540px; padding: 10px 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-size: 14px; line-height: 1.6; color: #d5deec; word-break: keep-all; text-align: left; }
.hook b { color: var(--red); }
.term-card { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 8px; padding: 10px 12px; border-radius: 10px; background: rgba(242,180,80,.07); border: 1px dashed rgba(242,180,80,.55); font-size: 14px; line-height: 1.55; word-break: keep-all; animation: rise .3s both; }
.term-card b { color: var(--amber); }
.term-card span:last-child { flex-basis: 100%; color: #d5deec; }
.glossary { margin: 0; display: grid; grid-template-columns: 100px 1fr; gap: 6px 10px; font-size: 13px; line-height: 1.5; }
.glossary dt { color: var(--amber); font-weight: 700; }
.glossary dd { margin: 0; color: #d5deec; word-break: keep-all; }
.note .key { font-size: 16.5px; font-weight: 800; color: #2a1d00; background: #f1dfae; border-radius: 8px; padding: 9px 11px; margin: 8px 0; }
.note p { font-size: 14.5px; }
.note .more { margin: 10px 0 6px; padding: 9px 11px; border-left: 4px solid #c9891a; background: #efe6cf; border-radius: 0 8px 8px 0; font-size: 14px; line-height: 1.6; word-break: keep-all; }
.note .more b { display: block; color: #8a5a00; font-size: 12.5px; margin-bottom: 2px; }
.card.tool { border-color: rgba(242,180,80,.55); }
.path-boxes { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.path-boxes .pb { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); text-align: center; }
.path-boxes .pb b { font-family: var(--mono); font-size: 13px; }
.path-boxes .pb span { font-size: 11px; color: var(--muted); word-break: keep-all; }
.path-boxes .pb.hl { border-color: var(--teal); background: rgba(63,193,176,.12); }
.path-boxes .pb.hl b { color: var(--teal); font-size: 11.5px; }
.addr { cursor: pointer; }
.addr.open { word-break: break-all; white-space: normal; }
.explorer .bar .mono { cursor: pointer; }
.explorer .bar .mono.wrap { white-space: normal; word-break: break-all; }
.field textarea { width: 100%; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: #0d182b; color: var(--text); font-family: var(--mono); font-size: 13.5px; resize: none; }
@media (max-width: 420px) {
  .hud-title { display: none; }
  .path-boxes { grid-template-columns: repeat(3, 1fr); }
  .glossary { grid-template-columns: 1fr; }
}

.field small, .fine, .hook, .cases div, .cta p { word-break: keep-all; }
body.nodlg #board { padding-bottom: 32px; }

.cta .quick { margin: 4px 0 10px; font-weight: 800; color: var(--amber); font-size: 15px; }
