:root {
  --ink: #162032;
  --muted: #5B6678;
  --paper: #EEF1F6;
  --card: #FFFFFF;
  --rule: #C9D3E0;
  --accent: #2458F5;
  --accent-2: #1437B0;
  --amber: #C67A00;
  --ok: #0D7A48;
  --ok-bg: #E5F6EE;
  --miss: #C23030;
  --miss-bg: #FDECEC;
  --chip: #E4EAF3;
  --shadow: 0 1px 0 rgba(22, 32, 50, 0.06), 0 12px 32px rgba(22, 32, 50, 0.06);
  --nav-h: 64px;
  --top-h: 56px;
  --radius: 14px;
  --font-ui: "Atkinson Hyperlegible", "Segoe UI", sans-serif;
  --font-display: "Syne", "Avenir Next", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

html[data-theme="dark"] {
  --ink: #E8EDF5;
  --muted: #9AA6B8;
  --paper: #0E141D;
  --card: #171F2B;
  --rule: #2C3848;
  --accent: #6B8CFF;
  --accent-2: #9BB0FF;
  --amber: #E8A317;
  --ok: #3DCA86;
  --ok-bg: #143326;
  --miss: #F07171;
  --miss-bg: #3A1A1A;
  --chip: #243041;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4), 0 16px 40px rgba(0, 0, 0, 0.28);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100dvh;
}
img { max-width: 100%; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; }
.skip {
  position: absolute;
  left: -999px;
  top: 0;
}
.skip:focus { left: 8px; top: 8px; z-index: 20; background: var(--card); padding: 8px; }

.app-top {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--top-h);
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}
.brand-kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.1;
}
.stamp {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--ink);
  color: var(--paper);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
html[data-theme="dark"] .stamp { color: #0E141D; }
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
}
.nav-desk { display: none; }
main {
  padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  max-width: 880px;
  margin: 0 auto;
  width: 100%;
}

.nav-phone {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--rule);
}
.nav-phone a, .nav-desk a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.nav-phone a.is-on, .nav-desk a.is-on { color: var(--accent); }
.nav-phone svg, .nav-desk svg { width: 20px; height: 20px; }

h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 8px; }
h1 { font-size: clamp(1.6rem, 5vw, 2.2rem); }
h2 { font-size: 1.25rem; }
.lede { color: var(--muted); margin: 0 0 18px; }
.kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h2 { margin-bottom: 10px; }
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.grid-2 {
  display: grid;
  gap: 12px;
}
.stat {
  flex: 1 1 90px;
  background: var(--chip);
  border-radius: 12px;
  padding: 10px 12px;
}
.stat b {
  display: block;
  font-family: var(--font-mono);
  font-size: 22px;
}
.stat span { font-size: 12px; color: var(--muted); }

.today-card {
  border: 2px solid var(--accent);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 10%, var(--card)), var(--card));
}
.btn, .choice {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  text-align: left;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
html[data-theme="dark"] .btn-primary { color: #0E141D; }
.btn-ghost { background: transparent; }
.choice { width: 100%; margin-bottom: 8px; }
.choice.is-on { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.choice.is-right { background: var(--ok-bg); border-color: var(--ok); }
.choice.is-wrong { background: var(--miss-bg); border-color: var(--miss); }
.choice:disabled { cursor: default; }

.cal-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}
.cal-item:last-child { border-bottom: 0; }
.cal-item.is-today { background: color-mix(in srgb, var(--accent) 8%, transparent); margin: 0 -8px; padding: 12px 8px; border-radius: 10px; }
.cal-item input { width: 20px; height: 20px; margin-top: 4px; }
.cal-date { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.done { text-decoration: line-through; opacity: 0.55; }

.lesson-link, .bank-link {
  display: block;
  padding: 14px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--card);
  text-decoration: none;
  color: inherit;
  margin-bottom: 10px;
}
.lesson-link strong, .bank-link strong { display: block; }
.cat {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
}

.passage {
  font-size: 1.02rem;
  line-height: 1.65;
}
.passage u { text-decoration: none; border-bottom: 2px solid var(--accent); font-style: inherit; }
.passage sup { color: var(--accent); font-family: var(--font-mono); font-size: 11px; }
.passage table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 12px 0; }
.passage th, .passage td { border: 1px solid var(--rule); padding: 6px 8px; text-align: left; }

.explain {
  margin-top: 10px;
  padding: 12px;
  border-radius: 10px;
  background: var(--chip);
}
.explain.ok { background: var(--ok-bg); }
.explain.bad { background: var(--miss-bg); }

label.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
input[type="number"], input[type="text"], textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
}
textarea { min-height: 88px; resize: vertical; }

.err-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.err-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.err-table td, .err-table th { border-bottom: 1px solid var(--rule); padding: 8px 6px; vertical-align: top; }

.video a { font-weight: 700; text-decoration: none; }

.progress {
  height: 8px;
  background: var(--chip);
  border-radius: 999px;
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0;
}

.formula {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
}
.formula b { font-family: var(--font-mono); font-size: 12px; }

ul.plain { padding-left: 18px; margin: 8px 0; }
.example { padding: 10px 0; border-bottom: 1px dashed var(--rule); }
.example:last-child { border-bottom: 0; }
.bad { color: var(--miss); }
.good { color: var(--ok); }

@media (min-width: 860px) {
  .nav-phone { display: none; }
  .layout { grid-template-columns: 220px 1fr; }
  .nav-desk {
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: var(--top-h);
    height: calc(100dvh - var(--top-h));
    padding: 16px 12px;
    border-right: 1px solid var(--rule);
  }
  .nav-desk a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
  }
  .nav-desk a.is-on { background: color-mix(in srgb, var(--accent) 12%, transparent); }
  main { padding: 28px 32px 48px; max-width: 820px; margin: 0; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 374px) {
  .stamp { font-size: 11px; padding: 5px 8px; }
  h1 { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
