:root {
  --bg: #f4f0e8;
  --paper: #fffdf8;
  --ink: #1c2430;
  --muted: #5d6773;
  --accent: #1f4e5f;
  --accent-soft: #e7f1f4;
  --line: #e2dacd;
  --ok: #1f6b4a;
  --ok-soft: #e5f4ec;
  --mark: #8a4b12;
  --mark-soft: #f8eadc;
  --alert: #9f2d2d;
  --alert-soft: #f8e6e6;
  --later: #3d4d99;
  --later-soft: #e8ebf8;
  --shadow: 0 1px 2px rgba(28, 36, 48, 0.06);
  --radius: 12px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

body {
  padding-top: var(--safe-top);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  z-index: 20;
}

.skip-link:focus { left: 8px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
}

.brand { flex: 1; min-width: 0; }

.brand-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.brand h1, #header-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 22px;
  border-radius: 10px;
  flex-shrink: 0;
}

.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--accent-soft);
}

.progress-slim {
  height: 3px;
  background: var(--line);
  border-radius: 99px;
  margin-top: 6px;
  overflow: hidden;
}

.progress-slim-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
}

.progress-meta {
  margin: 4px 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px calc(24px + var(--safe-bottom));
}

.hidden, [hidden] { display: none !important; }

.hero-card, .panel, .card-sheet, .list-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-card { padding: 14px; }

.hero-card h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.muted { color: var(--muted); font-size: 13px; margin: 0; }

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  padding: 8px 12px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  grid-column: 1 / -1;
}

.btn:disabled {
  opacity: 0.45;
}

.stats-row {
  display: flex;
  gap: 10px;
  margin: 12px 0;
  font-size: 13px;
  color: var(--muted);
}

.stats-row strong { color: var(--ink); }

.section-label {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.review-grid, .topic-list {
  display: grid;
  gap: 8px;
}

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

.chip-btn, .topic-btn, .list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 12px;
  text-align: left;
  font: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: inherit;
}

.chip-btn span, .count {
  font-size: 12px;
  color: var(--muted);
}

.topic-btn .topic-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 12px;
  color: var(--muted);
}

.mini-bar {
  width: 64px;
  height: 4px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}

.mini-bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
}

.card-sheet {
  padding: 16px 16px 12px;
}

.card-kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.pill.ext { background: #efe6f8; color: #5b2d86; }
.pill.core { background: var(--ok-soft); color: var(--ok); }

.card-sheet h2 {
  margin: 0 0 10px;
  font-size: 20px;
  line-height: 1.25;
}

.points {
  margin: 0;
  padding-left: 18px;
}

.points li { margin: 0 0 7px; }

.note-block {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}

.note-block p { margin: 0 0 4px; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.note-block ul { margin: 0; padding-left: 16px; }
.note-core { background: var(--ok-soft); }
.note-ext { background: #efe6f8; }
.note-ex { background: var(--accent-soft); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.action {
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
}

.action.on-read { background: var(--ok-soft); border-color: #b7dfc8; color: var(--ok); }
.action.on-mark { background: var(--mark-soft); border-color: #efd2b0; color: var(--mark); }
.action.on-alert { background: var(--alert-soft); border-color: #efc4c4; color: var(--alert); }
.action.on-later { background: var(--later-soft); border-color: #c5cceb; color: var(--later); }

.pager {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding: 8px 0 calc(8px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.pager .btn { width: 100%; }
.pager-pos {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-width: 72px;
}

.list-item {
  width: 100%;
  margin-bottom: 8px;
}

.list-item .list-title {
  font-weight: 650;
}

.empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
}

.menu-panel {
  position: fixed;
  top: calc(var(--safe-top) + 56px);
  right: 12px;
  z-index: 12;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(28, 36, 48, 0.12);
  overflow: hidden;
}

.menu-panel button, .menu-file {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
}

.menu-panel button:hover, .menu-file:hover { background: var(--accent-soft); }

.menu-file input[type="file"] { display: none; }

.menu-sync {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
}

.menu-sync label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.menu-sync input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: var(--paper);
}

.menu-sync-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.menu-sync-actions button {
  min-height: 40px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 36, 48, 0.2);
  z-index: 11;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 15;
  max-width: 90%;
}

@media (min-width: 720px) {
  .brand h1, #header-title { font-size: 18px; }
  .card-sheet h2 { font-size: 22px; }
  .main { padding-top: 16px; }
}

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