/* ── Theme palettes ────────────────────────────────────
   Variables that don't change across themes live in :root.
   Per-theme overrides live in [data-theme="..."] blocks below.
   The default (no attribute) palette mirrors `dark` so unthemed
   pages still render correctly. */
:root {
  --radius:       12px;
  --radius-lg:    16px;
  --font-body:    "Noto Sans Thai", "Space Grotesk", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", "Space Grotesk", ui-monospace, monospace;

  /* Dark theme (default) — deep navy with indigo / cyan accents */
  --brand:        #818cf8;
  --brand-deep:   #6366f1;
  --brand-2:      #22d3ee;
  --brand-3:      #a78bfa;
  --accent:       #f472b6;
  --accent-2:     #fbbf24;
  --bg:           #0a0e1a;
  --bg-deep:      #060914;
  --surface:      #11172c;
  --surface-soft: #171e36;
  --surface-2:    #1c2543;
  --border:       rgba(129,140,248,0.16);
  --border-soft:  rgba(255,255,255,0.06);
  --ink:          #e6eaf7;
  --ink-soft:     #a3aec8;
  --ink-mute:     #6b7795;
  --pass:         #34d399;
  --pass-bg:      rgba(16,185,129,0.16);
  --pass-border:  rgba(52,211,153,0.40);
  --fail:         #f87171;
  --fail-bg:      rgba(239,68,68,0.16);
  --fail-border:  rgba(248,113,113,0.40);
  --info:         #38bdf8;
  --info-bg:      rgba(14,165,233,0.16);
  --info-border:  rgba(56,189,248,0.40);
  --warn:         #fbbf24;
  --warn-bg:      rgba(245,158,11,0.16);
  --warn-border:  rgba(251,191,36,0.40);
  --shadow:       0 8px 28px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.30);
  --shadow-glow:  0 0 0 4px rgba(129,140,248,0.20);
  --shadow-lift:  0 18px 40px rgba(0,0,0,0.55), 0 0 32px rgba(129,140,248,0.18);
  --grad-brand:   linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #22d3ee 100%);
  --grad-pass:    linear-gradient(135deg, #34d399, #22d3ee);
  --grad-fail:    linear-gradient(135deg, #f87171, #f472b6);
  --grad-warn:    linear-gradient(135deg, #fbbf24, #f472b6);
  --body-glow-1:  rgba(129,140,248,0.18);
  --body-glow-2:  rgba(34,211,238,0.14);
  --body-glow-3:  rgba(244,114,182,0.10);
  color-scheme:   dark;
}

/* Light theme — soft slate-on-white with the same indigo accents */
[data-theme="light"] {
  --brand:        #4f46e5;
  --brand-deep:   #3730a3;
  --brand-2:      #0891b2;
  --brand-3:      #7c3aed;
  --accent:       #db2777;
  --accent-2:     #d97706;
  --bg:           #f4f6fb;
  --bg-deep:      #e9ecf5;
  --surface:      #ffffff;
  --surface-soft: #f1f3f9;
  --surface-2:    #e7ebf4;
  --border:       rgba(79,70,229,0.18);
  --border-soft:  rgba(15,23,42,0.08);
  --ink:          #0f172a;
  --ink-soft:     #475569;
  --ink-mute:     #94a3b8;
  --pass:         #047857;
  --pass-bg:      rgba(16,185,129,0.14);
  --pass-border:  rgba(5,150,105,0.40);
  --fail:         #b91c1c;
  --fail-bg:      rgba(239,68,68,0.12);
  --fail-border:  rgba(185,28,28,0.40);
  --info:         #0369a1;
  --info-bg:      rgba(14,165,233,0.12);
  --info-border:  rgba(3,105,161,0.40);
  --warn:         #b45309;
  --warn-bg:      rgba(245,158,11,0.14);
  --warn-border:  rgba(180,83,9,0.40);
  --shadow:       0 6px 18px rgba(15,23,42,0.08), 0 1px 3px rgba(15,23,42,0.06);
  --shadow-glow:  0 0 0 4px rgba(79,70,229,0.18);
  --shadow-lift:  0 18px 36px rgba(15,23,42,0.12), 0 0 24px rgba(79,70,229,0.10);
  --grad-brand:   linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #0891b2 100%);
  --grad-pass:    linear-gradient(135deg, #047857, #0891b2);
  --grad-fail:    linear-gradient(135deg, #b91c1c, #db2777);
  --grad-warn:    linear-gradient(135deg, #d97706, #db2777);
  --body-glow-1:  rgba(79,70,229,0.10);
  --body-glow-2:  rgba(8,145,178,0.08);
  --body-glow-3:  rgba(219,39,119,0.07);
  color-scheme:   light;
}

/* Ocean theme — deep teal night with seafoam accents */
[data-theme="ocean"] {
  --brand:        #5eead4;
  --brand-deep:   #14b8a6;
  --brand-2:      #38bdf8;
  --brand-3:      #818cf8;
  --accent:       #f0abfc;
  --accent-2:     #fde68a;
  --bg:           #04111a;
  --bg-deep:      #020a11;
  --surface:      #0a1f2c;
  --surface-soft: #0e2a3a;
  --surface-2:    #143447;
  --border:       rgba(94,234,212,0.18);
  --border-soft:  rgba(255,255,255,0.06);
  --ink:          #e0fbf6;
  --ink-soft:     #94c5c0;
  --ink-mute:     #5d8e8a;
  --pass:         #34d399;
  --pass-bg:      rgba(16,185,129,0.16);
  --pass-border:  rgba(52,211,153,0.40);
  --fail:         #fb7185;
  --fail-bg:      rgba(251,113,133,0.16);
  --fail-border:  rgba(251,113,133,0.40);
  --info:         #38bdf8;
  --info-bg:      rgba(56,189,248,0.16);
  --info-border:  rgba(56,189,248,0.40);
  --warn:         #fde68a;
  --warn-bg:      rgba(253,230,138,0.14);
  --warn-border:  rgba(253,230,138,0.40);
  --shadow:       0 8px 28px rgba(0,16,24,0.55), 0 2px 6px rgba(0,16,24,0.40);
  --shadow-glow:  0 0 0 4px rgba(94,234,212,0.25);
  --shadow-lift:  0 18px 40px rgba(0,16,24,0.65), 0 0 36px rgba(94,234,212,0.20);
  --grad-brand:   linear-gradient(135deg, #14b8a6 0%, #0891b2 50%, #38bdf8 100%);
  --grad-pass:    linear-gradient(135deg, #34d399, #5eead4);
  --grad-fail:    linear-gradient(135deg, #fb7185, #f0abfc);
  --grad-warn:    linear-gradient(135deg, #fde68a, #5eead4);
  --body-glow-1:  rgba(94,234,212,0.18);
  --body-glow-2:  rgba(56,189,248,0.16);
  --body-glow-3:  rgba(240,171,252,0.10);
  color-scheme:   dark;
}

/* Sunset theme — warm amber / rose evening */
[data-theme="sunset"] {
  --brand:        #fb923c;
  --brand-deep:   #ea580c;
  --brand-2:      #f472b6;
  --brand-3:      #fbbf24;
  --accent:       #f43f5e;
  --accent-2:     #facc15;
  --bg:           #1a0a14;
  --bg-deep:      #0f060d;
  --surface:      #2a1320;
  --surface-soft: #371826;
  --surface-2:    #461f30;
  --border:       rgba(251,146,60,0.20);
  --border-soft:  rgba(255,255,255,0.06);
  --ink:          #fff5ec;
  --ink-soft:     #d4b8a3;
  --ink-mute:     #8e7561;
  --pass:         #fde68a;
  --pass-bg:      rgba(253,230,138,0.18);
  --pass-border:  rgba(253,230,138,0.40);
  --fail:         #fb7185;
  --fail-bg:      rgba(251,113,133,0.18);
  --fail-border:  rgba(251,113,133,0.40);
  --info:         #fda4af;
  --info-bg:      rgba(253,164,175,0.16);
  --info-border:  rgba(253,164,175,0.40);
  --warn:         #fcd34d;
  --warn-bg:      rgba(252,211,77,0.16);
  --warn-border:  rgba(252,211,77,0.40);
  --shadow:       0 8px 28px rgba(40,8,16,0.55), 0 2px 6px rgba(40,8,16,0.40);
  --shadow-glow:  0 0 0 4px rgba(251,146,60,0.25);
  --shadow-lift:  0 18px 40px rgba(40,8,16,0.65), 0 0 36px rgba(251,146,60,0.22);
  --grad-brand:   linear-gradient(135deg, #ea580c 0%, #f43f5e 50%, #facc15 100%);
  --grad-pass:    linear-gradient(135deg, #fde68a, #fb923c);
  --grad-fail:    linear-gradient(135deg, #f43f5e, #fb7185);
  --grad-warn:    linear-gradient(135deg, #facc15, #f472b6);
  --body-glow-1:  rgba(251,146,60,0.20);
  --body-glow-2:  rgba(244,63,94,0.16);
  --body-glow-3:  rgba(252,211,77,0.12);
  color-scheme:   dark;
}

/* Forest theme — deep emerald with golden highlights */
[data-theme="forest"] {
  --brand:        #4ade80;
  --brand-deep:   #16a34a;
  --brand-2:      #facc15;
  --brand-3:      #a3e635;
  --accent:       #f97316;
  --accent-2:     #fde047;
  --bg:           #0a1a10;
  --bg-deep:      #060f09;
  --surface:      #102718;
  --surface-soft: #163220;
  --surface-2:    #1c3f29;
  --border:       rgba(74,222,128,0.18);
  --border-soft:  rgba(255,255,255,0.06);
  --ink:          #e6f5e8;
  --ink-soft:     #a3c2a5;
  --ink-mute:     #6f8a72;
  --pass:         #4ade80;
  --pass-bg:      rgba(74,222,128,0.18);
  --pass-border:  rgba(74,222,128,0.40);
  --fail:         #f87171;
  --fail-bg:      rgba(248,113,113,0.16);
  --fail-border:  rgba(248,113,113,0.40);
  --info:         #facc15;
  --info-bg:      rgba(250,204,21,0.16);
  --info-border:  rgba(250,204,21,0.40);
  --warn:         #fbbf24;
  --warn-bg:      rgba(251,191,36,0.16);
  --warn-border:  rgba(251,191,36,0.40);
  --shadow:       0 8px 28px rgba(0,16,8,0.55), 0 2px 6px rgba(0,16,8,0.40);
  --shadow-glow:  0 0 0 4px rgba(74,222,128,0.20);
  --shadow-lift:  0 18px 40px rgba(0,16,8,0.65), 0 0 36px rgba(74,222,128,0.18);
  --grad-brand:   linear-gradient(135deg, #16a34a 0%, #4ade80 50%, #facc15 100%);
  --grad-pass:    linear-gradient(135deg, #4ade80, #facc15);
  --grad-fail:    linear-gradient(135deg, #f87171, #f97316);
  --grad-warn:    linear-gradient(135deg, #facc15, #f97316);
  --body-glow-1:  rgba(74,222,128,0.18);
  --body-glow-2:  rgba(250,204,21,0.14);
  --body-glow-3:  rgba(249,115,22,0.10);
  color-scheme:   dark;
}

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

body {
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse at 10% 0%, var(--body-glow-1), transparent 50%),
    radial-gradient(ellipse at 90% 10%, var(--body-glow-2), transparent 50%),
    radial-gradient(ellipse at 50% 100%, var(--body-glow-3), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Login ──────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.login-wrap::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(129,140,248,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(129,140,248,0.08) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
  mask-image: radial-gradient(ellipse at center, black, transparent 75%);
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lift), 0 0 0 1px var(--border);
  width: 100%;
  max-width: 440px;
  overflow: hidden;
  position: relative;
}

.login-hero {
  background: var(--grad-brand);
  color: #fff;
  text-align: center;
  padding: 38px 24px 30px;
  position: relative;
  overflow: hidden;
}
.login-hero::after {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 25% 30%, rgba(255,255,255,0.25), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(255,255,255,0.15), transparent 35%);
  pointer-events: none;
}

.login-logo {
  width: 84px; height: 84px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  z-index: 1;
}
.login-logo img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 22%;     /* iOS-style squircle clips the PNG's white edge */
  box-shadow:
    0 12px 32px rgba(0,0,0,0.30),
    0 0 0 2px rgba(255,255,255,0.45),
    inset 0 0 24px rgba(255,255,255,0.10);
  background: transparent;
}
.login-hero h1 { font-size: 20px; font-weight: 700; letter-spacing: .3px; position: relative; z-index: 1; }
.login-hero p  { opacity: .9; margin-top: 6px; font-size: 13px; position: relative; z-index: 1; }

.login-form { padding: 28px 28px 20px; display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }
.field input, .modal-input {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface-soft);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input::placeholder, .modal-input::placeholder { color: var(--ink-mute); }
.field input:focus, .modal-input:focus { outline: none; border-color: var(--brand); box-shadow: var(--shadow-glow); }

/* Kill the browser autofill yellow on dark theme — Chrome/Safari ignore
   `background-color` for autofilled inputs, so we paint the field ourselves
   via an enormous inset box-shadow and force the text color. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
.field input:-webkit-autofill,
.modal-input:-webkit-autofill,
.text-input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--surface-soft) inset !important;
  box-shadow: 0 0 0 1000px var(--surface-soft) inset !important;
  -webkit-text-fill-color: var(--ink) !important;
  caret-color: var(--ink);
  border-color: var(--border) !important;
  transition: background-color 9999s ease-in-out 0s;
}
input:-webkit-autofill:focus { border-color: var(--brand) !important; }

.login-note { font-size: 12px; color: var(--ink-soft); text-align: center; padding: 0 28px 20px; line-height: 1.7; }

/* ── Buttons ─────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 11px 18px;
  background: var(--grad-brand);
  background-size: 150% 150%;
  color: #fff;
  border: none; border-radius: 10px;
  font-family: var(--font-body); font-size: 14px; font-weight: 700;
  cursor: pointer;
  letter-spacing: .2px;
  box-shadow: 0 4px 14px rgba(99,102,241,0.32);
  transition: transform .15s ease, box-shadow .15s ease, background-position .25s ease;
  width: 100%;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(99,102,241,0.45); background-position: 100% 50%; }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  padding: 9px 14px;
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(6,182,212,0.10));
  color: var(--brand-deep);
  border: 1.5px solid rgba(99,102,241,0.30);
  border-radius: 10px;
  font-family: var(--font-body); font-size: 13px; font-weight: 700; cursor: pointer;
  transition: background .15s, border-color .15s, transform .12s;
}
.btn-secondary:hover { background: linear-gradient(135deg, rgba(99,102,241,0.16), rgba(6,182,212,0.16)); border-color: var(--brand); transform: translateY(-1px); }

.btn-outline {
  padding: 7px 14px; background: var(--surface); color: var(--brand-deep);
  border: 1.5px solid var(--brand); border-radius: 10px;
  font-family: var(--font-body); font-size: 13px; font-weight: 700; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-outline:hover { background: var(--brand); color: #fff; }

.btn-ghost {
  padding: 7px 12px; background: transparent; color: var(--ink-soft);
  border: 1.5px solid var(--border); border-radius: 10px;
  font-family: var(--font-body); font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); background: rgba(99,102,241,0.06); }

.btn-sm { font-size: 12px; padding: 5px 10px; }

/* ── Messages ────────────────────────────────────────── */
.msg { padding: 9px 12px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; }
.msg.info   { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }
.msg.ok     { background: var(--pass-bg); color: var(--pass); border-color: var(--pass-border); }
.msg.error  { background: var(--fail-bg); color: var(--fail); border-color: var(--fail-border); }
.hidden     { display: none !important; }

/* ── App Shell ───────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  box-shadow: 1px 0 0 var(--border-soft);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-icon { font-size: 22px; }
.brand-icon-img {
  width: 36px; height: 36px;
  object-fit: cover;
  border-radius: 22%;     /* iOS-style squircle clips the PNG's white edge */
  box-shadow:
    0 4px 10px rgba(99,102,241,0.30),
    0 0 0 1px rgba(99,102,241,0.18);
  background: transparent;
}
.brand-name { font-weight: 700; font-size: 14px; color: var(--ink); letter-spacing: .2px; }

.nav-list { list-style: none; padding: 10px 8px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  transition: background .15s, color .15s, transform .12s;
  margin-bottom: 4px;
  position: relative;
}
.nav-item:hover  { background: rgba(99,102,241,0.06); color: var(--brand-deep); }
.nav-item.active {
  background: var(--grad-brand);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 14px rgba(99,102,241,0.32);
}
.nav-item.active::after {
  content: "";
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 6px; height: 6px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 8px #fff;
}
.nav-icon { font-size: 16px; }
.nav-icon-cal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
}
.nav-icon-cal svg {
  width: 18px; height: 18px;
  color: currentColor;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
.nav-icon-cal .cal-band  { stroke-width: 1.6; opacity: .85; }
.nav-icon-cal .cal-mark  { stroke-linecap: round; }
.nav-icon-cal .cal-day {
  font-family: var(--font-mono), monospace;
  font-size: 11px;
  font-weight: 700;
  fill: currentColor;
  stroke: none;
}

.badge-new {
  margin-left: auto;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 999px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 8px;
}
.student-chip {
  background: linear-gradient(135deg, rgba(129,140,248,0.20), rgba(34,211,238,0.20));
  color: var(--brand);
  font-weight: 700; font-size: 12px;
  padding: 5px 12px; border-radius: 999px;
  text-align: center;
  font-family: var(--font-mono);
  letter-spacing: 1px;
  border: 1px solid rgba(129,140,248,0.30);
}

/* ── Main content ────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
  position: relative;
}

.panel { display: none; }
.panel.active { display: block; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.panel-header h2 { font-size: 20px; font-weight: 700; }

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  position: relative;
}
.card-title {
  font-size: 12px; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .8px;
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.card-title::before {
  content: "";
  width: 4px; height: 14px; border-radius: 999px;
  background: var(--grad-brand);
  display: inline-block;
}
.mt-2 { margin-top: 16px; }

/* ── Summary grid ────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 4px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
  position: relative; overflow: hidden;
}
.summary-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--grad-brand);
  opacity: .9;
}
.summary-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.summary-label { font-size: 10px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .6px; }
.summary-value { font-size: 22px; font-weight: 700; color: var(--ink); margin-top: 6px; font-family: var(--font-mono); }
.summary-value.pass { color: var(--pass); }
.summary-value.fail { color: var(--fail); }

/* ── Tables ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table th {
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  text-align: left;
}
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(99,102,241,0.04); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.dim { color: var(--ink-soft); font-style: italic; }

.kv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv-table th {
  width: 180px; text-align: left;
  padding: 7px 10px;
  color: var(--ink-soft); font-weight: 600; font-size: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}
.kv-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }

/* ── Status badges ───────────────────────────────────── */
.badge-pass  { display: inline-block; background: var(--pass-bg); color: var(--pass); padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: 11px; letter-spacing: .5px; border: 1px solid var(--pass-border); }
.badge-fail  { display: inline-block; background: var(--fail-bg); color: var(--fail); padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: 11px; letter-spacing: .5px; border: 1px solid var(--fail-border); }
.badge-neu   { display: inline-block; background: var(--surface-soft); color: var(--ink-soft); padding: 2px 10px; border-radius: 999px; font-size: 11px; letter-spacing: .5px; border: 1px solid var(--border); }

.grade-chip {
  display: inline-block;
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(6,182,212,0.10));
  color: var(--brand-deep);
  font-weight: 700; padding: 2px 8px; border-radius: 6px; font-size: 12px;
  font-family: var(--font-mono);
  border: 1px solid rgba(99,102,241,0.20);
}

/* ── Term accordion ──────────────────────────────────── */
.term-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.term-card summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  background: var(--surface-soft);
  list-style: none;
  display: flex; align-items: center;
  gap: 8px;
}
.term-card summary::before { content: "▶"; font-size: 10px; color: var(--brand); }
.term-card[open] summary::before { content: "▼"; }
.term-card .data-table { border-radius: 0; }

/* ── What-If ─────────────────────────────────────────── */
.whatif-controls {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}
.field-row { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 160px; }
.field-row label { font-size: 11px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .3px; }
.field-row select {
  padding: 9px 10px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-family: var(--font-body); font-size: 13px; color: var(--ink);
  background: var(--surface-soft);
}

.override-list { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.override-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(99,102,241,0.10); border: 1.5px solid rgba(99,102,241,0.30);
  border-radius: 999px; padding: 4px 10px; font-size: 13px;
}
.chip-remove {
  background: none; border: none; cursor: pointer;
  color: var(--fail); font-size: 13px; line-height: 1;
  padding: 0 2px;
}

.action-row { display: flex; gap: 10px; align-items: center; }
.row-changed td { background: rgba(245,158,11,0.10) !important; }

.scope-cell {
  min-width: 280px;
  max-width: 520px;
}

.scope-note {
  font-size: 12px;
  color: var(--warn);
  background: rgba(245,158,11,0.10);
  border: 1px solid rgba(245,158,11,0.30);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 4px;
}

.scope-include {
  font-size: 12px;
  color: var(--ink-soft);
  white-space: normal;
  word-break: break-word;
}

/* ── Planner ─────────────────────────────────────────── */
.planner-coming-soon {
  text-align: center; padding: 60px 40px;
  color: var(--ink-soft);
}
.coming-soon-icon { font-size: 56px; margin-bottom: 16px; }
.planner-coming-soon h3 { font-size: 18px; color: var(--ink); margin-bottom: 10px; }
.planner-coming-soon p { line-height: 1.8; }

/* ── Planner (Experimental) ───────────────────────── */
.planner-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.planner-program-select {
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 13px;
}

.planner-toolbar .btn-primary,
.planner-toolbar .btn-outline,
.planner-toolbar .btn-secondary,
.planner-toolbar .btn-ghost {
  width: auto;
}

.planner-note {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.7;
}

.planner-terms-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.planner-table td {
  vertical-align: middle;
}

.planner-input,
.planner-grade {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--font-body);
  font-size: 12px;
  background: var(--surface-soft);
}

.planner-term-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.planner-tag {
  display: inline-block;
  margin-left: 6px;
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(6,182,212,0.10));
  color: var(--brand-deep);
  border: 1px solid rgba(99,102,241,0.30);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 10px;
  font-weight: 700;
}

.planner-history-green summary {
  background: linear-gradient(90deg, rgba(16,185,129,0.10), transparent);
  border-bottom: 1px solid rgba(16,185,129,0.20);
}

.planner-history-blue summary {
  background: linear-gradient(90deg, rgba(99,102,241,0.10), transparent);
  border-bottom: 1px solid rgba(99,102,241,0.20);
}

.term-card-summer {
  border-style: dashed;
  opacity: .85;
}
.term-card-summer summary {
  background: linear-gradient(90deg, rgba(245,158,11,0.10), transparent);
  border-bottom-color: var(--warn-border);
}
.planner-summer-tag {
  display: inline-block;
  background: rgba(245,158,11,0.15);
  color: var(--warn);
  border: 1px solid var(--warn-border);
  font-size: 10px; font-weight: 700;
  padding: 1px 8px; border-radius: 999px;
  margin-left: 6px;
  letter-spacing: .3px;
}

/* ── Loading overlay ─────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10,14,26,0.78);
  backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  color: var(--ink);
}
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--brand);
  border-right-color: var(--brand-2);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  box-shadow: 0 0 24px rgba(99,102,241,0.30);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift), 0 0 0 1px var(--border);
  padding: 28px 30px; width: 100%; max-width: 400px;
  border-top: 4px solid transparent;
  border-image: var(--grad-brand) 1;
  border-image-slice: 1;
}
.modal-box h3 { font-size: 16px; margin-bottom: 8px; }
.modal-box p  { color: var(--ink-soft); font-size: 13px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn-primary { width: auto; flex: 1; }

/* ── Teacher banner ──────────────────────────────────── */
.teacher-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: linear-gradient(135deg, rgba(245,158,11,0.10), rgba(236,72,153,0.10));
  border: 1.5px solid rgba(245,158,11,0.30);
  border-radius: var(--radius); padding: 10px 16px;
  margin-bottom: 18px; font-size: 13px;
}
.teacher-banner strong { color: var(--brand-deep); font-size: 14px; font-family: var(--font-mono); letter-spacing: 1px; }

/* ── Login field hint ────────────────────────────────── */
.field-hint { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

/* ── Game-style profile panel ────────────────────────── */
.profile-panel {
  background: var(--grad-brand);
  background-size: 200% 200%;
  animation: brandShift 18s ease infinite;
  border-radius: 22px;
  padding: 2px;
  box-shadow: 0 18px 40px rgba(99,102,241,0.18);
  margin-bottom: 14px;
}
@keyframes brandShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.profile-loading {
  background: var(--surface);
  border-radius: 20px;
  padding: 28px;
  text-align: center;
}
.profile-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 20px 22px;
  display: grid;
  grid-template-columns: 120px 1fr 380px;
  gap: 22px;
  align-items: stretch;
  position: relative;
  overflow: hidden;
}
.profile-card::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(129,140,248,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(129,140,248,0.07) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  mask-image: radial-gradient(ellipse at 80% 50%, black, transparent 70%);
}
.profile-card > * { position: relative; z-index: 1; }

.profile-avatar {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.avatar-circle {
  width: 104px; height: 104px;
  border-radius: 26%;     /* outer squircle */
  background: var(--grad-brand);
  display: flex; align-items: center; justify-content: center;
  box-shadow:
    0 14px 30px rgba(99,102,241,0.40),
    0 0 0 1px rgba(255,255,255,0.20);
  position: relative;
}
.avatar-circle img {
  width: 92px; height: 92px;
  object-fit: cover;
  border-radius: 22%;     /* inner squircle clips the PNG's white edge,
                             leaves a thin gradient ring as a frame */
  display: block;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.30);
  background: transparent;
}
.avatar-circle::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 30% 20%, rgba(255,255,255,0.35), transparent 55%);
  pointer-events: none;
}
.avatar-level {
  display: flex; align-items: baseline; gap: 4px;
  background: var(--bg-deep);
  color: var(--ink);
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid rgba(129,140,248,0.40);
  box-shadow:
    0 4px 14px rgba(0,0,0,0.50),
    0 0 0 2px rgba(129,140,248,0.20),
    inset 0 0 12px rgba(34,211,238,0.10);
  font-family: var(--font-mono);
}
.avatar-level .lvl-label { font-size: 10px; letter-spacing: 1.5px; color: var(--ink-soft); }
.avatar-level .lvl-value { font-size: 16px; color: var(--brand-2); text-shadow: 0 0 12px rgba(34,211,238,0.6); }

.profile-info {
  display: flex; flex-direction: column; gap: 10px;
  min-width: 0;
}
.profile-id-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.profile-id {
  font-size: 22px; font-weight: 700; color: var(--ink);
  font-family: var(--font-mono);
  letter-spacing: 1.5px;
}
.profile-status-pill {
  font-size: 10px; font-weight: 800; padding: 4px 12px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 1.2px;
  border: 1px solid transparent;
}
.profile-status-pill.pass { background: var(--pass-bg); color: var(--pass); border-color: var(--pass-border); box-shadow: 0 0 12px rgba(16,185,129,0.25); }
.profile-status-pill.fail { background: var(--fail-bg); color: var(--fail); border-color: var(--fail-border); box-shadow: 0 0 12px rgba(239,68,68,0.20); }
.profile-status-pill.neu  { background: var(--surface-soft); color: var(--ink-soft); border-color: var(--border); }

.profile-stars {
  font-size: 18px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 3px; margin-bottom: 2px;
}

.stat-row { display: flex; flex-direction: column; gap: 4px; }
.stat-line {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-size: 13px;
}
.stat-label { color: var(--ink-soft); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }
.stat-value { color: var(--ink); font-size: 13px; font-family: var(--font-mono); }
.stat-value strong { font-size: 16px; color: var(--brand-deep); }
.stat-missing { color: var(--fail); font-weight: 700; margin-left: 6px; font-size: 11px; font-family: var(--font-mono); }
.stat-done { color: var(--pass); font-weight: 700; margin-left: 6px; font-size: 11px; font-family: var(--font-mono); }

.stat-bar {
  height: 10px; border-radius: 999px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 1px 2px rgba(15,23,42,0.08);
}
.stat-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .4s cubic-bezier(.4,0,.2,1);
  position: relative;
  box-shadow: 0 0 12px currentColor;
}
.stat-bar-fill::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.45), transparent);
  animation: shine 2.4s linear infinite;
}
@keyframes shine { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.stat-gold { background: linear-gradient(90deg, var(--accent-2), var(--accent)); color: var(--accent-2); }
.stat-blue { background: linear-gradient(90deg, var(--brand-2), var(--brand)); color: var(--brand-2); }

.stat-chip-row {
  display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px;
}
.stat-chip {
  background: var(--surface-soft); color: var(--ink); font-size: 11px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border);
}
.stat-chip.pass { background: var(--pass-bg); color: var(--pass); border-color: var(--pass-border); }
.stat-chip.fail { background: var(--fail-bg); color: var(--fail); border-color: var(--fail-border); }

/* ── Radar chart ─────────────────────────────────────── */
.profile-radar {
  background:
    radial-gradient(circle at 50% 50%, rgba(129,140,248,0.18), transparent 60%),
    linear-gradient(180deg, var(--surface-soft), var(--surface));
  border-radius: 16px;
  padding: 14px 14px 10px;
  display: flex; flex-direction: column; gap: 6px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.profile-radar::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(129,140,248,0.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(129,140,248,0.10) 1px, transparent 1px);
  background-size: 18px 18px;
  pointer-events: none;
  mask-image: radial-gradient(circle at center, black, transparent 75%);
}
.profile-radar > * { position: relative; z-index: 1; }
.radar-title {
  font-size: 11px; font-weight: 800; color: var(--brand-deep);
  text-transform: uppercase; letter-spacing: 1.5px; text-align: center;
}
.radar-chart-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
}
.radar-svg { width: 100%; max-width: 360px; height: auto; }
.radar-empty { padding: 20px; text-align: center; }

.radar-ring { fill: rgba(129,140,248,0.04); stroke: rgba(129,140,248,0.30); stroke-width: 1; stroke-dasharray: 2 3; }
.radar-ring-1 { fill: rgba(129,140,248,0.08); }
.radar-ring-4 { stroke: rgba(129,140,248,0.50); stroke-dasharray: none; }
.radar-ring-label { font-size: 8px; fill: var(--ink-mute); font-family: var(--font-mono); font-weight: 600; }
.radar-axis { stroke: rgba(129,140,248,0.30); stroke-width: 1; }
.radar-data { fill: rgba(129,140,248,0.30); stroke: var(--brand); stroke-width: 2; filter: drop-shadow(0 0 8px rgba(129,140,248,0.55)); }
.radar-vertex { fill: var(--brand-2); stroke: var(--surface); stroke-width: 1.5; filter: drop-shadow(0 0 6px rgba(34,211,238,0.85)); }
.radar-label { font-size: 10px; font-weight: 700; fill: var(--ink); font-family: var(--font-mono); }
.radar-label-gpa { font-size: 9px; fill: var(--brand-deep); font-weight: 700; font-family: var(--font-mono); }

.radar-legend {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 11px; color: var(--ink-soft);
  justify-content: center;
}
.legend-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 4px; vertical-align: middle;
  box-shadow: 0 0 6px currentColor;
}
.legend-data { background: var(--brand); color: var(--brand); }
.legend-ring { background: rgba(129,140,248,0.40); box-shadow: none; }

/* ── What-If: hint text + manual entry ───────────────── */
.muted-hint {
  color: var(--ink-soft); font-size: 12px; line-height: 1.7;
  margin-bottom: 12px;
  background: linear-gradient(135deg, rgba(99,102,241,0.05), rgba(6,182,212,0.05));
  border: 1px dashed rgba(99,102,241,0.30); border-radius: 10px;
  padding: 10px 12px;
}
.muted-hint strong { color: var(--brand-deep); }
.muted-hint code {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 4px; color: var(--brand-deep);
}

.manual-entry-card { border-left: 4px solid var(--accent); }
.manual-entry-card .card-title::before { background: var(--grad-warn); }

.move-elective-card { border-left: 4px solid var(--brand-2); }
.move-elective-card .card-title::before { background: linear-gradient(135deg, var(--brand-2), var(--brand)); }
.move-chip {
  background: linear-gradient(135deg, rgba(34,211,238,0.18), rgba(129,140,248,0.18));
  border-color: rgba(34,211,238,0.30);
}
.move-chip em { color: var(--brand-2); font-style: normal; font-weight: 700; }
.text-input {
  padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-family: var(--font-body); font-size: 13px; color: var(--ink);
  background: var(--surface-soft);
  transition: border-color .15s, box-shadow .15s;
}
.text-input::placeholder { color: var(--ink-mute); }
.text-input:focus { outline: none; border-color: var(--brand); box-shadow: var(--shadow-glow); }

.field-row select optgroup { font-weight: 700; color: var(--ink); }

.manual-chip {
  background: linear-gradient(135deg, rgba(245,158,11,0.10), rgba(236,72,153,0.10));
  border-color: rgba(236,72,153,0.30);
}

/* ── Planner: matched group / coverage ───────────────── */
.planner-cat {
  font-size: 12px; color: var(--ink-soft); margin-bottom: 4px;
}
.planner-match {
  font-size: 11px; color: var(--brand-deep); font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.planner-match .match-code {
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(6,182,212,0.10));
  color: var(--brand-deep);
  border: 1px solid rgba(99,102,241,0.30); border-radius: 6px;
  padding: 1px 7px; font-weight: 700;
  font-family: var(--font-mono);
}
.planner-match-miss { color: var(--ink-soft); font-style: italic; font-weight: 400; }
.planner-placeholder-hint {
  font-size: 11px; color: var(--warn); margin-top: 4px;
  background: rgba(245,158,11,0.10); border-left: 3px solid var(--accent-2);
  padding: 4px 9px; border-radius: 4px;
}
.planner-row-placeholder td:first-child input {
  background: rgba(245,158,11,0.10);
  border-color: rgba(245,158,11,0.30);
}

.group-coverage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.coverage-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
  transition: transform .15s, box-shadow .15s;
}
.coverage-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.coverage-item.ok   { border-left: 4px solid var(--pass); }
.coverage-item.warn { border-left: 4px solid var(--fail); }
.coverage-item.neu  { border-left: 4px solid var(--ink-mute); }
.coverage-head {
  display: flex; gap: 8px; align-items: baseline;
}
.coverage-code {
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(6,182,212,0.10));
  color: var(--brand-deep);
  border: 1px solid rgba(99,102,241,0.20);
  font-weight: 700; font-size: 12px;
  padding: 1px 8px; border-radius: 6px;
  font-family: var(--font-mono);
}
.coverage-label {
  font-size: 12px; color: var(--ink); font-weight: 600;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.coverage-bar {
  height: 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px; overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.40);
}
.coverage-bar-fill {
  height: 100%; background: var(--grad-pass);
  border-radius: 999px;
  box-shadow: 0 0 8px rgba(16,185,129,0.40);
}
.coverage-item.warn .coverage-bar-fill { background: var(--grad-fail); box-shadow: 0 0 8px rgba(239,68,68,0.30); }
.coverage-foot {
  display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-soft);
  font-family: var(--font-mono);
}
.remain-warn { color: var(--fail); font-weight: 700; }
.remain-ok   { color: var(--pass); font-weight: 700; }

/* ── Profile mini-stats grid ─────────────────────────── */
.profile-mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 6px;
}
.mini-tile {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, rgba(99,102,241,0.06), rgba(6,182,212,0.06));
  border: 1px solid rgba(99,102,241,0.18);
  border-radius: 12px;
  padding: 9px 12px;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.mini-tile:hover {
  transform: translateY(-1px);
  border-color: rgba(99,102,241,0.40);
  box-shadow: 0 4px 14px rgba(99,102,241,0.16);
}
.mini-icon {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  border-radius: 10px;
  font-size: 18px;
  box-shadow: 0 2px 6px rgba(99,102,241,0.10);
  flex-shrink: 0;
}
.mini-body { min-width: 0; }
.mini-label {
  font-size: 10px; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .6px;
}
.mini-value {
  font-size: 16px; font-weight: 700; color: var(--ink);
  font-family: var(--font-mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mini-value small {
  font-size: 11px; color: var(--ink-soft); font-weight: 500;
  margin-left: 2px;
}

/* ── Audit hierarchy ─────────────────────────────────── */
.topics-hierarchy {
  display: flex; flex-direction: column; gap: 12px;
}

.topic-tree {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
}
.topic-tree::before {
  content: "";
  position: absolute; top: 0; bottom: 0; left: 0;
  width: 5px;
  background: var(--ink-mute);
}
.topic-tree.topic-pass::before { background: var(--grad-pass); }
.topic-tree.topic-fail::before { background: var(--grad-fail); }
.topic-tree.topic-info::before { background: linear-gradient(180deg, var(--info), var(--brand)); }

.topic-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px 14px 22px;
  background: linear-gradient(90deg, rgba(99,102,241,0.05), transparent 60%);
  border-bottom: 1px solid var(--border-soft);
}
.topic-head-code {
  font-family: var(--font-mono);
  font-weight: 700; font-size: 14px;
  color: var(--brand-deep);
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(6,182,212,0.10));
  border: 1px solid rgba(99,102,241,0.30);
  padding: 4px 12px;
  border-radius: 8px;
  letter-spacing: .5px;
}
.topic-head-name {
  flex: 1; min-width: 0;
  font-size: 15px; font-weight: 700; color: var(--ink);
}
.topic-head-metrics {
  padding: 12px 18px 12px 22px;
}
.topic-head-metrics .topic-row-metrics {
  margin-bottom: 10px;
}
.topic-head-metrics .topic-progress {
  margin-top: 4px;
}

.topic-row-metrics {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
}
.metric {
  display: inline-flex; align-items: baseline; gap: 6px;
  font-family: var(--font-mono);
}
.metric-label { font-size: 10px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .8px; }
.metric-value { font-size: 14px; font-weight: 700; color: var(--ink); }
.metric-gpa .metric-value { padding: 1px 8px; border-radius: 6px; }
.metric-gpa.metric-excellent .metric-value { background: rgba(52,211,153,0.16); color: var(--pass); border: 1px solid var(--pass-border); }
.metric-gpa.metric-good      .metric-value { background: rgba(129,140,248,0.18); color: var(--brand); border: 1px solid rgba(129,140,248,0.40); }
.metric-gpa.metric-ok        .metric-value { background: rgba(251,191,36,0.16); color: var(--warn); border: 1px solid var(--warn-border); }
.metric-gpa.metric-low       .metric-value { background: rgba(248,113,113,0.16); color: var(--fail); border: 1px solid var(--fail-border); }
.metric-gpa.metric-none      .metric-value { color: var(--ink-mute); }

.topic-progress {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px; overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.40);
}
.topic-progress-fill {
  height: 100%; border-radius: 999px;
  background: var(--grad-pass);
  box-shadow: 0 0 8px rgba(16,185,129,0.30);
}
.topic-fail .topic-progress-fill { background: var(--grad-fail); box-shadow: 0 0 8px rgba(239,68,68,0.30); }

.topic-status-pill {
  font-size: 10px; font-weight: 800; padding: 4px 12px;
  border-radius: 999px; letter-spacing: 1px; text-transform: uppercase;
  border: 1px solid transparent;
  flex-shrink: 0;
}
.topic-status-pass { background: var(--pass-bg); color: var(--pass); border-color: var(--pass-border); }
.topic-status-fail { background: var(--fail-bg); color: var(--fail); border-color: var(--fail-border); }
.topic-status-info { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }
.topic-status-neu  { background: var(--surface-soft); color: var(--ink-soft); border-color: var(--border); }

.topic-note {
  margin: 0 18px 14px 22px;
  font-size: 11px;
  color: var(--warn);
  background: rgba(245,158,11,0.10);
  border-left: 3px solid var(--accent-2);
  padding: 6px 10px;
  border-radius: 6px;
  font-family: var(--font-mono);
}

.topic-children {
  padding: 6px 14px 14px 22px;
  display: flex; flex-direction: column; gap: 6px;
  border-top: 1px dashed var(--border-soft);
  background: var(--surface-soft);
}

.topic-child {
  --indent: 18px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 9px 12px 9px calc(var(--indent) * var(--depth, 1) + 12px);
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
  transition: border-color .15s;
}
.topic-child[data-depth="1"] { --depth: 1; }
.topic-child[data-depth="2"] { --depth: 2; }
.topic-child[data-depth="3"] { --depth: 3; }
.topic-child[data-depth="4"] { --depth: 4; }
.topic-child::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--ink-mute);
  border-top-left-radius: 10px; border-bottom-left-radius: 10px;
}
.topic-child.topic-pass::before { background: var(--pass); }
.topic-child.topic-fail::before { background: var(--fail); }
.topic-child.topic-info::before { background: var(--info); }
.topic-child:hover { border-color: rgba(99,102,241,0.30); }

.topic-child-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.topic-code-chip {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 700;
  color: var(--brand-deep);
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.20);
  padding: 1px 8px;
  border-radius: 6px;
}
.topic-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: var(--ink); }

.topic-child .topic-row-metrics { gap: 14px; }
.topic-child .topic-progress { margin-top: 2px; }
.topic-child .topic-note { margin: 4px 0 0; }

/* ── Disclosure / expandable group ───────────────────── */
.topic-tree-details, .topic-child {
  list-style: none;
}
.topic-tree-details > summary,
.topic-child > summary {
  list-style: none;
  cursor: pointer;
}
.topic-tree-details > summary::-webkit-details-marker,
.topic-child > summary::-webkit-details-marker { display: none; }

.topic-disclosure {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  color: var(--ink-mute);
  font-size: 12px;
  transition: transform .2s ease, color .2s ease;
  flex-shrink: 0;
}
.topic-tree-details[open] > summary > .topic-disclosure,
.topic-child[open] > summary > .topic-disclosure {
  transform: rotate(90deg);
  color: var(--brand);
}
.topic-tree-details > summary:hover { background: rgba(129,140,248,0.06); }

/* Topic course list */
.topic-courses-panel {
  margin: 4px 18px 14px 22px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.topic-child .topic-courses-panel {
  margin: 8px 0 4px 0;
}
.topic-courses-empty {
  padding: 10px 14px;
  margin: 4px 18px 14px 22px;
  color: var(--ink-mute);
  background: var(--surface-soft);
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-style: italic;
}

.course-block {
  background: var(--surface-soft);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
}
.course-block-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(129,140,248,0.07);
  border-bottom: 1px solid var(--border-soft);
}
.course-block-title {
  font-size: 12px; font-weight: 700; color: var(--ink);
  letter-spacing: .2px;
}
.course-block-count {
  font-size: 11px; font-weight: 700; color: var(--brand);
  font-family: var(--font-mono);
  background: rgba(129,140,248,0.16);
  border: 1px solid rgba(129,140,248,0.30);
  padding: 1px 8px; border-radius: 999px;
}
.course-empty {
  padding: 10px 14px;
  font-size: 12px; font-style: italic;
}

.course-mini-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.course-mini-table th {
  background: rgba(0,0,0,0.18);
  color: var(--ink-soft);
  font-weight: 700; font-size: 10px; text-transform: uppercase;
  letter-spacing: .6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
}
.course-mini-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--ink);
}
.course-mini-table tr:last-child td { border-bottom: none; }
.course-mini-table tr:hover td { background: rgba(129,140,248,0.05); }
.course-code-cell { font-family: var(--font-mono); font-weight: 600; color: var(--brand); white-space: nowrap; }

.grade-chip-pass {
  background: var(--pass-bg); color: var(--pass);
  border-color: var(--pass-border);
}
.grade-chip-fail {
  background: var(--fail-bg); color: var(--fail);
  border-color: var(--fail-border);
}
.grade-chip-empty {
  background: rgba(255,255,255,0.04); color: var(--ink-mute);
  border-color: var(--border);
  font-style: italic;
}

/* ── Adventure tab ───────────────────────────────────── */
.adv-toolbar {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.adv-card {
  padding: 18px 18px 14px;
}
.adv-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 900 / 320;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.04),
    0 12px 32px rgba(0,0,0,0.40);
  background: var(--bg-deep);
  margin-top: 10px;
}
#advCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
}

/* ── Fullscreen + pseudo-fullscreen ──────────────────── */
.adv-stage:fullscreen,
.adv-stage:-webkit-full-screen,
.adv-stage.pseudo-fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.adv-stage.pseudo-fullscreen {
  /* iOS / older browsers fallback — fixed-position cover */
  position: fixed;
  inset: 0;
  z-index: 999;
}
.adv-stage:fullscreen #advCanvas,
.adv-stage:-webkit-full-screen #advCanvas,
.adv-stage.pseudo-fullscreen #advCanvas {
  /* Preserve aspect ratio, letterbox via flex centering above. */
  width: auto;
  height: auto;
  max-width: 100vw;
  max-height: 100vh;
  /* fit: width when wide enough, height-bound otherwise */
  aspect-ratio: 900 / 320;
}
/* Wide screens (real landscape) — bind to viewport width */
@media (min-aspect-ratio: 900/320) {
  .adv-stage:fullscreen #advCanvas,
  .adv-stage:-webkit-full-screen #advCanvas,
  .adv-stage.pseudo-fullscreen #advCanvas {
    height: 100vh;
    width: calc(100vh * (900/320));
  }
}
/* Narrow screens (portrait or near-square) — bind to viewport height */
@media (max-aspect-ratio: 900/320) {
  .adv-stage:fullscreen #advCanvas,
  .adv-stage:-webkit-full-screen #advCanvas,
  .adv-stage.pseudo-fullscreen #advCanvas {
    width: 100vw;
    height: calc(100vw * (320/900));
  }
}
body.adv-fs-lock { overflow: hidden; }

.adv-fs-exit-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px; height: 38px;
  background: rgba(10,14,26,0.78);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  z-index: 50;
  display: none;
  align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
  transition: background .15s, border-color .15s;
}
.adv-fs-exit-btn:hover {
  background: rgba(248,113,113,0.20);
  border-color: var(--fail);
  color: var(--fail);
}
.adv-stage:fullscreen .adv-fs-exit-btn,
.adv-stage:-webkit-full-screen .adv-fs-exit-btn,
.adv-stage.pseudo-fullscreen .adv-fs-exit-btn {
  display: flex;
}

.adv-char-picker {
  display: flex; gap: 14px; justify-content: center;
  margin: 6px 0 18px;
}
.adv-char-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 12px 10px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 2px solid var(--border);
  color: var(--ink-soft);
  font-size: 12px; font-weight: 700;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s, color .15s;
  font-family: var(--font-body);
}
.adv-char-btn img {
  width: 84px; height: 84px;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.45));
  transition: filter .15s;
}
.adv-char-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(129,140,248,0.45);
  color: var(--ink);
}
.adv-char-btn.selected {
  border-color: var(--brand);
  color: var(--brand);
  background: linear-gradient(135deg, rgba(129,140,248,0.16), rgba(34,211,238,0.16));
  box-shadow: 0 8px 22px rgba(129,140,248,0.30), inset 0 0 0 1px rgba(255,255,255,0.06);
}
.adv-char-btn.selected img {
  filter: drop-shadow(0 6px 14px rgba(129,140,248,0.55));
}

.adv-hud {
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  display: flex; gap: 10px; flex-wrap: wrap;
  pointer-events: none;
}
.adv-stat {
  background: rgba(10,14,26,0.78);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  display: flex; align-items: center; gap: 8px;
  color: var(--ink);
  font-size: 12px;
  font-family: var(--font-mono);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.30);
}
.adv-stat-label {
  font-size: 10px; font-weight: 800;
  color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .8px;
}
.adv-stat-value {
  font-weight: 700;
  color: var(--brand);
}
.adv-bar {
  width: 110px; height: 8px;
  background: rgba(255,255,255,0.10);
  border-radius: 999px; overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.40);
}
.adv-bar-fill {
  height: 100%;
  background: var(--grad-pass);
  border-radius: 999px;
  box-shadow: 0 0 8px rgba(52,211,153,0.50);
  transition: width .25s ease;
}

.adv-overlay {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(99,102,241,0.18), transparent 60%),
    rgba(10,14,26,0.86);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
  transition: opacity .25s ease;
}
.adv-overlay.hidden { display: none; }
.adv-overlay-inner {
  text-align: center;
  padding: 32px 36px;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lift);
}
.adv-overlay-icon {
  font-size: 48px;
  margin-bottom: 10px;
  filter: drop-shadow(0 4px 12px rgba(129,140,248,0.45));
}
.adv-overlay-inner h3 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 12px;
  background: var(--grad-brand);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: .3px;
}
.adv-overlay-inner p {
  color: var(--ink-soft);
  margin-bottom: 18px;
  line-height: 1.7;
}
.adv-overlay-inner p strong { color: var(--ink); }
.adv-overlay-inner .btn-primary { width: auto; padding: 10px 24px; }

/* ── Mobile topbar + drawer (hidden on desktop) ──────── */
.mobile-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  height: 56px;
  z-index: 250;
  align-items: center; gap: 12px;
  padding: 0 14px;
  background: rgba(10,14,26,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0,0,0,0.40);
}
.mobile-topbar-icon {
  width: 32px; height: 32px;
  border-radius: 22%;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(99,102,241,0.30);
}
.mobile-topbar-title {
  font-size: 15px; font-weight: 700; color: var(--ink);
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.mobile-menu-btn {
  width: 38px; height: 38px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  cursor: pointer; padding: 0;
  transition: background .15s, border-color .15s;
}
.mobile-menu-btn:hover { background: rgba(129,140,248,0.10); border-color: var(--brand); }
.mobile-menu-btn span {
  display: block;
  width: 18px; height: 2px;
  background: var(--ink);
  border-radius: 999px;
  transition: transform .25s ease, opacity .15s ease;
}
.mobile-menu-btn.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.mobile-menu-btn.open span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  z-index: 290;
  opacity: 0;
  transition: opacity .25s ease;
}
.sidebar-backdrop.open {
  display: block;
  opacity: 1;
}

body.nav-open { overflow: hidden; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1100px) {
  .profile-card {
    grid-template-columns: 100px 1fr;
  }
  .profile-radar {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  /* Mobile topbar visible */
  .mobile-topbar { display: flex; }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: 248px; height: 100vh;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 300;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0,0,0,0.50);
    padding-top: 4px;
  }
  .sidebar.open { transform: translateX(0); }
  /* Restore the sidebar text/badges that the old breakpoint hid */
  .brand-name, .nav-item, .badge-new { display: flex; }
  .nav-item { padding: 12px 14px; font-size: 14px; }
  .student-chip { display: inline-block; }
  .sidebar-footer { padding: 14px 16px; }
  .sidebar-footer .btn-ghost { width: 100%; }

  /* Main content takes the full width and accounts for the topbar */
  .main-content {
    padding: 70px 14px 28px;
    width: 100%;
    /* Safety net — keeps anything that accidentally overflows from
       producing a horizontal scroll on the whole page */
    overflow-x: hidden;
  }
  .panel { min-width: 0; }
  .card  { min-width: 0; max-width: 100%; box-sizing: border-box; }
  .panel-header h2 { font-size: 17px; flex: 1 0 100%; }
  .panel-header { gap: 10px; flex-wrap: wrap; }
  /* Force any toolbar inside the panel header to claim full width on mobile */
  .panel-header > .planner-toolbar,
  .panel-header > .adv-toolbar { flex: 1 0 100%; width: 100%; }
  .planner-program-select { width: 100%; }
  .teacher-banner { font-size: 12px; padding: 8px 12px; }

  /* Cards: tighter padding, smaller titles */
  .card { padding: 14px 14px; border-radius: 14px; }
  .card-title { font-size: 11px; margin-bottom: 12px; }
  .mt-2 { margin-top: 12px; }

  /* Forms / what-if / planner controls — fully stack */
  .whatif-controls { flex-direction: column; align-items: stretch; gap: 8px; }
  .field-row { min-width: 0; width: 100%; }
  .planner-toolbar { flex-direction: column; align-items: stretch; }
  .planner-toolbar .btn-primary,
  .planner-toolbar .btn-outline,
  .planner-toolbar .btn-secondary,
  .planner-toolbar .btn-ghost { width: 100%; }
  .action-row { flex-direction: column; align-items: stretch; }
  .action-row .btn-primary,
  .action-row .btn-ghost { width: 100%; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-value { font-size: 18px; }
  .group-coverage-grid { grid-template-columns: 1fr; width: 100%; }
  .coverage-item   { min-width: 0; max-width: 100%; box-sizing: border-box; }
  .coverage-label  { white-space: normal; word-break: break-word; line-height: 1.4; }
  .coverage-foot   { gap: 8px; flex-wrap: wrap; }

  /* Profile panel — single column, smaller avatar inline */
  .profile-card {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 16px 14px;
  }
  .profile-avatar { flex-direction: row; justify-content: flex-start; gap: 12px; }
  .avatar-circle { width: 76px; height: 76px; }
  .avatar-circle img { width: 66px; height: 66px; }
  .avatar-level { padding: 3px 10px; }
  .profile-mini-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mini-tile { padding: 8px 10px; }
  .mini-icon { width: 28px; height: 28px; font-size: 16px; }
  .mini-value { font-size: 14px; }

  /* Audit hierarchy — wrap heads cleanly, less indent */
  .topic-head { flex-wrap: wrap; padding: 12px 12px 12px 18px; gap: 8px; }
  .topic-head-code { font-size: 12px; padding: 3px 9px; }
  .topic-head-name { width: 100%; order: 3; font-size: 14px; }
  .topic-head-metrics { padding: 10px 12px 10px 18px; }
  .topic-children { padding: 6px 8px 10px 14px; }
  .topic-child {
    --indent: 8px;
    padding: 8px 10px 8px calc(8px * var(--depth, 1) + 10px);
  }
  .topic-row-metrics { gap: 10px; }
  .metric-value { font-size: 13px; }
  .topic-courses-panel { margin: 4px 8px 10px 14px; }
  .course-mini-table th, .course-mini-table td { padding: 5px 7px; font-size: 11px; }

  /* Adventure — keep the canvas readable, stack toolbar buttons */
  .adv-toolbar { width: 100%; }
  .adv-toolbar .btn-primary,
  .adv-toolbar .btn-outline { flex: 1; }
  .adv-stat { padding: 4px 9px; font-size: 11px; }
  .adv-stat-label { font-size: 9px; }
  .adv-bar { width: 80px; }
  .adv-overlay-inner h3 { font-size: 18px; }
  .adv-char-btn img { width: 64px; height: 64px; }

  /* The canvas is very short (~128 px) on a portrait phone, so the start /
     game-over overlay would clip its character picker if it stayed bound to
     the stage. Promote it to a full-viewport modal on mobile so the picker
     and start button are always reachable. */
  .adv-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    padding: 20px 16px;
    overflow-y: auto;
    align-items: flex-start;
  }
  .adv-overlay-inner {
    max-width: 360px;
    max-height: none;
    margin: auto;
    padding: 22px 20px;
  }
  /* When the rotate prompt is up, hide the start-game overlay so the player
     rotates first instead of seeing two stacked dialogs. */
  body.adv-rotate-active .adv-overlay { display: none; }

  /* The rotate overlay now lives at the body level so it can fully cover
     the viewport without being clipped by .adv-stage's aspect-ratio +
     overflow:hidden. Push it down below the mobile topbar so the
     "เริ่มเกม" button isn't competing with it. */
  .adv-rotate-overlay {
    position: fixed;
    inset: 0;
    z-index: 220;          /* above start overlay (200), below topbar (250) */
    padding: 90px 16px 24px;
    align-items: center;
  }

  /* Modals — full-width with margin */
  .modal-box { max-width: calc(100vw - 32px); padding: 22px 20px; }

  /* Login — already mostly centered, just shrink padding */
  .login-card { max-width: calc(100vw - 32px); }
  .login-hero { padding: 28px 20px 24px; }
}

@media (max-width: 480px) {
  .mobile-topbar-title { font-size: 14px; }
  .summary-grid { grid-template-columns: 1fr; }
  .profile-mini-grid { grid-template-columns: 1fr; }
  .panel-header h2 { font-size: 16px; }
  .topic-head-name { font-size: 13px; }
  .login-hero h1 { font-size: 18px; }
  .login-logo { width: 72px; height: 72px; }
}

/* ── Mobile-only: planner table → stacked cards ──────── */
@media (max-width: 768px) {
  .planner-table { border-collapse: separate; border-spacing: 0; }
  .planner-table thead { display: none; }
  .planner-table, .planner-table tbody, .planner-table tr, .planner-table td {
    display: block;
    width: 100%;
  }
  .planner-table tbody { display: flex; flex-direction: column; gap: 10px; }
  .planner-table tr {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 12px 6px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.20);
  }
  .planner-table tr:hover td { background: transparent; }
  .planner-table td {
    padding: 6px 0;
    border: none;
  }
  .planner-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 4px;
  }
  .planner-table .planner-cell-action {
    display: flex;
    justify-content: flex-end;
    padding-top: 8px;
  }
  .planner-table .planner-cell-action::before { display: none; }
  .planner-table .planner-cell-action .btn-ghost {
    width: auto;
    padding: 5px 14px;
  }
  .planner-table .planner-input,
  .planner-table .planner-grade { width: 100%; }
  .planner-row-placeholder {
    border-color: rgba(245,158,11,0.40);
    background: linear-gradient(135deg, rgba(245,158,11,0.06), rgba(245,158,11,0));
  }
  .planner-term-actions { padding: 0 4px; }
}

/* ── Mobile-only: adventure character picker stacks ──── */
@media (max-width: 768px) {
  .adv-char-picker {
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 280px;
    margin: 6px auto 14px;
  }
  .adv-char-btn {
    flex-direction: row;
    width: 100%;
    justify-content: flex-start;
    padding: 8px 14px;
    gap: 12px;
  }
  .adv-char-btn img {
    width: 56px; height: 56px;
    flex-shrink: 0;
  }
  .adv-char-btn span { font-size: 14px; }
  .adv-overlay-inner { max-height: calc(100vh - 120px); overflow-y: auto; }
}

/* ── Rotate-to-landscape prompt (mobile portrait, adventure tab) ── */
.adv-rotate-overlay {
  position: absolute; inset: 0;
  z-index: 6;          /* above HUD, below the start/game-over overlay */
  background:
    radial-gradient(ellipse at center, rgba(99,102,241,0.20), transparent 60%),
    rgba(10,14,26,0.92);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  text-align: center;
}
.adv-rotate-overlay.hidden { display: none; }
.adv-rotate-inner {
  padding: 24px 26px;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lift);
}
.adv-rotate-icon {
  font-size: 56px;
  animation: advRotateBounce 1.6s ease-in-out infinite;
  margin-bottom: 10px;
  filter: drop-shadow(0 4px 14px rgba(129,140,248,0.60));
  line-height: 1;
}
@keyframes advRotateBounce {
  0%, 100% { transform: rotate(-12deg); }
  50%      { transform: rotate(12deg); }
}
.adv-rotate-inner h3 {
  font-size: 18px;
  background: var(--grad-brand);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
  font-weight: 800;
  line-height: 1.4;
}
.adv-rotate-inner p {
  color: var(--ink-soft);
  font-size: 14px; line-height: 1.7;
  margin-bottom: 16px;
}
.adv-rotate-inner .btn-primary { width: auto; padding: 10px 22px; font-size: 13px; }

/* ── Settings panel ──────────────────────────────────── */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 6px;
}
.theme-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--ink);
  text-align: left;
  transition: transform .12s ease, border-color .15s, box-shadow .15s;
}
.theme-card:hover { transform: translateY(-1px); border-color: var(--brand); }
.theme-card.active {
  border-color: var(--brand);
  box-shadow: var(--shadow-glow);
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(34,211,238,0.06));
}
.theme-swatch {
  display: block;
  height: 72px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  position: relative;
  overflow: hidden;
}
.theme-swatch::after {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.18), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(0,0,0,0.18), transparent 45%);
  pointer-events: none;
}
.theme-swatch-dark   { background: linear-gradient(135deg, #0a0e1a 0%, #1c2543 50%, #22d3ee 110%); }
.theme-swatch-light  { background: linear-gradient(135deg, #f4f6fb 0%, #c7d2fe 60%, #4f46e5 130%); }
.theme-swatch-ocean  { background: linear-gradient(135deg, #04111a 0%, #0e2a3a 45%, #5eead4 120%); }
.theme-swatch-sunset { background: linear-gradient(135deg, #1a0a14 0%, #ea580c 60%, #facc15 120%); }
.theme-swatch-forest { background: linear-gradient(135deg, #0a1a10 0%, #16a34a 60%, #facc15 130%); }
.theme-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.theme-name small {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-top: 2px;
}

.settings-profile-row {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 24px;
  align-items: flex-start;
}
@media (max-width: 640px) {
  .settings-profile-row { grid-template-columns: 1fr; }
}
.settings-avatar-block {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px;
}
.settings-avatar-preview {
  width: 140px; height: 140px;
  border-radius: 50%;
  background: var(--surface-soft);
  border: 2px solid var(--border);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.settings-avatar-preview img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.settings-avatar-btn { cursor: pointer; }
.settings-avatar-note { font-size: 11px; color: var(--ink-mute); margin-top: 2px; }

.settings-fields-block {
  display: flex; flex-direction: column;
  gap: 10px;
}
.settings-fields-block .field input {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface-soft);
  transition: border-color .15s, box-shadow .15s;
}
.settings-fields-block .field input:focus {
  outline: none; border-color: var(--brand); box-shadow: var(--shadow-glow);
}
.settings-fields-block .field label {
  font-size: 12px; font-weight: 600;
  color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px;
}
.settings-hint { font-size: 11px; color: var(--ink-mute); margin-top: 4px; }
.settings-save-btn { width: auto; padding: 10px 22px; }

/* Profile panel — show real avatar / display name */
.avatar-circle img.avatar-photo {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.profile-display-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 2px;
  letter-spacing: .2px;
}
.profile-display-name-empty {
  color: var(--ink-mute);
  font-style: italic;
  font-weight: 600;
}
