:root {
  --blue-900: #0a2540;
  --blue-700: #0b57a4;
  --blue-600: #1976d2;
  --blue-500: #2196f3;
  --blue-100: #e3f2fd;
  --ink: #16324f;
  --muted: #6b7f95;
  --bg: #eef4fb;
  --white: #ffffff;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(10, 37, 64, 0.12);
  color-scheme: only light;
}

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--white);
  min-height: 100dvh;
  color: var(--ink);
}

/* ---------- App stage: full-screen edge-to-edge on every device ---------- */
.phone {
  position: relative;
  width: 100%;
  height: 100dvh;
  background: var(--white);
  overflow: hidden;
}
.phone-notch { display: none; }
@supports not (height: 100dvh) {
  body { min-height: 100vh; }
  .phone { height: 100vh; }
}
.screen-host { width: 100%; height: 100%; overflow-y: auto; overflow-x: clip; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
.screen-host.has-tabbar { padding-bottom: 62px; }

/* ---------- Generic screen ---------- */
.screen { min-height: 100%; display: flex; flex-direction: column; }
.screen-pad { padding: 44px 24px 24px; flex: 1; }

.brand-name { font-size: 30px; font-weight: 800; letter-spacing: .5px; color: var(--blue-700); }
.brand-tag  { font-size: 14px; color: var(--muted); margin-top: 4px; }

.screen-title {
  font-size: 20px; font-weight: 700; color: var(--blue-700);
  margin-bottom: 18px;
}
.section-title { font-size: 15px; font-weight: 700; color: var(--ink); margin: 8px 0 12px; }

/* ---------- Splash ---------- */
.splash {
  justify-content: center; align-items: center; text-align: center;
  background: linear-gradient(160deg, var(--blue-700), var(--blue-500));
  color: #fff; padding: 40px;
}
.splash .brand-name { color: #fff; font-size: 40px; }
.splash .brand-tag  { color: #dbeafe; font-size: 15px; margin-top: 10px; }
.splash-hero {
  width: 200px; height: 200px; object-fit: cover;
  border-radius: 24px; margin-bottom: 28px; box-shadow: var(--shadow);
}

/* ---------- Form elements ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid #cfddeb; border-radius: 10px; background: #f7fbff; color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--blue-500); background: #fff; }

.btn {
  width: 100%; padding: 14px; font-size: 16px; font-weight: 700;
  color: #fff; background: var(--blue-600); border: none; border-radius: 12px;
  cursor: pointer; transition: background .15s;
}
.btn:hover { background: var(--blue-700); }
.btn.secondary { background: transparent; color: var(--blue-700); border: 1px solid var(--blue-600); }
.btn.ghost { background: transparent; color: var(--muted); border: none; font-weight: 600; }

.link { color: var(--blue-600); font-size: 13px; text-decoration: none; cursor: pointer; }
.link:hover { text-decoration: underline; }

.row-between { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 20px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.center { text-align: center; }

/* ---------- Footer ---------- */
.screen-footer {
  padding: 14px; text-align: center; font-size: 11px; color: var(--muted);
  border-top: 1px solid #e6eef7;
}
.help-icon {
  position: absolute; top: 34px; right: 20px; z-index: 15;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--blue-100); color: var(--blue-700);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; cursor: pointer; border: none; font-size: 16px;
}

/* ---------- Subscription ---------- */
.subscription {
  justify-content: center; text-align: center; align-items: center;
  background: linear-gradient(160deg, #eaf3fc, #ffffff);
}
.sub-badge {
  width: 90px; height: 90px; border-radius: 50%;
  background: var(--blue-100); color: var(--blue-700);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; margin-bottom: 24px;
}

/* ---------- Home / App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--blue-700); color: #fff;
  padding: max(34px, calc(env(safe-area-inset-top) + 14px)) 18px 14px; display: flex; align-items: center; gap: 12px;
}
.appbar .menu-btn, .appbar .title { color: #fff; }
.menu-btn { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }
.appbar .title { font-size: 18px; font-weight: 700; }

.search-wrap { padding: 14px 18px; background: var(--blue-700); }
.search-wrap input {
  width: 100%; padding: 11px 14px; border-radius: 20px; border: none;
  font-size: 16px; background: #fff;
}

.year-block { padding: 6px 18px 4px; }
.year-title {
  font-size: 15px; font-weight: 800; color: var(--blue-700);
  margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--blue-100);
}
.subject-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.subject-card {
  background: #fff; border: 1px solid #e2edf8; border-radius: 12px;
  padding: 14px 12px; font-size: 14px; font-weight: 600; color: var(--ink);
  cursor: pointer; box-shadow: 0 2px 6px rgba(10,37,64,.05);
  display: flex; align-items: center; gap: 8px; transition: transform .1s, border-color .1s;
}
.subject-card:hover { transform: translateY(-2px); border-color: var(--blue-500); }
.subject-card .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue-500); flex: none; }

/* ---------- Side drawer ---------- */
.drawer-overlay {
  position: absolute; inset: 0; background: rgba(10,37,64,.45);
  z-index: 30; display: none;
}
.drawer-overlay.open { display: block; }
.drawer {
  position: absolute; top: 0; left: 0; height: 100%; width: 74%;
  background: #fff; z-index: 31; transform: translateX(-100%);
  transition: transform .22s ease; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  background: var(--blue-700); color: #fff; padding: 40px 20px 20px;
}
.drawer-head .brand-name { color: #fff; font-size: 22px; }
.drawer-links { padding: 12px 0; }
.drawer-links a {
  display: block; padding: 14px 22px; font-size: 15px; color: var(--ink);
  text-decoration: none; border-bottom: 1px solid #f0f5fb; cursor: pointer;
}
.drawer-links a:hover { background: var(--blue-100); }

/* ---------- Subject detail ---------- */
.detail-topics { list-style: none; }
.detail-topics li {
  background: #fff; border: 1px solid #e2edf8; border-radius: 10px;
  padding: 12px 14px; margin-bottom: 10px; font-size: 14px;
}
.empty-note { color: var(--muted); font-size: 14px; padding: 20px 0; text-align: center; }
.back-btn { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; }

.drawer-legal { border-top: 1px solid rgba(255,255,255,0.15); margin-top: 6px; padding-top: 6px; }
.drawer-legal-head { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; opacity: .7; padding: 8px 16px 4px; }

/* ---------- Bottom tab bar (persistent footer) ---------- */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; background: #fff; border-top: 1px solid #e2edf8;
  box-shadow: 0 -4px 16px rgba(10,37,64,.06);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar.hidden { display: none; }
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 8px 2px 7px; color: var(--muted); font-size: 11px; font-weight: 600;
  transition: color .12s ease, transform .08s ease;
}
.tab .tab-ic { font-size: 21px; line-height: 1; filter: grayscale(.4); opacity: .8; }
.tab.active { color: var(--blue-700); }
.tab.active .tab-ic { filter: none; opacity: 1; }
.tab:active { transform: scale(.92); }

/* ---------- Add-to-Home-Screen install banner ---------- */
.installbar {
  position: absolute; left: 12px; right: 12px; z-index: 40;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px;
  background: var(--blue-700); color: #fff;
  border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(10,37,64,.28);
  font-size: 13.5px; line-height: 1.3;
  animation: mm-install-in .28s ease;
}
.installbar.above-tabbar { bottom: calc(62px + 12px + env(safe-area-inset-bottom)); }
.installbar span { flex: 1; }
.installbar button {
  background: #fff; color: var(--blue-700); border: none; border-radius: 8px;
  padding: 7px 14px; font-weight: 800; cursor: pointer; white-space: nowrap;
}
.installbar button#mm-install-x { background: transparent; color: #fff; padding: 6px 6px; font-size: 15px; }
@keyframes mm-install-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Subject detail: Save / Important toggles ---------- */
.detail-actions { display: flex; gap: 10px; margin: 14px 0 18px; }
.mark-btn {
  flex: 1; padding: 11px 8px; border-radius: 12px; border: 1px solid #dbe7f5;
  background: #fff; color: var(--ink); font-size: 13px; font-weight: 700; cursor: pointer;
  transition: transform .08s ease, background .12s ease, border-color .12s ease;
}
.mark-btn:active { transform: scale(.96); }
.mark-btn.on { background: var(--blue-100); border-color: var(--blue-500); color: var(--blue-700); }

/* ---------- Saved / Important lists ---------- */
.mark-list { display: flex; flex-direction: column; gap: 10px; }
.mark-meta { flex: 1; min-width: 0; }
.mark-name { font-weight: 700; font-size: 14px; color: var(--ink); }

/* ---------- Account ---------- */
.account-card {
  display: flex; align-items: center; gap: 14px; background: #fff;
  border: 1px solid #e2edf8; border-radius: 16px; padding: 16px; box-shadow: var(--shadow);
}
.account-avatar {
  width: 52px; height: 52px; border-radius: 14px; flex: none; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--blue-700), var(--blue-500)); color: #fff;
}
.account-who { min-width: 0; }
.account-name { font-weight: 800; font-size: 16px; color: var(--ink); }
.account-row {
  background: #fff; border: 1px solid #e2edf8; border-radius: 12px;
  padding: 14px; font-size: 14px; color: var(--ink);
}
.muted-sm { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.account-stats { display: flex; gap: 12px; }
.stat {
  flex: 1; background: #fff; border: 1px solid #e2edf8; border-radius: 14px;
  padding: 16px; text-align: center; cursor: pointer; box-shadow: 0 2px 6px rgba(10,37,64,.05);
  transition: transform .08s ease;
}
.stat:active { transform: scale(.97); }
.stat-n { font-size: 24px; font-weight: 800; color: var(--blue-700); }
.stat-l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.account-links { display: flex; flex-direction: column; gap: 8px; }
.account-link {
  display: block; background: #fff; border: 1px solid #e2edf8; border-radius: 12px;
  padding: 13px 14px; font-size: 14px; color: var(--ink); text-decoration: none; font-weight: 600;
}
.account-link:active { background: var(--blue-100); }

/* ---------- Tap feedback ---------- */
.btn:active { transform: scale(.98); }
.subject-card:active { transform: scale(.98); }

/* ---------- Monochrome reading mode ---------- */
html.mono .phone { filter: grayscale(1) contrast(1.02); }

/* ---------- iOS-style toggle switch ---------- */
.switch-row { display: flex; align-items: center; gap: 12px; }
.switch-label { flex: 1; min-width: 0; }
.switch-title { font-weight: 700; font-size: 14px; color: var(--ink); }
.switch {
  flex: 0 0 auto; width: 48px; height: 28px; border-radius: 999px; border: none;
  background: #cdd8e4; position: relative; cursor: pointer; padding: 0;
  transition: background .16s ease;
}
.switch .switch-knob {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .16s ease;
}
.switch.on { background: var(--blue-600); }
.switch.on .switch-knob { transform: translateX(20px); }
