/* Clean, Apple-style interface: system font, grouped lists, restrained colour, light and dark mode. */
:root {
  color-scheme: light dark;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --label: #000000;
  --secondary: rgba(60, 60, 67, 0.6);
  --tertiary: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.18);
  --fill: rgba(120, 120, 128, 0.12);
  --accent: #007AFF;
  --accent-tint: rgba(0, 122, 255, 0.1);
  --green: #34C759;
  --green-tint: rgba(52, 199, 89, 0.12);
  --red: #FF3B30;
  --red-tint: rgba(255, 59, 48, 0.1);
  --orange: #FF9500;
  --yellow: #FFCC00;
  --indigo: #5856D6;
  --teal: #30B0C7;
  --pink: #FF2D55;
  --purple: #AF52DE;
  --nav: rgba(242, 242, 247, 0.8);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --card: #1C1C1E; --label: #FFFFFF;
    --secondary: rgba(235, 235, 245, 0.6); --tertiary: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6); --fill: rgba(120, 120, 128, 0.24);
    --accent: #0A84FF; --accent-tint: rgba(10, 132, 255, 0.18);
    --green: #30D158; --green-tint: rgba(48, 209, 88, 0.16);
    --red: #FF453A; --red-tint: rgba(255, 69, 58, 0.16);
    --orange: #FF9F0A; --yellow: #FFD60A; --indigo: #5E5CE6; --teal: #40C8E0; --pink: #FF375F; --purple: #BF5AF2;
    --nav: rgba(0, 0, 0, 0.72); --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --card: #1C1C1E; --label: #FFFFFF;
  --secondary: rgba(235, 235, 245, 0.6); --tertiary: rgba(235, 235, 245, 0.3);
  --separator: rgba(84, 84, 88, 0.6); --fill: rgba(120, 120, 128, 0.24);
  --accent: #0A84FF; --accent-tint: rgba(10, 132, 255, 0.18);
  --green: #30D158; --green-tint: rgba(48, 209, 88, 0.16);
  --red: #FF453A; --red-tint: rgba(255, 69, 58, 0.16);
  --orange: #FF9F0A; --yellow: #FFD60A; --indigo: #5E5CE6; --teal: #40C8E0; --pink: #FF375F; --purple: #BF5AF2;
  --nav: rgba(0, 0, 0, 0.72); --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--label);
  font: 17px/1.41 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -0.01em; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* Navigation bar */
.nav {
  position: sticky; top: 0; z-index: 10; height: 52px;
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  background: var(--nav); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.nav .title { font-weight: 600; font-size: 17px; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.nav a, .nav button.link { background: none; border: 0; color: var(--accent); font-size: 17px; cursor: pointer; padding: 8px 0; display: inline-flex; align-items: center; gap: 4px; }
.nav .spacer { width: 60px; }

main { max-width: 720px; margin: 0 auto; padding: 8px 16px 120px; }
.large-title { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: 0.01em; margin: 16px 0 4px; }
.subtitle { color: var(--secondary); margin: 0 0 24px; font-size: 17px; }
h2.section { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--secondary); letter-spacing: 0.02em; margin: 28px 16px 8px; }
h2.section-lg { font-size: 22px; font-weight: 700; margin: 32px 0 10px; letter-spacing: 0.01em; }
.footnote { font-size: 13px; color: var(--secondary); margin: 8px 16px 0; }

/* Cards and grouped lists */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card.pad { padding: 16px; }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list > li { position: relative; }
.list > li + li::before { content: ""; position: absolute; top: 0; right: 0; left: 60px; border-top: 0.5px solid var(--separator); }
.list.plain > li + li::before { left: 16px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 16px; width: 100%; background: none; border: 0; text-align: left; cursor: pointer; color: var(--label); }
.row:active { background: var(--fill); }
@media (hover: hover) { .row:hover { background: var(--fill); } }
.row .text { flex: 1; min-width: 0; }
.row .primary { font-size: 17px; }
.row .secondary { font-size: 13px; color: var(--secondary); margin-top: 1px; }
.row .value { color: var(--secondary); font-size: 15px; white-space: nowrap; }
.chev { width: 8px; height: 13px; flex: none; color: var(--tertiary); }
.icon { width: 30px; height: 30px; border-radius: 7px; flex: none; display: grid; place-items: center; color: #fff; }
.icon svg { width: 18px; height: 18px; }

/* Hero tiles on home */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tile { background: var(--card); border-radius: 16px; padding: 16px; border: 0; text-align: left; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; min-height: 132px; color: var(--label); transition: transform .15s ease; }
.tile:active { transform: scale(0.98); }
.tile .icon { width: 36px; height: 36px; border-radius: 9px; }
.tile .icon svg { width: 22px; height: 22px; }
.tile .t { font-size: 17px; font-weight: 600; margin-top: auto; }
.tile .d { font-size: 13px; color: var(--secondary); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 20px; border-radius: 12px; border: 0; font-size: 17px; font-weight: 600; cursor: pointer; background: var(--accent); color: #fff; width: 100%; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.secondary { background: var(--accent-tint); color: var(--accent); }
.btn.plain { background: none; color: var(--accent); font-weight: 400; }
.btn-row { display: flex; gap: 12px; }

/* Progress */
.progress { height: 4px; background: var(--fill); border-radius: 2px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s ease; }
.meter { height: 6px; background: var(--fill); border-radius: 3px; overflow: hidden; width: 72px; flex: none; }
.meter > span { display: block; height: 100%; border-radius: 3px; }

/* Quiz */
.q-head { display: flex; justify-content: space-between; align-items: center; margin: 16px 4px 10px; font-size: 13px; color: var(--secondary); }
.q-area { font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.03em; font-size: 12px; }
.q-text { font-size: 22px; line-height: 28px; font-weight: 600; margin: 4px 4px 16px; letter-spacing: 0; }
.stim { margin: 0 0 16px; padding: 12px; }
.options { display: grid; gap: 10px; }
.options.visual { grid-template-columns: repeat(2, 1fr); }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; min-height: 56px; background: var(--card); border: 1.5px solid transparent; border-radius: 12px; text-align: left; cursor: pointer; box-shadow: var(--shadow); font-size: 17px; color: var(--label); transition: border-color .15s, background .15s; }
@media (hover: hover) { .opt:not(:disabled):hover { border-color: var(--accent); } }
.opt .key { width: 26px; height: 26px; border-radius: 13px; border: 1.5px solid var(--tertiary); display: grid; place-items: center; font-size: 13px; font-weight: 600; color: var(--secondary); flex: none; }
.opt .ot { flex: 1; }
.opt.visual-opt { flex-direction: column; align-items: stretch; padding: 10px; }
.opt.visual-opt .key { align-self: flex-start; }
.opt:disabled { cursor: default; }
.opt.correct { border-color: var(--green); background: var(--green-tint); }
.opt.correct .key { background: var(--green); border-color: var(--green); color: #fff; }
.opt.wrong { border-color: var(--red); background: var(--red-tint); }
.opt.wrong .key { background: var(--red); border-color: var(--red); color: #fff; }
.opt.dim { opacity: 0.5; }

.feedback { margin-top: 16px; padding: 16px; animation: rise .25s ease; }
.feedback .verdict { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.feedback .verdict.ok { color: var(--green); }
.feedback .verdict.no { color: var(--red); }
.feedback p { margin: 6px 0; font-size: 16px; line-height: 1.45; }
.feedback .why { color: var(--label); }
.feedback .label { font-size: 13px; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: 0.02em; margin-top: 14px; }
.figure { background: var(--bg); border-radius: 10px; padding: 12px; margin-top: 12px; }
details.figure summary { cursor: pointer; color: var(--accent); font-size: 15px; list-style: none; }
details.figure summary::-webkit-details-marker { display: none; }

.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--nav); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: 0.5px solid var(--separator); }
.dock > div { max-width: 720px; margin: 0 auto; }

/* Illustrations */
svg.illus { width: 100%; height: auto; display: block; max-height: 260px; }
svg.illus .lbl { fill: var(--label); font-size: 11px; font-family: inherit; }
svg.illus .lbl.small { font-size: 10px; }
svg.illus .lbl.strong { font-weight: 600; font-size: 12px; }
svg.illus .lbl.sec { fill: var(--secondary); }
svg.illus .lbl.accent { fill: var(--accent); }
svg.illus .lbl.inv { fill: var(--card); }

/* Summary */
.score { text-align: center; padding: 28px 16px 20px; }
.ring { width: 132px; height: 132px; margin: 0 auto 12px; }
.score .big { font-size: 34px; font-weight: 700; }
.score .sub { color: var(--secondary); }
.status { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--secondary); font-size: 13px; margin-top: 10px; }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--tertiary); }
.dot.ok { background: var(--green); }

/* Forms */
.field { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 52px; }
.field label { width: 110px; flex: none; }
.field input { flex: 1; border: 0; background: none; font: inherit; color: var(--label); padding: 14px 0; outline: none; min-width: 0; }
.field input::placeholder { color: var(--tertiary); }

/* Segmented control */
.segmented { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; margin: 0 0 16px; }
.segmented button { flex: 1; border: 0; background: none; padding: 7px 8px; font-size: 13px; font-weight: 500; border-radius: 7px; cursor: pointer; color: var(--label); }
.segmented button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* Learn sheet */
.sqa { font-size: 15px; color: var(--secondary); line-height: 1.45; }
.fig-grid { display: grid; gap: 12px; }

/* Lecturer table */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); }
table.heat { border-collapse: collapse; font-size: 13px; min-width: 100%; }
table.heat th, table.heat td { padding: 8px 10px; text-align: center; border-bottom: 0.5px solid var(--separator); white-space: nowrap; }
table.heat th { font-weight: 600; color: var(--secondary); font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; }
table.heat th:first-child, table.heat td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
.pill { display: inline-block; min-width: 42px; padding: 2px 8px; border-radius: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pill.hi { background: var(--green-tint); color: var(--green); }
.pill.mid { background: rgba(255,149,0,.14); color: var(--orange); }
.pill.lo { background: var(--red-tint); color: var(--red); }
.pill.na { color: var(--tertiary); }

.empty { text-align: center; color: var(--secondary); padding: 32px 16px; }
.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--card); padding: 10px 16px; border-radius: 20px; box-shadow: 0 4px 20px rgba(0,0,0,.15); font-size: 15px; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 420px) { .options.visual { grid-template-columns: 1fr; } .q-text { font-size: 20px; line-height: 25px; } }
.fig-cap { font-size: 14px; color: var(--secondary); margin-top: 8px; line-height: 1.4; }
.fig-cap strong { color: var(--label); font-weight: 600; }
.lib-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.prose h3 { font-size: 17px; margin: 18px 0 4px; }
.prose h3:first-child { margin-top: 0; }
.prose p { margin: 0; color: var(--label); font-size: 16px; }
.feedback .verdict svg { width: 22px; height: 22px; flex: none; }
.tiles { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { min-height: 124px; }
@media print { .nav, .btn, .btn-row, #manage { display: none !important; } body { background: #fff; } }
table.heat th { white-space: normal; max-width: 96px; line-height: 1.2; vertical-align: bottom; }
.fig-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* ===== Apple-style refinement (redesign proposal) ===== */
:root {
  --elevated: #FFFFFF;
  --art-bg: #F7F7F9;
  /* Layered, soft shadows: only on elevated surfaces (hero, artwork cards, sheet). Lists stay flat, as in iOS. */
  --shadow-card: 0 0.5px 1px rgba(0,0,0,.04), 0 2px 6px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --shadow-hero: 0 1px 2px rgba(0,0,0,.04), 0 6px 16px rgba(0,0,0,.06), 0 18px 48px rgba(0,0,0,.08);
  --shadow-sheet: 0 -1px 0 rgba(0,0,0,.04), 0 -8px 40px rgba(0,0,0,.14);
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --elevated: #2C2C2E; --art-bg: #2C2C2E; --shadow-card: none; --shadow-hero: none; --shadow-sheet: 0 -1px 0 rgba(255,255,255,.06); }
}
:root[data-theme="dark"] { --elevated: #2C2C2E; --art-bg: #2C2C2E; --shadow-card: none; --shadow-hero: none; --shadow-sheet: 0 -1px 0 rgba(255,255,255,.06); }

.large-title { margin-top: 20px; }
.section-lg { font-size: 22px; font-weight: 700; letter-spacing: 0.005em; margin: 36px 4px 12px; }

/* Hero */
.hero { background: var(--card); border-radius: 20px; box-shadow: var(--shadow-hero); overflow: hidden; display: grid; grid-template-columns: 1fr; }
.hero-art { background: var(--art-bg); padding: 18px 24px 8px; }
.hero-art svg.illus { max-height: 170px; }
.hero-body { padding: 18px 20px 20px; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }
.hero-title { font-size: 22px; line-height: 27px; font-weight: 700; margin: 4px 0 4px; }
.hero-sub { margin: 0 0 16px; color: var(--secondary); font-size: 15px; }
.capsule { border: 0; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; height: 44px; padding: 0 28px; border-radius: 22px; cursor: pointer; }
.capsule:active { opacity: .75; }
@media (min-width: 640px) { .hero { grid-template-columns: 1.1fr 1fr; align-items: center; } .hero-art { padding: 24px; height: 100%; display: grid; align-items: center; } }

/* Topic cards with diagram artwork */
.topic-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (min-width: 640px) { .topic-grid { grid-template-columns: repeat(3, 1fr); } }
.topic-card { border: 0; padding: 0; text-align: left; background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-card); cursor: pointer; color: var(--label); display: flex; flex-direction: column; transition: transform .2s cubic-bezier(.2,.8,.2,1); }
@media (hover: hover) { .topic-card:hover { transform: translateY(-2px); } }
.topic-card:active { transform: scale(.98); }
.topic-art { background: var(--art-bg); aspect-ratio: 16 / 10; display: grid; place-items: center; padding: 10px; overflow: hidden; }
.topic-art svg.illus { max-height: 100%; }
.topic-art svg .lbl { display: none; } /* artwork only: labels are unreadable at thumbnail size */
.topic-art img { width: 100%; height: 100%; object-fit: cover; }
.topic-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 12px; }
.topic-name { font-size: 15px; font-weight: 600; line-height: 20px; }
.topic-meta .secondary { font-size: 12px; color: var(--secondary); margin-top: 1px; }
.mini-ring { flex: none; }

/* Lists: flat, iOS inset grouped */
.list { box-shadow: none; }
.list.plain > li + li::before, .list > li + li::before { left: 16px; }

/* Answers as one grouped list */
.options.grouped { gap: 0; background: var(--card); border-radius: 12px; overflow: hidden; }
.options.grouped .opt { border: 0; border-radius: 0; box-shadow: none; background: none; min-height: 52px; position: relative; }
.options.grouped .opt + .opt::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--separator); }
.options.grouped .opt.correct { background: var(--green-tint); }
.options.grouped .opt.wrong { background: var(--red-tint); }
.opt .mark { width: 22px; height: 22px; flex: none; }
.opt .mark .sym, .verdict .sym { width: 22px; height: 22px; display: block; }
.opt.visual-opt { position: relative; box-shadow: var(--shadow-card); border: 2px solid transparent; }
.opt.visual-opt .corner { position: absolute; top: 8px; left: 10px; font-size: 12px; font-weight: 600; color: var(--secondary); }
.opt.visual-opt .mark { position: absolute; top: 8px; right: 8px; }
.opt.visual-opt.correct { border-color: var(--green); }
.opt.visual-opt.wrong { border-color: var(--red); }
.hint { text-align: center; color: var(--secondary); font-size: 13px; margin: 14px 0 0; }
body.has-sheet .hint { display: none; }

/* Bottom sheet */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; pointer-events: none; animation: sheet-in .38s cubic-bezier(.2,.9,.25,1); }
.sheet-inner { pointer-events: auto; width: 100%; max-width: 720px; max-height: 56vh; display: flex; flex-direction: column; background: var(--elevated); border-radius: 14px 14px 0 0; box-shadow: var(--shadow-sheet); }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--tertiary); margin: 6px auto 4px; flex: none; }
.sheet-body { overflow-y: auto; padding: 8px 20px 4px; }
.sheet-body p { margin: 4px 0 8px; font-size: 16px; line-height: 1.45; }
.sheet-body .label { font-size: 13px; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: .02em; margin-top: 14px; }
.sheet-body .verdict { display: flex; gap: 8px; align-items: center; font-size: 20px; font-weight: 700; margin: 4px 0 6px; }
.sheet-body .verdict.ok { color: var(--green); } .sheet-body .verdict.no { color: var(--red); }
.sheet-body .figure { background: var(--bg); border-radius: 12px; padding: 12px; margin: 12px 0 8px; }
.sheet-foot { padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 0.5px solid var(--separator); }
body.has-sheet main { padding-bottom: 70vh; }
@media (min-width: 760px) { .sheet { bottom: 16px; } .sheet-inner { border-radius: 16px; } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }

/* Score card */
.card.score { box-shadow: var(--shadow-card); border-radius: 20px; }
