:root {
  --bg: #07111f;
  --panel: #101e31;
  --line: #28415d;
  --text: #eff6ff;
  --muted: #9fb2c8;
  --cyan: #42d7e9;
  --green: #5ee6a8;
  --red: #ff7785;
  --amber: #ffce69;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 80% 0, #15355a, transparent 37%), var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Noto Sans KR", sans-serif;
}

.shell { max-width: 1180px; min-height: 100vh; margin: auto; padding: 22px 30px; }
.brand { display: flex; align-items: center; justify-content: space-between; color: var(--cyan); font-weight: 800; letter-spacing: .12em; }
.brand small, .muted { color: var(--muted); font-weight: 500; letter-spacing: .04em; }

.panel {
  padding: 28px;
  background: rgba(16, 30, 49, .94);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px #0004;
}

.welcome { max-width: 680px; margin: 9vh auto; }
.mission-welcome { max-width: 920px; margin: 3vh auto; }
.welcome h1 { margin: 10px 0; font-size: clamp(2.2rem, 5vw, 4rem); }
.welcome p { color: var(--muted); font-size: 1.08rem; line-height: 1.7; }
.briefing { max-width: 760px; margin: 4vh auto; }
.briefing h1 { margin: 12px 0; font-size: clamp(2rem, 4vw, 3.2rem); }
.zone-briefing { max-width: 660px; }
.long-briefing { max-width: 1040px; margin: 1vh auto; padding: 20px; }
.long-briefing .story-lines { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 22px; row-gap: 6px; margin: 12px 0; font-size: .92rem; }
.long-briefing .radio-line { padding-left: 10px; }
.long-briefing .radio-line small { font-size: .68rem; }
.long-briefing .radio-line span { font-size: .95rem; }
.scene-art-slot { margin-top: 10px; }
.long-briefing .scene-art { height: clamp(120px, 16vw, 150px); }
.long-briefing .zone-chapter-art { height: clamp(108px, 14vw, 140px); }
.zone-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.zone-heading h1 { margin-bottom: 10px; }
.story-lines { display: grid; gap: 7px; margin: 18px 0; color: var(--muted); font-size: 1rem; line-height: 1.45; }
.story-lines p { margin: 0; }
.radio-line { padding-left: 12px; border-left: 2px solid #365979; }
.radio-line small { display: block; margin-bottom: 1px; color: var(--cyan); font-size: .74rem; font-weight: 800; letter-spacing: .09em; }
.radio-line span { display: block; color: var(--text); font-size: 1.05rem; }
/* 한 사람이 이어서 말하면 한 묶음 안에 대사만 여러 줄로 들어간다. */
.radio-line span + span { margin-top: 4px; }
.brief-note { color: var(--amber); line-height: 1.55; }

.rules-panel { max-width: 920px; margin: 3vh auto; padding: 22px; }
.rules-panel h1 { margin: 8px 0 12px; font-size: clamp(1.8rem, 3vw, 2.5rem); }
.rule-overview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rule-overview > div { display: grid; gap: 2px; padding: 8px 12px; background: #0a1726; border: 1px solid var(--line); border-radius: 8px; }
.rule-overview strong { color: var(--cyan); font-size: 1.4rem; }
.rule-overview span, .answer-example small, .status-guide span, .format-guide span { color: var(--muted); font-size: .8rem; }
.answer-guide { display: grid; grid-template-columns: 190px 1fr; gap: 14px; align-items: center; padding: 12px; margin-top: 12px; background: #0a1726; border: 1px solid #3b5876; border-radius: 10px; }
.answer-guide h2 { margin: 4px 0 0; font-size: 1.05rem; }
.answer-examples { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.answer-example { position: relative; display: grid; justify-items: center; gap: 5px; padding: 8px 6px; border: 1px solid var(--line); border-radius: 8px; }
.answer-example.correct { border-color: var(--green); background: #5ee6a80d; }
.answer-example.incorrect { border-color: var(--red); background: #ff77850d; }
.answer-mark { position: absolute; top: 4px; left: 6px; font-size: 1.15rem; line-height: 1; }
.answer-example.correct .answer-mark { color: var(--green); }
.answer-example.incorrect .answer-mark { color: var(--red); }
.mini-answer { display: flex; align-items: center; gap: 5px; min-height: 54px; }
.mini-slot { display: grid; place-items: center; min-width: 38px; min-height: 32px; padding: 2px 5px; color: var(--text); font-weight: 800; background: #081421; border: 1px solid #476482; border-radius: 5px; }
.mini-frac { display: grid; grid-template-rows: 1fr 2px 1fr; gap: 2px; }
.mini-frac .mini-slot { min-height: 22px; }
.mini-frac i { display: block; background: var(--text); }
.rules-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.status-guide, .format-guide { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 10px; background: #0a1726; border: 1px solid var(--line); border-radius: 9px; }
.status-guide .zone, .format-guide .zone { grid-column: 1 / -1; }
.status-guide > div:not(.zone), .format-guide > div:not(.zone) { display: flex; align-items: baseline; gap: 7px; }
.status-guide b { color: var(--cyan); font-size: .72rem; letter-spacing: .04em; }
.format-guide b { color: var(--amber); font-size: .78rem; }
.rules-panel .start-row { justify-content: flex-end; margin-top: 12px; }

input {
  min-height: 48px;
  padding: 13px 15px;
  color: white;
  font-size: 1.1rem;
  background: #081421;
  border: 1px solid #476482;
  border-radius: 8px;
}

button {
  min-height: 50px;
  padding: 0 22px;
  color: #052031;
  font-size: 1rem;
  font-weight: 800;
  background: var(--cyan);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }
button:disabled { opacity: .42; cursor: not-allowed; }
.secondary { color: var(--text); background: #17304a; border: 1px solid #476482; }
.start-row, .actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 25px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1.2fr .9fr 1.25fr .8fr .9fr auto;
  gap: 8px;
  padding: 12px 0;
  background: #07111fee;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.metric { padding-left: 10px; color: var(--muted); font-size: .78rem; letter-spacing: .08em; border-left: 2px solid var(--cyan); }
.metric strong { display: block; margin-top: 3px; color: var(--text); font-size: 1.15rem; letter-spacing: 0; }
.security-gauge { height: 8px; margin-top: 5px; overflow: hidden; background: #081421; border: 1px solid #476482; border-radius: 999px; }
.security-gauge i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--green)); border-radius: inherit; transition: width .35s ease-out; }
.game-panel { max-width: 860px; margin: 22px auto; }
.zone { color: var(--cyan); font-weight: 800; letter-spacing: .13em; }
.question { margin: 12px 0 20px; color: var(--muted); font-size: 1.1rem; font-weight: 650; line-height: 1.45; }

.equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  min-height: 102px;
  margin: 12px 0 4px;
  padding: 8px 18px;
  color: var(--text);
  font-size: clamp(2.5rem, 5vw, 3.6rem);
  background: #0a1726;
  border: 1px solid #3b5876;
  border-radius: 10px;
}

.equation b { color: var(--cyan); font-weight: 500; }
.math-whole { line-height: 1; }
.math-frac { display: inline-grid; grid-template-rows: 1fr 3px 1fr; gap: 5px; min-width: .95em; text-align: center; line-height: 1.02; vertical-align: middle; }
.math-frac i { display: block; background: currentColor; }
.math-mixed { display: inline-flex; align-items: center; gap: 8px; }
.math-inline-whole { display: inline-block; }
.math-inline-mixed { display: inline-block; vertical-align: middle; white-space: nowrap; }
.math-inline-fraction {
  display: inline-block;
  min-width: 1.1em;
  margin: 0 .08em;
  font-size: .9em;
  line-height: .9;
  text-align: center;
  vertical-align: middle;
}
.math-inline-fraction > span { display: block; padding: 0 .08em; }
.math-inline-fraction i { display: block; height: 1px; margin: .08em 0; background: currentColor; }
.question, .choice, .error-lines li, .hint, .feedback, .review p { line-height: 1.65; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { min-height: 70px; color: var(--text); font-size: 1.2rem; text-align: left; background: #0a1726; border: 1px solid #3b5876; }
.choice.selected { outline: 3px solid var(--cyan); border-color: var(--cyan); }
.answer-area { display: flex; flex-direction: column; gap: 14px; }
.fraction-input { display: flex; align-items: center; gap: 10px; min-height: 94px; }
.fraction-input input { width: 105px; color: white; font-size: 1.8rem; font-weight: 700; text-align: center; }
.frac-box { display: grid; grid-template-rows: 1fr 3px 1fr; width: 105px; gap: 3px; }
.frac-box input { width: 100%; }
.frac-line { margin: 0 4px; background: var(--text); }
.keypad { display: grid; max-width: 600px; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.keypad button { font-size: 1.3rem; }
.hint, .feedback, .notice { min-height: 24px; color: var(--amber); line-height: 1.55; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }
.feedback.form { color: var(--amber); }
.equipment-note { margin: 10px 0 0; color: var(--muted); font-size: .88rem; }
.game-navigation { display: flex; justify-content: flex-start; margin-top: 18px; }
.game-navigation button, .review-navigation button { min-height: 42px; padding: 0 16px; }
.review-mode { border-color: #4a6785; }
.review-notice { margin: 0 0 16px; padding: 10px 13px; color: var(--amber); font-weight: 800; background: #ffce6914; border: 1px solid #8a6d36; border-radius: 8px; }
.review-report { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 14px 0; }
.review-report > div { display: grid; gap: 4px; padding: 10px; background: #0a1726; border: 1px solid var(--line); border-radius: 8px; }
.review-report small { color: var(--muted); font-size: .78rem; }
.review-report strong { min-height: 25px; color: var(--text); }
.review-report .correct { color: var(--green); }
.review-report .incorrect { color: var(--red); }
.review-report .review-solution { grid-column: 1 / -1; }
.review-report .review-solution p { margin: 0; color: var(--muted); line-height: 1.6; }
.review-navigation { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-top: 20px; }
.review-navigation #return-current { margin-left: auto; }
.story-review-zone { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.story-review-zone h2 { margin: 5px 0 12px; }
.final-timer { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 8px 0; color: var(--cyan); font-size: .85rem; font-weight: 800; letter-spacing: .12em; }
.final-timer strong { font-size: 2rem; letter-spacing: 0; }
.final-timer.urgent { color: var(--red); }

@keyframes answer-unlock {
  0% { transform: scale(1); box-shadow: 0 12px 32px #0004; }
  55% { transform: scale(1.012); border-color: var(--green); box-shadow: 0 0 0 4px #5ee6a833; }
  100% { transform: scale(1); box-shadow: 0 12px 32px #0004; }
}

@keyframes answer-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.answer-unlock { animation: answer-unlock .28s ease-out; }
.answer-shake { animation: answer-shake .22s ease-out; }

.error-lines { padding: 0; margin: 0 0 20px; list-style: none; counter-reset: line; }
.error-lines li { padding: 8px 14px; margin: 7px 0; font-size: 1.25rem; border-left: 2px solid var(--line); counter-increment: line; }
.error-lines li::before { color: var(--cyan); content: counter(line) ". "; }
.error-operation { margin: 10px 0; color: var(--text); font-size: 1.3rem; text-align: center; }
.result { max-width: 920px; margin: 35px auto; }
.epilogue { padding: 16px; margin: 16px 0 22px; background: #0a1726; border: 1px solid var(--line); border-left: 4px solid var(--cyan); border-radius: 9px; }
.epilogue-full { border-left-color: var(--green); }
.epilogue-partial { border-left-color: var(--amber); }
.epilogue-unstable { border-left-color: var(--red); }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.summary-grid > div { padding: 15px; background: #0a1726; border: 1px solid var(--line); border-radius: 9px; }
.mission-overview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.mission-overview > div { display: grid; gap: 3px; padding: 14px; background: #0a1726; border: 1px solid var(--line); border-radius: 9px; }
.mission-overview small, .mission-overview span { color: var(--muted); font-size: .78rem; }
.mission-overview strong { color: var(--green); font-size: 1.35rem; }
.case-files { margin-top: 12px; padding: 10px; background: #0a1726; border: 1px solid var(--line); border-radius: 9px; }
.case-files h2, .case-files p { margin: 3px 0; }
.case-files > p { color: var(--muted); font-size: .78rem; }
.case-file-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.case-file { display: grid; gap: 3px; min-width: 0; padding: 7px; background: #102238; border: 1px solid #3b5876; border-radius: 7px; }
.case-file.cleared { border-color: var(--green); }
.case-file small { color: var(--amber); font-size: .7rem; }
.case-file.cleared small { color: var(--green); }
.case-file strong { overflow: hidden; font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
.case-image-slot { min-height: 72px; overflow: hidden; border: 1px dashed #476482; border-radius: 8px; background: linear-gradient(135deg, #132942, #0a1726); }
.case-file.open .case-card-art { filter: brightness(.34) saturate(.55); }
.case-image-slot.art-unavailable { min-height: 72px; }
.case-complete { margin: 10px 0; color: var(--green); font-weight: 800; }
.mission-picker { margin-top: 18px; }
.mission-picker h2, .mission-picker p { margin: 4px 0; }
.mission-picker > p { font-size: .9rem; }
.mission-card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
.mission-card {
  display: grid;
  gap: 6px;
  min-width: 0;
  height: 100%;
  padding: 10px;
  color: var(--text);
  text-align: left;
  background: #0a1726;
  border: 1px solid #3b5876;
}
.mission-card.cleared { background: #0d201f; border-color: var(--green); }
.mission-card.open { border-color: var(--amber); }
.mission-card.open .case-card-art { filter: brightness(.55) saturate(.7); }
.mission-card small { color: var(--amber); font-size: .75rem; }
.mission-card.cleared small { color: var(--green); }
.mission-card strong { overflow: hidden; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.mission-card-action { color: var(--cyan); font-size: .82rem; font-weight: 800; }
.mission-card:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.review { margin-top: 24px; }
.review-table-wrap { width: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; }
.review-table { width: 100%; min-width: 0; table-layout: fixed; border-collapse: collapse; }
.review-table .review-number { width: 7%; }
.review-table .review-skill { width: 17%; }
.review-table .review-answer { width: 12%; }
.review-table .review-outcome { width: 16%; }
.review-table .review-equipment { width: 11%; }
.review-table .review-explanation { width: 25%; }
.review-table th, .review-table td { padding: 11px 8px; font-size: .82rem; line-height: 1.5; vertical-align: top; overflow-wrap: anywhere; }
.review-table thead { background: #081421; }
.review-table tbody tr:last-child > * { border-bottom: 0; }
.review-row.correct { background: #5ee6a80d; }
.review-row.incorrect { background: #ff77850d; }
.review-row.correct > :first-child { box-shadow: inset 4px 0 var(--green); }
.review-row.incorrect > :first-child { box-shadow: inset 4px 0 var(--red); }
.review-row.correct .review-result { color: var(--green); font-weight: 800; }
.review-row.incorrect .review-result { color: var(--red); font-weight: 800; }
.review-solution details { color: var(--muted); }
.review-solution summary { color: var(--cyan); font-weight: 800; cursor: pointer; }
.review-row.incorrect .review-solution summary { color: var(--red); }
.solution-content { margin-top: 8px; }
.solution-content p { display: grid; grid-template-columns: 2.5rem minmax(0, 1fr); gap: 6px; margin: 5px 0; line-height: 1.6; }
.solution-content strong { color: var(--text); }
.status { position: fixed; right: 16px; bottom: 12px; color: var(--muted); font-size: .82rem; }

.teacher { max-width: 1400px; }
.teacher .panel { max-width: 500px; margin: 12vh auto; }
.teacher input { width: 100%; margin: 12px 0; }
.teacher .student-qr { max-width: 900px; margin: 18px auto; }
.student-qr-body { display: flex; align-items: center; gap: 24px; }
.student-qr-code { flex: 0 0 auto; padding: 12px; background: #fff; border-radius: 8px; }
.student-qr-text { min-width: 0; }
.student-qr-url { display: block; color: var(--cyan); word-break: break-all; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; min-width: 950px; border-collapse: collapse; }
th, td { padding: 5px 8px; font-size: .78rem; text-align: left; border-bottom: 1px solid #243a52; }
th { color: var(--muted); font-weight: 600; }
.teacher .summary-grid > div { padding: 9px; }
.student-actions { display: flex; gap: 6px; white-space: nowrap; }
.teacher .student-actions button { min-height: 36px; padding: 0 12px; font-size: .76rem; }
.teacher .delete-student { color: #fff; background: #9f2635; border: 1px solid var(--red); }
.rate-high { color: var(--green); }
.rate-mid { color: var(--amber); }
.rate-low { color: var(--red); }

@media (max-width: 720px) {
  .shell { padding: 16px; }
  .topbar { grid-template-columns: repeat(2, 1fr); }
  /* 브랜드를 한 줄로 분리하면 네 상태값이 2×2 격자에 같은 높이로 놓인다. */
  .topbar .brand { grid-column: 1 / -1; }
  .choice-grid, .summary-grid, .mission-overview { grid-template-columns: 1fr 1fr; }
  .review-report { grid-template-columns: 1fr; }
  .review-report .review-solution { grid-column: auto; }
  .game-panel { margin: 15px auto; }
  .keypad { grid-template-columns: repeat(4, 1fr); }
  .rule-overview, .answer-examples { grid-template-columns: repeat(2, 1fr); }
  .answer-guide, .rules-bottom { grid-template-columns: 1fr; }
  .student-qr-body { flex-direction: column; align-items: flex-start; }
  .long-briefing .story-lines { grid-template-columns: 1fr; }
  .case-file-grid { grid-template-columns: 1fr; }
  .mission-card-grid { grid-template-columns: 1fr; }
  .review-table-wrap { overflow: visible; border: 0; }
  .review-table, .review-table tbody, .review-table tr { display: block; width: 100%; }
  .review-table colgroup { display: none; }
  .review-table thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  .review-table tr { margin-bottom: 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; }
  .review-table th, .review-table td { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: 8px; width: 100%; border-bottom: 1px solid #243a52; }
  .review-table th::before, .review-table td::before { color: var(--muted); font-weight: 600; content: attr(data-label); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
