:root {
  color-scheme: light;
  --ink: #1f2228;
  --ink-2: #4b5059;
  --ink-3: #868b95;
  --line: #e2e4e8;
  --line-strong: #cfd2d8;
  --panel: #f3f4f6;
  --surface: #ffffff;
  --page: #f7f7f9;
  --chip: #3a3433;
  --save: #1fae8b;
  --save-hover: #18957a;
  --agent: #4f55c8;
  --agent-soft: #eef0fb;
  --danger: #d6353a;
  --danger-soft: #fdeced;
  --warn: #c77700;
  --warn-soft: #fff4e0;
  --ok: #188a55;
  --ok-soft: #e6f6ee;
  --radius: 8px;
  --font: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--surface);
  word-break: keep-all;
  overflow-wrap: anywhere;
}
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--agent); outline-offset: 2px; }
h1, h2, h3, h4, p { margin: 0; }

.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 7px 14px;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel); }
.btn:disabled { opacity: .55; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #000; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b92a2f; }
.btn-save { background: var(--save); border-color: var(--save); color: #fff; padding: 9px 30px; }
.btn-save:hover:not(:disabled) { background: var(--save-hover); }
.chip {
  display: inline-block;
  background: var(--chip);
  color: #fff;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.chip-soft { background: var(--panel); color: var(--ink-2); }
.muted { color: var(--ink-3); }

/* ---------- 로비 ---------- */
/* 응시 화면과 같은 1730×953 화면으로, fitStage가 창 크기에 맞게 배율만 조절한다. */
.lobby-viewport { background: var(--page); }
.lobby {
  position: absolute; left: 0; top: 0; width: 1730px; height: 953px; transform-origin: 0 0;
  display: flex; flex-direction: column; background: var(--page); font-size: 16px;
}
.lobby .btn { padding: 11px 20px; font-size: 16px; border-radius: 8px; }
.lobby-head { flex: none; padding: 26px 46px 18px; border-bottom: 1px solid var(--line-strong); }
.lobby-head h1 { font-size: 32px; font-weight: 800; }
.lobby-head .practice { margin-left: 10px; vertical-align: 6px; font-size: 14px; }
.lobby-sub { color: var(--ink-2); margin-top: 4px; font-size: 17px; }
.lobby-head-row { display: flex; align-items: flex-end; gap: 24px; }
.lobby-head-title { flex: 1; min-width: 0; }
.lobby-account { flex: none; display: flex; align-items: center; gap: 12px; }
.lobby-account a.btn { text-decoration: none; color: inherit; }
.auth-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 20px; }
.lobby .auth-card { width: 560px; display: flex; flex-direction: column; gap: 14px; }
.lobby .auth-card h2 { margin-bottom: 2px; font-size: 24px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.auth-field input { font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 8px; }
.auth-notice { background: var(--panel); border-radius: 8px; padding: 12px 14px; font-size: 14px; color: var(--ink-2); }
.auth-notice ul { margin: 0 0 8px; padding-left: 18px; display: grid; gap: 4px; }
.auth-consent { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); cursor: pointer; }
.auth-error { color: var(--danger); font-weight: 600; min-height: 1.55em; }
.auth-code { font-size: 56px; font-weight: 800; letter-spacing: 12px; text-align: center; color: var(--agent); font-variant-numeric: tabular-nums; }
.auth-switch { background: none; border: 0; color: var(--agent); font-weight: 600; padding: 2px; }
.lobby-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; padding: 20px 46px 24px; }
.lobby-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 46fr 54fr; gap: 18px; }
.lobby-col { min-height: 0; display: flex; flex-direction: column; gap: 18px; }
.lobby .card { padding: 22px 26px; }
.lobby .card h2 { font-size: 20px; flex: none; }
.lobby .notice { font-size: 15px; flex: none; }
.card-rules { flex: none; }
.card-history { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.card-history .table-scroll { flex: 1; min-height: 0; overflow: auto; }
.card-history thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.card-history th:not(:nth-child(2)), .card-history td:not(:nth-child(2)) { white-space: nowrap; }
.card-scenarios { min-height: 0; display: flex; flex-direction: column; }
.card-scenarios .scenario-list { flex: 1; min-height: 0; overflow-y: auto; grid-auto-rows: 1fr; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px 22px; }
.card h2 { font-size: 16px; font-weight: 800; margin-bottom: 12px; }
.rules { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); }
.notice { border-radius: var(--radius); padding: 12px 14px; font-size: 13px; }
.notice code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }
.notice-warn { background: var(--warn-soft); color: #7a4a00; }
.notice-danger { background: var(--danger-soft); color: #8e1e22; }
.notice-info { background: var(--agent-soft); color: #30358a; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.scenario-list { display: grid; gap: 8px; }
.scenario-item {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 14px; cursor: pointer; background: var(--surface);
}
.scenario-item:hover { background: #fafafb; }
.scenario-item:has(input:checked) { border-color: var(--agent); background: var(--agent-soft); }
.scenario-item input { accent-color: var(--agent); margin: 0; flex: none; }
.scenario-item .name { flex: 1; font-weight: 600; }
.lobby-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.lobby-actions .btn { padding: 13px 40px; font-size: 17px; }
.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history th, .history td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.history th { color: var(--ink-3); font-weight: 600; }
.history td.num, .history th.num { text-align: right; font-variant-numeric: tabular-nums; }
.history a { color: var(--agent); font-weight: 600; text-decoration: none; }
.history a:hover { text-decoration: underline; }
.lobby .history .btn { padding: 2px 9px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); border-radius: 6px; }
.table-scroll { overflow-x: auto; }

/* ---------- 응시 화면 ---------- */
/* 응시 화면은 캡처본 해상도(1730×953)로 고정하고, exam.js에서 창 크기에 맞게 배율만 조절한다. */
.exam-viewport { position: fixed; inset: 0; overflow: hidden; background: var(--surface); }
.exam {
  position: absolute; left: 0; top: 0; width: 1730px; height: 953px; transform-origin: 0 0;
  display: flex; flex-direction: column; background: var(--surface); font-size: 16px;
}
.exam .btn { padding: 11px 20px; font-size: 16px; border-radius: 8px; }
.exam-head {
  flex: none; display: flex; align-items: center; gap: 18px;
  padding: 26px 46px 18px; border-bottom: 1px solid var(--line-strong);
}
.exam-head h1 { font-size: 32px; font-weight: 800; flex: 1; min-width: 0; }
.exam-head .practice { margin-left: 10px; vertical-align: 6px; font-size: 14px; }
.timer-wrap { display: flex; align-items: baseline; gap: 12px; }
.timer-label { font-size: 18px; color: var(--ink-2); }
.timer { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 134px; text-align: right; }
.timer.warn { color: var(--warn); }
.timer.danger { color: var(--danger); }
.timer.paused { color: var(--ink-3); }
.exam-grid {
  flex: 1; min-height: 0; position: relative; margin: 0 46px;
  display: grid; grid-template-columns: 26fr 45fr 29fr;
}
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane + .pane { border-left: 1px solid var(--line-strong); }

.pane-problem { padding: 16px 16px 16px 0; overflow-y: auto; gap: 14px; }
.problem-meta { display: flex; align-items: center; gap: 8px; color: var(--ink-3); font-weight: 700; font-size: 16px; }
.problem-meta .chip { font-size: 13px; }
.problem-title { font-size: 18px; font-weight: 800; margin-top: 5px; }
.problem-card { background: var(--panel); border-radius: 12px; padding: 18px; }
.problem-card h3 { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.problem-card .md { font-size: 15px; }
.problem-card .muted { font-size: 15px !important; }
.refs h3 { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.ref-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border-radius: 12px; padding: 14px 16px; margin-bottom: 8px;
}
.ref-item .ref-name { flex: 1; min-width: 0; font-size: 15px; color: var(--ink-2); }
.ref-item button { background: var(--chip); color: #fff; border: 0; border-radius: 999px; padding: 3px 13px; font-size: 14px; font-weight: 700; flex: none; }

.ref-viewer {
  position: absolute; z-index: 5; top: 0; bottom: 0; left: 0;
  width: 71%; background: var(--surface);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line-strong);
  box-shadow: 4px 0 18px rgba(0,0,0,.08);
}
.ref-viewer header { display: flex; align-items: center; gap: 12px; padding: 14px 22px; border-bottom: 1px solid var(--line); }
.ref-viewer header h3 { flex: 1; font-size: 18px; font-weight: 800; }
.ref-viewer .ref-body { flex: 1; overflow: auto; padding: 22px 26px; font-size: 16px; }
.exam .wafer { width: 230px; height: 230px; }

.pane-answer { min-width: 0; }
.answer-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; padding: 16px 22px 14px; }
.answer-head h2 { font-size: 21px; font-weight: 800; white-space: nowrap; flex: none; }
.answer-note { color: var(--danger); font-size: 12.5px; line-height: 1.4; flex: 1 1 440px; text-align: right; }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px;
  padding: 8px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.toolbar button {
  width: 34px; height: 34px; border: 0; background: none; border-radius: 4px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2);
}
.toolbar button:hover { background: var(--panel); }
.toolbar button.active { background: var(--line); color: var(--ink); }
.toolbar select { width: 58px; height: 34px; border: 0; background: none; border-radius: 4px; color: var(--ink-2); padding: 0 2px; font-size: 16px; }
.toolbar select:hover { background: var(--panel); }
.toolbar .sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 6px; }
.toolbar svg { width: 20px; height: 20px; }
.color-btn { position: relative; }
.color-btn input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; padding: 0; border: 0; }
.editor {
  flex: 1; min-height: 0; overflow-y: auto; padding: 18px 22px; outline: none; font-size: 17px; line-height: 1.7;
}
.editor:empty::before { content: attr(data-placeholder); color: var(--ink-3); pointer-events: none; }
.editor ul, .editor ol, .rendered-answer ul, .rendered-answer ol { padding-left: 24px; margin: 4px 0; }
.editor table, .rendered-answer table { border-collapse: collapse; margin: 6px 0; }
.editor th, .editor td, .rendered-answer th, .rendered-answer td { border: 1px solid var(--line-strong); padding: 4px 8px; }
.answer-foot {
  flex: none; display: flex; align-items: center; gap: 12px;
  padding: 16px 22px; border-top: 1px solid var(--line);
}
.save-status { flex: 1; font-weight: 700; font-size: 16px; }
.save-status.dirty { color: var(--ink-2); }
.save-status.saved { color: var(--save-hover); }
.save-status.error { color: var(--danger); }
.char-count { font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.exam .btn-save { padding: 13px 46px; }
.char-count.over { color: var(--danger); font-weight: 700; }

.pane-chat { background: var(--surface); }
.chat-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 16px 0 14px 18px; border-bottom: 1px solid var(--line); }
.chat-head h2 { font-size: 20px; font-weight: 800; flex: 1; }
.chat-head select { max-width: 110px; font-size: 14px; border: 1px solid var(--line-strong); border-radius: 5px; padding: 4px 5px; background: var(--surface); }
.exam .chat-head .btn { padding: 4px 11px; font-size: 14px; font-weight: 500; color: var(--ink-2); border-radius: 5px; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 0 18px 18px; display: flex; flex-direction: column; gap: 16px; }
.msg-agent-name { display: flex; align-items: center; gap: 7px; font-weight: 800; margin-bottom: 5px; }
.agent-badge {
  width: 22px; height: 22px; border-radius: 50%; background: var(--agent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800;
}
.msg-user { align-self: flex-end; max-width: 88%; background: var(--agent-soft); border-radius: 10px 10px 2px 10px; padding: 10px 14px; white-space: pre-wrap; }
.msg-agent { max-width: 100%; }
.msg-agent .md { font-size: 15px; }
.result .msg-agent .md { font-size: 13.5px; }
.msg-error { background: var(--danger-soft); color: #8e1e22; border-radius: var(--radius); padding: 9px 12px; font-size: 13px; }
.msg-welcome { color: var(--ink-3); }
.typing { display: inline-flex; gap: 3px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; background: var(--ink-3); border-radius: 50%; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .6; } }
.chat-input { flex: none; margin: 10px 0 16px 18px; border: 1px solid var(--line-strong); border-radius: 12px; padding: 12px 12px 8px; }
.chat-input:focus-within { border-color: var(--agent); }
.chat-input-row { display: flex; align-items: flex-end; gap: 6px; }
.chat-input textarea { flex: 1; border: 0; outline: none; resize: none; max-height: 140px; min-height: 24px; padding: 2px 0; background: none; line-height: 1.5; }
.icon-btn { width: 28px; height: 28px; flex: none; border: 0; background: none; border-radius: 6px; color: var(--ink-3); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover:not(:disabled) { background: var(--panel); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.send-btn { color: var(--agent); }
.send-btn:disabled { color: var(--line-strong); }
.chat-count { font-size: 13px; color: var(--ink-3); margin: 2px 0 0 34px; font-variant-numeric: tabular-nums; }
.chat-count.over { color: var(--danger); font-weight: 700; }
.attach-wrap { position: relative; }
.attach-menu {
  position: absolute; bottom: 34px; left: 0; z-index: 6;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0,0,0,.12); padding: 4px; width: 190px;
}
.attach-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 5px; font-size: 13px; }
.attach-menu button:hover { background: var(--panel); }

.pause-overlay {
  position: absolute; inset: 0; z-index: 8; background: rgba(247,247,249,.97);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 16px;
}
.pause-overlay h2 { font-size: 22px; font-weight: 800; }

/* ---------- 마크다운 ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1.05em; font-weight: 800; margin: 14px 0 6px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md li { margin-bottom: 2px; }
.md code { background: var(--panel); padding: 1px 4px; border-radius: 3px; font-size: .92em; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.md-table { overflow-x: auto; margin: 0 0 10px; }
.md table { border-collapse: collapse; font-size: .93em; min-width: 100%; }
.md th, .md td { border: 1px solid var(--line-strong); padding: 5px 8px; text-align: left; vertical-align: top; overflow-wrap: normal; }
.md th { background: var(--panel); font-weight: 700; white-space: nowrap; }
.md td.right, .md th.right { text-align: right; font-variant-numeric: tabular-nums; }
.wafer { display: block; margin: 6px 0 14px; width: 170px; height: 170px; }

/* ---------- 대화상자, 토스트 ---------- */
dialog { border: 0; border-radius: 12px; padding: 22px 24px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0,0,0,.25); zoom: var(--dialog-zoom, 1); }
dialog::backdrop { background: rgba(20,20,30,.45); }
dialog h3 { font-size: 16px; font-weight: 800; margin-bottom: 8px; }
dialog p { color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(460px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 8px; font-weight: 700; box-shadow: 0 8px 26px rgba(0,0,0,.25); text-align: center; }
.toast.alarm { background: var(--danger); font-size: 16px; }

/* ---------- 결과 ---------- */
body:has(.result) { background: var(--page); }
.result { padding: 30px 16px 60px; }
.result-inner { max-width: 880px; margin: 0 auto; display: grid; gap: 16px; }
.result-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.result-head > div:first-child { flex: 1; min-width: 240px; }
.result-head h1 { font-size: 22px; font-weight: 800; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--ink-3); }
.stat .value { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-top { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.score-total { font-size: 42px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score-total small { font-size: 16px; color: var(--ink-3); font-weight: 600; }
.score-top p { flex: 1; min-width: 240px; color: var(--ink-2); }
.criterion { padding: 12px 0; border-top: 1px solid var(--line); }
.criterion-head { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; }
.criterion-head span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 6px; background: var(--panel); border-radius: 3px; margin: 6px 0 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--agent); border-radius: 3px; }
.criterion p { font-size: 13px; color: var(--ink-2); }
.criterion blockquote { margin: 6px 0 0; padding-left: 10px; border-left: 3px solid var(--line-strong); font-size: 12.5px; color: var(--ink-3); }
.trap { display: flex; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.trap .chip { flex: none; margin-top: 2px; }
.trap .chip.refuted { background: var(--ok-soft); color: var(--ok); }
.trap .chip.accepted { background: var(--danger-soft); color: var(--danger); }
.trap .chip.not_encountered { background: var(--panel); color: var(--ink-3); }
.trap div { font-size: 13px; }
.trap .evidence { color: var(--ink-3); font-size: 12.5px; }
.sub-title { font-size: 13px; font-weight: 800; margin: 16px 0 6px; }
.plain-list { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 13.5px; color: var(--ink-2); }
.plain-list.danger { color: #8e1e22; }
.muted-strong { color: var(--ink-2); margin-bottom: 8px; }
.claude-request { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: var(--radius); padding: 10px 12px; }
.claude-request code { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; }
.grade-state { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; color: var(--ink-2); }
.rendered-answer { line-height: 1.7; }
.rendered-answer:empty::before { content: "(빈 답안)"; color: var(--ink-3); }
details summary { font-weight: 800; font-size: 16px; cursor: pointer; }
details[open] summary { margin-bottom: 12px; }
.replay { display: flex; flex-direction: column; gap: 12px; }
.thread-title { font-size: 12px; font-weight: 700; color: var(--ink-3); }

.loading { padding: 60px 16px; text-align: center; color: var(--ink-3); }

@media (max-width: 1040px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}
