/* Family Study Hub Design System (V2 UI/UX Redesign)
 * - Apple Notes / Notion serene desk aesthetic for Vison (13yo)
 * - Warm cream storybook / Duolingo-inspired tactile aesthetic for Vinnie (8-9yo)
 * - Collapsible sidebar on landscape tablets (>=900px), clean single-row bar on portrait/mobile
 * - Strict 3-tier touch button hierarchy (48px primary, 42px secondary, >=44px icon tap target)
 */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #3b5bdb;
  --accent-soft: #eef2ff;
  --accent-text: #312e81;
  --vison: #3b5bdb;
  --vinnie: #e05263;
  --parent: #0f766e;
  --ok: #15803d;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
}

/* Age-Adaptive Theme: Vison (Serene Deep Slate-Blue Study Desk) */
body.theme-vison {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --accent: #3b5bdb;
  --accent-soft: #eef2ff;
  --accent-text: #1e3a8a;
}

/* Age-Adaptive Theme: Vinnie (Warm Cream Paper & Friendly Coral) */
body.theme-vinnie {
  --bg: #fdfaf5;
  --surface: #ffffff;
  --surface-subtle: #fffbf2;
  --border: #f0e6d8;
  --accent: #e05263;
  --accent-soft: #fff1f2;
  --accent-text: #9f1239;
  --radius: 22px;
}

body.theme-parent {
  --bg: #f4f6f8;
  --accent: #0f766e;
  --accent-soft: #f0fdfa;
  --accent-text: #115e59;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* ==================== TOPBAR (Slim 58px Glass) ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
  cursor: pointer;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--vison), var(--vinnie));
}

.nav-pills {
  display: flex;
  gap: 6px;
  background: var(--surface-subtle);
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.nav-pills .pill {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  transition: all 0.16s ease;
}
.nav-pills .pill.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}
.nav-pills .pill.active[data-route="/kid/Vison"] { color: var(--vison); }
.nav-pills .pill.active[data-route="/kid/Vinnie"] { color: var(--vinnie); }
.nav-pills .pill-parent.active { color: var(--parent); }

/* ==================== CONTAINER & TABLET WORKSPACE ==================== */
.container {
  max-width: 1260px;
  margin: 0 auto;
  padding: 20px 18px 72px;
}

/* Landscape Tablet Workspace: Collapsible Left Sidebar + Focus Main Area */
.workspace-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.workspace-shell.sidebar-collapsed {
  grid-template-columns: 1fr;
}
.workspace-shell.sidebar-collapsed .workspace-sidebar {
  display: none;
}

.workspace-sidebar {
  position: sticky;
  top: 76px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.sidebar-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 10px 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.14s ease, color 0.14s ease;
}
.sidebar-item:hover {
  background: var(--surface-subtle);
  color: var(--text);
}
.sidebar-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.sidebar-subitem {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px 8px 24px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  min-height: 40px;
}
.sidebar-subitem:hover { background: var(--surface-subtle); color: var(--text); }
.sidebar-subitem.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }

.workspace-main {
  min-width: 0;
}

/* Split-Pane for Wrong-Question Review & History Causal Timeline (Landscape Tablet) */
.split-pane {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

/* Focused Centered Single Card for KET Vocab & Speaking */
.focus-center {
  max-width: 760px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .workspace-shell {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .workspace-sidebar {
    position: static;
    max-height: none;
    padding: 10px 12px;
  }
  .split-pane {
    grid-template-columns: 1fr;
  }
  .topbar {
    padding: 0 12px;
  }
}

/* ==================== TYPOGRAPHY & CARDS ==================== */
h1, h2 {
  font-size: 22px;
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin: 0 0 8px;
}
h3 {
  font-size: 18px;
  line-height: 1.4;
  font-weight: 700;
  margin: 0 0 8px;
}
h4 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 6px;
}
.muted {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.hero-card {
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.hero-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

/* ==================== 3-TIER ERGONOMIC BUTTONS ==================== */
/* Tier 1: Primary Action (48px, single focus) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 20px;
  font-size: 15.5px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(59, 91, 219, 0.18);
  transition: transform 0.1s ease, opacity 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-vinnie { background: var(--vinnie); box-shadow: 0 2px 6px rgba(224, 82, 99, 0.22); }
.btn-parent { background: var(--parent); box-shadow: 0 2px 6px rgba(15, 118, 110, 0.2); }

/* Tier 2: Secondary Action (42px, clean outline) */
.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border-strong);
  box-shadow: none;
  min-height: 42px;
  padding: 0 15px;
  font-size: 14.5px;
}
.btn-outline:hover { background: var(--surface-subtle); }

.btn-sm {
  padding: 0 14px;
  font-size: 14px;
  min-height: 42px;
}

/* Tier 3: Tool / Icon Tap Target (>=44x44px ergonomic) */
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.12s ease;
}
.tool-btn:active { transform: scale(0.96); }
.tool-btn.active { outline: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent-text); }

/* Clean Segmented Pills (used sparingly inside content cards) */
.pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  padding: 0 15px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  transition: all 0.14s ease;
}
.pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ==================== BADGES & INPUTS ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-due { background: var(--danger-soft); color: var(--danger); }

.input, textarea, select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  min-height: 46px;
}
.input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.65; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 16px; }

/* ==================== STEPPER & CONTENT BOXES ==================== */
.stepper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0 18px;
}
.step-box {
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-subtle);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  transition: all 0.14s ease;
}
.step-box.current {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.step-box.done {
  border-color: #86efac;
  background: var(--ok-soft);
  color: var(--ok);
}

.md-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  line-height: 1.75;
  font-size: 15.5px;
}
.md-box p { margin: 6px 0; }

.due-banner {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 16px;
}

/* ==================== CANVAS & CHAT ==================== */
.canvas-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #0f172a;
}
.canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.canvas-stage {
  position: relative;
  width: 100%;
  overflow: auto;
  background: #1e293b;
  display: flex;
  justify-content: center;
  padding: 10px;
}
canvas.draw-canvas {
  background: #fff;
  max-width: 100%;
  height: auto;
  touch-action: none;
  border-radius: 8px;
}

.chat-box, .voice-chat-log {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: var(--surface-subtle);
}
.chat-msg {
  margin: 8px 0;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.65;
}
.chat-kid { background: var(--accent-soft); color: var(--accent-text); margin-left: 14%; }
.chat-tutor { background: var(--surface); border: 1px solid var(--border); margin-right: 10%; }

.voice-card {
  background: var(--surface);
  border: 1.5px solid #c7d2fe;
}
.voice-card-vinnie {
  background: #fffbf7;
  border: 1.5px solid #fecdd3;
}
.btn-recording {
  background: #dc2626 !important;
  color: #fff !important;
  animation: pulseRec 1.1s infinite;
}
@keyframes pulseRec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.42); }
  50% { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
}

/* ==================== KET & BRIDGE UP ==================== */
.ket-mode-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.ket-hero {
  background: linear-gradient(135deg, #fff5f5 0%, #fffbeb 60%, #f0f9ff 100%);
  border: 1px solid #f0e6d8;
}
.ket-star-pill {
  background: #fef9c3;
  color: #92400e;
  border: 1px solid #fde68a;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14.5px;
}
.ket-subnav { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.ket-part-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}
.ket-part-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}
.ket-option-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  margin-top: 10px;
  border-radius: 14px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-size: 15.5px;
  min-height: 48px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.ket-option-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.ket-option-btn.selected { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.ket-option-btn.correct { border-color: #16a34a; background: #dcfce7; font-weight: 700; }
.ket-option-btn.wrong { border-color: #dc2626; background: #fee2e2; }

.ket-vocab-card {
  background: var(--surface);
  border: 1.5px solid #f0e6d8;
  border-radius: var(--radius);
  padding: 24px;
}
.ket-word-big { font-size: 32px; font-weight: 800; color: var(--text); letter-spacing: 0.4px; }
.ket-badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.ket-badge-chip.locked { opacity: 0.42; filter: grayscale(1); }
.ket-scribble-input { min-height: 50px; font-size: 20px; font-weight: 600; letter-spacing: 0.8px; }
.ket-pad-wrap { margin-top: 12px; border: 1.5px dashed #93c5fd; border-radius: 14px; background: #fff; padding: 12px; }
.ket-pad-canvas {
  width: 100%;
  height: 156px;
  display: block;
  touch-action: none;
  border-radius: 10px;
  background:
    linear-gradient(to bottom,
      transparent 24%, #e2e8f0 24.5%, transparent 25.5%,
      transparent 49%, #cbd5e1 49.5%, transparent 50.5%,
      transparent 74%, #fca5a5 74.5%, transparent 75.5%,
      transparent 94%, #e2e8f0 94.5%, transparent 95.5%);
}
.ket-paper-img { width: 100%; max-width: 780px; display: block; margin: 10px auto; border-radius: 12px; border: 1px solid var(--border); }
.ket-sheet-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.ket-mini-opt {
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.ket-mini-opt.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.ket-mini-opt.correct { background: #dcfce7; border-color: #16a34a; color: #15803d; }
.ket-mini-opt.wrong { background: #fee2e2; border-color: #dc2626; color: #b91c1c; }
.ket-tier-badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: #fef3c7; color: #92400e; }

.bu-token-zone {
  min-height: 58px;
  padding: 12px;
  border-radius: 14px;
  border: 2px dashed #93c5fd;
  background: var(--surface-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.bu-token {
  display: inline-flex;
  align-items: center;
  padding: 10px 15px;
  border-radius: 12px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  min-height: 44px;
  cursor: grab;
  user-select: none;
  box-shadow: var(--shadow-sm);
}
.bu-token.in-slot { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.bu-phonics { display: inline-block; padding: 3px 10px; border-radius: 8px; background: #fef3c7; color: #92400e; font-weight: 700; font-size: 14px; }
.ket-native-paper { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; font-size: 16px; line-height: 1.8; white-space: pre-wrap; }

/* ==================== HISTORY V2 ==================== */
.hist-hero {
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 60%, #fffbeb 100%);
  border: 1px solid #c7d2fe;
}
.hist-branch {
  border-left: 4px solid var(--accent);
  background: var(--surface);
  border-radius: 0 14px 14px 0;
  padding: 14px 16px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.hist-branch-title { font-weight: 800; font-size: 15.5px; color: var(--accent-text); margin-bottom: 6px; }
.hist-cloze {
  display: inline-block;
  padding: 2px 9px;
  margin: 2px;
  border-radius: 8px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-text);
  cursor: pointer;
}
.hist-cloze.masked { background: #1e293b; color: transparent; user-select: none; }
.hist-table { width: 100%; border-collapse: collapse; font-size: 14.5px; margin-top: 10px; }
.hist-table th, .hist-table td { border: 1px solid var(--border); padding: 10px 12px; text-align: left; vertical-align: top; }
.hist-table th { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.causal-arrow {
  margin: 6px 0 6px 18px;
  padding: 8px 14px;
  border-left: 3px dashed #6366f1;
  color: #4338ca;
  font-size: 13.5px;
  background: #f5f3ff;
  border-radius: 0 10px 10px 0;
}
.pitfall-box {
  background: var(--danger-soft);
  border: 1.5px solid #fca5a5;
  color: var(--danger);
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 10px;
  font-size: 14.5px;
}

/* ==================== TOAST & MISC ==================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  z-index: 99;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}
.hidden { display: none !important; }
.preview-thumb { max-width: 100%; max-height: 260px; border-radius: 12px; border: 1px solid var(--border); }
