:root {
  color-scheme: light;
  --ink: #f7fbff;
  --navy-900: #eaf3ff;
  --navy-800: #dcecff;
  --navy-700: #c7dcff;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-solid: #ffffff;
  --text: #071426;
  --muted: #52647f;
  --line: rgba(59, 111, 190, 0.2);
  --line-soft: rgba(59, 111, 190, 0.12);
  --brand: #1f6fff;
  --brand-dim: #0f4fbd;
  --brand-2: #0b57cf;
  --ok: #5ecf9a;
  --bad: #f08080;
  --warn: #e8c06a;
  --shadow: 0 18px 48px rgba(31, 91, 166, 0.16);
  --glow-brand: 0 0 28px rgba(31, 111, 255, 0.18);
  --topbar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(232, 243, 255, 0.76) 100%);
  --sidebar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.72) 0%, rgba(231, 242, 255, 0.5) 100%);
  --input-bg: rgba(255, 255, 255, 0.72);
  --button-soft: rgba(255, 255, 255, 0.66);
  --calc-bg: rgba(255, 255, 255, 0.78);
  font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* MathJax SVG can sit on a huge hit target and swallow clicks — keep math visual only */
mjx-container,
mjx-container svg {
  pointer-events: none;
}

body.dark {
  color-scheme: dark;
  --ink: #010205;
  --panel: rgba(5, 8, 14, 0.88);
  --panel-solid: #05080d;
  --text: #f3f7ff;
  --muted: #8b9bb8;
  --line: rgba(73, 124, 220, 0.34);
  --line-soft: rgba(73, 124, 220, 0.16);
  --brand: #68a2ff;
  --brand-dim: #2f74e8;
  --brand-2: #78b2ff;
  --shadow: 0 22px 56px rgba(0, 0, 0, 0.64);
  --topbar-bg: linear-gradient(180deg, rgba(4, 7, 13, 0.96) 0%, rgba(2, 4, 8, 0.82) 100%);
  --sidebar-bg: linear-gradient(180deg, rgba(5, 8, 14, 0.78) 0%, rgba(1, 2, 5, 0.52) 100%);
  --input-bg: rgba(0, 0, 0, 0.36);
  --button-soft: rgba(255, 255, 255, 0.04);
  --calc-bg: rgba(0, 0, 0, 0.44);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background-color: var(--ink);
  background-image:
    radial-gradient(ellipse 110% 70% at 12% -10%, rgba(108, 169, 255, 0.34), transparent 56%),
    radial-gradient(ellipse 90% 55% at 100% 12%, rgba(203, 228, 255, 0.88), transparent 58%),
    linear-gradient(145deg, #ffffff 0%, #f5faff 38%, #dbeeff 72%, #ffffff 100%);
  -webkit-font-smoothing: antialiased;
}

body.dark {
  background-image:
    radial-gradient(ellipse 95% 58% at 50% -18%, rgba(29, 83, 173, 0.2), transparent 54%),
    radial-gradient(ellipse 65% 42% at 100% 8%, rgba(33, 108, 230, 0.12), transparent 60%),
    linear-gradient(168deg, #000102 0%, #03060c 46%, #000103 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: rgba(107, 149, 255, 0.25);
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -4rem;
  background: var(--text);
  color: var(--ink);
  padding: 0.7rem 1rem;
  z-index: 100;
  border-radius: 8px;
  font-weight: 700;
}

.skip-link:focus {
  top: 1rem;
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line-soft);
  background: var(--topbar-bg);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(16px);
  pointer-events: auto;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  font-weight: 700;
  background: linear-gradient(90deg, var(--text) 0%, var(--muted) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

body.dark .topbar h1 {
  background: none;
  -webkit-background-clip: unset;
  background-clip: unset;
  color: var(--text);
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--brand-2);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: calc(100vh - 76px);
  position: relative;
}

.sidebar {
  padding: 1rem;
  border-right: 1px solid var(--line-soft);
  position: sticky;
  top: 76px;
  height: calc(100vh - 76px);
  align-self: start;
  background: var(--sidebar-bg);
  z-index: 1;
  pointer-events: auto;
}

.nav-link {
  width: 100%;
  display: block;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.25rem;
  font-weight: 600;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(107, 149, 255, 0.1);
  border-color: var(--line-soft);
}

.nav-link:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.nav-link.active {
  color: var(--text);
  background: linear-gradient(135deg, rgba(74, 120, 217, 0.35) 0%, rgba(45, 70, 130, 0.25) 100%);
  border-color: rgba(107, 149, 255, 0.35);
  box-shadow: var(--glow-brand);
}

main {
  width: min(1180px, 100%);
  padding: clamp(1rem, 3vw, 2rem);
  min-width: 0;
  position: relative;
  z-index: 2;
  isolation: isolate;
  pointer-events: auto;
}

.hero {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
  align-items: stretch;
}

.panel,
.question-panel,
.tool-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.panel {
  padding: clamp(1rem, 2.4vw, 1.5rem);
}

.hero h2,
.page-title {
  margin: 0 0 0.7rem;
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  letter-spacing: -0.03em;
  line-height: 1.08;
  font-weight: 700;
}

.muted {
  color: var(--muted);
}
.stack {
  display: grid;
  gap: 1rem;
}
.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
}
.split {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.55fr);
}

.stat {
  border-left: 4px solid var(--brand);
  padding: 0.6rem 0.8rem;
  background: linear-gradient(90deg, rgba(107, 149, 255, 0.12) 0%, transparent 100%);
  border-radius: 8px;
}

.action-row {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: center;
  position: relative;
  z-index: 2;
}

.primary,
.secondary,
.choice,
.small-button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-weight: 600;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.primary {
  background: linear-gradient(145deg, var(--brand) 0%, var(--brand-dim) 100%);
  border-color: rgba(107, 149, 255, 0.5);
  color: #0a0f18;
  box-shadow: 0 4px 20px rgba(74, 120, 217, 0.35);
}

body.dark .primary {
  color: #0a0f18;
}

.secondary,
.choice,
.small-button {
  background: var(--button-soft);
  color: var(--text);
  border-color: var(--line);
}

.secondary:hover,
.small-button:hover {
  transform: translateY(-1px);
  background: rgba(107, 149, 255, 0.12);
  border-color: rgba(107, 149, 255, 0.35);
}

.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(74, 120, 217, 0.45);
}

.choice:hover {
  transform: translateY(-1px);
  border-color: rgba(107, 149, 255, 0.4);
  background: rgba(107, 149, 255, 0.08);
}

.icon-button {
  border: 1px solid var(--line);
  width: 44px;
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--button-soft);
  color: var(--brand-2);
  font-weight: 900;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.icon-button:hover {
  border-color: rgba(107, 149, 255, 0.45);
  color: var(--brand);
}

.question-panel {
  padding: clamp(1rem, 2vw, 1.35rem);
  position: relative;
  z-index: 1;
}
.question-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.92rem;
}
.question-text {
  font-size: 1.12rem;
  line-height: 1.58;
  position: relative;
  z-index: 0;
}
.choices {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0;
  position: relative;
  z-index: 3;
  pointer-events: auto;
}
.choice {
  text-align: left;
  min-height: 48px;
  position: relative;
  z-index: 1;
}
.choice:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.choice.correct {
  border-color: var(--ok);
  background: rgba(94, 207, 154, 0.15);
  box-shadow: 0 0 0 1px rgba(94, 207, 154, 0.25);
}
.choice.wrong {
  border-color: var(--bad);
  background: rgba(240, 128, 128, 0.12);
}
.solution {
  border-top: 1px solid var(--line-soft);
  margin-top: 1rem;
  padding-top: 1rem;
  animation: fadeUp 0.35s ease;
  position: relative;
  z-index: 1;
}
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.85rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  position: relative;
  z-index: 2;
}
.filter-label {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--muted);
}
.chapter-select {
  flex: 1;
  min-width: min(100%, 280px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  background: var(--input-bg);
  color: var(--text);
  pointer-events: auto;
}
.chapter-select:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.chapter-drills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.chapter-pill {
  font-size: 0.88rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  background: linear-gradient(135deg, rgba(212, 184, 122, 0.2) 0%, rgba(107, 149, 255, 0.12) 100%);
  border: 1px solid rgba(212, 184, 122, 0.25);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
}

.formula-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.formula {
  font-size: 1.15rem;
  overflow-x: auto;
  padding: 0.35rem 0;
}

.tools-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(300px, 1fr);
  gap: 1rem;
}

.tool-panel {
  padding: 1rem;
  position: relative;
  z-index: 1;
}
.calc-display {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--calc-bg);
  color: var(--text);
  min-height: 62px;
  padding: 0.8rem;
  text-align: right;
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.75rem;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.45rem;
  position: relative;
  z-index: 2;
}

.calc-grid button {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--button-soft);
  color: var(--text);
  font-weight: 600;
}

.calc-grid button:hover {
  background: rgba(107, 149, 255, 0.15);
  border-color: rgba(107, 149, 255, 0.35);
}

.calc-grid .accent {
  background: linear-gradient(145deg, rgba(74, 120, 217, 0.45) 0%, rgba(45, 70, 130, 0.35) 100%);
  border-color: rgba(107, 149, 255, 0.4);
}
.tvm-values {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
}
.timer-face {
  font-size: clamp(2.2rem, 8vw, 4.2rem);
  font-weight: 900;
  margin: 0.4rem 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
}
.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 0.6rem;
}
.field-row label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.field-row input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  background: var(--input-bg);
  color: var(--text);
  pointer-events: auto;
}
.field-row input:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.alarm-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
  align-items: end;
  margin-top: 0.7rem;
}

.alarm-row label,
.toggle-line {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.alarm-row label {
  display: grid;
  gap: 0.25rem;
}

.alarm-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  background: var(--input-bg);
  color: var(--text);
}

.mini-copy {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
}

.toggle-line {
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
  margin-top: 0.7rem;
}

.floating-timer {
  position: fixed;
  width: min(236px, calc(100vw - 24px));
  z-index: 80;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 0.65rem;
  align-items: center;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
}

.floating-timer.dragging {
  user-select: none;
  box-shadow: 0 22px 56px rgba(31, 111, 255, 0.28);
}

.floating-drag {
  width: 36px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: linear-gradient(145deg, var(--brand) 0%, var(--brand-dim) 100%);
  color: #ffffff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: grab;
  touch-action: none;
}

.floating-drag:active {
  cursor: grabbing;
}

.floating-copy {
  display: grid;
  min-width: 0;
}

.floating-copy span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.floating-copy strong {
  font-size: 1.55rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.floating-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.floating-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button-soft);
  color: var(--text);
  font-weight: 700;
}

.flashcard {
  min-height: 190px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(107, 149, 255, 0.1) 0%, rgba(20, 30, 50, 0.4) 100%);
  font-size: 1.08rem;
  line-height: 1.45;
  font-weight: 500;
}

.flashcard:hover {
  border-color: rgba(107, 149, 255, 0.35);
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: sticky;
    top: 76px;
    height: auto;
    z-index: 3;
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    -webkit-overflow-scrolling: touch;
  }
  .nav-link {
    white-space: nowrap;
    width: auto;
  }
  .hero,
  .split,
  .tools-grid {
    grid-template-columns: 1fr;
  }
  .calc-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .tvm-values {
    grid-template-columns: repeat(2, 1fr);
  }
}
