:root {
  --bg: #faf8f4;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e7e3db;
  --accent: #b33a3a;
  --accent-soft: #f4d8d8;
  --good: #2f8c4a;
  --warn: #d28a00;
  --bad: #c44545;
  --easy: #3578c4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI",
    Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 {
  font-size: 18px;
  margin: 0;
  color: var(--accent);
  letter-spacing: 0.3px;
}
.topbar nav { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: var(--muted);
}
.tab.active {
  color: var(--ink);
  background: var(--accent-soft);
  border-color: var(--accent);
}

main { max-width: 880px; margin: 0 auto; padding: 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.screen { display: block; }
.screen.hidden { display: none !important; }

.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.who-profile { color: var(--ink); font-weight: 500; }

.auth-card { max-width: 460px; margin: 60px auto; }
.auth-card h2 { margin-bottom: 8px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-radius: 0;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-card button.primary { width: 100%; padding: 12px; margin-top: 18px; }
label.block { display: block; margin: 14px 0 6px; font-size: 12px; color: var(--muted); }
label.block input,
label.block textarea {
  display: block;
  width: 100%;
  padding: 10px;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 4px;
}

.auth-status { margin-top: 16px; min-height: 1.5em; font-size: 13px; }

.profiles-list { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.profile-row { display: flex; gap: 10px; align-items: center; }
.profile-pick {
  flex: 1;
  text-align: left;
  padding: 14px 18px;
  font-size: 18px;
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}
.profile-pick:hover { filter: brightness(0.97); }
.sep { border: none; border-top: 1px solid var(--line); margin: 24px 0 12px; }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  padding: 8px 16px;
  border-radius: 8px;
}
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover { filter: brightness(1.05); }
button.ghost {
  background: transparent;
  color: var(--muted);
}
button:disabled { opacity: 0.5; cursor: default; }

.hint { text-align: center; margin-top: 12px; font-size: 12px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ----------- forms ----------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.form-grid label,
.form-row label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}
.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.form-row input,
.form-row select,
.form-grid input {
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

textarea {
  width: 100%;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  line-height: 1.5;
}

/* ----------- tables ----------- */

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; }
td.actions { text-align: right; }
td .icon-btn {
  border: none;
  background: transparent;
  font-size: 16px;
  padding: 4px 8px;
  color: var(--muted);
}
td .icon-btn.danger:hover { color: var(--bad); }
.kind-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.kind-tag.passage { background: #eaf2fb; color: var(--easy); }
.kind-tag.book { background: var(--accent-soft); color: var(--accent); }

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ----------- passage / book reading + quiz ----------- */

.story-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.story-read-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.story-body {
  font-size: 19px;
  line-height: 1.8;
  white-space: pre-wrap;
  margin: 16px 0 28px;
  padding: 18px;
  background: #fefcf7;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
}

.quiz-divider { border-top: 1px dashed var(--line); margin: 26px 0 2px; }
.quiz-heading { margin: 10px 0 2px; font-size: 16px; }
.quiz-form { display: flex; flex-direction: column; gap: 22px; margin: 16px 0; }
.quiz-question { display: flex; flex-direction: column; gap: 6px; }
.quiz-prompt { font-size: 16px; line-height: 1.4; }
.quiz-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}
.quiz-choice:hover { background: var(--accent-soft); }
.quiz-choice input { margin: 0; }
.quiz-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.result-score { font-size: 18px; margin: 4px 0 14px; }
.result-detail { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.quiz-detail { padding: 10px 12px; border-radius: 6px; border-left: 3px solid var(--line); }
.quiz-detail.q-correct { border-left-color: var(--good); background: #f4fbf4; }
.quiz-detail.q-wrong { border-left-color: var(--bad); background: #fdf4f4; }
.quiz-detail .mark { float: right; font-weight: 600; }

/* ----------- book list ----------- */

.book-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.book-item {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font: inherit;
}
.book-item:hover { border-color: var(--accent); background: #fcfbf8; }
.book-item .book-title { font-size: 17px; font-weight: 600; }
.book-item .book-author { color: var(--muted); font-size: 14px; }
.book-item .book-meta { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.book-item .pass { color: var(--good); font-weight: 600; }

/* ----------- stats: history ----------- */

#history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font: inherit;
}
.history-item:hover { border-color: var(--accent); background: #fcfbf8; }
.history-item .hist-title { font-weight: 600; }
.history-item .hist-date { margin-left: auto; }
.history-item .pass { color: var(--good); font-weight: 600; }
.history-item .fail { color: var(--bad); font-weight: 600; }
.history-detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.history-story { margin-bottom: 14px; }
.history-story summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.history-story .story-body { margin-top: 10px; }

.stat-line { margin: 4px 0; }

/* ----------- progress: stat tiles ----------- */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat-tile {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: #fefcf7;
}
.stat-tile .tile-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
}
.stat-tile .tile-big {
  font-size: 26px;
  font-weight: 700;
  margin: 6px 0 2px;
  color: var(--accent);
}
.stat-tile .tile-sub { font-size: 12px; }

/* ----------- progress: daily activity chart ----------- */

.daily-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 120px;
  padding-top: 8px;
}
.day-col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.day-bar { width: 100%; border-radius: 3px 3px 0 0; min-height: 2px; background: var(--line); }
.day-bar.good { background: var(--good); }
.day-bar.ok { background: var(--warn); }
.day-bar.bad { background: var(--bad); }
.day-bar.empty { height: 2px !important; background: var(--line); opacity: 0.6; }
.daily-axis { display: flex; justify-content: space-between; font-size: 11px; margin-top: 4px; }
.chart-legend { font-size: 12px; margin: 8px 0 0; }

/* ----------- progress: accuracy bars ----------- */

.acc-bar {
  position: relative;
  background: #f0ece4;
  border-radius: 6px;
  height: 16px;
  min-width: 90px;
  overflow: hidden;
}
.acc-fill { height: 100%; border-radius: 6px; }
.acc-fill.good { background: var(--good); }
.acc-fill.ok { background: var(--warn); }
.acc-fill.bad { background: var(--bad); }
.acc-fill.na { background: var(--line); }
.acc-num {
  position: absolute;
  right: 6px;
  top: 0;
  line-height: 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
}

/* ----------- progress: lexile estimate ----------- */

.lexile-headline { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 6px; }
.lexile-big { font-size: 40px; font-weight: 800; color: var(--accent); line-height: 1; }
.lexile-side { display: flex; flex-direction: column; gap: 6px; }
.pill {
  display: inline-block;
  width: fit-content;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 999px;
}
.pill.high { background: #e3f3e8; color: var(--good); }
.pill.medium { background: #fbf0d8; color: var(--warn); }
.pill.low { background: #f6e2e2; color: var(--bad); }
.method { margin: 10px 0 14px; }
.method summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.method p { margin: 8px 0 0; }
table.bins td, table.bins th { vertical-align: middle; }
table.bins td:nth-child(2) { width: 80px; }
table.bins td:nth-child(3) { width: 140px; }

/* ----------- progress: skills ----------- */

.skill-highlights { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.chip.good { background: #e3f3e8; color: var(--good); }
.chip.bad { background: #f6e2e2; color: var(--bad); }
.skill-list { display: flex; flex-direction: column; gap: 10px; }
.skill-row { display: flex; align-items: center; gap: 12px; }
.skill-row .skill-name { flex: 1; font-size: 14px; }
.skill-row .skill-count { font-size: 12px; }
.skill-row .skill-acc { width: 150px; }
.skill-row.untested { opacity: 0.65; }

/* ----------- progress: per-book ----------- */

.book-prog { padding: 10px 0; border-bottom: 1px solid var(--line); }
.book-prog:last-child { border-bottom: none; }
.book-prog-head { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.book-prog-head .book-title { font-size: 15px; font-weight: 600; }
.book-prog-head .book-prog-acc { margin-left: auto; font-size: 13px; }
.prog-bar { background: #f0ece4; border-radius: 6px; height: 10px; margin: 6px 0 4px; overflow: hidden; }
.prog-fill { height: 100%; background: var(--good); border-radius: 6px; }
.book-prog-sub { font-size: 12px; }

/* ============================ responsive ============================ */

@media (max-width: 860px) {
  main { padding: 16px; }
  .card { padding: 16px; }
}

@media (max-width: 600px) {
  main { padding: 12px; }
  .card { padding: 14px; margin-bottom: 12px; overflow-x: auto; }

  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .topbar h1 { font-size: 16px; }
  #main-nav { order: 3; width: 100%; justify-content: center; }
  .tab { padding: 6px 12px; }
  .who { font-size: 12px; gap: 6px; }

  .form-grid { grid-template-columns: 1fr; }
  .story-body { font-size: 18px; line-height: 1.8; padding: 14px; }
  #library-table { min-width: 560px; }

  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
  .stat-tile .tile-big { font-size: 22px; }
  .lexile-big { font-size: 32px; }
  .skill-row .skill-acc { width: 110px; }
  .daily-chart { height: 96px; }
}
