/* =========================================================================
   해기사 기출 트레이너 — Design system
   Light mode · Toss-inspired warmth + Microsoft Fluent 2 depth/motion
   ========================================================================= */

:root {
  /* ---- palette ---- */
  --blue-50:  #EAF2FE;
  --blue-100: #C9DEFB;
  --blue-300: #6BA4F8;
  --blue-500: #3182F6;   /* primary (Toss blue) */
  --blue-600: #2272EB;
  --blue-700: #1B64D6;

  --green-50:  #E7F9F1;
  --green-500: #00C471;
  --green-600: #00A864;
  --green-700: #048a55;

  --red-50:  #FDECEE;
  --red-500: #F04452;
  --red-600: #E02D3C;

  --amber-500: #FF9500;

  --grey-0:  #FFFFFF;
  --grey-50: #F9FAFB;
  --grey-100:#F2F4F6;
  --grey-150:#EBEEF1;
  --grey-200:#E5E8EB;
  --grey-300:#D1D6DB;
  --grey-400:#B0B8C1;
  --grey-500:#8B95A1;
  --grey-600:#6B7684;
  --grey-700:#4E5968;
  --grey-800:#333D4B;
  --grey-900:#191F28;

  --bg: var(--grey-100);
  --surface: var(--grey-0);
  --text: var(--grey-900);
  --text-2: var(--grey-700);
  --text-3: var(--grey-500);
  --line: var(--grey-200);

  /* ---- radius ---- */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* ---- shadow (Fluent depth, Toss softness) ---- */
  --sh-1: 0 1px 2px rgba(23,31,40,.06), 0 1px 3px rgba(23,31,40,.04);
  --sh-2: 0 2px 6px rgba(23,31,40,.06), 0 8px 20px rgba(23,31,40,.06);
  --sh-3: 0 6px 16px rgba(23,31,40,.08), 0 18px 44px rgba(23,31,40,.10);
  --sh-blue: 0 6px 18px rgba(49,130,246,.30);
  --sh-blue-sm: 0 2px 8px rgba(49,130,246,.24);

  /* ---- motion (Fluent 2 curves) ---- */
  --e-out: cubic-bezier(.33, 1, .68, 1);
  --e-inout: cubic-bezier(.65, 0, .35, 1);
  --e-spring: cubic-bezier(.34, 1.56, .64, 1);

  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR",
    system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-feature-settings: "tnum";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
:focus-visible { outline: 3px solid var(--blue-100); outline-offset: 2px; }

/* ===================== layout ===================== */
#app { min-height: 100dvh; }

.shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 18px calc(40px + env(safe-area-inset-bottom));
}

/* sticky app header */
.appbar {
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: saturate(180%) blur(14px);
  background: rgba(249, 250, 251, .82);
  border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: 760px; margin: 0 auto;
  height: 56px; padding: 0 14px;
  display: flex; align-items: center; gap: 10px;
}
.appbar .brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 16px; letter-spacing: -.02em;
}
.brand .logo {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  box-shadow: var(--sh-blue-sm);
  display: grid; place-items: center; color: #fff; font-size: 14px;
}
.appbar .spacer { flex: 1; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  height: 38px; min-width: 38px; padding: 0 12px;
  border-radius: var(--r-pill);
  color: var(--text-2); font-weight: 600; font-size: 14px;
  transition: background .16s var(--e-out), color .16s var(--e-out), transform .1s var(--e-out);
}
.iconbtn:hover { background: var(--grey-150); color: var(--text); }
.iconbtn:active { transform: scale(.95); }
.iconbtn.active { color: var(--blue-600); background: var(--blue-50); }

/* ===================== headings ===================== */
.page-head { padding: 26px 2px 16px; }
.page-head h1 {
  margin: 0; font-size: 26px; line-height: 1.25; letter-spacing: -.03em;
  font-weight: 800;
}
.page-head p { margin: 8px 0 0; color: var(--text-3); font-size: 14.5px; font-weight: 500; }

.section { margin-top: 22px; }
.section > .label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--text-3);
  letter-spacing: .01em; margin: 0 2px 10px; text-transform: none;
}
.section > .label .hint { color: var(--grey-400); font-weight: 500; }

/* ===================== card ===================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sh-1);
}

/* ===================== exam cards ===================== */
.exam-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.exam-card {
  position: relative; text-align: left;
  padding: 18px 16px; border-radius: var(--r-md);
  background: var(--surface); border: 1.5px solid var(--line);
  box-shadow: var(--sh-1);
  transition: border-color .18s var(--e-out), box-shadow .18s var(--e-out), transform .12s var(--e-out);
}
.exam-card:hover:not(.disabled) { transform: translateY(-2px); box-shadow: var(--sh-2); }
.exam-card.selected { border-color: var(--blue-500); box-shadow: var(--sh-blue-sm); }
.exam-card .ec-badge {
  display: inline-flex; font-size: 11.5px; font-weight: 700; color: var(--blue-700);
  background: var(--blue-50); padding: 3px 9px; border-radius: var(--r-pill); margin-bottom: 10px;
}
.exam-card .ec-title { font-size: 16px; font-weight: 700; letter-spacing: -.02em; }
.exam-card .ec-sub { margin-top: 4px; font-size: 12.5px; color: var(--text-3); font-weight: 500; }
.exam-card.disabled { opacity: .55; cursor: not-allowed; }
.exam-card .ec-check {
  position: absolute; top: 14px; right: 14px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--blue-500); color: #fff; display: none;
  place-items: center; font-size: 13px; box-shadow: var(--sh-blue-sm);
}
.exam-card.selected .ec-check { display: grid; }

/* ===================== chips ===================== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 38px; padding: 0 15px; border-radius: var(--r-pill);
  background: var(--surface); border: 1.5px solid var(--grey-200);
  color: var(--text-2); font-size: 14px; font-weight: 600; letter-spacing: -.01em;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s var(--e-out);
}
.chip:hover { border-color: var(--grey-300); background: var(--grey-50); }
.chip:active { transform: scale(.96); }
.chip.on {
  background: var(--blue-500); border-color: var(--blue-500); color: #fff;
  box-shadow: var(--sh-blue-sm);
}
.chip.on:hover { background: var(--blue-600); }
.chip.all.on { background: var(--grey-900); border-color: var(--grey-900); box-shadow: none; }

/* ===================== segmented ===================== */
.segmented {
  display: inline-flex; padding: 4px; gap: 4px;
  background: var(--grey-150); border-radius: var(--r-pill);
}
.segmented button {
  height: 36px; padding: 0 18px; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 600; color: var(--text-2);
  transition: all .18s var(--e-out);
}
.segmented button.on {
  background: var(--surface); color: var(--blue-600);
  box-shadow: var(--sh-1);
}

/* ===================== mode cards ===================== */
.mode-grid { display: grid; gap: 12px; }
.mode-card {
  display: flex; align-items: center; gap: 15px; text-align: left;
  padding: 17px 18px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--sh-1);
  transition: transform .14s var(--e-out), box-shadow .18s var(--e-out), border-color .18s var(--e-out);
}
.mode-card:hover { transform: translateY(-2px); box-shadow: var(--sh-2); border-color: var(--grey-200); }
.mode-card:active { transform: translateY(0) scale(.99); }
.mode-card .mc-ic {
  flex: none; width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center; font-size: 22px;
}
.mode-card .mc-ic.flash { background: linear-gradient(135deg,#FFF1D6,#FFE0A6); }
.mode-card .mc-ic.practice { background: linear-gradient(135deg,var(--blue-50),#CFE2FD); }
.mode-card .mc-ic.exam { background: linear-gradient(135deg,#E7F9F1,#C7F0DC); }
.mode-card .mc-body { flex: 1; min-width: 0; }
.mode-card .mc-title { font-size: 16px; font-weight: 700; letter-spacing: -.02em; }
.mode-card .mc-desc { margin-top: 3px; font-size: 13px; color: var(--text-3); font-weight: 500; line-height: 1.4; }
.mode-card .mc-arrow { color: var(--grey-400); font-size: 20px; }

/* summary bar */
.summary {
  position: sticky; bottom: 14px; margin-top: 24px;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--r-md);
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(180%) blur(12px);
  border: 1px solid var(--line); box-shadow: var(--sh-2);
}
.summary .s-count { font-weight: 800; font-size: 15px; }
.summary .s-count b { color: var(--blue-600); }
.summary .s-meta { font-size: 12.5px; color: var(--text-3); font-weight: 500; }

/* ===================== buttons ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 22px; border-radius: var(--r-sm);
  font-size: 16px; font-weight: 700; letter-spacing: -.01em;
  background: var(--grey-100); color: var(--text);
  transition: transform .1s var(--e-out), background .16s var(--e-out), box-shadow .16s var(--e-out), opacity .16s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--blue-500); color: #fff; box-shadow: var(--sh-blue-sm); }
.btn.primary:hover { background: var(--blue-600); }
.btn.ghost { background: var(--surface); border: 1.5px solid var(--grey-200); color: var(--text-2); }
.btn.ghost:hover { background: var(--grey-50); border-color: var(--grey-300); }
.btn.danger { background: var(--red-500); color: #fff; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn.sm { height: 42px; font-size: 14.5px; border-radius: var(--r-xs); padding: 0 16px; }

/* ===================== session ===================== */
.session { padding-top: 10px; }
.s-top { display: flex; align-items: center; gap: 10px; padding: 14px 2px 8px; }
.s-top .s-mode {
  font-size: 12px; font-weight: 700; color: var(--blue-700);
  background: var(--blue-50); padding: 5px 11px; border-radius: var(--r-pill);
}
.s-top .s-mode.flash { color: #9a6a00; background: #FFF3D9; }
.s-top .s-mode.exam { color: var(--green-700); background: var(--green-50); }
.s-top .s-prog { font-size: 13.5px; color: var(--text-3); font-weight: 600; }
.s-top .spacer { flex: 1; }

.pbar { height: 6px; background: var(--grey-150); border-radius: var(--r-pill); overflow: hidden; margin: 4px 2px 0; }
.pbar > i {
  display: block; height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--blue-400, var(--blue-500)), var(--blue-500));
  background: linear-gradient(90deg, #5AA0FF, var(--blue-500));
  transition: width .35s var(--e-out);
}

/* question card */
.qcard {
  margin-top: 16px; padding: 22px 20px 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-2);
}
.q-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tag {
  font-size: 11.5px; font-weight: 700; color: var(--text-2);
  background: var(--grey-100); padding: 4px 10px; border-radius: var(--r-pill);
}
.tag.subj { color: var(--blue-700); background: var(--blue-50); }
.q-meta .spacer { flex: 1; }
.bm-btn { font-size: 21px; color: var(--grey-300); transition: transform .18s var(--e-spring), color .15s; }
.bm-btn:hover { color: var(--amber-500); }
.bm-btn.on { color: var(--amber-500); transform: scale(1.06); }

.q-text {
  font-size: 19px; line-height: 1.55; font-weight: 600; letter-spacing: -.02em;
  color: var(--text); word-break: keep-all;
}
.q-img {
  display: block; margin: 16px auto 4px; max-width: 100%;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: #fff; padding: 8px;
}
.q-img.full { max-width: 100%; }
.q-imgnote { text-align: center; font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* choices */
.choices { display: grid; gap: 10px; margin-top: 20px; }
.choice {
  display: flex; align-items: flex-start; gap: 13px; text-align: left;
  padding: 15px 16px; border-radius: var(--r-sm);
  background: var(--surface); border: 1.5px solid var(--grey-200);
  font-size: 15.5px; line-height: 1.5; font-weight: 500; color: var(--text);
  transition: border-color .15s var(--e-out), background .15s var(--e-out),
              box-shadow .15s var(--e-out), transform .08s var(--e-out);
}
.choice:hover:not(.locked) { border-color: var(--blue-300); background: var(--blue-50); }
.choice:active:not(.locked) { transform: scale(.99); }
.choice .mark {
  flex: none; width: 27px; height: 27px; border-radius: 9px;
  background: var(--grey-100); color: var(--text-2);
  display: grid; place-items: center; font-size: 14px; font-weight: 700;
  transition: all .15s var(--e-out);
}
.choice .ctext { flex: 1; padding-top: 2px; word-break: keep-all; }
.choice.locked { cursor: default; }

.choice.correct {
  border-color: var(--green-500); background: var(--green-50);
  box-shadow: 0 0 0 1px var(--green-500) inset;
}
.choice.correct .mark { background: var(--green-500); color: #fff; }
.choice.wrong {
  border-color: var(--red-500); background: var(--red-50);
  box-shadow: 0 0 0 1px var(--red-500) inset;
  animation: shake .4s var(--e-out);
}
.choice.wrong .mark { background: var(--red-500); color: #fff; }
.choice.selected { border-color: var(--blue-500); background: var(--blue-50); box-shadow: 0 0 0 1px var(--blue-500) inset; }
.choice.selected .mark { background: var(--blue-500); color: #fff; }
.choice.dimmed { opacity: .5; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* verdict line under choices (practice/flash) */
.verdict { margin-top: 16px; display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 14.5px; }
.verdict.ok { color: var(--green-700); }
.verdict.no { color: var(--red-600); }
.verdict .v-ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 13px; }
.verdict.ok .v-ic { background: var(--green-500); }
.verdict.no .v-ic { background: var(--red-500); }

/* nav footer */
.s-nav {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; gap: 10px; padding: 14px 0 calc(16px + env(safe-area-inset-bottom));
  margin-top: 18px;
  background: linear-gradient(180deg, rgba(242,244,246,0), var(--bg) 38%);
}
.s-nav .btn { flex: 1; }
.s-nav .btn.narrow { flex: 0 0 auto; min-width: 58px; padding: 0 16px; }

/* question card enter animation */
.qcard.enter { animation: qin .32s var(--e-out); }
@keyframes qin { from { opacity: 0; transform: translateY(10px) scale(.995); } to { opacity: 1; transform: none; } }
.qcard.enter-rev { animation: qinrev .32s var(--e-out); }
@keyframes qinrev { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ===================== results ===================== */
.result-hero {
  margin-top: 18px; padding: 30px 22px; text-align: center;
  background: linear-gradient(160deg, var(--blue-600), var(--blue-500));
  border-radius: var(--r-lg); color: #fff; box-shadow: var(--sh-blue);
}
.result-hero .rh-label { font-size: 14px; font-weight: 600; opacity: .9; }
.result-hero .rh-score { font-size: 54px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; margin: 6px 0 2px; }
.result-hero .rh-score small { font-size: 22px; font-weight: 700; opacity: .8; }
.result-hero .rh-sub { font-size: 14.5px; font-weight: 600; opacity: .95; }

.ring-wrap { display: flex; justify-content: center; gap: 26px; margin-top: 18px; }
.subj-bars { margin-top: 20px; display: grid; gap: 12px; }
.subj-row { display: grid; grid-template-columns: 64px 1fr 52px; align-items: center; gap: 12px; }
.subj-row .sr-name { font-size: 13.5px; font-weight: 700; color: var(--text-2); }
.subj-row .sr-track { height: 9px; background: var(--grey-150); border-radius: var(--r-pill); overflow: hidden; }
.subj-row .sr-fill { height: 100%; border-radius: var(--r-pill); background: var(--blue-500); transition: width .6s var(--e-out); }
.subj-row .sr-val { font-size: 13px; font-weight: 700; color: var(--text-3); text-align: right; }

.review-list { margin-top: 14px; display: grid; gap: 8px; }
.rev-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  text-align: left; transition: background .14s, box-shadow .14s;
}
.rev-item:hover { box-shadow: var(--sh-1); }
.rev-item .ri-ic { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700; }
.rev-item .ri-ic.ok { background: var(--green-500); }
.rev-item .ri-ic.no { background: var(--red-500); }
.rev-item .ri-num { font-size: 13px; font-weight: 700; color: var(--text-3); flex: none; }
.rev-item .ri-q { flex: 1; min-width: 0; font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }

/* ===================== empty / loading ===================== */
.empty { text-align: center; padding: 60px 20px; color: var(--text-3); }
.empty .em-ic { font-size: 40px; margin-bottom: 12px; }
.empty .em-title { font-size: 16px; font-weight: 700; color: var(--text-2); }
.empty .em-sub { margin-top: 6px; font-size: 13.5px; }

/* ===================== toast ===================== */
#toast-host {
  position: fixed; left: 0; right: 0; bottom: 22px; z-index: 80;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 16px;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  max-width: 440px; width: max-content;
  padding: 12px 14px 12px 16px; border-radius: var(--r-sm);
  background: var(--grey-900); color: #fff; box-shadow: var(--sh-3);
  font-size: 14px; font-weight: 600;
  animation: toastin .3s var(--e-spring);
}
.toast.out { animation: toastout .25s var(--e-out) forwards; }
.toast .t-act {
  color: #8FC0FF; font-weight: 700; padding: 6px 10px; margin: -4px -2px -4px 4px;
  border-radius: var(--r-xs); white-space: nowrap;
}
.toast .t-act:hover { background: rgba(255,255,255,.1); }
@keyframes toastin { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastout { to { opacity: 0; transform: translateY(10px); } }

/* ===================== dialog ===================== */
.scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(23,31,40,.42); backdrop-filter: blur(2px);
  display: grid; place-items: end center;
  animation: fade .2s var(--e-out);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 760px;
  background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--sh-3); animation: sheetin .28s var(--e-out);
}
@keyframes sheetin { from { transform: translateY(100%); } to { transform: none; } }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--grey-200); margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 6px; font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.sheet .sheet-body { margin: 0 0 18px; color: var(--text-3); font-size: 14px; line-height: 1.5; max-height: 60vh; overflow: auto; }
.sheet .sheet-body:empty { display: none; }
.sheet .sheet-actions { display: flex; gap: 10px; }
.sheet .sheet-actions .btn { flex: 1; }

/* utility */
.muted { color: var(--text-3); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.hide { display: none !important; }

@media (max-width: 480px) {
  .page-head h1 { font-size: 23px; }
  .exam-grid { grid-template-columns: 1fr; }
  .q-text { font-size: 18px; }
}
