:root {
  /* USER CUSTOM LUXURY EMERALD & CARBON PALETTE */
  --bg: #0B0D0C;               /* Fond principal: Noir carbone */
  --panel: #121614;            /* Fond secondaire: Noir graphite */
  --panel2: #1A1E1C;           /* Surface cabine: Anthracite */
  --emerald-deep: #00A878;     /* Accent principal: Émeraude profond */
  --emerald-neon: #00D99A;     /* Accent lumineux: Émeraude néon */
  --sage-dark: #507C6D;        /* Accent subtil: Vert sauge sombre */
  --text: #F1F3F1;             /* Texte principal: Blanc cassé */
  --muted: #A7AFAB;            /* Texte secondaire: Gris argent */
  --border: #303733;           /* Bordures: Gris graphite */
  --champagne: #C9B27C;        /* Luxe: Champagne */

  --shadow: 0 20px 60px rgba(0, 0, 0, 0.75);

  /* Mapping tokens for system compatibility */
  --orange: #00D99A;
  --pink: #00A878;
  --yellow: #C9B27C;
  --cyan: #00D99A;
  --red: #e64553;
  --green: #00D99A;
  --purple: #507C6D;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
}

body {
  background: radial-gradient(circle at 85% 0%, rgba(0, 217, 154, 0.12), transparent 40%),
              radial-gradient(circle at 0% 45%, rgba(0, 168, 120, 0.10), transparent 40%),
              var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

button, textarea, select, input { font: inherit; }
button { cursor: pointer; color: inherit; touch-action: manipulation; }

.app-shell {
  min-height: 100vh;
  max-width: 1050px;
  margin: auto;
  padding-bottom: calc(85px + env(safe-area-inset-bottom, 0px));
}

/* TOPBAR — FIXED FOR IPHONE NOTCH & DYNAMIC ISLAND */
.topbar {
  min-height: calc(64px + env(safe-area-inset-top, 0px));
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  padding-bottom: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(11, 13, 12, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--emerald-deep), var(--emerald-neon));
  box-shadow: 0 0 22px rgba(0, 217, 154, 0.4);
  font-weight: 900;
  font-size: 16px;
  color: #0B0D0C;
  flex-shrink: 0;
}

.brand b { display: block; letter-spacing: 0.06em; font-size: 14px; color: var(--text); line-height: 1.2; }
.brand small { display: block; color: var(--muted); font-size: 10.5px; margin-top: 1px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.neon-pill-btn {
  border: 1px solid rgba(201, 178, 124, 0.35);
  background: rgba(201, 178, 124, 0.1);
  color: var(--champagne);
  padding: 6px 10px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 11.5px;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.badge {
  background: var(--emerald-neon);
  color: #0B0D0C;
  font-size: 9.5px;
  padding: 2px 6px;
  border-radius: 99px;
  font-weight: 900;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--panel2);
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: 14px;
}

.ghost {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--champagne);
  font-size: 12px;
}

/* SCREENS */
.screen { display: none; padding: 24px 16px; }
.screen.active { display: block; }

.hero { padding: 18px 0 12px; }
.eyebrow, .label { font-size: 10.5px; letter-spacing: 0.14em; color: var(--champagne); font-weight: 800; }
.hero h1 { font-size: clamp(32px, 6.5vw, 64px); line-height: 1.02; margin: 10px 0; color: var(--text); }
.hero h1 span { color: var(--emerald-neon); text-shadow: 0 0 35px rgba(0, 217, 154, 0.45); }
.hero p { color: var(--muted); font-size: 15px; margin-top: 6px; }

/* CARDS */
.brain-card, .action-card, .stats, .word-card, .blurting-card, .hunt-card, .srs-card, .story-card, .analytics-grid, .mastery-section, .weak-section, .scenario-card, .dialogue-bubble {
  background: var(--panel2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 20px;
}

.brain-card {
  padding: 18px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
}
.brain-card h2 { margin: 4px 0 0; font-size: 20px; }
.modes { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.modes button {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.modes button.selected { border-color: var(--emerald-neon); color: var(--text); box-shadow: 0 0 18px rgba(0, 217, 154, 0.25); }

/* MAIN ACTIONS */
.main-actions { margin: 20px 0; }
.action-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 16px;
  margin-bottom: 10px;
  transition: transform 0.2s, border-color 0.2s;
  background: var(--panel2);
}
.action-card:hover { transform: translateY(-2px); border-color: var(--emerald-neon); }
.action-card.primary {
  background: linear-gradient(100deg, rgba(0, 168, 120, 0.25), rgba(0, 217, 154, 0.12));
  border-color: rgba(0, 217, 154, 0.45);
}
.action-icon { font-size: 24px; flex-shrink: 0; }
.action-card b { display: block; font-size: 14.5px; color: var(--text); }
.action-card small { display: block; color: var(--muted); margin-top: 2px; font-size: 11.5px; }

.grid-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 18px;
  text-align: center;
  background: var(--panel2);
}
.stats strong { display: block; font-size: 24px; color: var(--champagne); }
.stats small { color: var(--muted); font-size: 9.5px; letter-spacing: 0.12em; margin-top: 3px; display: block; }

/* SECTION HEAD */
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.section-head h2 { margin: 2px 0; font-size: 24px; }
.back { background: none; border: 0; font-size: 22px; padding: 0 4px; color: var(--text); }
.head-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.neon-mini {
  border: 1px solid rgba(0, 217, 154, 0.4);
  background: rgba(0, 217, 154, 0.12);
  color: var(--emerald-neon);
  font-weight: 800;
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 11.5px;
}

.stage-pill {
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.stage-1 { background: rgba(80, 124, 109, 0.2); color: var(--sage-dark); border: 1px solid rgba(80, 124, 109, 0.4); }
.stage-2 { background: rgba(201, 178, 124, 0.2); color: var(--champagne); border: 1px solid rgba(201, 178, 124, 0.4); }
.stage-3 { background: rgba(0, 168, 120, 0.2); color: var(--emerald-deep); border: 1px solid rgba(0, 168, 120, 0.4); }
.stage-4 { background: rgba(0, 217, 154, 0.2); color: var(--emerald-neon); border: 1px solid rgba(0, 217, 154, 0.4); }

/* WORD UNIVERSE */
.word-card {
  padding: 24px 20px;
  position: relative;
  overflow: hidden;
  background: var(--panel2);
}
.word-card:after {
  content: "";
  position: absolute;
  width: 160px;
  height: 160px;
  right: -50px;
  top: -50px;
  border-radius: 50%;
  background: var(--emerald-neon);
  filter: blur(60px);
  opacity: 0.18;
}
.word-card h1 { font-size: 44px; margin: 6px 0 2px; color: var(--text); word-break: break-word; }
.meaning { font-size: 19px; color: var(--emerald-neon); font-weight: 700; }
.phonetic { color: var(--sage-dark); margin-top: 6px; font-size: 14px; }
.hook {
  margin-top: 18px;
  padding: 12px;
  border-left: 3px solid var(--emerald-neon);
  background: rgba(0, 217, 154, 0.08);
  border-radius: 10px;
  line-height: 1.5;
  font-size: 14px;
}

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 14px 0 10px; padding-bottom: 4px; }
.tab {
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.tab.active { background: rgba(0, 217, 154, 0.16); border-color: rgba(0, 217, 154, 0.45); color: var(--text); }

#tabContent {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  line-height: 1.6;
}

.pill {
  display: inline-block;
  padding: 5px 9px;
  margin: 3px;
  background: rgba(0, 217, 154, 0.08);
  border: 1px solid rgba(0, 217, 154, 0.2);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text);
}

.example { font-size: 16.5px; margin: 12px 0; font-style: italic; color: var(--text); }
.translation { color: var(--muted); font-size: 14px; }

/* SRS GRADE BAR */
.srs-grade-bar {
  margin-top: 18px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.grade-btns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.grade-btn {
  padding: 9px 4px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 11px;
  border: 1px solid var(--border);
}
.g1 { background: rgba(230, 69, 83, 0.15); color: var(--red); border-color: rgba(230, 69, 83, 0.3); }
.g2 { background: rgba(80, 124, 109, 0.2); color: var(--sage-dark); border-color: rgba(80, 124, 109, 0.4); }
.g3 { background: rgba(201, 178, 124, 0.2); color: var(--champagne); border-color: rgba(201, 178, 124, 0.4); }
.g4 { background: rgba(0, 217, 154, 0.2); color: var(--emerald-neon); border-color: rgba(0, 217, 154, 0.4); }

/* MIND MAP SCREEN */
.canvas-container {
  position: relative;
  width: 100%;
  height: 520px;
  background: #0B0D0C;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
}
#mindmapCanvas { width: 100%; height: 100%; display: block; }

.mindmap-info-box {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  padding: 10px 14px;
  background: rgba(18, 22, 20, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 12px;
  pointer-events: none;
}

.neon-select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 12.5px;
  max-width: 170px;
}

/* SRS PRACTICE DECK */
.srs-card {
  max-width: 680px;
  margin: 16px auto;
  padding: 28px 18px;
  text-align: center;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* BLURTING & HUNT */
.blurting-card, .hunt-card, .story-card {
  max-width: 720px;
  margin: 16px auto;
  padding: 22px 18px;
}
.timer {
  font-size: 50px;
  text-align: center;
  color: var(--emerald-neon);
  font-weight: 900;
  text-shadow: 0 0 28px rgba(0, 217, 154, 0.4);
  margin: 8px 0;
}
.blurting-card textarea, #importInput, .form-input, .form-textarea {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  font-size: 14px;
}
.blurting-card textarea, #importInput { min-height: 160px; resize: vertical; line-height: 1.5; }
.form-input { height: 44px; }
.form-textarea { min-height: 80px; resize: vertical; }

.row { display: flex; gap: 8px; margin-top: 10px; }

.primary-btn {
  border: 0;
  background: linear-gradient(135deg, var(--emerald-deep), var(--emerald-neon));
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 900;
  color: #0B0D0C;
  font-size: 14px;
}
.secondary-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 11px 16px;
  border-radius: 12px;
  font-weight: 700;
  color: var(--text);
  font-size: 14px;
}

.result, .feedback {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(0, 217, 154, 0.08);
  border: 1px solid rgba(0, 217, 154, 0.25);
  line-height: 1.5;
  font-size: 14px;
}

.hunt-orb {
  width: 75px;
  height: 75px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 900;
  background: radial-gradient(circle, var(--emerald-neon), var(--emerald-deep));
  color: #0B0D0C;
  box-shadow: 0 0 40px rgba(0, 217, 154, 0.45);
}
.hunt-card { text-align: center; }
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}
.choices button {
  padding: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
}
.choices button:hover { border-color: var(--emerald-neon); }

/* STORY GENERATOR */
.story-pickers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.story-output {
  margin-top: 18px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  line-height: 1.6;
}

/* IMMERSION SCREEN */
.immersion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.scenario-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
  background: var(--panel2);
}
.scenario-card:hover { transform: translateY(-2px); border-color: var(--emerald-neon); }
.scenario-icon { font-size: 32px; }
.scenario-card h3 { margin: 0; font-size: 17px; color: var(--text); }
.scenario-card p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.4; }

.dialogue-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 16px;
}
.dialogue-bubble {
  padding: 16px;
  position: relative;
  background: var(--panel2);
}
.dialogue-bubble.local {
  border-left: 4px solid var(--sage-dark);
}
.dialogue-bubble.user {
  border-left: 4px solid var(--emerald-neon);
  background: linear-gradient(90deg, rgba(0, 217, 154, 0.06), transparent);
}
.dialogue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.dialogue-speaker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--champagne);
}
.dialogue-text {
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  font-weight: 600;
}
.dialogue-translation {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  font-size: 13.5px;
  color: var(--muted);
}
.dialogue-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ANALYTICS */
.analytics-wrapper { display: flex; flex-direction: column; gap: 16px; }
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  padding: 16px;
}
.stat-box { text-align: center; }
.stat-box .value { font-size: 28px; font-weight: 900; margin: 3px 0; color: var(--text); }
.stat-box small { color: var(--muted); font-size: 10.5px; }

.mastery-section, .weak-section { padding: 18px; }
.mastery-section h3, .weak-section h3 { margin-top: 0; font-size: 17px; }

.mastery-bar-container {
  display: flex;
  height: 16px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  margin: 14px 0;
}
.mastery-bar { height: 100%; transition: width 0.3s; }
.mastery-bar.stage-1 { background: var(--sage-dark); }
.mastery-bar.stage-2 { background: var(--champagne); }
.mastery-bar.stage-3 { background: var(--emerald-deep); }
.mastery-bar.stage-4 { background: var(--emerald-neon); }

.mastery-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11px;
  font-weight: 700;
}

.weak-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.weak-pill {
  padding: 6px 10px;
  background: rgba(230, 69, 83, 0.12);
  border: 1px solid rgba(230, 69, 83, 0.3);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text);
}

/* MODALS */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.84);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }

/* FORM GRID */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-group.full { grid-column: 1 / -1; }
.form-group label {
  font-size: 11px;
  font-weight: 800;
  color: var(--champagne);
  letter-spacing: 0.08em;
}

/* BOTTOM NAV — 7 TABS PERFECT FIT FOR IPHONE & ANDROID */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 1px;
  padding: 6px max(4px, env(safe-area-inset-left, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-right, 0px));
  background: rgba(11, 13, 12, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  box-sizing: border-box;
}

.nav {
  flex: 1 1 0;
  min-width: 0;
  width: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 4px 1px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.nav span {
  display: block;
  font-size: 8.5px;
  font-weight: 600;
  margin-top: 2px;
  white-space: nowrap;
  letter-spacing: -0.3px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: clip;
}

.nav.active {
  color: var(--emerald-neon);
  background: rgba(0, 217, 154, 0.15);
}

.hidden { display: none !important; }

/* RESPONSIVE BREAKPOINTS */
@media (max-width: 650px) {
  .brain-card { display: block; }
  .modes { justify-content: flex-start; margin-top: 12px; }
  .screen { padding: 18px 12px; }
  .word-card h1 { font-size: 38px; }
  .choices { grid-template-columns: 1fr; }
  .grade-btns { grid-template-columns: 1fr 1fr; }
  .canvas-container { height: 400px; }
  .form-grid { grid-template-columns: 1fr; }
}
