/* Locker — IBM Plex identity, phone-first, light+dark */
:root {
  --paper: #FBFBF8; --card: #FFFFFF; --ink: #22303F; --muted: #5D6B7A;
  --line: #E3E4DD; --chip: #F1F2EC; --accent: #2E5AAC; --accent-ink: #FFFFFF;
  --gold: #A87E22; --flag: #C0392B; --ok: #2E7D4F; --shadow: 0 1px 3px rgba(30,40,60,.07), 0 8px 24px rgba(30,40,60,.05);
  --sans: "IBM Plex Sans", -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: "IBM Plex Serif", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141A21; --card: #1C232C; --ink: #E6EBF1; --muted: #98A5B3;
    --line: #2A323D; --chip: #232B35; --accent: #82A9E8; --accent-ink: #10151C;
    --gold: #D2AC5A; --flag: #E06A5B; --ok: #6FBF8F; --shadow: 0 1px 3px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --paper: #141A21; --card: #1C232C; --ink: #E6EBF1; --muted: #98A5B3;
  --line: #2A323D; --chip: #232B35; --accent: #82A9E8; --accent-ink: #10151C;
  --gold: #D2AC5A; --flag: #E06A5B; --ok: #6FBF8F; --shadow: 0 1px 3px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input, select, textarea { font: inherit; color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

#app { min-height: 100dvh; }

/* ---------- shell layout ---------- */
.shell { padding: calc(var(--sat) + 8px) 16px calc(var(--sab) + 84px); max-width: 640px; margin: 0 auto; }
@media (min-width: 900px) {
  .shell { max-width: 720px; padding-left: 96px; padding-bottom: 40px; }
}

/* bottom nav (left rail on desktop) */
.nav {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(var(--sab) + 6px);
}
.nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 10.5px; font-weight: 500; letter-spacing: .02em; min-width: 56px; padding: 4px 6px; border-radius: 10px; }
.nav button svg { width: 22px; height: 22px; }
.nav button.on { color: var(--accent); }
.nav .fab {
  background: var(--accent); color: var(--accent-ink); border-radius: 16px;
  width: 52px; height: 40px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); min-width: 52px;
}
.nav .fab svg { width: 24px; height: 24px; }
@media (min-width: 900px) {
  .nav { left: 0; right: auto; top: 0; bottom: 0; flex-direction: column; justify-content: center; gap: 10px; border-top: 0; border-right: 1px solid var(--line); padding: 16px 12px; }
}

/* ---------- primitives ---------- */
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .13em; text-transform: uppercase; color: var(--gold); }
h1.page { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.15; margin: 2px 0 4px; text-wrap: balance; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.section-h { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 10px; }
.section-h h2 { font-family: var(--serif); font-weight: 600; font-size: 18px; margin: 0; }
.section-h .more { font-size: 13px; color: var(--accent); font-weight: 500; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 8px; }

.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.row + .row { border-top: 1px solid var(--line); }
.grow { flex: 1; min-width: 0; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chipbar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chipbar::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font-size: 13.5px; font-weight: 500; padding: 7px 13px; border-radius: 999px;
  background: var(--chip); border: 1px solid var(--line); color: var(--ink); transition: background .15s, color .15s;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .n { font-family: var(--mono); font-size: 12px; opacity: .75; margin-left: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px;
  border-radius: 12px; padding: 12px 18px; transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--chip); color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 7px 12px; font-size: 13.5px; border-radius: 9px; }
.btn.danger { background: var(--flag); color: #fff; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.badge { font-family: var(--mono); font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.badge.warn { background: color-mix(in srgb, var(--flag) 14%, transparent); color: var(--flag); }
.badge.gold { background: color-mix(in srgb, var(--gold) 15%, transparent); color: var(--gold); }
.badge.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 34px 20px; font-size: 14.5px; }
.empty .big { font-size: 26px; display: block; margin-bottom: 8px; }

input.field, select.field, textarea.field {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; font-size: 16px;
}
input.field:focus, select.field:focus, textarea.field:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label.lbl { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 12px 0 5px; letter-spacing: .02em; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { width: 100%; max-width: 360px; padding: 32px 28px; text-align: center; }
.login .mark { font-family: var(--serif); font-size: 34px; font-weight: 600; }
.login .mark .dot { color: var(--gold); }
.login .sub { margin-bottom: 22px; }
.login .err { color: var(--flag); font-size: 13.5px; min-height: 20px; margin: 10px 0 2px; }

/* ---------- home ---------- */
.today-line { display: flex; align-items: baseline; justify-content: space-between; }
.sync-dot { font-family: var(--mono); font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync-dot .spin { width: 10px; height: 10px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.due-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; }
.due-row + .due-row { border-top: 1px solid var(--line); }
.tick { width: 24px; height: 24px; flex: none; border: 2px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: transparent; transition: all .15s; }
.tick.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.due-row .when { font-family: var(--mono); font-size: 12px; color: var(--muted); flex: none; text-align: right; }
.due-row .when.urgent { color: var(--flag); font-weight: 500; }
.due-row .cdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.due-title { font-weight: 500; font-size: 14.5px; }
.due-sub { font-size: 12.5px; color: var(--muted); }

.confirm-card { border-left: 3px solid var(--gold); }

.class-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.class-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 13px 14px 12px; text-align: left; position: relative; overflow: hidden; transition: transform .12s;
}
.class-card:active { transform: scale(.98); }
.class-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--cc, var(--accent)); }
.class-card .code { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.class-card .cname { font-weight: 600; font-size: 14.5px; line-height: 1.25; margin: 3px 0 8px; min-height: 36px; }
.class-card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.class-card .meta b { color: var(--ink); font-weight: 600; }

/* ---------- class view ---------- */
.class-head { border-radius: 16px; padding: 18px 16px 14px; color: #fff; position: relative; overflow: hidden; background: var(--cc, var(--accent)); box-shadow: var(--shadow); }
.class-head::after { content: ""; position: absolute; inset: 0; background: linear-gradient(155deg, rgba(0,0,0,.05), rgba(0,0,0,.28)); }
.class-head > * { position: relative; z-index: 1; }
.class-head .code { font-family: var(--mono); font-size: 12px; opacity: .9; letter-spacing: .06em; }
.class-head h1 { font-family: var(--serif); font-size: 24px; margin: 2px 0 2px; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.2); }
.class-head .prof { font-size: 13px; opacity: .92; }
.back { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13.5px; font-weight: 500; margin-bottom: 10px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 14px -16px 16px; padding: 0 16px 2px; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; padding: 9px 13px; font-size: 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--cc, var(--accent)); }
.tabs button .n { font-family: var(--mono); font-size: 11px; margin-left: 3px; color: var(--gold); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .v { font-family: var(--mono); font-size: 20px; font-weight: 500; }
.stat .k { font-size: 11.5px; color: var(--muted); }

.lec-row { display: block; width: 100%; text-align: left; padding: 12px 14px; }
.lec-row + .lec-row { border-top: 1px solid var(--line); }
.lec-row .t { font-weight: 500; font-size: 14.5px; }
.lec-row .d { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 10px; }

.note-card { padding: 12px 14px; }
.note-card + .note-card { border-top: 1px solid var(--line); }
.note-card .prev { font-size: 13px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.flag-item { display: flex; gap: 10px; padding: 11px 14px; align-items: flex-start; }
.flag-item + .flag-item { border-top: 1px solid var(--line); }
.flag-item .star { color: var(--flag); flex: none; margin-top: 1px; }
.flag-item .topic { font-size: 12.5px; color: var(--muted); }

/* ---------- lecture detail ---------- */
.digest h3 { font-family: var(--serif); font-size: 16px; margin: 18px 0 8px; }
.kc { padding: 10px 14px; }
.kc + .kc { border-top: 1px solid var(--line); }
.kc b { display: block; font-size: 14px; }
.kc span { font-size: 13.5px; color: var(--muted); }
details.transcript { margin-top: 18px; }
details.transcript summary { font-weight: 600; cursor: pointer; padding: 10px 0; }
details.transcript pre { white-space: pre-wrap; font-family: var(--sans); font-size: 14px; color: var(--muted); line-height: 1.6; }

/* ---------- sheet (capture etc) ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(10,14,20,.45); z-index: 60; opacity: 0; transition: opacity .2s; }
.sheet-back.show { opacity: 1; }
.sheet {
  position: fixed; z-index: 61; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto;
  background: var(--paper); border-radius: 18px 18px 0 0; padding: 10px 18px calc(var(--sab) + 20px);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.3,.9,.3,1);
  max-width: 640px; margin: 0 auto;
}
.sheet.show { transform: none; }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { font-family: var(--serif); font-size: 20px; margin: 0 0 4px; }
.cap-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 4px; }
.cap-btn { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); }
.cap-btn svg { width: 26px; height: 26px; color: var(--accent); }
.up-item { display: flex; align-items: center; gap: 10px; padding: 10px 2px; font-size: 14px; }
.up-item .bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 5px; }
.up-item .bar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

/* ---------- study / flashcards ---------- */
.fc-stage { perspective: 1200px; margin: 14px 0; }
.fc {
  position: relative; min-height: 250px; border-radius: 18px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow); width: 100%; text-align: center;
  display: flex; align-items: center; justify-content: center; padding: 28px 22px;
  font-size: 18px; line-height: 1.45; transition: transform .15s;
}
.fc:active { transform: scale(.99); }
.fc .cls { position: absolute; top: 12px; left: 14px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.fc .side { position: absolute; top: 12px; right: 14px; font-family: var(--mono); font-size: 11px; color: var(--gold); }
.fc-grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.fc-grades button { border-radius: 12px; padding: 12px 4px; font-weight: 600; font-size: 14px; background: var(--chip); border: 1px solid var(--line); }
.fc-grades .g0 { color: var(--flag); } .fc-grades .g3 { color: var(--ok); }
.fc-progress { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: center; margin-top: 12px; }

/* ---------- grades ---------- */
.grade-big { font-family: var(--mono); font-size: 38px; font-weight: 500; }
.gcat { display: flex; justify-content: space-between; padding: 9px 14px; font-size: 14px; }
.gcat + .gcat { border-top: 1px solid var(--line); }
.gcat .avg { font-family: var(--mono); }

/* ---------- tutor chat ---------- */
.chat-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
#chat-log { display: flex; flex-direction: column; gap: 10px; padding-bottom: 90px; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.5; overflow-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.bubble.tutor { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.tutor p { margin: 0 0 8px; } .bubble.tutor p:last-child { margin: 0; }
.bubble.tutor ul, .bubble.tutor ol { margin: 0 0 8px; padding-left: 20px; }
.bubble.tutor h4 { margin: 4px 0 6px; font-size: 14.5px; }
.bubble.tutor code { font-family: var(--mono); font-size: 13px; background: var(--chip); padding: 1px 5px; border-radius: 5px; }
.bubble.thinking { display: flex; gap: 5px; padding: 14px 16px; }
.bubble.thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: think 1.2s infinite; }
.bubble.thinking span:nth-child(2) { animation-delay: .2s; }
.bubble.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes think { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
.chat-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--sab) + 66px); z-index: 30;
  display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  max-width: 640px; margin: 0 auto;
}
.chat-bar textarea { resize: none; max-height: 140px; border-radius: 14px; }
.chat-bar .btn { border-radius: 12px; padding: 11px 16px; font-size: 18px; line-height: 1; }
@media (min-width: 900px) { .chat-bar { bottom: 0; padding-left: 96px; max-width: 720px; } }

/* ---------- practice ---------- */
.prac { padding: 12px 14px; border-top: 1px solid var(--line); font-size: 14.5px; }
.prac-q { line-height: 1.5; }
.prac-steps { white-space: pre-wrap; color: var(--muted); font-size: 13.5px; margin-top: 4px; }

/* ---------- toast ---------- */
#toasts { position: fixed; z-index: 100; left: 0; right: 0; bottom: calc(var(--sab) + 92px); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--paper); font-size: 14px; font-weight: 500;
  padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); max-width: 88vw;
  animation: toast-in .25s cubic-bezier(.3,.9,.3,1);
}
.toast.warn { background: var(--flag); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.skel { border-radius: 12px; background: linear-gradient(90deg, var(--chip) 25%, var(--line) 50%, var(--chip) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.seg { display: flex; background: var(--chip); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; padding: 7px 4px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
