@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700&family=Inter:wght@400;500;600&display=swap');

:root {
  /* Brand colors */
  --color-primary: #004e9f;
  --color-primary-container: #d6e4ff;
  --color-on-primary: #ffffff;
  --color-secondary: #5f5e5e;
  --color-tertiary: #a40015;
  --color-on-surface: #191c1e;
  --color-on-surface-variant: #72777f;

  /* Surface layers (tonal depth — no 1px borders) */
  --color-surface: #f8f9fa;
  --color-surface-low: #f0f2f4;
  --color-surface-lowest: #ffffff;

  /* Ghost border (accessibility fallback only) */
  --color-outline-variant: rgba(116, 119, 127, 0.15);

  /* Typography */
  --font-display: 'Plus Jakarta Sans', sans-serif;
  --font-body: 'Inter', sans-serif;
  --text-display: 3.5rem;
  --text-headline: 1.75rem;
  --text-title: 1.375rem;
  --text-body: 0.875rem;
  --text-label: 0.75rem;

  /* Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;

  /* Shadow (ambient only — no hard shadows) */
  --shadow-ambient: 0 12px 32px rgba(25, 28, 30, 0.06);

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.8);
  --glass-blur: blur(24px);

  /* Layout */
  --nav-width: 18%;
  --canvas-width: 52%;
  --sidebar-width: 30%;
}

/* Global reset */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--color-surface);
  color: var(--color-on-surface);
  font-family: var(--font-body);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* No pure black anywhere */
* {
  color: inherit;
}

button, input, select, textarea, [class] {
  border-radius: var(--radius-sm);
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: none;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

input:not([type="radio"]):not([type="checkbox"]), select, textarea {
  font-family: var(--font-body);
  color: var(--color-on-surface);
  border-radius: var(--radius-md);
  border: none;
  background: var(--color-surface-low);
  padding: 10px 14px;
  font-size: var(--text-body);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  box-shadow: 0 0 0 2px rgba(0, 78, 159, 0.2);
}

        /* ===== TRIPLE-LAYER WORD UNIT ===== */
.triple-layer-word {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0 6px;
  vertical-align: top;
  cursor: pointer;
  padding: 4px 2px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.triple-layer-word:hover {
  background: var(--color-surface-low);
}

/* Layer 1 — Pinyin hint (exactly 1/3 of Hanzi size) */
.tlw-pinyin {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--color-secondary);
  min-height: 16px;
  line-height: 1;
  text-align: center;
}

/* Layer 2 — Hanzi anchor */
.tlw-hanzi {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.1;
  color: var(--color-on-surface);
  font-weight: 600;
}

/* Layer 3 — Translation (revealed on hover/tap) */
.tlw-trans {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--color-secondary);
  min-height: 16px;
  line-height: 1;
  text-align: center;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.triple-layer-word:hover .tlw-trans,
.triple-layer-word.revealed .tlw-trans {
  opacity: 1;
}

/* Unknown word: subtle primary underline */
.unknown-word .tlw-hanzi {
  border-bottom: 2px solid rgba(0, 78, 159, 0.3);
}

/* Known word: plain */
.known-word .tlw-hanzi {
  border-bottom: none;
}

        /* MoKe Native Hover Dictionary (Zhongwen Style) */
        .moke-tooltip {
            position: absolute;
            background-color: #ffffe1;
            /* Classic Zhongwen yellow */
            border: 1px solid #999;
            box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.2);
            padding: 8px 12px;
            border-radius: 4px;
            font-family: Arial, sans-serif;
            z-index: 10000;
            pointer-events: none;
            /* Let mouse naturally move over text */
            max-width: 350px;
            display: none;
            /* Hidden by default */
        }

        .moke-tooltip-pinyin {
            color: #d2691e;
            /* Classic Zhongwen orange-brown */
            font-size: 1.1em;
            margin-bottom: 5px;
        }

        .moke-tooltip-pinyin strong {
            color: #333;
            /* Darker grey for Hanzi in header */
            margin-right: 8px;
            font-size: 1.25em;
        }

        .moke-tooltip-trans {
            color: #000;
            font-size: 0.95em;
            line-height: 1.4;
        }

/* ===== OVERLAYS (auth, invite) ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.overlay-card {
  background: var(--color-surface-lowest);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-ambient);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.overlay-title {
  font-family: var(--font-display);
  font-size: var(--text-headline);
  font-weight: 700;
  color: var(--color-primary);
  margin: 0;
  text-align: center;
}

.overlay-subtitle {
  font-size: var(--text-body);
  color: var(--color-secondary);
  margin: 0;
  text-align: center;
}

.overlay-row {
  display: flex;
  gap: 8px;
}

.overlay-input {
  flex: 1;
  background: var(--color-surface-low);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

.overlay-divider {
  text-align: center;
  color: var(--color-secondary);
  font-size: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: relative;
}

.overlay-message {
  font-size: var(--text-label);
  color: var(--color-tertiary);
  min-height: 18px;
  text-align: center;
}

.overlay-message--success {
  color: #2e7d32;
}

/* ===== APP LAYOUT ===== */
.app-layout {
  display: grid;
  grid-template-columns: var(--nav-width) var(--canvas-width) var(--sidebar-width);
  min-height: 100vh;
}

/* ===== LEFT NAV ===== */
.nav-col {
  background: var(--color-surface-lowest);
  box-shadow: var(--shadow-ambient);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: background 0.2s, backdrop-filter 0.2s;
}

.nav-col.scrolled {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.nav-brand {
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 700;
  color: var(--color-primary);
  padding: 0 8px 20px;
}

.btn-start {
  width: 100%;
  padding: 14px;
  background: var(--color-on-surface);
  color: var(--color-surface-lowest);
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 600;
  border: none;
  cursor: pointer;
  min-height: 48px;
  margin-bottom: 8px;
  transition: opacity 0.15s;
}

.btn-start:hover {
  opacity: 0.9;
}

.nav-divider {
  height: 1px;
  background: var(--color-surface-low);
  margin: 12px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  color: var(--color-secondary);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--color-surface-low);
  color: var(--color-on-surface);
}

.nav-item.active {
  background: var(--color-surface-low);
  color: var(--color-primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

.nav-spacer {
  flex: 1;
}

.nav-logout {
  margin-top: 4px;
  padding: 8px 12px;
  font-size: var(--text-label);
  color: var(--color-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
}

.nav-logout:hover {
  color: var(--color-tertiary);
}

/* ===== BUTTONS (global) ===== */
.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-container));
  color: var(--color-on-primary);
  border-radius: var(--radius-full);
  padding: 12px 24px;
  font-weight: 600;
  min-height: 48px;
  border: none;
  cursor: pointer;
}

.btn-secondary {
  background: var(--color-surface-low);
  color: var(--color-on-surface);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: var(--text-body);
  border: none;
  cursor: pointer;
}

.btn-secondary:hover {
  background: #e2e5e8;
}

.btn-tertiary {
  background: transparent;
  color: var(--color-primary);
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  font-size: var(--text-body);
}

.btn-sm { padding: 8px 14px; min-height: 40px; }
.btn-full { width: 100%; }

/* ===== SETTINGS DRAWER ===== */
.settings-drawer {
  position: fixed;
  top: 0;
  left: var(--nav-width);
  width: 280px;
  height: 100vh;
  background: var(--color-surface-lowest);
  box-shadow: var(--shadow-ambient);
  padding: 24px;
  z-index: 500;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--text-body);
  color: var(--color-secondary);
}

.settings-row select {
  background: var(--color-surface-low);
  color: var(--color-on-surface);
}

.settings-row--check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

/* ===== CANVAS COLUMN ===== */
.canvas-col {
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  overflow-y: auto;
}

/* ===== SESSION SETUP ===== */
.session-setup {
  padding: 40px 40px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.setup-heading {
  font-family: var(--font-display);
  font-size: var(--text-headline);
  font-weight: 600;
  color: var(--color-on-surface);
  margin: 0;
}

.setup-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setup-label {
  font-size: var(--text-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-secondary);
}

.setup-label-note {
  font-weight: 400;
  opacity: 0.7;
  text-transform: none;
  letter-spacing: 0;
}

/* Pill group (radio options in a row) */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-group--col {
  flex-direction: column;
}

.pill-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--color-surface-lowest);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-ambient);
  transition: background 0.15s, box-shadow 0.15s;
  font-size: var(--text-body);
  color: var(--color-secondary);
}

.pill-option input[type="radio"],
.pill-option input[type="checkbox"] {
  display: none;
}

.pill-option:has(input:checked),
.pill-option.active {
  background: var(--color-primary-container);
  color: var(--color-primary);
  font-weight: 600;
}

.pill-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pill-body strong {
  font-weight: 600;
  color: var(--color-on-surface);
}

.pill-body span {
  font-size: var(--text-label);
  color: var(--color-secondary);
}

.pill-option:has(input:checked) .pill-body strong {
  color: var(--color-primary);
}

/* Chip group (checkbox tools) */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-option {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface-lowest);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(25, 28, 30, 0.04);
  font-size: var(--text-body);
  color: var(--color-secondary);
  transition: background 0.15s, color 0.15s;
}

.chip-option input {
  display: none;
}

.chip-option:has(input:checked) {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

/* ===== SESSION CANVAS (active) ===== */
.session-canvas {
  flex: 1;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-bottom: 120px; /* space for sticky mic dock */
}

/* End Session button — secondary, sits at bottom of canvas flow */
.btn-end-session {
  align-self: flex-start;
  background: none;
  border: 1px solid rgba(116, 119, 127, 0.3);
  color: var(--color-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-end-session:hover {
  background: var(--color-surface-low);
  color: var(--color-on-surface);
}

/* AI response — editorial document flow */
.canvas-response {
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.6;
  color: var(--color-on-surface);
}

/* User transcript */
.canvas-transcript {
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-style: italic;
  color: var(--color-secondary);
  min-height: 20px;
}

.canvas-transcript:not(:empty)::before {
  content: "You: ";
  font-style: normal;
  font-weight: 600;
}

/* Status indicator */
.canvas-status {
  font-family: var(--font-body);
  font-size: var(--text-label);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-primary);
  min-height: 16px;
}

/* Shadow Boxing banner */
.shadow-boxing-banner {
  background: var(--color-surface-low);
  border-radius: var(--radius-xl);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shadow-boxing-banner h3 {
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 600;
  color: var(--color-primary);
  margin: 0;
}

.shadow-boxing-scene {
  font-size: var(--text-body);
  color: var(--color-on-surface);
  line-height: 1.6;
}

.shadow-boxing-prompt {
  font-size: var(--text-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-secondary);
  margin-top: 4px;
}

/* ===== MIC DOCK (sticky bottom of canvas) ===== */
.mic-dock {
  position: sticky;
  bottom: 0;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  padding: 16px 40px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 -4px 24px rgba(25, 28, 30, 0.06);
}

.mic-btn {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--color-surface-low);
  color: var(--color-primary);
  border: none;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  box-shadow: var(--shadow-ambient);
}

.mic-btn:hover:not(:disabled) {
  background: var(--color-primary-container);
}

.mic-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.mic-btn.recording {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-container));
  color: var(--color-on-primary);
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@media (prefers-reduced-motion: reduce) {
  .mic-btn.recording {
    animation: none;
  }
}

.mic-btn--stop {
  background: var(--color-tertiary);
  color: white;
}

.mic-text-input {
  flex: 1;
  background: var(--color-surface-low);
  border-radius: var(--radius-full);
  padding: 12px 20px;
  font-size: var(--text-body);
  border: none;
}

.mic-text-input:disabled {
  opacity: 0.5;
}

/* ===== IMITATION PANEL ===== */
.imitation-panel {
  background: var(--color-surface-lowest);
  border-radius: var(--radius-xl);
  padding: 16px 20px;
  box-shadow: var(--shadow-ambient);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.imitation-text {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--color-on-surface);
  line-height: 1.5;
}

.imitation-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.imitation-listening {
  font-size: var(--text-label);
  color: var(--color-secondary);
  opacity: 0.8;
}

/* ===== RIGHT SIDEBAR ===== */
.sidebar-col {
  background: var(--color-surface-lowest);
  display: flex;
  flex-direction: column;
  padding: 32px 20px;
  gap: 32px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-heading {
  font-family: var(--font-body);
  font-size: var(--text-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-secondary);
  margin: 0;
}

.sidebar-empty {
  font-size: var(--text-body);
  color: var(--color-secondary);
  opacity: 0.6;
  font-style: italic;
}

/* Words of the Day list */
.wod-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Each word card in the sidebar */
.wod-card {
  background: var(--color-surface-low);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.wod-card:hover {
  background: #e8edf2;
}

.wod-word-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  flex: 1;
}

.wod-pinyin {
  font-size: 10px;
  color: var(--color-secondary);
  line-height: 1;
}

.wod-hanzi {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--color-on-surface);
  font-weight: 600;
  line-height: 1.1;
}

.wod-translation {
  font-size: var(--text-label);
  color: var(--color-secondary);
}

/* Progress orb */
.wod-orb {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: conic-gradient(var(--color-primary) calc(var(--mastery) * 1%), var(--color-surface-low) 0);
  box-shadow: 0 0 8px rgba(0, 78, 159, 0.1);
  flex-shrink: 0;
}

/* Dictionary panel */
.dict-empty {
  font-size: var(--text-body);
  color: var(--color-secondary);
  opacity: 0.6;
  font-style: italic;
}

.dict-entry {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dict-hanzi {
  font-family: var(--font-display);
  font-size: 36px;
  color: var(--color-on-surface);
  font-weight: 700;
  line-height: 1;
}

.dict-pinyin {
  font-size: var(--text-body);
  color: var(--color-secondary);
}

.dict-pos {
  font-size: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-secondary);
}

.dict-definition {
  font-size: var(--text-body);
  color: var(--color-on-surface);
  line-height: 1.5;
}

.dict-mastery-bar {
  height: 4px;
  background: var(--color-surface-low);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 4px;
}

.dict-mastery-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width 0.3s;
}

/* Hide tab bar on desktop (shown via media query below) */
.tab-bar {
  display: none;
}

/* ===== RESPONSIVE ≤768px ===== */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    padding-bottom: 64px; /* space for bottom tab bar */
  }

  .nav-col {
    display: none; /* replaced by bottom tab bar */
  }

  .sidebar-col {
    display: none; /* replaced by slide-up drawer */
    position: fixed;
    bottom: 64px;
    left: 0;
    right: 0;
    height: 60vh;
    z-index: 300;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 32px rgba(25, 28, 30, 0.12);
  }

  .sidebar-col.open {
    display: flex;
  }

  /* Bottom tab bar */
  .tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    z-index: 400;
    align-items: center;
    justify-content: space-around;
    box-shadow: 0 -2px 16px rgba(25, 28, 30, 0.08);
  }

  .tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--color-secondary);
    font-size: 10px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    min-width: 60px;
    min-height: 48px;
  }

  .tab-btn .tab-icon {
    font-size: 1.3rem;
  }

  .tab-btn.active {
    color: var(--color-primary);
  }

  .session-setup {
    padding: 20px 16px;
  }

  .session-canvas {
    padding: 20px 16px;
    padding-bottom: 100px;
  }

  .mic-dock {
    padding: 12px 16px;
  }
}
