:root,
html.theme-light {
  color-scheme: light;
  --bg: #edf7ff;
  --card: rgba(255, 255, 255, 0.72);
  --ink: #0f172a;
  --muted: #5b6b7f;
  --blue: #0284c7;
  --navy: #312e81;
  --line: rgba(255, 255, 255, 0.55);
  --key: rgba(255, 255, 255, 0.5);
  --key-num: rgba(255, 255, 255, 0.62);
  --key-special: rgba(236, 236, 239, 0.55);
  --surface: rgba(255, 255, 255, 0.4);
  --header: rgba(255, 255, 255, 0.38);
  --header-ink: #0f172a;
  --ghost: rgba(255, 255, 255, 0.35);
  --ghost-ink: #0f172a;
  --choice: rgba(255, 255, 255, 0.32);
  --choice-on: rgba(255, 255, 255, 0.72);
  --danger: #c62828;
  --ok-bg: rgba(52, 199, 89, 0.16);
  --ok-ink: #0d6a32;
  --err-bg: rgba(255, 59, 48, 0.12);
  --err-ink: #b42318;
  --shadow: 0 12px 38px rgba(15, 76, 129, 0.13);
  --kb-bar: rgba(255, 255, 255, 0.28);
  --grad: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
  --glass: blur(28px) saturate(180%);
  --glass-border: 1px solid rgba(255, 255, 255, 0.55);
  --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  --orb-a: rgba(14, 165, 233, 0.48);
  --orb-b: rgba(99, 102, 241, 0.32);
  --orb-c: rgba(45, 212, 191, 0.35);
}

html.theme-dark {
  color-scheme: dark;
  --bg: #07111f;
  --card: rgba(15, 35, 55, 0.56);
  --ink: #f2f2f7;
  --muted: #9898a6;
  --blue: #f2f2f7;
  --navy: #f2f2f7;
  --line: rgba(255, 255, 255, 0.12);
  --key: rgba(255, 255, 255, 0.08);
  --key-num: rgba(255, 255, 255, 0.12);
  --key-special: rgba(255, 255, 255, 0.06);
  --surface: rgba(255, 255, 255, 0.06);
  --header: rgba(18, 20, 28, 0.55);
  --header-ink: #f2f2f7;
  --ghost: rgba(255, 255, 255, 0.08);
  --ghost-ink: #f2f2f7;
  --choice: rgba(255, 255, 255, 0.06);
  --choice-on: rgba(255, 255, 255, 0.16);
  --danger: #ff6b6b;
  --ok-bg: rgba(48, 209, 88, 0.14);
  --ok-ink: #7ee2a8;
  --err-bg: rgba(255, 69, 58, 0.14);
  --err-ink: #ff8a80;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --kb-bar: rgba(255, 255, 255, 0.06);
  --grad: linear-gradient(135deg, rgba(37, 99, 235, 0.88), rgba(6, 182, 212, 0.82));
  --glass: blur(32px) saturate(160%);
  --glass-border: 1px solid rgba(255, 255, 255, 0.14);
  --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  --orb-a: rgba(14, 165, 233, 0.32);
  --orb-b: rgba(99, 102, 241, 0.26);
  --orb-c: rgba(45, 212, 191, 0.22);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: -0.01em;
}
body {
  position: relative;
  isolation: isolate;
}
body::before {
  content: "";
  position: fixed;
  inset: -25%;
  z-index: -1;
  background:
    radial-gradient(42% 36% at 18% 12%, var(--orb-a), transparent 70%),
    radial-gradient(38% 32% at 88% 18%, var(--orb-b), transparent 68%),
    radial-gradient(40% 34% at 52% 92%, var(--orb-c), transparent 70%);
  filter: blur(48px);
  pointer-events: none;
}

html { -webkit-tap-highlight-color: transparent; }
button, .btn { font-family: inherit; }
:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px calc(28px + env(safe-area-inset-bottom, 0px));
}
html.kb-open .wrap { padding-bottom: min(72dvh, 540px); }

.card,
.test-tile,
.qcard,
.student-card,
.choices label,
.theme-toggle {
  background: var(--card);
  -webkit-backdrop-filter: var(--glass);
  backdrop-filter: var(--glass);
  border: var(--glass-border);
  box-shadow: var(--shadow), var(--glass-inset);
}

.card {
  color: var(--ink);
  border-radius: 22px;
  padding: 20px;
}
.brand-lockup { display: inline-flex; align-items: center; gap: 9px; min-width: 0; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 12px; object-fit: cover;
  border: 1px solid rgba(6, 182, 212, .28);
  box-shadow: 0 6px 18px rgba(2, 132, 199, .2);
}
.brand-name { font-weight: 720; letter-spacing: -.025em; color: var(--ink); }
h1, h2, h3, h4 {
  color: var(--ink);
  font-weight: 590;
  letter-spacing: -0.03em;
}
h1 { font-size: 28px; font-weight: 600; }
h2 { font-size: 22px; }
p { color: var(--muted); font-weight: 400; }

input, input[type=text], input[type=password], select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: var(--glass-border);
  border-radius: 14px;
  font-size: 16px;
  background: var(--surface);
  color: var(--ink);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  box-shadow: var(--glass-inset);
}
input::placeholder { color: var(--muted); }

.btn, button.btn {
  width: 100%;
  border: var(--glass-border);
  background: var(--grad);
  color: #fff;
  padding: 13px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 10px;
  letter-spacing: -0.01em;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow), var(--glass-inset);
}
html.theme-dark .btn,
html.theme-dark button.btn {
  color: var(--ink);
}
.btn.ghost, button.ghost {
  background: var(--ghost);
  color: var(--ghost-ink);
}
.hidden { display: none !important; }
.q { padding: 4px 0; border-bottom: 0; }
.q.card { margin-bottom: 8px; padding: 14px 16px; }
.q-title { font-weight: 590; margin-bottom: 8px; color: var(--ink); }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices label {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 12px;
  border-radius: 12px;
  color: var(--ink);
  font-weight: 650;
  cursor: pointer;
}
.choices input { display: none; }
.choices input:checked + span,
.choices label:has(input:checked) {
  background: var(--ink);
  color: var(--bg);
  box-shadow: none;
  border-color: var(--ink);
}
.q-row .choices label {
  min-width: 36px;
  min-height: 36px;
  padding: 4px 10px;
}
.written { display: grid; gap: 8px; }
.written-row { display: flex; gap: 8px; align-items: center; }
.math-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.math-tool {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 0;
  padding: 0;
  background: transparent;
  color: #2f80ff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.math-tool.active { color: #1760d8; }
html.theme-dark .math-tool { color: #6aa8ff; }
.written-row input, .written-row math-field.math-in { flex: 1; width: auto; min-width: 0; }
math-field.math-in {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 10px;
  border-radius: 14px;
  border: 1.5px solid rgba(28, 28, 30, 0.22);
  background: var(--surface);
  font-size: 22px;
  --caret-color: var(--ink);
  --contains-highlight-background-color: transparent;
}
html.theme-dark math-field.math-in {
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
}
math-field.math-in [part="virtual-keyboard-toggle"],
math-field.math-in [part="menu-toggle"],
math-field.math-in .ML__toggles,
math-field.math-in .ML__virtual-keyboard-toggle,
math-field.math-in .ML__menu-toggle {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}
math-field.math-in::part(virtual-keyboard-toggle),
math-field.math-in::part(menu-toggle),
math-field.math-in::part(toggles) {
  display: none !important;
}

.mathkb {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  max-width: 560px;
  margin: 0 auto;
  max-height: min(72dvh, 560px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #111;
  border: 0;
  border-radius: 16px 16px 0 0;
  padding: 6px 6px max(10px, env(safe-area-inset-bottom, 0px));
  color: #eee;
  box-sizing: border-box;
}
html.kb-open { padding-bottom: 0; }
.mathkb-top {
  display: flex;
  justify-content: flex-end;
  padding: 2px 2px 6px;
}
.mathkb .kb-tools { display: flex; gap: 4px; }
.mathkb-row {
  display: grid;
  gap: 4px;
  margin-bottom: 4px;
  min-width: 0;
}
.mathkb-row.n10 { grid-template-columns: repeat(10, minmax(0, 1fr)); }
.mathkb-row.n9 { grid-template-columns: repeat(9, minmax(0, 1fr)); }
.mathkb-row.n6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.mathkb-row.n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mathkb .key {
  height: 38px;
  min-width: 0;
  width: 100%;
  padding: 0 1px;
  border: 0;
  border-radius: 8px;
  background: #2b2b2b;
  color: #f3f3f3;
  font-size: 15px;
  font-family: KaTeX_Main, "Times New Roman", Times, serif;
  line-height: 1.05;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.mathkb .key.num { font-weight: 600; font-size: 16px; }
.mathkb .key.special { background: #3a3a3a; }
.mathkb .key.enter { background: #3a3a3a; font-size: 18px; }
.mathkb .key.tool {
  width: 36px;
  height: 32px;
  background: transparent;
  font-size: 16px;
}
.mathkb .key i {
  font-style: normal;
  font-size: 11px;
  border: 1px solid #bbb;
  padding: 0 3px;
  border-radius: 2px;
  line-height: 1.2;
}
.mathkb .key.tall { height: 38px; font-size: 13px; }
.mathkb .kfrac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  gap: 1px;
}
.mathkb .kfrac i { font-size: 10px; }
.mathkb .kfrac i:first-child {
  border-bottom: 1px solid #ddd;
  padding-bottom: 1px;
}
.mathkb sup { font-size: 10px; }
.mathkb sub { font-size: 10px; }
.msg {
  padding: 12px;
  border-radius: 14px;
  background: var(--ok-bg);
  color: var(--ok-ink);
  border: var(--glass-border);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.err {
  background: var(--err-bg);
  color: var(--err-ink);
  padding: 10px 12px;
  border-radius: 14px;
  border: var(--glass-border);
}
.theme-toggle {
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--ghost-ink);
}
@media (max-width: 420px) {
  .mathkb .key { height: 34px; font-size: 12px; }
  .mathkb .key.num { font-size: 14px; }
}

.hero {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.hero-mark { display: none; }
.hero h1 { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 14px; }
.chip {
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  border: var(--glass-border);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.q-title { display: flex; align-items: center; gap: 8px; }
.q-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  border: var(--glass-border);
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-weight: 500;
  color: var(--muted);
  font-size: 13px;
}

.code-input {
  text-align: center;
  letter-spacing: 0.18em;
  font-size: 22px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.sec-head {
  margin: 0;
  padding: 12px 14px 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: none;
}
.sheet-card {
  overflow: hidden;
  padding: 4px 0 8px;
  margin-bottom: 12px;
}
.card.sheet-card { padding: 4px 0 8px; }
.sheet-row,
.q-row {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 8px;
  align-items: center;
  padding: 6px 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}
.sheet-row.has-subj {
  grid-template-columns: 40px auto 1fr;
}
.sheet-n, .q-num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  text-align: center;
}
.sheet-row .subj { margin: 0; }
.sheet-row .opts, .q-row .choices { margin: 0; }
.sheet-row:last-child, .q-row:last-child { border-bottom: 0; }
.q-row.need, .sheet-row.need, .q.card.need {
  background: var(--err-bg);
}
.q-row.picked .q-num { color: var(--ok-ink); }

.exam-sticky {
  position: sticky;
  top: 0;
  z-index: 18;
  margin: 0 0 12px;
  padding: 12px 14px 10px;
  border-radius: 18px;
  background: var(--header);
  -webkit-backdrop-filter: var(--glass);
  backdrop-filter: var(--glass);
  border: var(--glass-border);
}
.exam-sticky h1 { font-size: 20px; margin: 0; }
.exam-sticky p { margin: 4px 0 0; font-size: 13px; }
.exam-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.exam-bar {
  height: 8px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(28, 28, 30, 0.14);
  overflow: hidden;
}
html.theme-dark .exam-bar {
  background: rgba(255, 255, 255, 0.16);
}
.exam-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ink);
  border-radius: inherit;
  transition: width .2s ease;
}
.exam-count {
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  white-space: nowrap;
}
.exam-map {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
  max-height: 92px;
  overflow-y: auto;
}
.exam-map button {
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 650;
  background: var(--surface);
  color: var(--muted);
  border: var(--glass-border);
}
.exam-map button.on {
  background: var(--ink);
  color: var(--bg);
}
.exam-map button.miss {
  color: var(--err-ink);
  border-color: var(--danger);
}
.exam-dock {
  position: sticky;
  bottom: 0;
  z-index: 17;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.exam-dock .btn { margin-top: 0; }
.exam-dock p:empty { display: none; }
.exam-dock .err, .exam-dock .msg { margin: 0 0 8px; }
.done-card { text-align: center; padding: 36px 20px; }
.done-card h1 { margin-bottom: 8px; }

.action-stack { display: grid; gap: 12px; margin: 14px 0; }
.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: var(--glass-border);
}
.action-label {
  width: 100%;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 2px;
}
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: none;
}
@media (max-width: 640px) {
  .home-grid { grid-template-columns: 1fr; }
  .sheet-row.has-subj {
    grid-template-columns: 40px 1fr;
  }
  .sheet-row.has-subj .subj { grid-column: 2; }
  .sheet-row.has-subj .opts { grid-column: 1 / -1; }
}
@media (min-width: 860px) {
  .admin-main { max-width: 1080px; }
}
