:root {
  color-scheme: light;
  --ink: #101820;
  --paper: #f6f4ef;
  --line: #d8d3c8;
  --green: #2d7d63;
  --red: #b8443c;
  --teal: #287c7a;
  --gold: #d59f2a;
  --muted: #66706b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

[hidden] { display: none !important; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-panel { width: min(100%, 420px); padding: 24px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.auth-intro { margin: 12px 0 20px; color: var(--muted); line-height: 1.5; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 18px; padding: 4px; background: var(--paper); border-radius: 8px; }
.auth-tabs button { min-height: 42px; background: transparent; }
.auth-tabs button.active { background: var(--ink); color: #fff; }
.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; }
.auth-form input { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line); background: #fff; }
.auth-message { min-height: 20px; margin-top: 12px; color: var(--red); font-size: 13px; }
.account-box { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.account-box span { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 800; }

.app {
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(88px + env(safe-area-inset-bottom));
}

.topbar, .section-head, .topic-row, .hero, .result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  max-width: 860px;
  margin: 0 auto 18px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 24px; line-height: 1.1; }
h3 { font-size: 18px; line-height: 1.25; }

.eyebrow, .pill, .source, small {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

.view {
  display: none;
  max-width: 860px;
  margin: 0 auto;
}
.view.active { display: block; }

.hero {
  min-height: 168px;
  padding: 22px;
  background:
    radial-gradient(circle at 82% 24%, rgba(213,159,42,.32), transparent 28%),
    linear-gradient(135deg, #101820, #244c4d 65%, #7d6b38);
  color: #fff;
  border-radius: 8px;
  overflow: hidden;
}
.hero .eyebrow { color: #f2dca0; }
.score-ring {
  width: 104px;
  height: 104px;
  border: 7px solid rgba(255,255,255,.34);
  border-top-color: var(--gold);
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  text-align: center;
}
.score-ring span { font-size: 25px; font-weight: 800; }
.score-ring small { color: #fff; display: block; }

button, select, input {
  font: inherit;
  border-radius: 8px;
}
button {
  border: 0;
  cursor: pointer;
  color: inherit;
}
.icon-btn {
  width: 44px;
  height: 44px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 22px;
}

.quick-grid, .tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.mode-btn {
  min-height: 96px;
  padding: 14px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
}
.mode-btn span { display: block; font-weight: 800; margin-bottom: 8px; }

.band, .question-panel, .flashcard, .notes-list article, .tool-grid label, .tool-grid output {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.band { padding: 14px; }
.topic-list { display: grid; gap: 8px; margin-top: 12px; }
.topic-row {
  width: 100%;
  min-height: 44px;
  padding: 10px;
  background: #faf9f5;
  text-align: left;
}
.bar {
  flex: 1;
  height: 8px;
  background: #e8e3d7;
  border-radius: 99px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  background: var(--teal);
}

.question-panel {
  margin-top: 14px;
  padding: 18px;
}
.question-panel h3 { margin: 10px 0 16px; }
.answers { display: grid; gap: 10px; }
.answers button {
  min-height: 48px;
  padding: 12px;
  text-align: left;
  background: #f8f7f2;
  border: 1px solid var(--line);
}
.answers .correct { background: #e5f3ec; border-color: var(--green); }
.answers .wrong { background: #f8e4e1; border-color: var(--red); }
.explain {
  margin: 14px 0;
  padding: 12px;
  border-left: 4px solid var(--teal);
  background: #eef6f5;
  border-radius: 4px;
}
.primary, .secondary {
  min-height: 42px;
  padding: 0 16px;
  color: #fff;
  background: var(--ink);
}
.secondary { background: var(--teal); }
.wide { width: 100%; margin-top: 12px; }
select, input {
  min-height: 42px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 10px;
  min-width: 0;
}

.muted-panel { color: var(--muted); }
.result {
  padding: 16px;
  margin-bottom: 14px;
  border-radius: 8px;
  color: #fff;
}
.result span { font-size: 38px; font-weight: 900; }
.pass { background: var(--green); }
.fail { background: var(--red); }
.weak-list {
  padding-left: 18px;
  display: grid;
  gap: 10px;
}
.weak-list small {
  display: block;
  margin-top: 4px;
}

.flashcard {
  min-height: 260px;
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 24px;
  margin-top: 14px;
  background: #101820;
  color: #fff;
}
.flashcard .eyebrow { color: #f2dca0; }
.flashcard h3 { font-size: 32px; }
.flashcard p:not(.eyebrow) { font-size: 18px; line-height: 1.45; }
.flipped { background: #235f5c; }

.notes-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.notes-list article { padding: 14px; }
.notes-list p { margin-top: 8px; line-height: 1.5; color: #34413b; }

.tool-grid {
  grid-template-columns: 1fr;
}
.tool-grid label, .tool-grid output {
  display: grid;
  gap: 8px;
  padding: 14px;
}
.tool-grid output {
  color: var(--teal);
  font-weight: 800;
}

.app-credit {
  margin-top: 28px;
  padding: 16px 0 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(246,244,239,.95);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.tabbar button {
  min-height: 48px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.tabbar .active {
  background: var(--ink);
  color: #fff;
}

@media (max-width: 560px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .hero { align-items: flex-start; }
  .quick-grid { grid-template-columns: 1fr; }
  .score-ring { width: 86px; height: 86px; border-width: 6px; }
  .section-head { align-items: flex-start; }
  .section-head select, .section-head input { width: 100%; }
  .topbar { align-items: center; flex-wrap: wrap; }
  .account-box { width: 100%; justify-content: space-between; padding-top: 10px; border-top: 1px solid var(--line); }
  .account-box span { width: auto; max-width: 180px; text-align: left; }
  .account-box .secondary { min-height: 44px; padding: 0 10px; }
}
