:root {
  --fs: 1.2;   /* 카드 본문 글자 배율 (기본 '보통') */

  /* ===== 라이트 테마 (기본값) ===== */
  --bg: #f4f5f7;
  --fg: #222;
  --panel-bg: #fff;
  --panel-border: #e0e2e6;
  --muted: #555;
  --muted-lt: #9aa0a8;
  --border: #ccc;
  --border-lt: #c6cbd4;
  --input-bg: #fff;
  --hover-bg: #eef2f8;
  --chip-bg: #fafbfc;
  --chip-border: #c6cbd4;
  --disabled-fg: #aaa;
  --disabled-border: #e0e2e6;
  --note-fg: #a05a00;

  --brand: #2b5fb8;
  --brand-fg: #fff;
  --green: #1e8e4e;
  --red: #c0392b;
  --amber: #d9932c;

  --card-bg: #fff;
  --card-border: #dcdfe5;
  --card-shadow: rgba(0,0,0,0.05);
  --term-var-fg: #7a828c;
  --meta-fg: #999;
  --axis-label-bg: #eef1f5;
  --axis-label-fg: #4a5563;
  --caption-fg: #444;
  --explore-bg: #f7f9fb;
  --rel-kind-bg: #e4dcf1;
  --rel-kind-fg: #5b4a80;
  --sib-tag-bg: #dfeae2;
  --sib-tag-fg: #3f6b4e;
  --crumb-fg: #aab2bc;
  --src-fg: #a08a5b;
  --dashed: #d0d4da;

  --link-bg: #fff;
  --link-border: #ccd3db;
  --link-fg: #2c3742;
  --link-hover-bg: #eef3fa;
  --link-hover-border: #8fa8c6;
  --link-active-bg: #dce6f4;

  --overlay-bg: rgba(20, 26, 34, 0.45);
  --peek-shadow: rgba(0, 0, 0, 0.28);
  --peek-border: #eee;
  --peek-path-fg: #8b939d;

  --table-border: #e8eaee;
  --table-th-fg: #666;
  --bar-bg: #e4e7ec;

  --ov-bg: #f7f8fa;
  --ov-border: #e8eaee;
  --ov-k-fg: #6b7280;
  --ov-sub-fg: #8b919a;
  --stack-bg: #eceef1;
  --legend-fg: #444;
}

/* ===== 다크 테마: 시스템 설정을 따를 때 ===== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1d23;
    --fg: #e4e6ea;
    --panel-bg: #23262d;
    --panel-border: #343841;
    --muted: #aab0ba;
    --muted-lt: #767c87;
    --border: #454a54;
    --border-lt: #454a54;
    --input-bg: #2a2e36;
    --hover-bg: #2d3542;
    --chip-bg: #2a2e36;
    --chip-border: #454a54;
    --disabled-fg: #5b6068;
    --disabled-border: #343841;
    --note-fg: #e0a763;

    --brand: #5b8fdb;
    --brand-fg: #0d1117;
    --green: #4caf76;
    --red: #e0685a;
    --amber: #e0ab5c;

    --card-bg: #23262d;
    --card-border: #383c46;
    --card-shadow: rgba(0,0,0,0.35);
    --term-var-fg: #9aa1ab;
    --meta-fg: #868c96;
    --axis-label-bg: #2e333c;
    --axis-label-fg: #b9c0cc;
    --caption-fg: #c3c8d1;
    --explore-bg: #2a2e36;
    --rel-kind-bg: #3a3350;
    --rel-kind-fg: #cbb9ec;
    --sib-tag-bg: #263b2c;
    --sib-tag-fg: #a3d4b0;
    --crumb-fg: #6b7078;
    --src-fg: #cbab6f;
    --dashed: #40454f;

    --link-bg: #2a2e36;
    --link-border: #454a54;
    --link-fg: #dfe3e8;
    --link-hover-bg: #313847;
    --link-hover-border: #5b7ba8;
    --link-active-bg: #38455a;

    --overlay-bg: rgba(0, 0, 0, 0.6);
    --peek-shadow: rgba(0, 0, 0, 0.55);
    --peek-border: #343841;
    --peek-path-fg: #868c96;

    --table-border: #343841;
    --table-th-fg: #9aa0a8;
    --bar-bg: #343841;

    --ov-bg: #2a2e36;
    --ov-border: #343841;
    --ov-k-fg: #9aa0a8;
    --ov-sub-fg: #767c87;
    --stack-bg: #343841;
    --legend-fg: #c3c8d1;
  }
}
/* ===== 다크 테마: 사용자가 명시적으로 고른 경우 ===== */
:root[data-theme="dark"] {
  --bg: #1a1d23;
  --fg: #e4e6ea;
  --panel-bg: #23262d;
  --panel-border: #343841;
  --muted: #aab0ba;
  --muted-lt: #767c87;
  --border: #454a54;
  --border-lt: #454a54;
  --input-bg: #2a2e36;
  --hover-bg: #2d3542;
  --chip-bg: #2a2e36;
  --chip-border: #454a54;
  --disabled-fg: #5b6068;
  --disabled-border: #343841;
  --note-fg: #e0a763;

  --brand: #5b8fdb;
  --brand-fg: #0d1117;
  --green: #4caf76;
  --red: #e0685a;
  --amber: #e0ab5c;

  --card-bg: #23262d;
  --card-border: #383c46;
  --card-shadow: rgba(0,0,0,0.35);
  --term-var-fg: #9aa1ab;
  --meta-fg: #868c96;
  --axis-label-bg: #2e333c;
  --axis-label-fg: #b9c0cc;
  --caption-fg: #c3c8d1;
  --explore-bg: #2a2e36;
  --rel-kind-bg: #3a3350;
  --rel-kind-fg: #cbb9ec;
  --sib-tag-bg: #263b2c;
  --sib-tag-fg: #a3d4b0;
  --crumb-fg: #6b7078;
  --src-fg: #cbab6f;
  --dashed: #40454f;

  --link-bg: #2a2e36;
  --link-border: #454a54;
  --link-fg: #dfe3e8;
  --link-hover-bg: #313847;
  --link-hover-border: #5b7ba8;
  --link-active-bg: #38455a;

  --overlay-bg: rgba(0, 0, 0, 0.6);
  --peek-shadow: rgba(0, 0, 0, 0.55);
  --peek-border: #343841;
  --peek-path-fg: #868c96;

  --table-border: #343841;
  --table-th-fg: #9aa0a8;
  --bar-bg: #343841;

  --ov-bg: #2a2e36;
  --ov-border: #343841;
  --ov-k-fg: #9aa0a8;
  --ov-sub-fg: #767c87;
  --stack-bg: #343841;
  --legend-fg: #c3c8d1;
}

* { box-sizing: border-box; margin: 0; }
html { background: var(--bg); }
body {
  font-family: "Malgun Gothic", "맑은 고딕", sans-serif;
  background: var(--bg); color: var(--fg);
  max-width: 760px; margin: 0 auto; padding: 16px;
  /* 홈 화면 앱(전체 화면)에서 노치·홈 인디케이터 영역을 피한다 */
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
}
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
h1 { font-size: 1.25rem; }
nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
nav button {
  border: 1px solid var(--border); background: var(--panel-bg); color: var(--fg); padding: 8px 14px;
  border-radius: 8px; cursor: pointer; font-size: 0.95rem;
}
nav button.active { background: var(--brand); color: var(--brand-fg); border-color: var(--brand); }
#theme-toggle .chip { padding: 6px 12px; }

.hidden { display: none !important; }
.panel {
  background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 12px;
  padding: 16px; margin-bottom: 14px;
}
.panel h2 { font-size: 1.05rem; margin-bottom: 10px; }
.panel.center { text-align: center; }

.filter-block h3 { font-size: 0.9rem; color: var(--muted); margin: 10px 0 6px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-block h3 .hint { font-weight: normal; font-size: 0.78rem; color: var(--muted-lt); }
.filter-block h3 .bulk { margin-left: auto; display: flex; gap: 5px; }

/* 태그처럼 종류가 많아 기본적으로 접어 두는 항목 */
.filter-collapsible summary { font-size: 0.9rem; color: var(--muted); cursor: pointer;
                              margin: 10px 0 6px; list-style: revert; }
.filter-collapsible summary .hint { font-weight: normal; font-size: 0.78rem; color: var(--muted-lt); margin-left: 6px; }
.filter-collapsible[open] summary { margin-bottom: 8px; }
.filter-collapsible summary .sel-count { font-weight: normal; font-size: 0.78rem; color: var(--muted-lt); margin-left: 6px; }
.filter-collapsible summary .sel-count.partial { color: var(--brand); }
.filter-collapsible h3.bulk-only { margin: 4px 0 6px; justify-content: flex-end; }
button.mini {
  border: 1px solid var(--border-lt); background: var(--panel-bg); color: var(--muted);
  border-radius: 6px; padding: 2px 9px; font-size: 0.78rem; cursor: pointer;
}
button.mini:hover { background: var(--hover-bg); border-color: var(--brand); color: var(--brand); }
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-group.scroll { max-height: 132px; overflow-y: auto; padding: 2px; }
.chip-group .empty { color: var(--disabled-fg); font-size: 0.85rem; padding: 2px; }
.chip {
  border: 1px solid var(--chip-border); background: var(--chip-bg); color: var(--fg); padding: 5px 12px;
  border-radius: 999px; cursor: pointer; font-size: 0.88rem; user-select: none;
}
.chip.on { background: var(--brand); color: var(--brand-fg); border-color: var(--brand); }
.pool-count { margin-top: 12px; font-weight: bold; color: var(--brand);
              display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pool-count .zero { color: var(--red); }
button.mini:disabled { color: var(--disabled-fg); border-color: var(--disabled-border); cursor: default; background: var(--panel-bg); }

.mode-group { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.mode-group label { cursor: pointer; }
.count-row { margin-bottom: 14px; }
.count-row input { width: 70px; padding: 6px; font-size: 1rem; background: var(--input-bg); color: var(--fg); border: 1px solid var(--border-lt); border-radius: 6px; }
.note { color: var(--note-fg); font-size: 0.85rem; margin-left: 8px; }

.start-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.hint-center { text-align: center; font-size: 0.8rem; color: var(--muted-lt); margin-top: 10px; }

button.primary { background: var(--brand); color: var(--brand-fg); border: none; border-radius: 10px; cursor: pointer; }
button.correct { background: var(--green); color: #fff; border: none; border-radius: 10px; cursor: pointer; }
button.wrong   { background: var(--red); color: #fff; border: none; border-radius: 10px; cursor: pointer; }
button.ghost   { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; color: var(--muted); }
button.big     { padding: 12px 28px; font-size: 1.05rem; }
button:active  { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:disabled:active { transform: none; }

.quiz-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#quiz-progress { font-weight: bold; color: var(--muted); }

.card {
  background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 16px;
  min-height: 280px; padding: 24px; margin-bottom: 16px;
  display: flex; flex-direction: column; justify-content: center; gap: 16px;
  box-shadow: 0 2px 8px var(--card-shadow);
}
.card-face { text-align: center; }
.card-face .term { font-size: calc(var(--fs) * 1.45rem); font-weight: bold; line-height: 1.35; }
.card-face .term-var { font-size: calc(var(--fs) * 0.82rem); color: var(--term-var-fg); margin-top: 4px; letter-spacing: 0.02em; }
.card-face .desc { font-size: calc(var(--fs) * 0.98rem); line-height: 1.75; text-align: left; }
.card-face img { max-width: 100%; max-height: 300px; margin-top: 12px; border-radius: 8px; }
/* 다크 모드: 흰 배경 그림(도식 SVG 등)이 카드에 떠 보이지 않도록 흰 매트를 둔다 */
:root[data-theme="dark"] .card-face img { background: #fff; padding: 8px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .card-face img { background: #fff; padding: 8px; }
}
.card-face .meta { margin-top: 10px; font-size: 0.8rem; color: var(--meta-fg); }
.card-face .hint-line { margin-top: 10px; font-size: calc(var(--fs) * 1.1rem); font-weight: bold;
                        letter-spacing: 0.15em; color: var(--brand); min-height: 1.3em; }

/* 축(출제 각도) — "라벨: 내용" 형식 */
.card-face .axis { font-size: calc(var(--fs) * 0.98rem); line-height: 1.75; text-align: left;
                   margin-top: 8px; padding-left: 2px; }
.card-face .axis:first-child { margin-top: 0; }
.card-face .axis-label { display: inline-block; min-width: 4.2em; margin-right: 6px;
                         padding: 1px 6px; border-radius: 4px;
                         background: var(--axis-label-bg); color: var(--axis-label-fg);
                         font-size: calc(var(--fs) * 0.8rem); font-weight: bold;
                         text-align: center; vertical-align: 2px; }
/* 작품 캡션(작가·제목·연도) */
.card-face .caption { font-size: calc(var(--fs) * 0.88rem); color: var(--caption-fg); margin-top: 8px; }
/* 관련 항목 — 항상 보이며, 표제어를 누르면 미리보기가 뜬다 */
.card-face .explore { margin-top: 12px; text-align: left; }
.card-face .explore-body { padding: 8px 10px;
                           background: var(--explore-bg); border-radius: 6px;
                           font-size: calc(var(--fs) * 0.85rem); line-height: 1.6; }
.card-face .rel-row, .card-face .sib-row { margin-bottom: 4px; }
.card-face .rel-kind, .card-face .sib-tag {
  display: inline-block; min-width: 4.2em; margin-right: 6px; padding: 1px 6px;
  border-radius: 4px; font-size: 0.78rem; font-weight: bold; text-align: center; }
.card-face .rel-kind { background: var(--rel-kind-bg); color: var(--rel-kind-fg); }
.card-face .sib-tag  { background: var(--sib-tag-bg); color: var(--sib-tag-fg); }
.card-face .crumb { color: var(--crumb-fg); margin:0 2px; font-weight:bold; }
.card-face .rel-memo { color: var(--term-var-fg); margin: 0 8px 0 4px; font-size: 0.94em; }

/* 클릭 가능한 표제어 */
.link-card { display: inline-block; margin: 2px 5px 2px 0; padding: 2px 9px;
             background: var(--link-bg); border: 1px solid var(--link-border); border-radius: 12px;
             font-family: inherit; font-size: 0.95em; font-weight: bold;
             color: var(--link-fg); cursor: pointer; line-height: 1.5; }
.link-card:hover { background: var(--link-hover-bg); border-color: var(--link-hover-border); }
.link-card:active { background: var(--link-active-bg); }

/* 관련 항목 미리보기 (회전에 영향 없음) */
.peek { position: fixed; inset: 0; z-index: 50; display: flex;
        align-items: center; justify-content: center;
        background: var(--overlay-bg); padding: 16px; }
.peek.hidden { display: none; }
.peek-box { background: var(--panel-bg); border-radius: 12px; width: min(680px, 100%);
            max-height: 86vh; overflow-y: auto; padding: 14px 18px 20px;
            box-shadow: 0 12px 40px var(--peek-shadow); }
.peek-bar { display: flex; align-items: center; gap: 10px;
            position: sticky; top: -14px; background: var(--panel-bg);
            padding: 6px 0 10px; margin: -4px 0 6px; border-bottom: 1px solid var(--peek-border); }
.peek-path { flex: 1; font-size: 0.8rem; color: var(--peek-path-fg); overflow: hidden;
             text-overflow: ellipsis; white-space: nowrap; }
.peek-box .card-face { text-align: center; }
.peek-box img { max-height: 240px; }
/* 기출 출처 */
.card-face .src { margin-top: 6px; font-size: 0.78rem; color: var(--src-fg); text-align: left; }
#card-back { border-top: 2px dashed var(--dashed); padding-top: 16px; }

.quiz-controls { text-align: center; }
.quiz-controls > button { margin: 0 6px; }
#judge-buttons { display: flex; justify-content: center; gap: 14px; }

.result-big { font-size: 1.5rem; margin: 14px 0; }
#result-wrong-list { text-align: left; margin: 14px 0; }
#result-wrong-list h3 { font-size: 0.95rem; margin-bottom: 6px; }
#result-wrong-list .cleared { color: var(--green); font-weight: bold; text-align: center; margin-bottom: 10px; }
#result-wrong-list li { margin: 4px 0 4px 20px; }

.stats-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.stats-table th, .stats-table td { border-bottom: 1px solid var(--table-border); padding: 7px 8px; text-align: left; }
.stats-table th { color: var(--table-th-fg); font-size: 0.85rem; }
.stats-table td.num { text-align: right; }
.bar-cell { min-width: 120px; }
.bar {
  height: 12px; border-radius: 6px; background: var(--bar-bg); overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--green); }
.bar.low > i { background: var(--red); }
.bar.mid > i { background: var(--amber); }

/* 전체 진도 요약 */
.ov-nums { display: grid; gap: 10px; margin-bottom: 14px;
           grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
.ov-num { background: var(--ov-bg); border: 1px solid var(--ov-border);
          border-radius: 8px; padding: 10px 12px; }
.ov-num .k { font-size: 0.8rem; color: var(--ov-k-fg); }
.ov-num .v { font-size: 1.5rem; font-weight: bold; line-height: 1.3; white-space: nowrap; color: var(--fg); }
.ov-num .v small { font-size: 0.85rem; font-weight: normal; color: var(--ov-k-fg); margin-left: 3px; }
.ov-num .sub { font-size: 0.78rem; color: var(--ov-sub-fg); margin-top: 1px; }
.ov-num.ok .v { color: var(--green); }
.ov-num.no .v { color: var(--red); }
.stack { display: flex; height: 20px; border-radius: 10px; overflow: hidden; background: var(--stack-bg); }
.stack > i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 9px;
          font-size: 0.84rem; color: var(--legend-fg); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend b { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.ov-note { font-size: 0.8rem; color: var(--muted-lt); margin-top: 10px; }

/* 약점 지도 */
.map-hint { margin-bottom: 10px; }
.map-legend { justify-content: center; margin-bottom: 14px; }
.area-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
             gap: 6px; }
.area-cell { border: none; border-radius: 6px; padding: 6px 4px; color: #fff;
             cursor: pointer; text-align: center; min-height: 56px;
             display: flex; flex-direction: column; align-items: center; justify-content: center;
             gap: 3px; transition: transform 0.08s; }
.area-cell:hover { transform: scale(1.05); z-index: 1; }
.area-cell:active { transform: scale(0.97); }
.area-label { font-size: 0.72rem; font-weight: bold; line-height: 1.25;
              text-shadow: 0 1px 2px rgba(0,0,0,0.35); }
.area-count { font-size: 0.68rem; opacity: 0.9; }

/* 카드 목록을 같은 창 안에 띄울 때 (팝업이 막힌 경우) */
.listbox-box { width: min(960px, 96vw); height: 88vh; display: flex; flex-direction: column; padding: 0; }
.listbox-box .peek-bar { padding: 10px 14px; justify-content: space-between; }
#listbox-frame { flex: 1; border: 0; width: 100%; background: var(--panel-bg); border-radius: 0 0 12px 12px; }

/* ===== 로그인 / 사용자 ===== */
.login-panel { max-width: 420px; margin: 24px auto; display: flex; flex-direction: column; gap: 12px; }
.login-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.95em; }
.login-field input { font-size: 1.05em; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--input-bg); color: var(--fg); }
.login-msg { min-height: 1.4em; margin: 0; text-align: center; font-size: 0.95em; opacity: 0.8; }
.login-msg.error { color: #c0392b; opacity: 1; }

/* ===== 카드 신고 ===== */
.report-box { margin-top: 16px; }
#btn-report { color: var(--fg); border-color: var(--border-lt); }
.report-form { max-width: 420px; margin: 8px auto 0; display: flex; flex-direction: column; gap: 6px; }
.report-form textarea { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--input-bg); color: var(--fg); font: inherit; font-size: 0.95em; resize: vertical; }
.report-actions { display: flex; justify-content: center; gap: 8px; }
#btn-report.done { color: var(--green); border-color: var(--green); cursor: default; opacity: 1; }
.report-reasons { justify-content: center; }
.report-reasons .chip { font-size: 0.95rem; padding: 8px 14px; }

/* ===== 화면 전환 ===== */
section.enter { animation: screen-in 0.22s ease-out; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { section.enter { animation: none; } }

/* ===== 갱신 알림 띠 ===== */
.update-banner { display: flex; justify-content: center; align-items: center; gap: 12px; margin: -6px 0 12px;
  padding: 8px 12px; border-radius: 8px; background: var(--brand); color: var(--brand-fg); font-size: 0.9rem; }
.update-banner button { background: var(--brand-fg); color: var(--brand); border: 0; }

/* ===== 도움말 ===== */
.help-box { line-height: 1.55; font-size: 0.95rem; }
.help-box h3 { margin: 18px 0 6px; font-size: 1rem; color: var(--brand); }
.help-box p, .help-box ul, .help-box ol { margin: 4px 0 8px; }
.help-box ul, .help-box ol { padding-left: 20px; }
.help-box li { margin: 3px 0; }
.help-info { border-collapse: collapse; font-size: 0.9rem; }
.help-info th { text-align: left; font-weight: normal; color: var(--muted); padding: 3px 14px 3px 0; white-space: nowrap; }
.help-info td { padding: 3px 0; word-break: break-all; }

/* ===== 헤더 아이콘 버튼 · 내 정보 ===== */
.icon-btn { border: 1px solid var(--border); background: var(--panel-bg); border-radius: 8px; cursor: pointer;
  font-size: 1.1rem; padding: 6px 10px; line-height: 1; }
.me-email { font-size: 1.05rem; font-weight: bold; word-break: break-all; margin: 0 0 4px; }
#me-summary { display: flex; gap: 10px; flex-wrap: wrap; }
.me-stat { flex: 1 1 120px; background: var(--chip-bg); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 12px; }
.me-stat b { display: block; font-size: 1.3rem; color: var(--brand); }
.me-stat span { font-size: 0.82rem; color: var(--muted); }

/* ===== 네비게이션: 데스크톱은 헤더, 폰은 하단 고정 바 ===== */
svg.ico { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; }
h1 { display: flex; align-items: center; gap: 8px; }
h1 .title-ico { width: 1.3em; height: 1.3em; color: var(--brand); }
nav button { display: inline-flex; align-items: center; gap: 6px; }
.icon-btn svg.ico { width: 1.25em; height: 1.25em; vertical-align: middle; color: var(--muted); }
#judge-buttons button { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 640px) {
  body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }   /* 하단 바에 가리지 않게 */
  #main-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; justify-content: space-around; gap: 0; flex-wrap: nowrap;
    background: var(--panel-bg); border-top: 1px solid var(--panel-border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  #main-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    border: 0; background: none; color: var(--muted); padding: 4px 2px; border-radius: 8px; font-size: 0.72rem; }
  #main-nav button svg.ico { width: 1.5rem; height: 1.5rem; }
  #main-nav button.active { background: none; color: var(--brand); font-weight: bold; }
}

/* 유형 칩은 폰에서 한 줄에 들어가도록 좁게 */
#filter-type .chip { padding: 5px 9px; font-size: 0.84rem; }

/* ===== 기출문제 ===== */
.exam-list { display: flex; flex-direction: column; gap: 8px; }
.exam-item { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--panel-border); border-radius: 10px; background: var(--chip-bg); cursor: pointer; }
.exam-item:hover { background: var(--hover-bg); }
.exam-item b { font-size: 1rem; }
.exam-item span { font-size: 0.85rem; color: var(--muted); }
.exam-q-nums { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 10px; }
.exam-q-nums button { min-width: 34px; padding: 5px 0; border: 1px solid var(--chip-border); background: var(--chip-bg);
  color: var(--fg); border-radius: 8px; font-size: 0.85rem; cursor: pointer; }
.exam-q-nums button.active { background: var(--brand); color: var(--brand-fg); border-color: var(--brand); }
/* 시험지는 항상 흰 종이 위에. 확대하면 패널 안에서 스크롤한다 */
.exam-q-panel { padding: 6px; background: #fff; border: 1px solid var(--panel-border); border-radius: 10px;
  overflow: auto; max-height: 72vh; margin-bottom: 10px; touch-action: pan-x pan-y pinch-zoom; -webkit-overflow-scrolling: touch; }
.exam-q-panel img, .peek-box .exam-q-panel img { display: block; width: 100%; max-width: none; max-height: none; height: auto; }
.zoom-bar { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; flex-wrap: wrap; }
.zoom-bar .zoom-val { min-width: 44px; text-align: center; font-size: 0.85rem; color: var(--muted); }
.zoom-bar .hint { font-size: 0.75rem; }
.exam-nav { display: flex; justify-content: center; gap: 14px; }

.src-link { border: 1px solid var(--brand); background: none; color: var(--brand); border-radius: 999px;
  padding: 1px 8px; font-size: 0.78rem; cursor: pointer; }
.src-link:hover { background: var(--hover-bg); }
.exam-peek-box { width: min(1100px, 100%); max-height: 96vh; padding: 10px 10px 12px; }
.exam-peek-box .exam-q-panel { max-height: calc(96vh - 110px); margin-bottom: 0; }
#exam-peek.peek { padding: 6px; }
@media (max-width: 640px) {
  .exam-peek-box { border-radius: 8px; padding: 8px 6px 10px; }
  .exam-peek-box .peek-bar { top: -8px; }
  .exam-peek-box .zoom-bar .hint { display: none; }
  .exam-q-panel { padding: 2px; }
}

#peek { z-index: 60; }

/* ===== 예상 점수 ===== */
.est { text-align: center; padding: 14px 10px 16px; margin-bottom: 14px; border-radius: 12px;
  background: var(--chip-bg); border: 1px solid var(--panel-border); }
.est-label { font-size: 0.9rem; color: var(--muted); }
.est-score { font-size: 2.4rem; font-weight: bold; color: var(--brand); line-height: 1.15; margin: 2px 0; }
.est-score small { font-size: 1rem; font-weight: normal; color: var(--muted); margin-left: 4px; }
.est-sub { font-size: 0.88rem; color: var(--muted); }
.est-sub .hint { display: block; font-size: 0.75rem; margin-top: 2px; }

/* ===== 기출 참고 답안 ===== */
.exam-answer { margin: 0 0 12px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--panel-border);
  background: var(--chip-bg); font-size: 0.95rem; line-height: 1.6; }
.exam-answer .ans-note { font-size: 0.78rem; color: var(--muted-lt); margin: 0 0 8px; }
.exam-answer p { margin: 4px 0; }
.exam-answer .ans-none { color: var(--muted); }

.ans-link { border: 0; background: none; padding: 0; font: inherit; color: var(--brand); text-decoration: underline dotted; cursor: pointer; }
.ans-related { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--panel-border); }
.ans-related .hint { margin-right: 4px; }
.ans-related .chip { font: inherit; font-size: 0.85rem; }
