:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #15202d;
  --muted: #5f6c7b;
  --line: #dde3ea;
  --brand: #12355b;
  --primary: #1b4f86;
  --primary-ink: #ffffff;
  --accent: #c8352e;
  --ok: #1d7f47;
  --ok-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf1dc;
  --private: #6b4bb3;
  --private-soft: #f1ecfb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 8px rgba(16, 24, 40, .06);
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319;
    --surface: #161c24;
    --surface-2: #1f2731;
    --text: #e7edf4;
    --muted: #93a1b2;
    --line: #2a3441;
    --brand: #0f2740;
    --primary: #3d7fd1;
    --primary-ink: #ffffff;
    --accent: #ef6b62;
    --ok: #4fc283;
    --ok-soft: #173326;
    --warn: #f0b44f;
    --warn-soft: #3a2c12;
    --private: #b9a1f0;
    --private-soft: #2a2140;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- top bar & tab bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 650; font-size: 17px; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ball { width: 26px; height: 26px; color: #fff; flex: none; }
.brand { margin-right: auto; }
.who { font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 480px) { .who { display: none; } }
.topbar .btn.ghost { color: #fff; border-color: rgba(255, 255, 255, .35); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar a.active { color: var(--primary); }

.view { max-width: 860px; margin: 0 auto; padding: 16px 16px 40px; }

/* ---------- building blocks ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled, .btn.disabled { opacity: .55; cursor: default; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.linkbtn { background: none; border: 0; padding: 6px 0; color: var(--primary); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.page-head { display: flex; align-items: flex-end; gap: 12px; margin: 4px 0 16px; }
.page-head h1 { font-size: 26px; font-weight: 750; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 24px 0 10px; }

.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 15px; margin-bottom: 10px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .n { font-size: 24px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 600; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px;
  color: var(--text); background: none; border: 0; width: 100%; text-align: left; font: inherit; cursor: pointer;
}
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .chev { color: var(--muted); font-size: 20px; }
.empty { padding: 18px 16px; color: var(--muted); font-size: 15px; }

.avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--primary); font-weight: 750; font-size: 15px;
}
.avatar.lg { width: 58px; height: 58px; font-size: 20px; background: var(--primary); color: #fff; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 650; background: var(--surface-2); color: var(--muted);
}
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.private { background: var(--private-soft); color: var(--private); }

/* ---------- forms ---------- */

.field { display: block; font-size: 13px; font-weight: 650; color: var(--muted); }
.field > input, .field > select, .field > textarea, .field > .seg { margin-top: 6px; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iPhone zooming in on focus */
}
textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--primary); }
.subchecks { margin-top: 0 !important; padding-left: 32px; }
.subchecks .check { min-height: 38px; font-size: 14px; }
.subchecks .check:has(input:disabled) { opacity: .45; }
.preview-toggle { margin: -6px 0 6px; font-size: 14px; }
.seg { display: flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font: inherit; font-weight: 650; font-size: 14px; cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.err { color: var(--accent); font-size: 14px; font-weight: 600; min-height: 1em; }

/* ---------- sign in ---------- */

.signin { min-height: calc(100vh - 120px); display: grid; place-items: center; }
.signin .card { width: 100%; max-width: 400px; padding: 26px 22px; text-align: center; }
.signin .ball { width: 54px; height: 54px; color: var(--brand); margin-bottom: 10px; }
.signin h1 { font-size: 24px; margin-bottom: 6px; }
.signin form { text-align: left; margin-top: 20px; }
.signin .code-input { text-transform: uppercase; letter-spacing: .12em; font-weight: 700; text-align: center; font-size: 20px; }
.signin details { margin-top: 18px; text-align: left; }
.signin summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; text-align: center; list-style: none; }
.signin summary::-webkit-details-marker { display: none; }

/* ---------- player page ---------- */

.player-head { display: flex; gap: 14px; align-items: center; }
.player-head h1 { font-size: 24px; font-weight: 750; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: 13px; padding: 3px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-weight: 600; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.actions .btn { padding: 0 8px; font-size: 14px; }
.focus { border-left: 4px solid var(--accent); }
.focus h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin-bottom: 4px; }
.next { display: flex; gap: 10px; align-items: center; background: var(--ok-soft); color: var(--ok); border-radius: var(--radius); padding: 12px 14px; font-weight: 650; font-size: 15px; }

.lesson { padding: 14px 16px; }
.lesson header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.lesson .date { font-weight: 750; font-size: 17px; }
.lesson .when { color: var(--muted); font-size: 14px; }
.lesson header .linkbtn { margin-left: auto; }
.lesson.cancelled { opacity: .6; }
.lesson.cancelled .date { text-decoration: line-through; }
.note-block { margin-top: 10px; }
.note-block h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.note-block.homework { background: var(--warn-soft); border-radius: 10px; padding: 8px 10px; }
.note-block.homework h4 { color: var(--warn); }
.note-block.private { background: var(--private-soft); border-radius: 10px; padding: 8px 10px; }
.note-block.private h4 { color: var(--private); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lesson .thumbs { margin-top: 12px; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.thumb { position: relative; display: block; border-radius: 12px; overflow: hidden; background: #0b0f14; aspect-ratio: 3 / 4; color: #fff; }
.thumb.wide { aspect-ratio: 16 / 10; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px; opacity: .5; }
.thumb .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 7px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .78)); font-size: 12px; font-weight: 650; line-height: 1.25;
}
.thumb .cap .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb .cap .d { opacity: .8; font-weight: 500; }
.thumb .play {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0, 0, 0, .5); display: grid; place-items: center;
}
.thumb .play::after { content: ""; border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent; margin-left: 2px; }
.thumb .hidden-tag { position: absolute; top: 8px; left: 8px; }

/* ---------- families ---------- */

.code {
  font: 700 18px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .08em;
  background: var(--surface-2); border-radius: 9px; padding: 10px 12px; display: inline-block;
}

/* ---------- bottom sheet ---------- */

.sheet-backdrop { position: fixed; inset: 0; background: rgba(5, 10, 18, .45); z-index: 40; }
.sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0;
  max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 6vh; width: 600px; transform: translateX(-50%); border-radius: 18px; max-height: 88vh; }
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 19px; font-weight: 750; flex: 1; }

/* ---------- upload tray & toast ---------- */

.tray {
  position: fixed; z-index: 30; left: 10px; right: 10px;
  bottom: calc(var(--tabbar-h) + 10px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18); padding: 10px 12px;
}
body:not(.has-tabbar) .tray { bottom: calc(10px + env(safe-area-inset-bottom)); }
.tray-head { display: flex; align-items: center; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.tray-item { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.tray-item img, .tray-item .noimg { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; background: var(--surface-2); flex: none; }
.tray-item .main { flex: 1; min-width: 0; font-size: 13px; }
.tray-item .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.bar span { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.tray-item.done .bar span { background: var(--ok); }
.tray-item.failed .bar span { background: var(--accent); }

.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  top: calc(64px + env(safe-area-inset-top));
  background: #15202d; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 15px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: calc(100vw - 32px);
}

/* ---------- video page & breakdown viewer ---------- */

.video-page .meta-line { color: var(--muted); font-size: 14px; margin-top: 2px; }
.viewer { background: #05080c; border-radius: var(--radius); overflow: hidden; color: #fff; }
.viewer + .viewer { margin-top: 12px; }
.stage { position: relative; margin: 0 auto; background: #000; touch-action: manipulation; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: fill; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage.drawing canvas { pointer-events: auto; cursor: crosshair; touch-action: none; }
.stage .msg {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .7); padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  white-space: nowrap; pointer-events: none;
}
.vbar { padding: 10px 12px 12px; display: grid; gap: 10px; }
.scrub { display: flex; align-items: center; gap: 10px; }
.scrub input[type=range] { flex: 1; min-height: 0; padding: 0; border: 0; background: transparent; accent-color: #fff; height: 28px; }
.scrub .time { font: 600 13px/1 ui-monospace, Menlo, Consolas, monospace; min-width: 52px; text-align: right; opacity: .85; }
.transport { display: flex; gap: 6px; align-items: center; }
.vbtn {
  min-height: 42px; min-width: 42px; padding: 0 10px; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .16); background: rgba(255, 255, 255, .06); color: #fff;
  font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.vbtn.on { background: #fff; color: #05080c; border-color: #fff; }
.vbtn.play { min-width: 56px; font-size: 18px; }
.speeds { display: flex; gap: 4px; margin-left: auto; }
.speeds .vbtn { min-width: 38px; padding: 0 6px; font-size: 13px; }
.tools { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.tools .vbtn { flex: none; font-size: 13px; }
.readout { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; font-size: 13px; }
.readout:empty { display: none; }
.readout div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid rgba(255, 255, 255, .08); padding: 3px 0; }
.readout span:first-child { opacity: .7; }
.readout b { font-variant-numeric: tabular-nums; }
.readout .note { grid-column: 1 / -1; border: 0; opacity: .6; font-size: 12px; display: block; }
.legend { display: flex; gap: 12px; font-size: 12px; opacity: .8; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

.compare-bar { display: flex; gap: 8px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
@media (min-width: 900px) {
  .video-page.comparing { max-width: 1400px; }
  .video-page.comparing .viewers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .video-page.comparing .viewer + .viewer { margin-top: 0; }
}

/* ---------- books ---------- */

.chips-nav { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: -4px -16px 16px; padding: 0 16px; }
.chips-nav::-webkit-scrollbar { display: none; }
.chips-nav a {
  flex: none; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 14px; font-weight: 650; white-space: nowrap;
}
.chips-nav a.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.year-sel { width: auto; min-height: 38px; padding: 4px 10px; font-weight: 650; }
.stat .f { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.warn .n { color: var(--warn); }
.stat.good .n { color: var(--ok); }
.warn-card { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.warn-card .small { color: var(--muted); }
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.books { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.books th, table.books td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.books th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
table.books .num { text-align: right; }
table.books tfoot td { font-weight: 700; border-bottom: 0; }
details.card summary { cursor: pointer; }
details.card .tablewrap { margin-top: 12px; }
.item .amt { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; display: grid; gap: 3px; justify-items: end; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.completed { background: var(--ok-soft); color: var(--ok); }
.pill.scheduled { background: var(--warn-soft); color: var(--warn); }
.pill.cancelled { text-decoration: line-through; }
.card h3 { font-size: 15px; }
