/* =========================================================
   S² design system — shared by Mandarin² and Chemistry²
   Squared paper, biro-navy ink, highlighter yellow.
   Each subject sets --accent / --accent-ink / --accent-soft.
   ========================================================= */
@import url("https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400&family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,800&display=swap");

:root {
  --paper: var(--surface-2);
  --grid: #e4e8f3;
  --ink: #171b36;
  --ink-2: #4b5174;
  --ink-3: #7a809e;
  --line: #dce1ee;
  --card: #ffffff;
  --hl: #ffdf5d;
  --hl-soft: #fff6cc;
  --hl-ink: #5a4300;
  --good: #128a52;
  --good-soft: #def5e8;
  --bad: #c62835;
  --bad-soft: #fde6e8;
  --accent: #3b5bdb;
  --accent-ink: #263f9e;
  --accent-text: #263f9e;
  --accent-soft: #e8edff;
  --panel: #171b36;
  --surface-2: #f7f8fc;
  --track: #edf0f7;
  --bar: rgba(255,255,255,0.94);
  --r-card: 18px;
  --r-btn: 14px;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, "PingFang SC", "Noto Sans SC", sans-serif;
}
.s2-mandarin { --accent: #e0383e; --accent-ink: #a91f28; --accent-text: #a91f28; --accent-soft: #ffeced; }
.s2-chemistry { --accent: #10a074; --accent-ink: #0a7354; --accent-text: #0a7354; --accent-soft: #e1f5ee; }
.s2-english { --accent: #c2410c; --accent-ink: #9a3412; --accent-text: #9a3412; --accent-soft: #ffedd5; }
.s2-englit { --accent: #9f1239; --accent-ink: #881337; --accent-text: #881337; --accent-soft: #ffe4e6; }
.s2-cs { --accent: #0e7490; --accent-ink: #155e75; --accent-text: #155e75; --accent-soft: #cffafe; }
.s2-geog { --accent: #15803d; --accent-ink: #166534; --accent-text: #166534; --accent-soft: #dcfce7; }
.s2-hist { --accent: #92400e; --accent-ink: #78350f; --accent-text: #78350f; --accent-soft: #fef3c7; }
.s2-psych { --accent: #7e22ce; --accent-ink: #6b21a8; --accent-text: #6b21a8; --accent-soft: #f3e8ff; }
.s2-bus { --accent: #0369a1; --accent-ink: #075985; --accent-text: #075985; --accent-soft: #e0f2fe; }
.s2-econ { --accent: #4d7c0f; --accent-ink: #3f6212; --accent-text: #3f6212; --accent-soft: #ecfccb; }
.s2-maths { --accent: #6d4ed8; --accent-ink: #4c32a8; --accent-text: #4c32a8; --accent-soft: #efeaff; }
.s2-physics { --accent: #2f62d8; --accent-ink: #1f449e; --accent-text: #1f449e; --accent-soft: #e6edff; }
.s2-biology { --accent: #d9661f; --accent-ink: #a14810; --accent-text: #a14810; --accent-soft: #fff0e4; }

/* ---------- dark mode ---------- */
[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0e1120;
  --grid: #181c31;
  --ink: #e9ebf7;
  --ink-2: #b6bbd9;
  --ink-3: #868cad;
  --line: #2a2f4d;
  --card: #161a2e;
  --surface-2: #1c2038;
  --track: #262b47;
  --bar: rgba(14,17,32,0.92);
  --panel: #232a52;
  --hl: #ffd84d;
  --hl-soft: #2d2711;
  --hl-ink: #ffe27a;
  --good: #3fcf8e;
  --good-soft: #10301f;
  --bad: #ff6b78;
  --bad-soft: #3a1720;
  --accent-text: #9db5ff;
  --accent-soft: #1d2650;
}
[data-theme="dark"] .s2-mandarin { --accent-text: #ff8d92; --accent-soft: #3a1a1e; }
[data-theme="dark"] .s2-chemistry { --accent-text: #55d8aa; --accent-soft: #0f3328; }
[data-theme="dark"] .s2-english { --accent-text: #fdba74; --accent-soft: #3a1d0c; }
[data-theme="dark"] .s2-englit { --accent-text: #fda4af; --accent-soft: #3b0a18; }
[data-theme="dark"] .s2-cs { --accent-text: #67e8f9; --accent-soft: #083344; }
[data-theme="dark"] .s2-geog { --accent-text: #86efac; --accent-soft: #052e16; }
[data-theme="dark"] .s2-hist { --accent-text: #fcd34d; --accent-soft: #2d1a05; }
[data-theme="dark"] .s2-psych { --accent-text: #d8b4fe; --accent-soft: #2e1065; }
[data-theme="dark"] .s2-bus { --accent-text: #7dd3fc; --accent-soft: #082f49; }
[data-theme="dark"] .s2-econ { --accent-text: #bef264; --accent-soft: #1a2e05; }
[data-theme="dark"] .s2-maths { --accent-text: #b7a4ff; --accent-soft: #241a49; }
[data-theme="dark"] .s2-physics { --accent-text: #93b2ff; --accent-soft: #1a2549; }
[data-theme="dark"] .s2-biology { --accent-text: #ffaf73; --accent-soft: #3a2414; }
[data-theme="dark"] .s2-streak-card { border-color: #5a4a12; box-shadow: 0 3px 0 #5a4a12; }
[data-theme="dark"] .s2-day { border-color: #4a3f17; }
[data-theme="dark"] .s2-streak-pill.is-lit { background: var(--hl); color: #3a2d00; border-color: #c9a400; }
[data-theme="dark"] .s2-day.done { color: #3a2d00; }
[data-theme="dark"] .s2-logo { box-shadow: 0 3px 0 var(--accent); }
[data-theme="dark"] img { opacity: 0.94; }

/* theme switch */
.s2-theme-btn {
  flex: none; width: 38px; height: 38px; border-radius: 11px; border: 1.5px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 1.05rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 0 var(--line);
}
.s2-theme-btn:hover { border-color: var(--accent); }

/* ---------- base ---------- */
body.s2, body.s2 * { box-sizing: border-box; }
body.s2 [hidden] { display: none !important; }
:where(body.s2) :where(h1, h2, h3, h4, p) { margin: 0; }
body.s2 {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
  line-height: 1.6;
  font-size: 17px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
body.s2 h1, body.s2 h2, body.s2 h3, body.s2 h4 { font-family: var(--font-display); letter-spacing: -0.01em; line-height: 1.15; }
body.s2 :focus-visible { outline: 3px solid var(--hl); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { body.s2 *, body.s2 *::before, body.s2 *::after { transition: none !important; animation: none !important; } }

/* ---------- app bar ---------- */
.s2-appbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 10px clamp(14px, 3vw, 28px);
  background: var(--bar);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1.5px solid var(--line);
  color: var(--ink);
  text-align: left;
}
.s2-logo {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--panel); color: #fff; text-decoration: none;
  font-family: var(--font-display); font-weight: 800; font-size: 1.15rem;
  box-shadow: 0 3px 0 var(--accent);
}
.s2-logo sup { font-size: 0.6em; color: var(--hl); margin-left: 1px; }
.s2-brand { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.s2-brand .s2-title { font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; color: var(--ink); text-decoration: none; line-height: 1.1; white-space: nowrap; }
.s2-brand .s2-sub { font-size: 0.82rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s2-nav { display: flex; gap: 4px; }
.s2-nav a {
  white-space: nowrap;
  font-weight: 700; font-size: 0.95rem; color: var(--ink-2); text-decoration: none;
  padding: 8px 12px; border-radius: 10px;
}
.s2-nav a:hover { background: var(--accent-soft); color: var(--accent-text); }
.s2-nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.s2-streak-pill {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  font-weight: 700; font-size: 0.9rem; padding: 6px 12px; border-radius: 999px;
  background: var(--track); color: var(--ink-3); border: 1.5px solid var(--line);
}
.s2-streak-pill.is-lit { background: var(--hl); color: var(--hl-ink); border-color: #f0c400; }
@media (max-width: 1180px) {
  .s2-brand .s2-sub { display: none; }
  .s2-nav a { padding: 8px 9px; font-size: 0.9rem; }
}
@media (max-width: 1040px) {
  .s2-appbar { flex-wrap: wrap; }
  .s2-nav { order: 3; width: 100%; overflow-x: auto; }
}
@media (max-width: 760px) {
  .s2-appbar { flex-wrap: wrap; }
  .s2-nav { order: 3; width: 100%; overflow-x: auto; }
  .s2-brand .s2-sub { display: none; }
}

/* ---------- buttons ---------- */
.s2-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-body); font-weight: 700; font-size: 1rem; line-height: 1.2;
  padding: 12px 20px; border-radius: var(--r-btn); cursor: pointer; text-decoration: none;
  background: var(--accent); color: #fff; border: 0;
  box-shadow: 0 4px 0 var(--accent-ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s;
}
.s2-btn:hover { background: var(--accent-ink); }
.s2-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-ink); }
.s2-btn.ghost { background: var(--card); color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 1.5px solid var(--line); }
.s2-btn.ghost:hover { background: var(--accent-soft); color: var(--accent-text); }
.s2-btn.small { padding: 8px 14px; font-size: 0.9rem; border-radius: 11px; }

/* ---------- surfaces ---------- */
.s2-card {
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r-card);
  box-shadow: 0 3px 0 var(--line); padding: 22px;
}
.s2-wrap { width: min(1120px, 92%); margin: 28px auto 40px; flex: 1; }

/* ---------- dashboard ---------- */
.s2-hello { margin: 6px 0 18px; }
.s2-hello h1 { font-size: clamp(1.9rem, 4.6vw, 2.8rem); font-weight: 800; color: var(--ink); }
.s2-hello p { color: var(--ink-2); margin-top: 6px; max-width: 62ch; }
.s2-dash { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; margin-bottom: 18px; }
.s2-continue { display: flex; gap: 18px; align-items: center; }
.s2-continue .s2-ring { flex: none; }
.s2-continue h2 { font-size: 1.45rem; margin: 2px 0 4px; }
.s2-continue .meta { color: var(--ink-3); font-size: 0.92rem; }
.s2-continue .s2-btn { margin-top: 12px; }
.s2-kicker { font-weight: 700; color: var(--accent-text); font-size: 0.92rem; }
.s2-streak-card { background: var(--hl-soft); border-color: #f2d65a; box-shadow: 0 3px 0 #f2d65a; }
.s2-streak-card .big { font-family: var(--font-display); font-weight: 800; font-size: 2.6rem; line-height: 1; }
.s2-streak-card .big small { font-size: 1rem; font-weight: 700; margin-left: 4px; }
.s2-streak-card p { color: var(--hl-ink); font-size: 0.92rem; margin-top: 6px; }
.s2-week { display: flex; gap: 6px; margin-top: 14px; }
.s2-day {
  width: 32px; height: 32px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; background: var(--card); color: var(--ink-3); border: 1.5px solid #ecdca0;
}
.s2-day.done { background: var(--hl); color: var(--hl-ink); border-color: #e7c200; }
.s2-day.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.s2-day.future { opacity: 0.45; }
.s2-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 26px; }
.s2-stat .num { font-family: var(--font-display); font-weight: 800; font-size: 1.9rem; line-height: 1.1; }
.s2-stat .lbl { color: var(--ink-2); font-size: 0.92rem; }
.s2-bar { height: 10px; border-radius: 999px; background: var(--track); overflow: hidden; margin-top: 10px; }
.s2-bar > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.5s ease; }
.s2-section-title { font-size: 1.35rem; margin: 30px 0 12px; }
.s2-empty { color: var(--ink-2); }

/* ---------- mastery ring ---------- */
.s2-ring { flex: none; display: block; }
.s2-ring-track { fill: none; stroke: var(--track); stroke-width: 5; }
.s2-ring-fill { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.s2-ring-text { font-family: var(--font-display); font-weight: 800; font-size: 13px; fill: var(--ink); }
.s2-ring.big .s2-ring-text { font-size: 20px; }

/* ---------- topic rows ---------- */
.s2-rows { display: grid; gap: 10px; }
.s2-row {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; box-shadow: 0 3px 0 var(--line);
  text-decoration: none; color: var(--ink); transition: border-color 0.15s, transform 0.08s;
}
.s2-row:hover { border-color: var(--accent); }
.s2-row:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.s2-row .t { font-weight: 700; }
.s2-row .d { color: var(--ink-3); font-size: 0.9rem; }
.s2-row .grow { flex: 1; min-width: 0; }
.s2-row .when { color: var(--ink-3); font-size: 0.85rem; white-space: nowrap; }

/* ---------- toast ---------- */
.s2-toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--panel); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700;
  box-shadow: 0 4px 0 var(--accent); z-index: 100; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
}
.s2-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- footer ---------- */
.s2-footer {
  margin-top: 40px; padding: 22px clamp(14px, 3vw, 28px); background: var(--card); border-top: 1.5px solid var(--line);
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; color: var(--ink-3); font-size: 0.92rem; text-align: left;
}
.s2-footer a { color: var(--ink-2); margin-left: 14px; }

@media (max-width: 820px) {
  .s2-dash { grid-template-columns: 1fr; }
  .s2-stats { grid-template-columns: 1fr 1fr; }
  .s2-stats > :last-child { grid-column: span 2; }
}
@media (max-width: 560px) {
  .s2-continue { flex-direction: column; align-items: flex-start; }
}

/* ---------- XP, chips, confetti ---------- */
.s2-xp-pill {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: 5px; flex: none;
  font-weight: 700; font-size: 0.9rem; padding: 6px 12px; border-radius: 999px; background: var(--card); color: var(--ink);
  border: 1.5px solid var(--line); cursor: default;
}
.s2-xp-pill i { position: absolute; left: 0; bottom: 0; height: 3px; width: var(--p); background: var(--accent); }
.s2-chips { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; }
.s2-xp-chip {
  position: relative; background: var(--panel); color: #fff; font-weight: 700;
  padding: 8px 14px; border-radius: 12px; box-shadow: 0 4px 0 var(--hl); opacity: 0; transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s; pointer-events: none; max-width: 80vw;
}
.s2-xp-chip.go { opacity: 1; transform: translateY(0); animation: s2chip 1.6s ease forwards; }
.s2-xp-chip.big { position: fixed; z-index: 121; right: 50%; transform: translate(50%, 12px); bottom: 50%; font-size: 1.2rem; padding: 14px 22px; background: var(--hl); color: #3a2d00; box-shadow: 0 5px 0 #c9a400; }
.s2-xp-chip.big.go { transform: translate(50%, 0); }
@keyframes s2chip { 0% { opacity: 0; } 12% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
.s2-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 110; }
@media (max-width: 760px) { .s2-xp-pill { display: none; } }

/* ---------- notebook (OneNote-style) ---------- */
.s2-notebook { margin-top: 26px; }
.s2-notebook .nb-head h2 { font-size: 1.35rem; }
.s2-notebook .nb-head p { color: var(--ink-2); font-size: 0.95rem; margin: 4px 0 12px; }
.nb-paper { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; box-shadow: 0 3px 0 var(--line); overflow: hidden; }
.nb-tools { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; background: var(--surface-2); border-bottom: 1.5px solid var(--line); position: sticky; top: 0; }
.nb-tools button { font: inherit; font-size: 0.88rem; padding: 6px 10px; border-radius: 9px; border: 1.5px solid transparent; background: transparent; color: var(--ink-2); cursor: pointer; }
.nb-tools button:hover { background: var(--card); border-color: var(--line); color: var(--ink); }
.hl-swatch { background: #ffdf5d; color: #3a2d00; padding: 0 4px; border-radius: 3px; font-weight: 700; }
.nb-page {
  min-height: 220px; padding: 10px 22px 22px 62px; outline: none; line-height: 30px; font-size: 1.02rem; color: var(--ink);
  background-image:
    linear-gradient(90deg, transparent 46px, rgba(224, 56, 62, 0.35) 46px, rgba(224, 56, 62, 0.35) 48px, transparent 48px),
    repeating-linear-gradient(transparent 0 29px, var(--grid) 29px 30px);
  background-position: 0 10px;
}
.nb-page:empty::before { content: attr(data-placeholder); color: var(--ink-3); }
.nb-page h3 { font-size: 1.15rem; line-height: 30px; margin: 0; color: var(--accent-text); }
.nb-page p, .nb-page div { margin: 0; }
.nb-page ul, .nb-page ol { margin: 0; padding-left: 1.4em; }
.nb-page .nb-key { background: var(--hl-soft); border-left: 4px solid var(--hl); padding: 0 10px; border-radius: 6px; margin: 2px 0; }
.nb-page .nb-todo input { width: 16px; height: 16px; vertical-align: -2px; accent-color: var(--accent); }
.nb-foot { display: flex; justify-content: space-between; padding: 6px 14px; font-size: 0.82rem; color: var(--ink-3); border-top: 1px solid var(--line); background: var(--surface-2); }
.s2-notebook.compact .nb-page { min-height: 120px; }
[data-theme="dark"] .nb-page span[style*="background"] { color: #2a2000; }

/* ---------- floating notebook ---------- */
.nb-fab { position: fixed; right: 18px; bottom: 18px; z-index: 900; display: inline-flex; align-items: center; gap: 8px; padding: 12px 16px; border-radius: 999px; border: 0; background: var(--panel); color: #fff; font: inherit; font-weight: 700; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.22); }
.nb-fab:hover { transform: translateY(-1px); }
.nb-fab.pulse { animation: nbpulse .9s ease; }
@keyframes nbpulse { 30% { transform: scale(1.12); } }
.nb-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); z-index: 950; background: var(--card); border-left: 1.5px solid var(--line); box-shadow: -10px 0 40px rgba(0,0,0,.15); display: flex; flex-direction: column; padding: 14px 16px; overflow: auto; }
.nb-drawer[hidden] { display: none; }
.nb-drawer-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.nb-drawer-head div { flex: 1; }
.nb-drawer-head b { display: block; font-family: var(--font-display); font-size: 1.25rem; }
.nb-drawer-head span { color: var(--ink-2); font-size: .9rem; }
.nb-close { border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; width: 38px; height: 38px; font-size: 1.4rem; line-height: 1; cursor: pointer; }
.nb-drawer .s2-notebook { margin-top: 0; flex: 1; display: flex; flex-direction: column; }
.nb-drawer .nb-paper { flex: 1; display: flex; flex-direction: column; }
.nb-drawer .nb-page { flex: 1; min-height: 240px; }
.nb-tip { font-size: .85rem; color: var(--ink-3); margin: 10px 0 0; }
body.nb-open .nb-fab { right: min(458px, calc(100% - 70px)); }
@media (min-width: 1100px) { body.nb-open main { margin-right: 440px; transition: margin .2s; } }
@media (max-width: 600px) { .nb-fab .lbl { display: none; } .nb-fab { padding: 14px; } body.nb-open .nb-fab { display: none; } }
.nb-addsel { position: absolute; z-index: 960; padding: 8px 12px; border-radius: 10px; border: 0; background: var(--panel); color: #fff; font: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.nb-quote { margin: 8px 0; padding: 6px 12px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; color: var(--ink); }
@media print { .nb-fab, .nb-drawer, .nb-addsel { display: none !important; } }
/* A-level platforms */
.s2-alevel-chemistry { --accent: #0b7d6a; --accent-ink: #065a4c; --accent-text: #065a4c; --accent-soft: #dcf1ec; }
.s2-alevel-physics { --accent: #4150c8; --accent-ink: #2c3794; --accent-text: #2c3794; --accent-soft: #e7e9fb; }
.s2-alevel-biology { --accent: #c2410c; --accent-ink: #8f2f07; --accent-text: #8f2f07; --accent-soft: #fdebe1; }
[data-theme="dark"] .s2-alevel-chemistry { --accent-text: #5ed6bf; --accent-soft: #0d302a; }
[data-theme="dark"] .s2-alevel-physics { --accent-text: #9aa6ff; --accent-soft: #1d2250; }
[data-theme="dark"] .s2-alevel-biology { --accent-text: #ffa070; --accent-soft: #3a1c0d; }
