/* ===== 공인중개사 기출 학습기 ===== */
:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --ink: #1c2030;
  --ink-2: #5b6376;
  --ink-3: #8a91a3;
  --line: #e7e9f0;
  --brand: #4f46e5;
  --brand-2: #6366f1;
  --brand-soft: #eef0ff;
  --ok: #12a150;
  --ok-soft: #e6f7ee;
  --bad: #e5484d;
  --bad-soft: #fdecec;
  --warn: #f59e0b;
  --warn-soft: #fef3e2;
  --shadow: 0 1px 2px rgba(20,24,48,.06), 0 8px 24px rgba(20,24,48,.06);
  --radius: 16px;
  --tab-h: 62px;
  --maxw: 720px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
    "Apple SD Gothic Neo", Pretendard, Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px calc(var(--tab-h) + 24px);
  min-height: 100vh;
}
.loading { text-align: center; padding: 40vh 0; color: var(--ink-3); }

/* ===== 공통 헤더 ===== */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: 18px 2px 12px;
  display: flex; align-items: center; gap: 12px;
}
.app-header h1 { font-size: 20px; margin: 0; font-weight: 800; letter-spacing: -.02em; }
.app-header .sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.h-back {
  width: 38px; height: 38px; border-radius: 12px; background: var(--card);
  box-shadow: var(--shadow); display: grid; place-items: center; font-size: 18px;
  flex: none;
}

/* ===== 카드 ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px;
}
.card-h { font-size: 13px; font-weight: 700; color: var(--ink-3); letter-spacing: .02em;
  text-transform: none; margin: 6px 4px 10px; }

/* ===== 홈: 차수 카드 ===== */
.phase-card {
  display: flex; flex-direction: column; gap: 14px;
  cursor: pointer; position: relative; overflow: hidden;
  border: 1px solid transparent; transition: transform .12s ease;
}
.phase-card:active { transform: scale(.99); }
.phase-card .pc-top { display: flex; align-items: center; justify-content: space-between; }
.pc-title { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.pc-badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); }
.pc-subjects { color: var(--ink-2); font-size: 13.5px; }
.pc-stats { display: flex; gap: 8px; }
.stat {
  flex: 1; background: #f7f8fc; border-radius: 12px; padding: 10px 12px; text-align: center;
}
.stat b { display: block; font-size: 19px; font-weight: 800; }
.stat span { font-size: 11.5px; color: var(--ink-3); }
.progress-line { height: 8px; background: #eceef5; border-radius: 999px; overflow: hidden; }
.progress-line > i { display: block; height: 100%; background: linear-gradient(90deg,var(--brand),var(--brand-2)); border-radius: 999px; }

/* ===== 버튼 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 18px; border-radius: 13px; font-weight: 700; font-size: 15.5px;
  background: var(--brand); color: #fff; width: 100%;
  box-shadow: 0 6px 16px rgba(79,70,229,.25);
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }
.btn.ghost { background: #f2f3f8; color: var(--ink-2); box-shadow: none; }
.btn.sm { padding: 10px 14px; font-size: 14px; width: auto; }
.btn:disabled { opacity: .5; }

/* ===== 셋업 화면 ===== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border-radius: 999px; background: #f2f3f8; color: var(--ink-2);
  font-size: 14px; font-weight: 600; border: 1.5px solid transparent;
}
.chip.on { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.chip .n { opacity: .6; font-weight: 700; margin-left: 4px; }
.mode-list { display: flex; flex-direction: column; gap: 8px; }
.mode {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 13px;
  background: #f7f8fc; border: 1.5px solid transparent;
}
.mode.on { border-color: var(--brand); background: var(--brand-soft); }
.mode .m-ico { font-size: 20px; }
.mode .m-t { font-weight: 700; font-size: 15px; }
.mode .m-d { font-size: 12.5px; color: var(--ink-3); }
.mode .radio { margin-left: auto; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--ink-3); flex: none; }
.mode.on .radio { border-color: var(--brand); background:
  radial-gradient(circle at center, var(--brand) 0 5px, transparent 6px); }

/* ===== 퀴즈 화면 ===== */
.quiz-bar { position: sticky; top: 0; z-index: 20; background: var(--bg); padding: 12px 2px 8px; }
.qb-row { display: flex; align-items: center; gap: 10px; }
.qb-close { width: 34px; height: 34px; border-radius: 10px; background: var(--card);
  box-shadow: var(--shadow); font-size: 17px; flex: none; }
.qb-meta { flex: 1; min-width: 0; }
.qb-sub { font-size: 12px; color: var(--ink-3); }
.qb-title { font-weight: 800; font-size: 15px; }
.qb-count { font-size: 13px; color: var(--ink-2); font-weight: 700; }
.timer {
  display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums;
  font-weight: 800; font-size: 15px; padding: 6px 12px; border-radius: 999px;
  background: var(--ok-soft); color: var(--ok); flex: none;
}
.timer.warn { background: var(--warn-soft); color: var(--warn); }
.timer.danger { background: var(--bad-soft); color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.timebar { height: 5px; background: #e6e8f0; border-radius: 999px; margin-top: 9px; overflow: hidden; }
.timebar > i { display: block; height: 100%; width: 100%; background: var(--ok);
  border-radius: 999px; transition: width .3s linear, background .3s; }
.timebar > i.warn { background: var(--warn); }
.timebar > i.danger { background: var(--bad); }

.qimg-wrap {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin: 6px 0 14px; overflow-x: auto;
}
.qimg { display: block; width: 100%; height: auto; }

.choices { display: flex; flex-direction: column; gap: 9px; }
.choice {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 13px;
  background: var(--card); box-shadow: var(--shadow); font-size: 16px; font-weight: 600;
  border: 2px solid transparent; text-align: left; width: 100%;
}
.choice .num {
  width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: #f0f1f7; color: var(--ink-2); font-weight: 800; font-size: 15px;
}
.choice.picked { border-color: var(--brand); background: var(--brand-soft); }
.choice.picked .num { background: var(--brand); color: #fff; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .num { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .num { background: var(--bad); color: #fff; }
.choice .mark { margin-left: auto; font-weight: 800; }
.choice:disabled { cursor: default; }

.feedback {
  margin-top: 14px; padding: 16px; border-radius: var(--radius); box-shadow: var(--shadow);
  background: var(--card); display: flex; flex-direction: column; gap: 12px;
}
.fb-head { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; }
.fb-head.ok { color: var(--ok); } .fb-head.bad { color: var(--bad); } .fb-head.warn { color: var(--warn); }
.fb-line { font-size: 14px; color: var(--ink-2); }
.fb-line b { color: var(--ink); }
.fb-topic { display: inline-block; font-size: 12px; font-weight: 700; color: var(--brand);
  background: var(--brand-soft); padding: 3px 10px; border-radius: 999px; }

.sticky-next {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  max-width: var(--maxw); margin: 0 auto;
}

/* ===== 결과 ===== */
.result-hero { text-align: center; padding: 26px 0 10px; }
.result-hero .big { font-size: 46px; font-weight: 800; }
.result-hero .lbl { color: var(--ink-3); }
.res-stats { display: flex; gap: 8px; }

/* ===== 오답노트 / 리스트 ===== */
.seg { display: flex; gap: 6px; background: #eceef5; padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 9px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }

.group-h { display: flex; align-items: center; gap: 8px; margin: 18px 4px 8px; }
.group-h .g-sub { font-size: 12px; color: var(--ink-3); font-weight: 700; }
.group-h .g-topic { font-size: 15px; font-weight: 800; }
.group-h .g-count { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--bad);
  background: var(--bad-soft); padding: 3px 9px; border-radius: 999px; }

.q-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 15px; border-radius: 13px;
  background: var(--card); box-shadow: var(--shadow); margin-bottom: 8px; width: 100%; text-align: left;
}
.q-item .qi-num { font-weight: 800; color: var(--brand); font-size: 14px; flex: none; min-width: 60px; }
.q-item .qi-stem { flex: 1; font-size: 14px; color: var(--ink); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.q-item .qi-tag { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; flex: none; }
.qi-tag.wrong { background: var(--bad-soft); color: var(--bad); }
.qi-tag.timeout { background: var(--warn-soft); color: var(--warn); }
.qi-tag.mastered { background: var(--ok-soft); color: var(--ok); }
.qi-del { width: 28px; height: 28px; border-radius: 8px; flex: none; font-size: 13px;
  color: var(--ink-3); background: #f2f3f8; }
.qi-del:active { background: var(--bad-soft); color: var(--bad); }
.chip .n.bad { color: var(--bad); opacity: 1; }

/* ===== AI 오답 분석 ===== */
.analysis { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-top: 14px; }
.ana-head { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.ana-tag { font-size: 10.5px; font-weight: 700; color: var(--ink-3); background: #f0f1f7;
  padding: 3px 8px; border-radius: 999px; }
.ana-empty { color: var(--ink-3); font-size: 14px; margin-top: 10px; }
.ana-sec { margin-top: 13px; }
.ana-t { font-size: 12px; font-weight: 800; color: var(--brand); margin-bottom: 4px; }
.ana-sec p { margin: 0; font-size: 14px; color: var(--ink); line-height: 1.6; }
.ana-sec.pit .ana-t { color: var(--warn); }
.ana-sec.tip .ana-t { color: var(--ok); }
.ana-choices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ana-choice { display: flex; gap: 9px; align-items: flex-start; }
.ana-cnum { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 800; }
.ana-cnum.ok { background: var(--ok-soft); color: var(--ok); }
.ana-cnum.bad { background: var(--bad-soft); color: var(--bad); }
.ana-ctext { font-size: 13.5px; line-height: 1.55; }
.ana-ctext b.ok { color: var(--ok); } .ana-ctext b.bad { color: var(--bad); }
.tip-pattern { font-size: 14px; line-height: 1.55; font-weight: 600; color: var(--ink);
  background: var(--ok-soft); border-left: 3px solid var(--ok); border-radius: 8px; padding: 10px 12px; }
.tip-tablewrap { margin-top: 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tip-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.tip-table th, .tip-table td { border: 1px solid var(--line); padding: 7px 9px; text-align: left;
  vertical-align: top; line-height: 1.45; }
.tip-table thead th { background: var(--brand-soft); color: var(--brand); font-weight: 800;
  white-space: nowrap; }
.tip-table td.tt-key { background: #f7f8fc; font-weight: 700; color: var(--ink); white-space: nowrap; }
@media (prefers-color-scheme: dark) { .tip-table td.tt-key { background: #262a36; } }

.empty { text-align: center; color: var(--ink-3); padding: 60px 20px; }
.empty .e-ico { font-size: 40px; }

/* ===== 통계 ===== */
.stat-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.stat-row .sr-name { width: 130px; font-size: 13px; font-weight: 600; flex: none; }
.sr-bar { flex: 1; height: 22px; background: #eef0f5; border-radius: 8px; overflow: hidden; position: relative; }
.sr-bar > i { display: block; height: 100%; border-radius: 8px; background: linear-gradient(90deg,var(--ok),#3fbf72); }
.sr-bar > i.low { background: linear-gradient(90deg,var(--bad),#f2726f); }
.sr-bar > i.mid { background: linear-gradient(90deg,var(--warn),#f7bb4c); }
.sr-val { font-size: 12px; font-weight: 800; width: 78px; text-align: right; flex: none;
  font-variant-numeric: tabular-nums; }

/* ===== 모달 ===== */
.modal-back { position: fixed; inset: 0; background: rgba(15,18,35,.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--bg); border-radius: 20px 20px 0 0; width: 100%; max-width: var(--maxw);
  max-height: 90vh; overflow-y: auto; padding: 8px 16px 24px; }
.modal-grab { width: 40px; height: 4px; background: var(--line); border-radius: 999px; margin: 8px auto 12px; }

/* ===== 탭바 ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: flex;
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 11px; font-weight: 700; color: var(--ink-3); position: relative; }
.tab.is-active { color: var(--brand); }
.tab-ico { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tab.is-active .tab-ico { filter: none; opacity: 1; }
.tab .badge { position: absolute; top: 8px; left: 54%; background: var(--bad); color: #fff;
  font-size: 10px; font-weight: 800; min-width: 17px; height: 17px; border-radius: 999px;
  display: grid; place-items: center; padding: 0 4px; }

/* ===== 인앱 확인 모달 ===== */
.confirm-modal { border-radius: 20px; max-width: 460px; margin: auto auto 0; padding: 8px 20px 20px; }
@media (min-width: 520px) { .modal-back { align-items: center; } .confirm-modal { border-radius: 20px; margin: auto; } }
.cf-title { font-size: 17px; font-weight: 800; margin: 4px 2px 12px; }
.cf-body { font-size: 14.5px; line-height: 1.65; color: var(--ink-2); }
.cf-body b { color: var(--ink); }
.cf-muted { color: var(--ink-3); font-size: 13px; }

.hidden { display: none !important; }
.spacer { height: 8px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d; --card: #1e212b; --ink: #eef0f6; --ink-2: #aab2c5; --ink-3: #7b839a;
    --line: #2b2f3c; --brand-soft: #26264a; --ok-soft: #14301f; --bad-soft: #3a1c1e;
    --warn-soft: #3a2c12;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
  .stat, .mode, .chip, .seg { background: #262a36; }
  .tabbar { background: rgba(20,22,29,.9); }
  .qimg { border-radius: 8px; }
}
