/* =========================================================
   shan學習 · Apple-inspired interface pass
   Principles: clarity, deference, depth
   ========================================================= */

:root {
  color-scheme: light;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "PingFang TC", "Noto Sans TC", sans-serif;
  --font-mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: rgba(255, 255, 255, 0.86);
  --surface-soft: #f0f0f2;
  --ink: #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #86868b;
  --hairline: rgba(0, 0, 0, 0.09);
  --hairline-strong: rgba(0, 0, 0, 0.14);
  --accent: #0071e3;
  --accent-deep: #0066cc;
  --accent-ink: #ffffff;
  --accent-soft: rgba(0, 113, 227, 0.10);
  --accent-line: rgba(0, 113, 227, 0.24);
  --good: #00875a;
  --bad: #d70015;

  --glass-tint: var(--surface-raised);
  --glass-tint-strong: rgba(255, 255, 255, 0.94);
  --glass-border: rgba(0, 0, 0, 0.08);
  --glass-highlight: rgba(255, 255, 255, 0.7);
  --glass-blur: 20px;
  --glass-sat: 180%;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 14px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.05), 0 14px 34px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 8px 18px rgba(0, 0, 0, 0.07), 0 28px 70px rgba(0, 0, 0, 0.11);

  --r-card: 24px;
  --r-input: 14px;
  --r-pill: 980px;
  --blob-a: rgba(0, 113, 227, 0.08);
  --blob-b: rgba(90, 200, 250, 0.06);
  --blob-c: rgba(255, 255, 255, 0);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-raised: rgba(28, 28, 30, 0.86);
  --surface-soft: #2c2c2e;
  --ink: #f5f5f7;
  --ink-2: #c7c7cc;
  --ink-3: #8e8e93;
  --hairline: rgba(255, 255, 255, 0.12);
  --hairline-strong: rgba(255, 255, 255, 0.2);
  --accent: #2997ff;
  --accent-deep: #64b5ff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(41, 151, 255, 0.16);
  --accent-line: rgba(41, 151, 255, 0.34);
  --good: #30d158;
  --bad: #ff453a;

  --glass-tint: var(--surface-raised);
  --glass-tint-strong: rgba(28, 28, 30, 0.96);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-highlight: rgba(255, 255, 255, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45), 0 5px 16px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.45), 0 18px 44px rgba(0, 0, 0, 0.34);
  --shadow-lg: 0 10px 28px rgba(0, 0, 0, 0.5), 0 34px 90px rgba(0, 0, 0, 0.42);
}

html { scroll-behavior: smooth; }
body {
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { color: #fff; background: var(--accent); }

.page-bg {
  background:
    radial-gradient(1000px 560px at 50% -260px, var(--blob-a), transparent 68%),
    radial-gradient(760px 460px at 92% 12%, var(--blob-b), transparent 72%),
    var(--bg);
}
.page-bg::after { display: none; }

.wrap { max-width: 1080px; }
main {
  padding-top: clamp(38px, 6vw, 68px);
  padding-bottom: 88px;
}

/* Apple-like materials: translucent only where depth matters. */
.glass,
.glass-strong {
  border: 1px solid var(--glass-border);
  background: var(--glass-tint);
  box-shadow: var(--shadow-sm);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
}
.glass::after { display: none; }
.glass-strong { background: var(--glass-tint-strong); }

/* Header */
.topbar {
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--hairline);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
}
.topbar-inner,
.topbar-inner.glass {
  min-height: 56px;
  padding: 8px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.topbar-inner.glass::after { display: none; }
.brand {
  gap: 9px;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.025em;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  box-shadow: none;
}
.brand small {
  color: var(--ink-3);
  font-size: 0.67rem;
  font-weight: 500;
  letter-spacing: 0;
}
.nav {
  gap: 2px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.nav-btn {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 0.86rem;
  font-weight: 500;
}
.nav-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.nav-btn[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: none;
}
.top-actions { gap: 7px; }
.chip {
  min-height: 36px;
  padding: 6px 11px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 0;
  font-size: 0.8rem;
  font-weight: 600;
}
.icon-btn {
  width: 38px;
  height: 38px;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 74%, transparent);
  border: 1px solid var(--hairline);
  box-shadow: none;
}
.icon-btn:hover {
  color: var(--ink);
  background: var(--surface);
}

/* Mobile tab bar follows the iOS pattern: five destinations, labels always visible. */
.mobile-tabbar { display: none; }

/* Typography */
.page-title {
  max-width: 22ch;
  font-size: clamp(2.2rem, 5.6vw, 4rem);
  font-weight: 700;
  line-height: 1.04;
  letter-spacing: -0.048em;
}
.lede {
  max-width: 58ch;
  margin-top: 14px;
  color: var(--ink-2);
  font-size: clamp(1rem, 1.4vw, 1.14rem);
  line-height: 1.5;
}
.section-head {
  align-items: end;
  margin: 44px 0 16px;
}
.section-head h2 {
  color: var(--ink);
  font-size: clamp(1.35rem, 2.2vw, 1.7rem);
  font-weight: 650;
  letter-spacing: -0.025em;
}
.section-head .meta,
.meta { color: var(--ink-3); }

/* Controls */
.btn {
  min-height: 44px;
  padding: 0 19px;
  border-radius: 999px;
  font-size: 0.94rem;
  font-weight: 600;
  box-shadow: none;
}
.btn-primary,
.auth-link.primary {
  color: #fff;
  background: var(--accent);
  box-shadow: none;
}
.btn-primary:hover,
.auth-link.primary:hover {
  background: #0077ed;
  box-shadow: 0 8px 24px rgba(0, 113, 227, 0.24);
}
.btn-ghost {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
}
.btn-ghost:hover { background: var(--surface-soft); }
.btn-soft {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
}
.btn-danger {
  color: var(--bad);
  background: color-mix(in srgb, var(--bad) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 24%, transparent);
}
.cta-row { gap: 10px; margin-top: 26px; }

/* iOS segmented controls */
.seg {
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
.seg button {
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 9px;
  color: var(--ink-2);
  font-size: 0.88rem;
  font-weight: 500;
}
.seg button[aria-pressed="true"],
.seg button[aria-pressed="true"]:hover {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.13), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
}
[data-theme="dark"] .seg button[aria-pressed="true"],
[data-theme="dark"] .seg button[aria-pressed="true"]:hover {
  background: #636366;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.32);
}
#subject-seg button,
#subject-seg-lib button,
#math-lang-seg button,
#math-lang-seg-lib button { flex: 1 1 0; }
#grade-seg button,
#grade-seg-lib button { flex: 1 1 112px; }

/* Home */
.daily-goal {
  position: relative;
  margin-top: 32px;
  padding: 24px 26px 22px;
  overflow: hidden;
  border: 0;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(135deg, #0071e3 0%, #0a84ff 58%, #39a7ff 100%);
  box-shadow: 0 18px 46px rgba(0, 113, 227, 0.22);
}
.daily-goal::before {
  content: "";
  position: absolute;
  width: 280px;
  height: 280px;
  top: -180px;
  right: -80px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  pointer-events: none;
}
.daily-goal-top { position: relative; margin-bottom: 16px; }
.daily-goal-title { color: #fff; font-size: 1.16rem; font-weight: 600; letter-spacing: -0.015em; }
.daily-goal .meta { position: relative; color: rgba(255, 255, 255, 0.82); font-weight: 500; }
.daily-goal-row { position: relative; }
.stepper {
  gap: 5px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.14);
}
.step-btn {
  width: 34px;
  height: 34px;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  font-size: 1.15rem;
  font-weight: 600;
}
.step-btn:hover { background: rgba(255, 255, 255, 0.25); }
.step-num { color: #fff; font-size: 1.08rem; font-weight: 600; }
.daily-goal .goal-line {
  position: relative;
  height: 7px;
  margin-top: 16px;
  background: rgba(255, 255, 255, 0.24);
}
.daily-goal .goal-line > span { background: #fff; }

.grade-wrap {
  margin-top: 22px;
  padding: 24px;
  border-radius: 24px;
}
.grade-head { margin-bottom: 10px; }
.grade-title { font-size: 0.95rem; font-weight: 600; }
.grade-note { margin-top: 12px; line-height: 1.45; }
.grade-divider { margin: 20px 0; }
.grade-wrap .seg { width: 100%; max-width: 100%; }

.pack-grid { gap: 14px; }
.pack-card {
  min-height: 216px;
  padding: 22px;
  border: 1px solid var(--hairline);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 220ms ease, border-color 180ms ease;
}
.pack-card:hover {
  transform: translateY(-4px);
  border-color: var(--hairline-strong);
  box-shadow: var(--shadow-md);
}
.pack-badge {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  color: var(--accent);
  background: var(--accent-soft);
}
.pack-card h3 { font-size: 1.18rem; font-weight: 650; letter-spacing: -0.02em; }
.pack-count,
.pack-card .en { color: var(--ink-3); }
.progress-line {
  height: 7px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}
.progress-line > span { background: var(--accent); }

/* Study flow */
.stage {
  margin-top: 20px;
  padding: clamp(22px, 4vw, 36px);
  border-radius: 28px;
}
.study-head .back { color: var(--accent); font-weight: 500; }
.stage-bar { margin-bottom: 18px; }
.flip-face {
  border: 1px solid var(--hairline);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.flip-back { background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--accent) 4%, var(--surface))); }
.word-en,
.quiz-word,
.word-zh { font-weight: 650; letter-spacing: -0.035em; }
.word-pos { color: var(--accent); letter-spacing: 0.1em; }
.listen { color: var(--accent); font-weight: 500; }
.options { gap: 11px; }
.opt {
  min-height: 62px;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  font-size: 0.98rem;
  font-weight: 500;
}
.opt:hover:not(:disabled) { background: var(--surface-soft); }
.opt .opt-key { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.spell-input,
.search-box input,
.select,
.auth-input {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  box-shadow: none;
}
.spell-input:focus,
.search-box input:focus,
.select:focus,
.auth-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.feedback-box { border-radius: 12px; }

/* Library */
.filter-row { gap: 9px; margin-bottom: 16px; }
.search-box input,
.select { min-height: 46px; }
.word-row {
  min-height: 54px;
  padding: 13px 14px;
  border-radius: 12px;
  border: 0;
  border-bottom: 1px solid var(--hairline);
}
.word-row:hover {
  background: var(--surface-soft);
  border-color: var(--hairline);
}
.word-row:last-child { border-bottom: 0; }
.word-row .w { font-weight: 600; }
.word-row .p { color: var(--ink-3); }
.word-detail {
  margin: 0 8px 8px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface-soft);
}

/* Progress and leaderboard */
.stat-tile {
  padding: 22px;
  border-radius: 22px;
}
.stat-num { font-weight: 650; letter-spacing: -0.04em; }
.bars { padding: 24px; border-radius: 24px; }
.lb-row { min-height: 58px; padding: 12px 14px; }
.lb-rank { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lb-score { font-weight: 600; }
.share-box { border-radius: 24px; }
.lb-empty { padding: 38px 18px; }
.lb-empty-icon {
  display: grid;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  place-items: center;
  border-radius: 16px;
  color: var(--accent);
  background: var(--accent-soft);
}
.lb-empty-icon svg { width: 28px; height: 28px; }
.lb-empty h3 { font-size: 1.1rem; font-weight: 650; letter-spacing: -0.02em; }
.lb-empty p { margin-top: 6px; color: var(--ink-3); font-size: 0.9rem; }
.mini-btn {
  min-height: 32px;
  background: var(--surface);
  border-color: var(--hairline-strong);
  font-weight: 500;
}

/* Authentication and account sheets */
.auth-dialog {
  border: 1px solid var(--hairline);
  border-radius: 24px;
  background: var(--glass-tint-strong);
  box-shadow: var(--shadow-lg);
}
.auth-dialog::backdrop {
  background: rgba(0, 0, 0, 0.36);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.auth-form { gap: 9px; padding: 26px; }
.auth-head h2 { font-size: 1.35rem; font-weight: 650; letter-spacing: -0.025em; }
.auth-label { font-weight: 500; }
.auth-check input { accent-color: var(--accent); }
.auth-switch button { color: var(--accent); font-weight: 500; }

/* Accessibility */
a, button, input, select { touch-action: manipulation; }
:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .pack-card:hover { transform: none; }
}

/* Compact layouts */
@media (max-width: 900px) {
  .nav-btn { padding-inline: 9px; font-size: 0.82rem; }
  .brand small { display: none; }
}

@media (max-width: 760px) {
  body { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .topbar {
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: 6px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
  }
  .topbar-inner,
  .topbar-inner.glass {
    min-height: 52px;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 6px 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .brand { min-width: 0; flex: 1 1 auto; }
  .brand span:last-child { overflow: hidden; text-overflow: ellipsis; }
  .brand small { display: none; }
  .nav,
  .nav-scroll { display: none !important; }
  .top-actions { flex: 0 0 auto; }
  .chip { display: none; }

  main {
    padding-top: 34px;
    padding-bottom: 36px;
  }
  .page-title { font-size: clamp(2.25rem, 10vw, 3.25rem); }
  .lede { margin-top: 11px; font-size: 1rem; }
  .section-head { margin-top: 38px; }

  .daily-goal { margin-top: 26px; padding: 22px; border-radius: 22px; }
  .grade-wrap { padding: 20px; border-radius: 22px; }
  .pack-grid { grid-template-columns: 1fr; gap: 12px; }
  .pack-card { min-height: 196px; border-radius: 22px; }
  .stage { border-radius: 22px; }
  .stat-tile { border-radius: 20px; }

  .mobile-tabbar {
    position: fixed;
    z-index: 80;
    left: 12px;
    right: 12px;
    bottom: max(10px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 6px;
    border: 1px solid var(--hairline);
    border-radius: 24px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    box-shadow: 0 14px 42px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.06);
    -webkit-backdrop-filter: blur(28px) saturate(190%);
    backdrop-filter: blur(28px) saturate(190%);
  }
  [data-theme="dark"] .mobile-tabbar {
    background: rgba(28, 28, 30, 0.9);
    box-shadow: 0 16px 46px rgba(0, 0, 0, 0.58);
  }
  .mobile-tabbar .nav-btn {
    display: flex;
    min-width: 0;
    min-height: 52px;
    padding: 4px 2px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 17px;
    color: var(--ink-3);
    font-size: 0.66rem;
    font-weight: 500;
    line-height: 1;
  }
  .mobile-tabbar .nav-btn svg { width: 21px; height: 21px; }
  .mobile-tabbar .nav-btn[aria-current="page"] {
    color: var(--accent);
    background: var(--accent-soft);
  }
  .mobile-tabbar .nav-btn:active { transform: scale(0.94); }

  .auth-link { padding: 7px 9px; font-size: 0.82rem; }
  .icon-btn { width: 38px; height: 38px; }
}

@media (max-width: 390px) {
  .brand { font-size: 0.94rem; }
  .brand-mark { width: 30px; height: 30px; }
  .auth-link { padding-inline: 7px; font-size: 0.78rem; }
  .page-title { font-size: 2.25rem; }
  .daily-goal { padding: 20px; }
  .grade-wrap { padding: 18px; }
  .grade-wrap .seg button { flex-basis: calc(50% - 3px); }
}