:root {
  --bg: #14120f;
  --surface: #1c1916;
  --card: #23201b;
  --card-front: #2a261f;
  --text: #f3efe6;
  --muted: #a39b8c;
  --accent: #e8a54b;
  --accent-dim: #8a6430;
  --line: #3a342c;
  --again: #c45c5c;
  --hard: #c4923d;
  --good: #5d9a6c;
  --easy: #4d8fb3;
  --danger: #e07a7a;
  --ok: #8fca9c;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --tabbar: 64px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
}

button, a {
  font: inherit;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(12px + var(--safe-top)) 16px calc(var(--tabbar) + var(--safe-bottom) + 16px);
}

.topbar {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.topbar-title {
  text-align: center;
  min-width: 0;
}

.topbar-title h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.eyebrow, .kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-meta {
  text-align: right;
  color: var(--muted);
  font-size: 0.78rem;
}

.text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 8px 0;
  min-height: 44px;
  text-align: left;
}

.text-btn[hidden] {
  visibility: hidden;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(480px, 100%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #181613;
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + var(--safe-bottom));
  z-index: 10;
}

.tab {
  color: var(--muted);
  text-decoration: none;
  text-align: center;
  padding: 10px 4px;
  min-height: 44px;
  border-radius: 10px;
}

.tab.active {
  color: var(--text);
  background: var(--card);
}

h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.lede {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.hero-count {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 16px;
  margin-bottom: 16px;
}

.hero-count strong {
  display: block;
  font-size: 2.4rem;
  letter-spacing: -0.04em;
  line-height: 1;
}

.hero-count span {
  color: var(--muted);
  font-size: 0.9rem;
}

.actions {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  min-height: 52px;
  padding: 12px 14px;
  text-align: left;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn.primary {
  background: var(--accent);
  color: #1a140a;
  border-color: var(--accent);
  font-weight: 650;
}

.btn:disabled {
  opacity: 0.45;
}

.btn small, .meta-inline {
  color: var(--muted);
  font-weight: 400;
}

.btn.primary small {
  color: #5a4018;
}

.deck-grid {
  display: grid;
  gap: 10px;
}

.deck-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  text-decoration: none;
  color: inherit;
  display: block;
}

.deck-card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.deck-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.pill {
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.75rem;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  color: inherit;
  text-decoration: none;
  display: block;
}

.list-item h3 {
  margin: 0 0 6px;
  font-size: 1.02rem;
}

.list-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.study-stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 88px;
}

.flip-card {
  min-height: 280px;
  perspective: 1000px;
}

.flip-inner {
  position: relative;
  min-height: 280px;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
}

.flip-card.is-flipped .flip-inner {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  background: var(--card-front);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 18px;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: auto;
}

.face.back {
  background: var(--card);
  transform: rotateY(180deg);
}

.face h2 {
  font-size: 1.7rem;
  line-height: 1.2;
}

.face p, .prose p {
  margin: 0 0 10px;
  line-height: 1.5;
}

.example, .formula, .watch {
  background: #1a1814;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.92rem;
}

.formula {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent);
}

.rate-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  position: sticky;
  bottom: calc(var(--tabbar) + var(--safe-bottom) + 8px);
}

.rate-bar button {
  appearance: none;
  border: 0;
  border-radius: 12px;
  min-height: 56px;
  color: #fff;
  font-weight: 650;
}

.rate-bar .again { background: var(--again); }
.rate-bar .hard { background: var(--hard); }
.rate-bar .good { background: var(--good); }
.rate-bar .easy { background: var(--easy); }

.rate-bar small {
  display: block;
  font-weight: 500;
  opacity: 0.85;
  font-size: 0.68rem;
}

.choices {
  display: grid;
  gap: 8px;
}

.choice {
  appearance: none;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  min-height: 48px;
  padding: 12px 14px;
}

.choice.selected {
  border-color: var(--accent);
}

.choice.correct {
  border-color: var(--ok);
  background: #1d2a20;
}

.choice.wrong {
  border-color: var(--danger);
  background: #2a1b1b;
}

.metrics {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin: 12px 0;
}

.metrics th, .metrics td {
  text-align: left;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.metrics th {
  color: var(--muted);
  font-weight: 500;
}

.article {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 16px 8px;
}

.attribution {
  background: #1a1814;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
  font-size: 0.86rem;
  line-height: 1.45;
}

.attribution a {
  color: var(--accent);
}

.prose h2, .prose h3 {
  margin: 22px 0 8px;
}

.prose ul {
  padding-left: 1.15rem;
  color: var(--text);
}

.prose li {
  margin-bottom: 6px;
  line-height: 1.45;
}

.empty {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

.badge {
  display: inline-block;
  background: var(--card-front);
  color: var(--accent);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
