/* ============================================================
   SEPM Ch.9 Flashcards — iPhone / iPad first
   ============================================================ */

:root {
  --brand:        #00655f;
  --brand-soft:   #e3f1ef;
  --bg:           #f5f6f5;
  --surface:      #ffffff;
  --surface-2:    #eef0ef;
  --line:         #dcdfdd;
  --ink:          #16201f;
  --ink-2:        #5b6b68;
  --ink-3:        #8a9a97;

  --good:  #1c8b4b;
  --hard:  #c98a12;
  --again: #c0392b;
  --new:   #9aa8a5;

  --radius:  18px;
  --radius-s: 12px;
  --shadow: 0 1px 2px rgba(16,32,30,.06), 0 8px 24px -12px rgba(16,32,30,.18);
  --tap: 44px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

html[data-theme="dark"] {
  --brand:        #3fbfae;
  --brand-soft:   #103430;
  --bg:           #0b1114;
  --surface:      #151d20;
  --surface-2:    #1d272a;
  --line:         #2b373b;
  --ink:          #e7edec;
  --ink-2:        #a2b1af;
  --ink-3:        #6f807e;

  --good:  #45c47a;
  --hard:  #e0aa3e;
  --again: #ef6a5c;
  --new:   #55635f;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.8);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --brand:        #3fbfae;
    --brand-soft:   #103430;
    --bg:           #0b1114;
    --surface:      #151d20;
    --surface-2:    #1d272a;
    --line:         #2b373b;
    --ink:          #e7edec;
    --ink-2:        #a2b1af;
    --ink-3:        #6f807e;
    --good:  #45c47a;
    --hard:  #e0aa3e;
    --again: #ef6a5c;
    --new:   #55635f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.8);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
}

.mono { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- views ---------- */
.view {
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: max(16px, var(--safe-l));
  padding-right: max(16px, var(--safe-r));
}
#view-study { display: flex; flex-direction: column; padding: 0; }

/* ---------- banner ---------- */
.banner {
  position: sticky; top: 0; z-index: 40;
  padding: calc(8px + var(--safe-t)) 16px 8px;
  background: var(--hard); color: #12191b;
  font-size: 14px; text-align: center;
}

/* ============================ HOME ============================ */
.home-head { padding-top: calc(20px + var(--safe-t)); max-width: 900px; margin: 0 auto; }
.home-head-row { display: flex; align-items: flex-start; gap: 12px; }
.home-head-row > div { flex: 1; min-width: 0; }

.eyebrow {
  margin: 0 0 4px; font-size: 12px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--brand); font-weight: 700;
}
h1 { margin: 0 0 20px; font-size: 27px; line-height: 1.2; letter-spacing: -.02em; }
h1 .thin { color: var(--ink-3); font-weight: 300; }

.icon-btn {
  flex: none;
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface);
  transition: transform .12s, background .15s;
}
.icon-btn:active { transform: scale(.92); background: var(--surface-2); }

.ico-sun, .ico-back, .ico-shuffle { display: block; width: 20px; height: 20px; color: var(--ink-2); }
.ico-sun {
  border-radius: 50%;
  background: currentColor;
  box-shadow: inset -6px -3px 0 0 var(--surface);
}
.ico-back {
  width: 12px; height: 12px; margin-left: 4px;
  border-left: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor;
  transform: rotate(45deg);
}
.ico-shuffle {
  position: relative; width: 18px; height: 14px;
  border-top: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor;
  border-radius: 6px / 10px;
}

/* overview */
.overview {
  display: flex; align-items: center; gap: 18px;
  padding: 18px; margin-bottom: 16px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.ring-wrap { position: relative; width: 104px; height: 104px; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg {
  stroke: var(--brand); stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .6s cubic-bezier(.22,1,.36,1);
}
.ring-label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-label strong { font-size: 23px; letter-spacing: -.02em; }
.ring-label span { font-size: 11px; color: var(--ink-3); }

.overview-stats {
  flex: 1; min-width: 0;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px;
}
.stat { display: flex; align-items: baseline; gap: 6px; font-size: 13px; color: var(--ink-2); }
.stat b { font-size: 17px; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat.lv-good b  { color: var(--good); }
.stat.lv-hard b  { color: var(--hard); }
.stat.lv-again b { color: var(--again); }
.stat.lv-new b   { color: var(--ink-3); }

/* quick actions */
.quick { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-bottom: 28px; }
.quick-btn {
  min-height: 64px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: 2px; padding: 12px 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
  transition: transform .12s, border-color .15s;
}
.quick-btn:active { transform: scale(.97); }
.quick-btn b { font-size: 16px; letter-spacing: -.01em; }
.quick-btn span { font-size: 12.5px; color: var(--ink-3); line-height: 1.35; }
.quick-btn.primary {
  grid-column: 1 / -1;
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.quick-btn.primary span { color: rgba(255,255,255,.82); }

/* sections */
.sec-h {
  max-width: 900px; margin: 0 auto 10px;
  font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3);
}
.sec-list { list-style: none; margin: 0 auto 28px; padding: 0; max-width: 900px; display: grid; gap: 10px; }
.sec-item {
  width: 100%; min-height: var(--tap);
  display: block; padding: 14px 16px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
  transition: transform .12s;
}
.sec-item:active { transform: scale(.985); }
.sec-top { display: flex; align-items: baseline; gap: 10px; }
.sec-no {
  font-size: 13px; font-weight: 700; color: var(--brand);
  font-variant-numeric: tabular-nums; flex: none; min-width: 34px;
}
.sec-name { flex: 1; min-width: 0; font-size: 16px; letter-spacing: -.01em; }
.sec-n { font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; flex: none; }
.seg {
  display: flex; height: 6px; margin-top: 10px; border-radius: 3px; overflow: hidden;
  background: var(--surface-2);
}
.seg i { display: block; height: 100%; transition: width .45s cubic-bezier(.22,1,.36,1); }
.seg .s-good  { background: var(--good); }
.seg .s-hard  { background: var(--hard); }
.seg .s-again { background: var(--again); }

/* footer */
.home-foot {
  max-width: 900px; margin: 0 auto;
  padding-bottom: calc(28px + var(--safe-b));
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
}
.text-btn {
  min-height: var(--tap); padding: 0 2px;
  background: none; border: 0; color: var(--brand); font-size: 15px;
}
.text-btn.danger { color: var(--again); }
.disclaimer { flex-basis: 100%; margin: 4px 0 0; font-size: 12.5px; color: var(--ink-3); line-height: 1.5; }

/* ============================ STUDY ============================ */
.study-head {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) max(14px, var(--safe-r)) 10px max(14px, var(--safe-l));
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.study-meta { flex: 1; min-width: 0; text-align: center; }
#st-title {
  display: block; font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#st-count { display: block; font-size: 12.5px; color: var(--ink-3); }

.st-sub { display: flex; align-items: center; justify-content: center; gap: 8px; }
.lvl {
  padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  background: var(--surface-2); color: var(--ink-3);
}
.lvl[data-l="again"] { background: color-mix(in srgb, var(--again) 18%, transparent); color: var(--again); }
.lvl[data-l="hard"]  { background: color-mix(in srgb, var(--hard) 20%, transparent);  color: var(--hard); }
.lvl[data-l="good"]  { background: color-mix(in srgb, var(--good) 18%, transparent);  color: var(--good); }

/* toast */
.toast {
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-b));
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-size: 14.5px; font-weight: 600; text-align: center;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,.5);
  animation: toast-in .18s ease both;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.progress-track { height: 3px; background: var(--surface-2); }
.progress-fill {
  height: 100%; width: 0; background: var(--brand);
  transition: width .35s cubic-bezier(.22,1,.36,1);
}

.card-host {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px max(16px, var(--safe-r)) 8px max(16px, var(--safe-l));
}
.card {
  max-width: 46rem; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 18px;
}
.card-ref {
  display: inline-block; margin-bottom: 12px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand);
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.card-q {
  margin: 0; font-size: 20px; line-height: 1.4; letter-spacing: -.015em; font-weight: 600;
}
.card-hint { margin: 10px 0 0; font-size: 13.5px; color: var(--ink-3); }

/* answer block */
.answer { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.answer.reveal { animation: fadein .28s ease both; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.a-list { margin: 0; padding-left: 1.35em; display: grid; gap: 7px; }
.a-list li { font-size: 16.5px; line-height: 1.45; }
.a-list li::marker { color: var(--brand); font-weight: 700; font-variant-numeric: tabular-nums; }
.a-text { margin: 0; font-size: 16.5px; line-height: 1.5; }
.a-note {
  margin: 14px 0 0; padding: 10px 12px;
  background: var(--surface-2); border-radius: var(--radius-s);
  font-size: 14.5px; line-height: 1.45; color: var(--ink-2);
}
.a-note b { color: var(--ink); }

/* answer table (for comparison cards) */
.a-table { width: 100%; margin-top: 4px; border-collapse: collapse; font-size: 15px; }
.a-table th, .a-table td { padding: 7px 8px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.a-table th { color: var(--ink-2); font-size: 13px; font-weight: 700; }

/* ---------- choice questions ---------- */
.opts { display: grid; gap: 9px; margin-top: 18px; }
.opt {
  display: flex; align-items: flex-start; gap: 11px;
  min-height: var(--tap); width: 100%; padding: 12px 13px; text-align: left;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-s);
  transition: transform .1s, border-color .15s, background .15s;
}
.opt:active { transform: scale(.985); }
.opt-mark {
  flex: none; width: 24px; height: 24px; margin-top: 1px;
  display: grid; place-items: center;
  border: 1.5px solid var(--ink-3); border-radius: 50%;
  font-size: 12.5px; font-weight: 700; color: var(--ink-3);
  transition: all .15s;
}
.multi .opt-mark { border-radius: 7px; }
.opt-text { flex: 1; min-width: 0; font-size: 16px; line-height: 1.4; }

.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .opt-mark { border-color: var(--brand); background: var(--brand); color: #fff; }

.opt.ok      { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.opt.ok .opt-mark   { border-color: var(--good); background: var(--good); color: #fff; }
.opt.bad     { border-color: var(--again); background: color-mix(in srgb, var(--again) 12%, transparent); }
.opt.bad .opt-mark  { border-color: var(--again); background: var(--again); color: #fff; }
.opt.missed  { border-color: var(--good); border-style: dashed; }
.opt.missed .opt-mark { border-color: var(--good); color: var(--good); }
.opt[disabled] { opacity: 1; }

/* ---------- ordering question ---------- */
.order-list { display: grid; gap: 8px; margin-top: 18px; }
.ord {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 12px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-s);
}
.ord.ok  { border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, transparent); }
.ord.bad { border-color: var(--again); background: color-mix(in srgb, var(--again) 10%, transparent); }
.ord-n {
  flex: none; width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 50%; background: var(--brand); color: #fff;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.ord.bad .ord-n { background: var(--again); }
.ord.ok .ord-n  { background: var(--good); }
.ord-text { flex: 1; min-width: 0; font-size: 15.5px; line-height: 1.35; }
.ord-btns { flex: none; display: flex; gap: 4px; }
.ord-move {
  width: 38px; height: var(--tap);
  display: grid; place-items: center;
  background: var(--surface-2); border: 0; border-radius: 9px;
  transition: transform .1s, opacity .15s;
}
.ord-move:active { transform: scale(.9); }
.ord-move[disabled] { opacity: .3; }
.ord-move i {
  display: block; width: 9px; height: 9px;
  border-top: 2.5px solid var(--ink-2); border-right: 2.5px solid var(--ink-2);
}
.ord-move.up i   { transform: rotate(-45deg) translate(1px, 1px); }
.ord-move.down i { transform: rotate(135deg) translate(1px, 1px); }
.ord-fix { margin: 12px 0 0; font-size: 14px; color: var(--ink-2); }

/* verdict */
.verdict {
  display: flex; align-items: center; gap: 8px;
  margin-top: 16px; padding: 11px 13px; border-radius: var(--radius-s);
  font-size: 15.5px; font-weight: 600;
}
.verdict.ok  { background: color-mix(in srgb, var(--good) 14%, transparent);  color: var(--good); }
.verdict.bad { background: color-mix(in srgb, var(--again) 14%, transparent); color: var(--again); }

/* ---------- action bar ---------- */
.action-bar {
  flex: none;
  display: flex; gap: 8px;
  padding: 10px max(14px, var(--safe-r)) calc(10px + var(--safe-b)) max(14px, var(--safe-l));
  background: var(--surface); border-top: 1px solid var(--line);
}
.action-bar > * { flex: 1; }
.act {
  min-height: 52px; padding: 6px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border: 1.5px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  transition: transform .1s, filter .15s;
}
.act:active { transform: scale(.96); }
.act kbd {
  font: inherit; font-size: 11px; font-weight: 500; color: var(--ink-3);
  background: none; border: 0;
}
.act.wide { flex: 1; }
.act.brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.act.brand kbd { color: rgba(255,255,255,.7); }
.act.again { background: color-mix(in srgb, var(--again) 15%, var(--surface)); border-color: var(--again); color: var(--again); }
.act.hard  { background: color-mix(in srgb, var(--hard) 15%, var(--surface));  border-color: var(--hard);  color: var(--hard); }
.act.good  { background: color-mix(in srgb, var(--good) 15%, var(--surface));  border-color: var(--good);  color: var(--good); }
.act.again kbd, .act.hard kbd, .act.good kbd { color: currentColor; opacity: .65; }

/* ============================ DONE ============================ */
.done-wrap {
  max-width: 30rem; margin: 0 auto;
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  padding: 24px 0 calc(24px + var(--safe-b)); text-align: center;
}
.done-mark {
  width: 66px; height: 66px; margin: 0 auto 18px;
  border-radius: 50%; background: var(--brand-soft);
  position: relative;
}
.done-mark::after {
  content: ""; position: absolute; left: 24px; top: 19px;
  width: 15px; height: 26px;
  border-right: 4px solid var(--brand); border-bottom: 4px solid var(--brand);
  transform: rotate(45deg);
}
#view-done h2 { margin: 0 0 8px; font-size: 24px; letter-spacing: -.02em; }
.done-summary { margin: 0 0 24px; color: var(--ink-2); font-size: 16px; line-height: 1.55; }
.done-btns { display: grid; gap: 10px; }
.done-btns .quick-btn { align-items: center; text-align: center; }

/* ============================ TABLET / DESKTOP ============================ */
@media (min-width: 700px) {
  body { font-size: 17.5px; }
  h1 { font-size: 34px; }
  .quick { grid-template-columns: repeat(3, 1fr); }
  .quick-btn.primary { grid-column: auto; }
  .sec-list { grid-template-columns: 1fr 1fr; }
  .card { padding: 26px 24px; }
  .card-q { font-size: 22px; }
  .action-bar { justify-content: center; padding-left: 24px; padding-right: 24px; }
  .action-bar > * { max-width: 220px; }
  .card-host { padding-top: 24px; }
}

@media (min-width: 1000px) {
  .sec-list, .home-head, .sec-h, .home-foot { max-width: 900px; }
}

/* ---- dark theme: brand is light, so ink-on-brand must be dark ---- */
html[data-theme="dark"] .quick-btn.primary,
html[data-theme="dark"] .act.brand,
html[data-theme="dark"] .ord-n,
html[data-theme="dark"] .opt.sel .opt-mark,
html[data-theme="dark"] .opt.ok .opt-mark,
html[data-theme="dark"] .opt.bad .opt-mark { color: #08201d; }
html[data-theme="dark"] .quick-btn.primary span,
html[data-theme="dark"] .act.brand kbd { color: rgba(8,32,29,.7); }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .quick-btn.primary,
  html:not([data-theme="light"]) .act.brand,
  html:not([data-theme="light"]) .ord-n,
  html:not([data-theme="light"]) .opt.sel .opt-mark,
  html:not([data-theme="light"]) .opt.ok .opt-mark,
  html:not([data-theme="light"]) .opt.bad .opt-mark { color: #08201d; }
  html:not([data-theme="light"]) .quick-btn.primary span,
  html:not([data-theme="light"]) .act.brand kbd { color: rgba(8,32,29,.7); }
}

/* ============================ MOTION ============================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
