:root {
  --bg: #0d0c1d;
  --bg2: #131229;
  --card: #1a1834;
  --card2: #221f42;
  --line: #2c2952;
  --text: #f3f0ff;
  --muted: #a6a1c9;
  --dim: #6f6a96;
  --gold: #f2b54a;
  --gold2: #ffe3a3;
  --ok: #4fd1a5;
  --bad: #ff7a85;
  --blue: #8ab4ff;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --r: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { min-height: 100vh; overscroll-behavior-y: none; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; }

#view {
  padding: calc(var(--safe-top) + 14px) 16px calc(var(--safe-bot) + 96px);
  max-width: 720px; margin: 0 auto;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Tab bar ─────────────────────────────── */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 8px 6px calc(var(--safe-bot) + 6px);
  background: rgba(13, 12, 29, .86);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--dim); padding: 4px 0; }
#tabbar a .ti { font-size: 19px; line-height: 22px; font-weight: 600; font-family: var(--serif); }
#tabbar a.on { color: var(--gold); }

/* ── Type ────────────────────────────────── */
h1, h2, h3 { font-family: var(--serif); font-weight: 700; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 34px; line-height: 1.1; }
h2 { font-size: 22px; margin: 26px 0 12px; }
h3 { font-size: 18px; }
.eyebrow { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 13px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.top .logo { width: 40px; height: 40px; border-radius: 11px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--gold); font-size: 15px; padding: 6px 0; margin-bottom: 8px; }

/* ── Cards ───────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.card + .card { margin-top: 10px; }
.card.hero {
  background: radial-gradient(120% 140% at 0% 0%, #2f2760 0%, #1a1834 55%);
  border-color: #3a3470; padding: 20px;
}
.card.tap:active { transform: scale(.985); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stat b { display: block; font-family: var(--serif); font-size: 28px; color: var(--gold2); }
.stat span { font-size: 12px; color: var(--muted); }

.row { display: flex; align-items: center; gap: 12px; }
.emoji { width: 46px; height: 46px; flex: 0 0 46px; border-radius: 14px; background: var(--card2); display: grid; place-items: center; font-size: 24px; }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 650; font-size: 16px; }
.sub { color: var(--muted); font-size: 13.5px; line-height: 1.4; margin-top: 2px; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.check { color: var(--ok); font-size: 18px; }

.pill { display: inline-block; font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.pill.gold { color: #1a1300; background: var(--gold); border-color: var(--gold); font-weight: 600; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.chip.on { background: var(--gold); color: #1a1300; border-color: var(--gold); font-weight: 600; }

.search { width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); margin-bottom: 12px; outline: none; }
.search:focus { border-color: var(--gold); }

.seg { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 9px; border-radius: 9px; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg button.on { background: var(--card2); color: var(--text); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 18px; border-radius: 14px; background: var(--gold); color: #1a1300; font-weight: 700; font-size: 16px; width: 100%; }
.btn.ghost { background: var(--card2); color: var(--text); border: 1px solid var(--line); }
.btn:active { transform: scale(.98); }
.btns { display: flex; gap: 10px; margin-top: 14px; }

/* ── Topic detail ────────────────────────── */
.detail-head { margin-bottom: 16px; }
.detail-head .big-emoji { font-size: 48px; }
.detail-head h1 { margin: 8px 0 6px; }
.lead { font-size: 17px; line-height: 1.5; color: var(--muted); }
.quote { border-left: 3px solid var(--gold); padding: 10px 14px; background: var(--bg2); border-radius: 0 12px 12px 0; color: var(--muted); font-style: italic; line-height: 1.5; }
.quote .t { font-style: normal; color: var(--gold); font-size: 12px; font-weight: 600; display: block; margin-bottom: 4px; }

.prose { font-size: 16.5px; line-height: 1.65; color: #e3e0f7; }
.prose h3 { font-size: 19px; margin: 22px 0 6px; color: var(--gold2); }
.prose p { margin: 0 0 12px; }
.prose ul { padding-left: 20px; margin: 0 0 12px; }
.prose li { margin-bottom: 6px; }
.prose strong { color: var(--text); }

.facts { list-style: none; padding: 0; margin: 0; }
.facts li { padding: 12px 0 12px 30px; position: relative; border-bottom: 1px solid var(--line); line-height: 1.5; }
.facts li:last-child { border-bottom: 0; }
.facts li::before { content: "✦"; position: absolute; left: 4px; top: 12px; color: var(--gold); }

.nums { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.nums div { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.nums b { display: block; font-family: var(--serif); font-size: 19px; color: var(--gold2); }
.nums span { font-size: 12.5px; color: var(--muted); }

.impress { background: linear-gradient(135deg, #3b2c10, #241b0b); border: 1px solid #6b5020; border-radius: var(--r); padding: 16px; line-height: 1.5; }
.impress .eyebrow { margin-bottom: 6px; }

/* ── Quiz ────────────────────────────────── */
.q { margin-top: 12px; }
.q .qt { font-weight: 650; font-size: 16.5px; line-height: 1.4; margin-bottom: 10px; }
.opt { display: block; width: 100%; text-align: left; padding: 13px 14px; border-radius: 13px; background: var(--bg2); border: 1px solid var(--line); margin-bottom: 8px; line-height: 1.35; }
.opt.ok { border-color: var(--ok); background: rgba(79, 209, 165, .14); }
.opt.bad { border-color: var(--bad); background: rgba(255, 122, 133, .12); }
.expl { font-size: 14px; color: var(--muted); line-height: 1.5; padding: 4px 2px 6px; }
.progress { height: 6px; background: var(--card2); border-radius: 99px; overflow: hidden; margin: 6px 0 16px; }
.progress i { display: block; height: 100%; background: var(--gold); border-radius: 99px; transition: width .3s; }

/* ── Words ───────────────────────────────── */
.word { cursor: pointer; }
.word .term { font-family: var(--serif); font-size: 19px; font-weight: 700; }
.word .def { color: var(--muted); font-size: 14.5px; line-height: 1.45; margin-top: 4px; }
.word .more { margin-top: 12px; display: none; font-size: 14.5px; line-height: 1.5; }
.word.open .more { display: block; }
.word .more p { margin: 8px 0; }
.word .lbl { color: var(--gold); font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; display: block; margin-top: 10px; }
.star { font-size: 20px; color: var(--dim); padding: 4px; }
.star.on { color: var(--gold); }

/* ── Flashcard ───────────────────────────── */
.flash { perspective: 1200px; height: 380px; margin: 10px 0 16px; }
.flash .inner { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.flash.flip .inner { transform: rotateY(180deg); }
.flash .face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 22px; border: 1px solid #3a3470; padding: 24px; display: flex; flex-direction: column; justify-content: center; text-align: center; overflow-y: auto;
  background: radial-gradient(120% 120% at 50% 0%, #2f2760, #1a1834 70%);
}
.flash .back { transform: rotateY(180deg); text-align: left; justify-content: flex-start; }
.flash .front .term { font-family: var(--serif); font-size: 32px; font-weight: 700; line-height: 1.2; }
.flash .hint { color: var(--dim); font-size: 13px; margin-top: 18px; }
.grade { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grade button { padding: 13px 6px; border-radius: 13px; font-weight: 700; font-size: 14.5px; border: 1px solid var(--line); background: var(--card); }
.grade .g0 { color: var(--bad); }
.grade .g1 { color: var(--gold); }
.grade .g2 { color: var(--ok); }

.empty { text-align: center; padding: 50px 16px; color: var(--muted); }
.empty .e { font-size: 44px; margin-bottom: 10px; }

.linklist a { display: inline-block; margin: 0 6px 8px 0; }
.section-gap { height: 8px; }
.ep-art { width: 64px; height: 64px; border-radius: 14px; background: linear-gradient(135deg, #3a1d5c, #13112a); display: grid; place-items: center; font-size: 30px; flex: 0 0 64px; }
