/* X(트위터) 감성: 흰 바탕, 검정 알약 버튼, 둥근 16px 미디어, 다크는 완전 검정.
   모양 규칙: 버튼은 전부 알약(9999px), 사진/보기/상자는 16px */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --sunk: #f7f9f9;
  --line: #eff3f4;
  --line-strong: #cfd9de;
  --ink: #0f1419;
  --text: #0f1419;
  --text-2: #536471;
  --text-3: #536471;
  --on-ink: #ffffff;
  --mark: #ffd400;
  --mark-ink: #0f1419;
  --ok: #00875a;
  --ok-bg: #e6f6ee;
  --bad: #e0182a;
  --bad-bg: #fee8ea;
  --radius: 16px;
  --pill: 9999px;
  --header: rgb(255 255 255 / .85);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #000000;
    --sunk: #16181c;
    --line: #2f3336;
    --line-strong: #536471;
    --ink: #e7e9ea;
    --text: #e7e9ea;
    --text-2: #8b98a5;
    --text-3: #8b98a5;
    --on-ink: #0f1419;
    --mark: #ffd400;
    --mark-ink: #0f1419;
    --ok: #00ba7c;
    --ok-bg: #002d1c;
    --bad: #ff4d5a;
    --bad-bg: #2c0b0e;
    --header: rgb(0 0 0 / .65);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
button { font: inherit; color: inherit; }
img, video { max-width: 100%; display: block; }

#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------- 버튼 ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--pill);
  min-height: 52px;
  padding: 0 20px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  white-space: nowrap;
  transition: background-color .12s, border-color .12s, opacity .12s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn-primary:hover { opacity: .9; }
.btn-secondary:hover, .btn-hint:hover { background: var(--sunk); }
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-hint { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-hint[aria-pressed="true"] { background: var(--mark); color: var(--mark-ink); border-color: var(--mark); }
.btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.btn:focus-visible, .choice:focus-visible, .home-btn:focus-visible { outline: 3px solid var(--text-3); outline-offset: 2px; }
.btn-split { display: flex; justify-content: space-between; align-items: center; padding: 0 24px; }
.btn-split small { font-size: 14px; font-weight: 400; opacity: .8; }

.bottom-bar {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.bottom-bar.stack { grid-auto-flow: row; border-top: 0; padding-left: 0; padding-right: 0; }
.exam-bar { grid-template-columns: 1fr 1fr 1.4fr; grid-auto-flow: row; }
.exam-bar .btn { padding: 0 8px; }

/* ---------- 홈 ---------- */
.home { flex: 1; display: flex; flex-direction: column; padding: 0 16px; }
.home-photo {
  width: 100%;
  height: auto;
  margin: 16px 0 0;
  aspect-ratio: 1280 / 526;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--sunk);
}
.home-body { padding: 28px 0 8px; }
.home h1 { font-size: 31px; line-height: 1.2; letter-spacing: -0.02em; font-weight: 800; margin: 0 0 10px; }
.lead { color: var(--text-2); margin: 0; max-width: 34em; }
.spec { margin: 24px 0 0; border-top: 1px solid var(--line); }
.spec div { display: grid; grid-template-columns: 4.5em 1fr; padding: 10px 0; border-bottom: 1px solid var(--line); }
.spec dt { color: var(--text-3); }
.spec dd { margin: 0; font-weight: 500; }
.home .bottom-bar { margin-top: auto; padding-top: 24px; background: transparent; }
.source { font-size: 12px; color: var(--text-3); margin: 0; padding: 0 0 calc(14px + env(safe-area-inset-bottom)); }

/* ---------- 상단 바 (시험) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--header);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}
.home-btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--pill);
  height: 34px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.home-btn:active { background: var(--sunk); }
.topbar-title { flex: 1; min-width: 0; font-size: 15px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.topbar-title b { color: var(--text); font-size: 17px; font-weight: 800; }
.topbar-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title .lic { margin-left: 10px; color: var(--text-3); font-size: 14px; }
@media (max-width: 374px) {
  .timer-label { display: none; }
  .topbar-row { gap: 8px; }
  .topbar-title .lic { margin-left: 6px; }
}
.timer { font-size: 14px; color: var(--text-3); white-space: nowrap; }
#timer { font-size: 16px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
#timer.low { color: var(--bad); }
.progress { height: 3px; background: var(--sunk); }
.progress > i { display: block; height: 100%; background: var(--ink); transition: width .2s; }

/* ---------- 공통 페이지 ---------- */
.screen-pad { padding: 8px 16px 0; flex: 1; display: flex; flex-direction: column; }
.page-title { font-size: 26px; line-height: 1.3; letter-spacing: -0.02em; font-weight: 800; margin: 28px 0 6px; }
.page-sub { color: var(--text-2); margin: 0 0 20px; }
.layout-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.layout-table caption { text-align: left; font-weight: 600; color: var(--text-3); font-size: 14px; padding-bottom: 6px; }
.layout-table th { text-align: left; font-weight: 400; color: var(--text-2); padding: 10px 0; border-top: 1px solid var(--line); }
.layout-table td { text-align: right; padding: 10px 0 10px 12px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.layout-table tr:last-child th, .layout-table tr:last-child td { border-bottom: 1px solid var(--line); }
.select-bar, .screen-pad .bottom-bar.stack { padding-top: 24px; }

/* ---------- 문제 ---------- */
.question { padding: 18px 16px 12px; }
.q-meta { margin: 0 0 8px; font-size: 14px; color: var(--text-3); }
.q-meta strong { margin-left: 8px; color: var(--text); font-weight: 600; }
.q-meta .no-answer { color: var(--bad); }
.q-text { font-size: 19px; line-height: 1.5; font-weight: 700; margin: 0 0 16px; }
.q-text .num { font-variant-numeric: tabular-nums; }
.q-figure {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  display: flex;
  justify-content: center;
}
.q-figure img { width: 100%; height: auto; max-height: 360px; object-fit: contain; }
.q-figure.sign img { width: auto; max-height: 220px; padding: 10px; }
.q-figure.video { background: #000; }
.q-figure video { width: 100%; aspect-ratio: 16 / 9; background: #000; }
/* 영상 사본을 받는 동안: 썸네일 위에 안내 */
.q-figure.video { position: relative; }
.q-figure.video.is-loading::after {
  content: "영상을 불러오는 중입니다";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / .45);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
}
/* 그림·영상이 다시 받아지는 동안 깨진 아이콘 숨김 */
.media-wait { visibility: hidden; }
.q-figure:has(.media-wait) { min-height: 160px; background: var(--sunk); }
.media-fail {
  appearance: none;
  width: 100%;
  min-height: 160px;
  margin: 0;
  padding: 20px 16px;
  border: 0;
  background: var(--sunk);
  color: var(--text);
  display: grid;
  place-content: center;
  gap: 4px;
  text-align: center;
  cursor: pointer;
  font: inherit;
}
.media-fail strong { font-size: 16px; }
.media-fail span { font-size: 14px; color: var(--text-2); }
.hint-box .media-fail { min-height: 100px; margin-top: 10px; border-radius: 12px; }
.video-note { margin: -4px 0 12px; font-size: 14px; color: var(--text-3); }
.situation {
  margin: 0 0 16px;
  padding: 10px 14px 10px 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sunk);
  font-size: 15px;
  color: var(--text-2);
}
.situation li + li { margin-top: 2px; }

.hint-box {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--mark);
  background: color-mix(in srgb, var(--mark) 10%, var(--surface));
  font-size: 15px;
  color: var(--text);
}
.hint-box strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 2px; }
.hint-box img { margin-top: 10px; border-radius: 12px; background: #fff; }

.choices { display: grid; gap: 8px; }
.choice {
  appearance: none;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  align-items: start;
  text-align: left;
  width: 100%;
  padding: 13px 14px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px;
  line-height: 1.5;
  cursor: pointer;
  transition: border-color .12s, background-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.choice:hover { background: var(--sunk); }
/* 답안지 마킹처럼: 빈 동그라미, 고르면 검게 칠함 */
.choice .mark, .r-choice .mark {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  display: grid; place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.choice[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.choice[aria-pressed="true"] .mark { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }

/* ---------- 결과 ---------- */
.result-head { padding: 36px 16px 20px; border-bottom: 1px solid var(--line); }
.verdict { margin: 0; font-size: 18px; font-weight: 700; }
.is-pass .verdict { color: var(--ok); }
.is-fail .verdict { color: var(--bad); }
.score { margin: 4px 0 6px; font-size: 56px; font-weight: 800; line-height: 1.1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.score small { font-size: 22px; font-weight: 600; margin-left: 4px; letter-spacing: 0; }
.score-sub { margin: 0; color: var(--text-2); }
.stats { margin: 0; padding: 16px; display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 4px 28px; border-bottom: 1px solid var(--line); }
.stats dt { font-size: 13px; color: var(--text-3); }
.stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats .dd-note { display: block; font-size: 12px; font-weight: 400; color: var(--bad); }
.by-type { margin: 20px 16px 0; width: calc(100% - 32px); }

/* ---------- 오답 ---------- */
.review-item { padding: 20px 16px; border-top: 1px solid var(--line); }
.review-item .q-text { font-size: 17px; }
.r-choices { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 4px; }
.r-choice { display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: start; padding: 8px 10px; border-radius: var(--radius); font-size: 15px; color: var(--text-2); }
.r-choice .mark { width: 22px; height: 22px; font-size: 12px; }
.r-choice.correct { background: var(--ok-bg); color: var(--text); }
.r-choice.correct .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.r-choice.wrong { background: var(--bad-bg); color: var(--text); }
.r-choice.wrong .mark { background: var(--bad); border-color: var(--bad); color: #fff; }
.r-tag { font-size: 12px; font-weight: 600; white-space: nowrap; padding-top: 2px; }
.r-choice.correct .r-tag { color: var(--ok); }
.r-choice.wrong .r-tag { color: var(--bad); }
.hint-box.static { margin: 0; }

/* ---------- 기록 ---------- */
.history { list-style: none; margin: 0 16px; padding: 0; border-top: 1px solid var(--line); }
.history li { display: grid; grid-template-columns: 3.2em 1fr auto; gap: 12px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.h-score { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.h-info { font-size: 14px; color: var(--text-3); }
.h-info b { color: var(--text); font-weight: 600; margin-right: 4px; }
.h-verdict { font-size: 14px; font-weight: 700; }
.h-verdict.pass { color: var(--ok); }
.h-verdict.fail { color: var(--bad); }
.empty { color: var(--text-2); margin: 8px 0 0; }

.spacer { height: 20px; }

/* ---------- 확인창 ---------- */
.ask-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(91 112 131 / .4);
}
.ask {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 22px 20px;
}
.ask-title { margin: 0; font-size: 20px; font-weight: 800; }
.ask-body { margin: 6px 0 0; color: var(--text-2); font-size: 15px; }
.ask-actions { display: grid; grid-auto-flow: row; gap: 10px; margin-top: 22px; }
.ask-actions .btn-primary { order: -1; }
.ask-actions .btn { min-height: 44px; font-size: 15px; }

@media (min-width: 700px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .home h1 { font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
