/* ============================================================
   设计令牌 · Design tokens
   ============================================================ */
:root {
  /* Palette */
  --bg:            #faf7f2;   /* warm cream */
  --bg-elevated:   #ffffff;
  --surface:       #ffffff;
  --surface-alt:   #f5f1ea;
  --border:        #eee7db;
  --border-strong: #d6cdbe;

  --text:          #16181d;   /* near-black */
  --text-2:        #4b5563;
  --muted:         #94a3b8;

  --brand:         #6366f1;   /* indigo */
  --brand-strong:  #4f46e5;
  --brand-soft:    #eef2ff;

  --accent:        #f97316;   /* CTA orange */
  --success:       #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;

  /* Radius */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, .06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, .07), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, .10), 0 4px 12px rgba(15, 23, 42, .06);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  /* Layout */
  --bar-h: 56px;
  --tab-h: 62px;
  --page-max: 720px;
  --gutter: 16px;

  /* Motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: 220ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0f1115;
    --bg-elevated:   #171922;
    --surface:       #1c1f2a;
    --surface-alt:   #232635;
    --border:        #2a2e40;
    --border-strong: #3a3f55;
    --text:          #f1f5f9;
    --text-2:        #cbd5e1;
    --muted:         #64748b;
    --brand-soft:    #1e1b4b;
  }
}

/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  text-rendering: optimizeLegibility;
}
body { min-height: 100dvh; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

/* Subtle background texture */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(circle at 15% -10%, rgba(99, 102, 241, .08), transparent 45%),
    radial-gradient(circle at 105% 15%, rgba(249, 115, 22, .06), transparent 40%);
}
@media (prefers-color-scheme: dark) {
  body::before {
    background:
      radial-gradient(circle at 15% -10%, rgba(99, 102, 241, .18), transparent 45%),
      radial-gradient(circle at 105% 15%, rgba(249, 115, 22, .10), transparent 40%);
  }
}

/* ============================================================
   App bar
   ============================================================ */
.app-bar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-inline: 8px;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.6) blur(20px);
  -webkit-backdrop-filter: saturate(1.6) blur(20px);
  border-bottom: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
}
.app-bar h1 {
  margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em;
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  background: transparent; border: 0; color: var(--text);
  width: 40px; height: 40px; border-radius: var(--r-md);
  font-size: 20px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.icon-btn:active { background: var(--surface-alt); transform: scale(.94); }

/* Search bar (drop-down) */
.search-bar {
  position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top)); z-index: 19;
  padding: 8px var(--gutter);
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid color-mix(in oklab, var(--border) 40%, transparent);
}
.search-bar input {
  width: 100%; height: 44px; padding: 0 44px 0 44px;
  border: 1px solid var(--border); border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text); font-size: 15px; outline: none;
  font-family: inherit;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='9' cy='9' r='7'/><path d='m14 14 5 5'/></svg>");
  background-repeat: no-repeat;
  background-position: 14px center;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.search-bar input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--brand) 15%, transparent);
}

/* ============================================================
   Layout
   ============================================================ */
.view {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 12px var(--gutter) calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  min-height: calc(100dvh - var(--bar-h) - var(--tab-h));
}
.loader { text-align: center; color: var(--muted); padding: 60px 0; font-size: 14px; }
.empty  { text-align: center; color: var(--muted); padding: 40px 12px; font-size: 14px; }

.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 24px 4px 12px;
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .12em; font-weight: 700;
}
.section-title:first-child { margin-top: 8px; }

/* ============================================================
   Home hero
   ============================================================ */
.hero-banner {
  position: relative; overflow: hidden;
  border-radius: var(--r-xl);
  padding: 22px 20px;
  margin-bottom: 8px;
  color: #fff;
  background: linear-gradient(130deg, #4f46e5 0%, #7c3aed 50%, #ec4899 100%);
  box-shadow: var(--shadow-md);
}
.hero-banner::before {
  content: ""; position: absolute; inset: -50% -20% auto auto;
  width: 240px; height: 240px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.28) 0%, rgba(255,255,255,0) 60%);
  pointer-events: none;
}
.hero-banner::after {
  content: "🎓"; position: absolute; right: 18px; bottom: 12px;
  font-size: 64px; opacity: .28; transform: rotate(-8deg);
}
.hero-title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 6px; }
.hero-sub   { font-size: 13.5px; line-height: 1.55; opacity: .92; max-width: 84%; }

/* ============================================================
   Subject grid
   ============================================================ */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.subject-card {
  position: relative; overflow: hidden;
  border-radius: var(--r-lg);
  padding: 16px;
  min-height: 118px;
  color: #fff;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  isolation: isolate;
}
.subject-card::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(160deg, rgba(255,255,255,.20) 0%, rgba(255,255,255,0) 55%);
  pointer-events: none; z-index: 0;
}
.subject-card:active { transform: scale(.97); box-shadow: var(--shadow-xs); }
.subject-card .icon {
  position: absolute; right: 10px; top: 10px;
  font-size: 44px; line-height: 1;
  opacity: .3; z-index: 0;
  transform: rotate(-8deg);
}
.subject-card .name  { font-size: 16px; font-weight: 700; letter-spacing: -.01em; z-index: 1; }
.subject-card .count { font-size: 12.5px; opacity: .92; z-index: 1; font-weight: 500; }
.subject-card .en-hint {
  font-size: 11px; opacity: .68; z-index: 1;
  font-family: var(--font-sans);
}

/* ============================================================
   Filter bar (in-subject search)
   ============================================================ */
.filter-bar {
  position: sticky;
  top: calc(var(--bar-h) + env(safe-area-inset-top));
  z-index: 5;
  margin: -12px calc(var(--gutter) * -1) 12px;
  padding: 10px var(--gutter) 8px;
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid color-mix(in oklab, var(--border) 40%, transparent);
}
.filter-summary {
  margin-top: 6px;
  font-size: 12px; color: var(--muted); font-weight: 500;
  padding-left: 4px;
}

/* Subject-scoped search */
.subject-search {
  position: relative;
}
.subject-search input {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 40px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  outline: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='9' cy='9' r='7'/><path d='m14 14 5 5'/></svg>");
  background-repeat: no-repeat;
  background-position: 13px center;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.subject-search input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--brand) 15%, transparent);
}
.subject-search input::-webkit-search-cancel-button { display: none; }
.subject-search .clear-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px;
  border: 0; border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text-2);
  font-size: 16px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
}
.subject-search .clear-btn:active { background: var(--border); }

/* ============================================================
   Cards (topic list)
   ============================================================ */
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  color: inherit;
}
.card:active { transform: scale(.985); box-shadow: none; }
.card h2 {
  margin: 0 0 4px;
  font-size: 16px; font-weight: 600; letter-spacing: -.005em;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card p {
  margin: 0; color: var(--text-2); font-size: 13.5px; line-height: 1.5;
}
.card .en-name {
  font-size: 12px; color: var(--muted); margin: -2px 0 6px;
  font-family: var(--font-sans);
  letter-spacing: -.005em;
}
.card .row {
  margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px;
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 600;
  background: var(--brand-soft); color: var(--brand-strong);
}
.chip.dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.tag {
  font-size: 11px; color: var(--muted); font-weight: 500;
  padding: 2px 6px; border-radius: var(--r-xs);
  background: var(--surface-alt);
}

.badge-video {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; padding: 3px 7px;
  background: linear-gradient(135deg, #fb923c, #f43f5e);
  color: #fff; border-radius: var(--r-pill); font-weight: 700;
  letter-spacing: .01em;
  box-shadow: 0 2px 6px rgba(244, 63, 94, .3);
}

/* ============================================================
   Topic detail hero
   ============================================================ */
.topic-hero {
  position: relative; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 20px 20px 22px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-md);
}
.topic-hero::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: var(--hero-accent, var(--brand));
}
.topic-hero .meta {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px;
}
.topic-hero h2 {
  margin: 0 0 6px;
  font-size: 24px; line-height: 1.25; letter-spacing: -.015em;
  font-weight: 700;
}
.topic-hero .en-name-hero {
  font-size: 13px; color: var(--muted); margin: 0 0 12px;
  font-family: var(--font-sans);
}
.topic-hero .desc {
  color: var(--text-2); font-size: 15px; line-height: 1.65; margin: 0;
}

/* ============================================================
   Panels (evidence / assessment / prereqs)
   ============================================================ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-xs);
}
.panel h3 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 10px;
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .12em; font-weight: 700;
}
.panel h3::before {
  content: ""; width: 3px; height: 12px; border-radius: 2px; background: var(--brand);
}
.panel ul { margin: 0; padding-left: 20px; }
.panel li { margin: 6px 0; color: var(--text-2); line-height: 1.5; }

.panel .assessment {
  position: relative;
  font-style: normal; color: var(--text);
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  padding: 14px 16px 14px 42px;
  border-radius: var(--r-md);
  margin: 0;
  line-height: 1.6;
  border-left: 3px solid #f59e0b;
}
.panel .assessment::before {
  content: "💡"; position: absolute; left: 14px; top: 12px; font-size: 18px;
}
@media (prefers-color-scheme: dark) {
  .panel .assessment {
    background: linear-gradient(135deg, #78350f 0%, #92400e 100%);
    color: #fef3c7;
  }
}

/* ============================================================
   Prereq rows
   ============================================================ */
.prereq {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface-alt);
  border: 1px solid transparent;
  margin-bottom: 6px;
  color: inherit;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.prereq:active { transform: scale(.99); }
.prereq:hover { border-color: var(--border-strong); }
.prereq .strength {
  flex: 0 0 auto;
  font-size: 10.5px; padding: 3px 8px; border-radius: var(--r-pill);
  font-weight: 700; letter-spacing: .04em;
}
.prereq .strength.hard { background: #fee2e2; color: #b91c1c; }
.prereq .strength.soft { background: #dbeafe; color: #1d4ed8; }
@media (prefers-color-scheme: dark) {
  .prereq .strength.hard { background: #451a1a; color: #fca5a5; }
  .prereq .strength.soft { background: #1e3a5f; color: #93c5fd; }
}
.prereq > span:nth-child(2) { flex: 1; min-width: 0; }
.prereq .name { display: block; font-size: 14px; font-weight: 600; line-height: 1.4; }
.prereq .reason {
  display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.45;
}
.prereq .arrow { color: var(--muted); align-self: center; font-size: 18px; }

/* ============================================================
   Video panel · The star of the topic detail
   ============================================================ */
.video-panel {
  background: linear-gradient(135deg, #fff7ed 0%, #fef3c7 100%);
  border: 1px solid #fde68a;
  padding: 18px;
}
@media (prefers-color-scheme: dark) {
  .video-panel {
    background: linear-gradient(135deg, #1c1a12 0%, #2a2410 100%);
    border-color: #4a3d1a;
  }
}
.video-panel h3::before { background: var(--accent); }

.video-list {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 14px;
}
.video-item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  color: inherit;
}
.video-item:active { transform: scale(.98); }
.video-item:hover { box-shadow: var(--shadow-sm); }
.video-thumb {
  flex: 0 0 52px; height: 52px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, #f43f5e, #f97316);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: #fff;
  box-shadow: 0 4px 14px rgba(244, 63, 94, .28);
  position: relative;
}
.video-thumb::after {
  content: "▶"; position: absolute; font-size: 18px;
}
.video-thumb.icon-emoji::after { content: none; }
.video-info { flex: 1; min-width: 0; }
.video-title {
  font-size: 14.5px; font-weight: 600; line-height: 1.35; margin-bottom: 2px;
  color: var(--text);
}
.video-note { font-size: 12px; color: var(--text-2); margin-bottom: 3px; line-height: 1.45; }
.video-source {
  font-size: 11px; color: var(--brand-strong); font-weight: 600; letter-spacing: .02em;
}

.empty-note { color: var(--text-2); font-size: 13px; margin: 4px 0 12px; }

.search-chips {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px dashed color-mix(in oklab, var(--border) 100%, transparent);
  margin-top: 4px;
  padding-top: 12px;
}
.search-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500;
  transition: all var(--dur) var(--ease);
  color: var(--text);
}
.search-chip:active { transform: scale(.96); background: var(--surface-alt); }

/* ============================================================
   Tab bar
   ============================================================ */
.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  display: grid; grid-template-columns: repeat(3, 1fr);
  max-width: var(--page-max); margin: 0 auto;
  border-radius: 0;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  color: var(--muted); font-size: 20px; font-weight: 500;
  transition: color var(--dur) var(--ease);
  position: relative;
}
.tab span { font-size: 10.5px; letter-spacing: .02em; }
.tab.active { color: var(--brand); }
.tab.active::before {
  content: ""; position: absolute; top: 8px;
  width: 24px; height: 3px; border-radius: 2px;
  background: var(--brand);
}

/* ============================================================
   Utility
   ============================================================ */
.fade-in { animation: fadeIn 320ms var(--ease) both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--surface-alt), var(--surface), var(--surface-alt));
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-md);
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
.sk-card { height: 108px; margin-bottom: 10px; }
