:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #58656f;
  --line: #d9e0e6;
  --paper: #f7f8f6;
  --panel: #ffffff;
  --green: #1f7a56;
  --teal: #0d6f81;
  --red: #b23434;
  --yellow: #ffc857;
  --blue: #345995;
  --shadow: 0 18px 45px rgba(25, 42, 52, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select {
  font: inherit;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 24px clamp(18px, 4vw, 48px);
  background: #143d42;
  color: white;
}

.eyebrow {
  margin: 0 0 6px;
  color: currentColor;
  opacity: .72;
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(1.5rem, 3vw, 2.5rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
}

.countdown {
  display: grid;
  place-items: center;
  min-width: 118px;
  min-height: 88px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 8px;
  background: rgba(255,255,255,.08);
}

.countdown span {
  font-size: 2.25rem;
  font-weight: 900;
  line-height: 1;
}

.countdown small { color: rgba(255,255,255,.78); }

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

body.locked .layout {
  display: none;
}

.auth-gate {
  min-height: calc(100vh - 136px);
  display: grid;
  place-items: center;
  padding: clamp(18px, 5vw, 52px);
  background: linear-gradient(180deg, #f7f8f6 0%, #edf3f0 100%);
}

body:not(.locked) .auth-gate {
  display: none;
}

.sidebar {
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #eef3f0;
}

.nav-button {
  width: 100%;
  min-height: 42px;
  margin-bottom: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 800;
  cursor: pointer;
}

.nav-button.active,
.nav-button:hover {
  background: white;
  border-color: var(--line);
}

.sync-card {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: .88rem;
}

.sync-card strong { color: var(--ink); }

.auth-card, .account-card {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: .86rem;
}

.auth-panel {
  width: min(100%, 420px);
  margin: 0;
  padding: 24px;
  box-shadow: var(--shadow);
}

.auth-panel strong {
  font-size: 1.45rem;
}

.auth-card strong, .account-card strong { color: var(--ink); }

.auth-card label {
  display: grid;
  gap: 4px;
  font-weight: 800;
}

.auth-card input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

.auth-message {
  min-height: 20px;
  color: var(--muted);
  font-weight: 700;
}

.hidden { display: none !important; }

.content {
  padding: clamp(18px, 4vw, 40px);
  overflow: hidden;
}

.view { display: none; }
.active-view { display: block; }

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

.search {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.search input, select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
}

.filters, .quiz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.chip, button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.chip.active {
  background: #173f44;
  border-color: #173f44;
  color: white;
}

.primary {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.secondary {
  background: #e9f3f5;
  border-color: #c8dce1;
  color: #0b5261;
}

.danger {
  background: #fff2f2;
  border-color: #efc3c3;
  color: var(--red);
}

.study-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(295px, 1fr));
  gap: 14px;
}

.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(30, 48, 58, .07);
}

.card h3 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf1f5;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 800;
}

.tag.high { background: #fff2cf; color: #7a5600; }
.tag.core { background: #e8f5ef; color: #1b6748; }

.card p, .card li {
  color: var(--muted);
  line-height: 1.5;
}

.card ul {
  padding-left: 20px;
  margin-bottom: 14px;
}

.progress-row {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf0;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--teal));
}

.quiz-panel, .flashcard, .review-list, .history, .metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.quiz-panel {
  min-height: 360px;
  padding: 18px;
}

.question-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-weight: 800;
}

.option {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  text-align: left;
}

.option.selected { border-color: var(--blue); background: #eef4ff; }
.option.correct { border-color: var(--green); background: #eaf7f0; }
.option.wrong { border-color: var(--red); background: #fff0f0; }

.quiz-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
}

.review-layout {
  display: grid;
  grid-template-columns: minmax(260px, 390px) minmax(0, 1fr);
  gap: 14px;
}

.flashcard {
  padding: 22px;
  min-height: 230px;
  background: #143d42;
  color: white;
}

.flashcard p { color: rgba(255,255,255,.84); }

.review-list {
  padding: 14px;
}

.pill-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.pill-row:last-child { border-bottom: 0; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  padding: 16px;
}

.metric strong {
  display: block;
  font-size: 1.8rem;
}

.history {
  padding: 16px;
}

.source-note {
  margin-top: 20px;
  color: var(--muted);
  font-size: .86rem;
}

@media (max-width: 760px) {
  .topbar, .section-head, .quiz-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-button { margin: 0; text-align: center; }
  .sync-card { grid-column: 1 / -1; margin-top: 0; }
  .account-card { grid-column: 1 / -1; margin-top: 0; }
  .review-layout { grid-template-columns: 1fr; }
}
