@import url("https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap");

:root {
  color-scheme: light;
  --text-strong: #222329;
  --text-primary: #3f3f49;
  --text-secondary: #5e5e6b;
  --ink: var(--text-primary);
  --ink-strong: var(--text-strong);
  --muted: var(--text-secondary);
  --line: #d9d7d2;
  --paper: #ffffff;
  --wash: #faf6ec;
  --functional: #287cae;
  --functional-dark: #216b96;
  --study-blue: #287cae;
  --study-blue-light: #397fa8;
  --terracotta: #b75017;
  --terracotta-dark: #8d3c12;
  --terracotta-soft: #f8e9e1;
  --terracotta-line: #dfb9a5;
  --soft: var(--terracotta-soft);
  --green: #23833a;
  --green-soft: #ebf5f3;
  --content-olive: #66733d;
  --review-orange: #b75017;
  --answer-no: #c9473a;
  --answer-part: #6b687a;
  --answer-yes: #23833a;
  --amber: #b56642;
  --amber-soft: #fdf0eb;
  --shadow: 0 16px 45px rgba(23, 32, 51, 0.07);
  font-family: "Open Sans", Arial, sans-serif;
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--wash); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--wash);
  color: var(--ink);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid var(--soft); box-shadow: 0 0 0 2px var(--study-blue-light); outline-offset: 2px; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  min-height: 64px;
  padding: 10px max(18px, calc((100vw - 1120px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
}
.brand { width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--ink-strong); padding: 4px; display: grid; place-items: center; cursor: pointer; }
.brand-mark { width: 30px; height: 36px; object-fit: contain; display: block; }

main { width: min(100%, 1120px); margin: 0 auto; flex: 1; padding: 34px 24px 60px; }
main:focus { outline: none; }
.loading-state { min-height: 60vh; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.loader { width: 34px; height: 34px; border: 3px solid var(--soft); border-top-color: var(--functional); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

.eyebrow { margin: 0 0 7px; color: var(--functional); text-transform: uppercase; letter-spacing: .13em; font-size: .65rem; font-weight: 700; }
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; color: var(--ink-strong); font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.05; letter-spacing: -.04em; font-weight: 600; }
h2 { margin: 0; color: var(--ink-strong); font-size: clamp(1.4rem, 3vw, 1.9rem); line-height: 1.15; letter-spacing: -.03em; font-weight: 600; }
.lede { max-width: 720px; margin: 15px 0 0; color: var(--muted); font-size: 1rem; line-height: 1.6; }
.hero-copy { max-width: 820px; }

.library-actions { margin: 24px 0 17px; display: flex; align-items: center; gap: 17px; }
.library-actions p { margin: 0; color: var(--muted); font-size: .84rem; }
.continue-button { min-height: 48px; }
.text-button, .back-link { min-height: 44px; border: 0; background: transparent; color: var(--functional-dark); font-weight: 700; cursor: pointer; padding: 8px 0; }
.library-options { width: max-content; max-width: 100%; margin: 18px 0 0 auto; color: var(--muted); font-size: .74rem; }
.library-options summary { min-height: 44px; display: flex; align-items: center; justify-content: flex-end; cursor: pointer; }
.library-options .text-button { display: block; margin-left: auto; font-size: .74rem; }

.deck-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.deck-card { width: 100%; min-height: 132px; padding: 0; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); color: var(--ink); text-align: left; cursor: pointer; box-shadow: 0 3px 12px rgba(23,32,51,.025); display: grid; grid-template-columns: 52px 1fr 28px; overflow: hidden; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.deck-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(23,32,51,.09); border-color: var(--terracotta-line); }
.deck-order { display: grid; place-items: center; background: var(--terracotta); color: #fff; font-weight: 700; font-size: 1rem; }
.deck-body { min-width: 0; padding: 15px 17px 13px; display: flex; flex-direction: column; }
.deck-meta { color: var(--muted); font-size: .63rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.deck-title { margin-top: 9px; color: var(--ink-strong); font-size: 1.02rem; line-height: 1.25; letter-spacing: -.015em; }
.deck-indicators { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: .68rem; }
.priority { color: var(--functional-dark); font-weight: 600; white-space: nowrap; }
.stars-filled { color: var(--functional); letter-spacing: .04em; }
.stars-empty { color: #c9c7cf; letter-spacing: .04em; }
.progress-track { display: block; height: 4px; margin-top: auto; padding-top: 10px; background: linear-gradient(to bottom, transparent 10px, #f1eef1 10px); border-radius: 99px; overflow: hidden; }
.progress-track > span { display: block; height: 4px; background: var(--study-blue); border-radius: 99px; }
.deck-arrow { display: grid; place-items: center; color: var(--functional); font-weight: 700; }

.back-link { margin-bottom: 13px; }
.chapter-hero { padding: 25px 27px; display: grid; grid-template-columns: 1fr auto; gap: 26px; align-items: end; background: var(--paper); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.chapter-hero .eyebrow { color: var(--functional); }
.chapter-hero h1 { color: var(--ink-strong); font-size: clamp(1.9rem, 4.5vw, 3rem); }
.chapter-priority { margin-top: 15px; display: flex; flex-wrap: wrap; gap: 9px 13px; color: var(--muted); font-size: .78rem; }
.chapter-scorecard { display: flex; gap: 8px; }
.chapter-scorecard span { min-width: 76px; padding: 11px; display: grid; text-align: center; border: 1px solid transparent; border-radius: 11px; color: #fff; font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.chapter-scorecard .scorecard-content { background: var(--content-olive); }
.chapter-scorecard .scorecard-review { background: var(--review-orange); }
.chapter-scorecard strong { color: #fff; font-size: 1.25rem; font-weight: 700; }
.mode-panel { margin: 20px 0 28px; padding: 13px 15px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); }
.mode-panel > div:first-child { display: grid; gap: 3px; }
.mode-panel span { color: var(--muted); font-size: .76rem; }
.mode-switch { padding: 4px; display: flex; border-radius: 10px; background: #f1eef1; }
.mode-switch button { min-height: 44px; border: 0; border-radius: 8px; padding: 8px 11px; background: transparent; color: var(--muted); font-size: .75rem; font-weight: 700; cursor: pointer; }
.mode-switch button.active { background: var(--functional); color: white; box-shadow: 0 0 0 3px var(--soft); }
.cf-heading { margin-bottom: 12px; }
.cf-list { display: grid; gap: 9px; }
.cf-card { width: 100%; min-height: 84px; padding: 0; display: grid; grid-template-columns: minmax(0,1fr) 120px 30px; align-items: stretch; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); color: var(--ink); text-align: left; cursor: pointer; overflow: hidden; transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease; }
.cf-card:hover { border-color: var(--terracotta-line); transform: translateX(3px); box-shadow: 0 7px 20px rgba(23,32,51,.07); }
.cf-main { min-width: 0; padding: 13px 17px; display: grid; align-content: center; }
.cf-main strong { color: var(--ink-strong); font-size: .9rem; line-height: 1.25; }
.cf-count { padding: 11px; display: grid; place-content: center; text-align: center; border-left: 1px solid #f1eef1; }
.cf-count strong { color: var(--functional-dark); font-size: .95rem; }
.cf-count small { color: var(--muted); font-size: .62rem; font-weight: 600; }
.cf-count span { color: var(--muted); font-size: .62rem; }
.cf-arrow { display: grid; place-items: center; color: var(--functional); font-weight: 700; }
.chapter-session { width: 100%; margin-top: 15px; padding: 15px 17px; display: flex; justify-content: space-between; gap: 18px; align-items: center; border: 0; border-radius: 13px; background: var(--functional); color: white; text-align: left; cursor: pointer; }
.chapter-session > span:first-child { display: grid; gap: 2px; }
.chapter-session small { color: rgba(255,255,255,.76); }

.session { width: min(100%, 1080px); min-height: calc(100vh - 32px); margin: 0 auto; display: flex; flex-direction: column; }
.session-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 13px; padding: 12px 14px; background: var(--study-blue-light); color: white; border-radius: 14px 14px 0 0; }
.back-button { width: 44px; height: 44px; border: 0; border-radius: 10px; background: rgba(255,255,255,.16); color: white; font-weight: 700; cursor: pointer; }
.session-title { min-width: 0; }
.session-title p, .session-title h1 { margin: 0; }
.session-title p { color: rgba(255,255,255,.82); font-size: .65rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.session-title h1 { margin-top: 3px; color: white; font-size: clamp(1.05rem, 3.8vw, 1.45rem); white-space: normal; overflow: visible; letter-spacing: -.02em; font-weight: 600; }
.counter { color: white; font-size: .78rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.session-progress { height: 4px; margin: 10px 0 13px; background: #e6e3e8; border-radius: 99px; overflow: hidden; }
.session-progress span { display: block; height: 100%; background: var(--functional); }

.flashcard { width: 100%; height: clamp(430px, 64vh, 680px); min-height: 430px; padding: clamp(24px, 5vw, 48px); display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); box-shadow: 0 8px 20px rgba(63,63,73,.09); position: relative; }
.flashcard.is-revealed { border-color: var(--line); background: var(--paper); }
.card-topline { display: flex; justify-content: space-between; gap: 18px; }
.card-kicker { color: var(--study-blue-light); font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; }
.card-side { color: var(--muted); font-size: .64rem; text-transform: uppercase; letter-spacing: .09em; }
.card-content { flex: 1; min-height: 0; margin: 0; padding: 28px 4px; display: flex; align-items: center; overflow-y: auto; overscroll-behavior: contain; }
.card-question { max-width: 800px; margin: auto; color: var(--ink); text-align: center; font-size: clamp(1.55rem, 4.6vw, 2.55rem); font-weight: 400; line-height: 1.4; letter-spacing: -.025em; white-space: pre-line; }
.quantity-join { white-space: nowrap; }
.quantity-separator { display: inline-block; margin: 0 .3em; color: currentColor; font-size: 1.35em; font-weight: 700; line-height: .75; vertical-align: -.06em; }
.card-answer { width: min(100%, 820px); min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.answer-question { margin: 0; color: var(--ink-strong); font-size: clamp(1rem, 2.2vw, 1.2rem); font-weight: 600; line-height: 1.45; text-align: left; }
.answer-divider { height: 2px; flex: 0 0 auto; background: var(--study-blue); border-radius: 99px; opacity: .7; }
.answer-body { flex: 1; display: grid; align-content: center; gap: 14px; text-align: center; }
.answer-main { margin: 0; color: var(--ink); font-size: clamp(1.2rem, 3.3vw, 1.85rem); font-weight: 400; line-height: 1.55; white-space: pre-line; }
.answer-extra { margin: 0; color: var(--muted); line-height: 1.62; white-space: pre-line; }
.answer-segments {
  width: min(100%, 780px);
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
  text-align: left;
  white-space: normal;
}
.answer-main.answer-segments { font-size: clamp(1rem, 2.25vw, 1.3rem); font-weight: 400; line-height: 1.45; }
.answer-extra.answer-segments,
.formula.answer-segments { margin: 0; line-height: 1.5; }
.answer-segments li {
  position: relative;
  padding: 13px 16px 13px 50px;
  border: 1px solid var(--terracotta-line);
  border-left: 4px solid var(--terracotta);
  border-radius: 9px;
  background: #fff8f4;
  box-shadow: 0 2px 7px rgba(183, 80, 23, .07);
}
.answer-segments li::before {
  content: "";
  position: absolute;
  left: 18px;
  top: 1.05em;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--terracotta);
  box-shadow: 0 0 0 5px var(--terracotta-soft);
}
.segment-label { color: var(--terracotta-dark); font-weight: 700; }
.segment-separator { color: var(--terracotta); font-weight: 700; }
.formula-answer { width: min(100%, 780px); margin: 0 auto; display: grid; justify-items: center; gap: 18px; text-align: center; }
.math-expression,
.formula {
  margin: 0;
  padding: 8px 0 8px 18px;
  border: 0;
  border-left: 4px solid var(--terracotta);
  border-radius: 0;
  background: transparent;
  color: var(--ink-strong);
  font-family: "Cambria Math", "STIX Two Math", Georgia, serif;
  font-size: clamp(1.35rem, 3.8vw, 2.15rem);
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  white-space: pre-line;
}
.math-expression sup { font-size: .62em; vertical-align: .55em; }
.mathml-expression {
  max-width: 100%;
  padding: .16em .08em;
  overflow-x: auto;
  overflow-y: hidden;
  font-family: inherit;
  font-size: 1em;
}
.mathml-expression mfrac { padding: 0 .2em; }
.answer-segments .mathml-expression { font-size: 1.12em; }
.formula-explanation { max-width: 720px; margin: 0; color: var(--ink); font-size: clamp(1.05rem, 2.7vw, 1.45rem); line-height: 1.55; }
.formula.answer-segments { padding: 0; border-left: 0; font-family: "Open Sans", Arial, sans-serif; font-size: inherit; }
.reveal { min-height: 54px; margin-top: 22px; padding: 13px 17px; border: 0; border-radius: 13px; background: var(--study-blue); color: white; font-weight: 600; cursor: pointer; }

.assessment { margin-top: 14px; padding: 13px 15px; display: grid; grid-template-columns: 1fr auto; gap: 17px; align-items: center; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); }
.assessment > div:first-child { display: grid; gap: 3px; }
.assessment > div:first-child span { color: var(--muted); font-size: .69rem; }
.rating-buttons { display: grid; grid-template-columns: repeat(3, minmax(108px, 1fr)); gap: 8px; }
.rating-button { min-height: 48px; padding: 8px 14px; border: 0; border-radius: 999px; color: white; font-weight: 600; cursor: pointer; box-shadow: 0 3px 9px rgba(112,96,112,.13); }
.rating-button.no { background: var(--answer-no); }
.rating-button.almost { background: var(--answer-part); }
.rating-button.yes { background: var(--answer-yes); }
.rating-button:hover { filter: brightness(.96); }

.completion, .empty-session { min-height: 66vh; display: grid; place-content: center; justify-items: center; text-align: center; }
.completion-mark { width: 68px; height: 68px; margin-bottom: 17px; display: grid; place-items: center; border-radius: 18px; background: var(--green-soft); color: var(--green); font-size: 1.8rem; font-weight: 700; }
.completion h1, .empty-session h1 { font-size: clamp(2rem, 6vw, 3.2rem); }
.completion p:not(.eyebrow), .empty-session p:not(.eyebrow) { max-width: 620px; color: var(--muted); line-height: 1.65; }
.completion-actions { margin-top: 15px; display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; }
.primary-button, .secondary-button { padding: 12px 16px; border-radius: 11px; font-weight: 700; cursor: pointer; }
.primary-button { border: 0; background: var(--functional); color: white; }
.secondary-button { border: 1px solid var(--line); background: var(--paper); color: var(--functional-dark); }
.error-state { max-width: 620px; margin: 12vh auto; padding: 23px; border: 1px solid #efd9cf; border-radius: 13px; background: var(--amber-soft); color: #70420c; }

footer { padding: 18px max(18px, calc((100vw - 1120px) / 2)); display: flex; justify-content: space-between; gap: 18px; border-top: 1px solid var(--line); background: rgba(255,255,255,.92); color: var(--muted); font-size: .68rem; }
footer p { margin: 0; }

body[data-view="session"] .topbar,
body[data-view="session"] footer { display: none; }
body[data-view="session"] main { width: 100%; max-width: none; padding: 16px 20px; }

@media (max-width: 820px) {
  .deck-grid { grid-template-columns: 1fr; }
  .chapter-hero { grid-template-columns: 1fr; }
  .chapter-scorecard { justify-content: flex-start; }
  .assessment { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { min-height: 58px; padding: 9px 14px; }
  .brand-mark { width: 27px; height: 32px; }
  main { padding: 24px 13px 40px; }
  .library-actions { align-items: flex-start; flex-direction: column; gap: 9px; }
  .deck-card { grid-template-columns: 44px 1fr 22px; }
  .deck-body { padding: 13px 11px 11px; }
  .chapter-hero { padding: 20px 17px; }
  .chapter-scorecard { display: grid; grid-template-columns: repeat(3, 1fr); }
  .chapter-scorecard span { min-width: 0; }
  .mode-panel { align-items: stretch; flex-direction: column; }
  .mode-switch { display: grid; grid-template-columns: 1fr 1fr; }
  .cf-card { min-height: 92px; grid-template-columns: minmax(0,1fr) 82px 24px; }
  .cf-count { padding: 8px 4px; }
  .cf-main { padding: 11px; }
  .cf-main strong { font-size: .83rem; }
  .chapter-session { align-items: flex-start; }
  .session-head { gap: 9px; padding: 10px; border-radius: 11px 11px 0 0; }
  .back-button { width: 44px; height: 44px; }
  body[data-view="session"] main { padding: 10px 12px 18px; }
  .flashcard { height: clamp(430px, 64vh, 600px); min-height: 430px; padding: 20px 18px; border-radius: 9px; }
  .card-content { padding: 22px 0; }
  .card-question { font-size: clamp(1.35rem, 6.5vw, 1.75rem); }
  .rating-buttons { grid-template-columns: repeat(3, 1fr); }
  .rating-button { min-width: 0; min-height: 48px; padding: 7px 5px; font-size: .72rem; }
  footer { padding: 14px; flex-direction: column; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
