:root {
  --bg: #06100d;
  --panel: #101715;
  --panel2: #16201d;
  --text: #f5f7f6;
  --muted: #aab4b0;
  --neon: #00e6a0;
  --gold: #d8bd78;
  --border: #29332f;
  --coral: #ff5a5f;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.75);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
  background: radial-gradient(circle at 85% 0%, rgba(0, 230, 160, 0.12), transparent 40%),
              radial-gradient(circle at 0% 45%, rgba(216, 189, 120, 0.10), transparent 40%),
              var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

button, select, textarea, input { font: inherit; }
button { cursor: pointer; color: inherit; touch-action: manipulation; }

.app {
  min-height: 100vh;
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}

/* TOPBAR */
header, .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(8, 16, 14, 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;
}

.logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #00b880, var(--neon));
  color: #00140d;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 0 22px rgba(0, 230, 160, 0.4);
  flex-shrink: 0;
}

.brand b {
  font-size: 14px;
  line-height: 1.15;
  letter-spacing: 0.04em;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 10.5px;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.neon-pill-btn {
  border: 1px solid rgba(216, 189, 120, 0.4);
  background: rgba(216, 189, 120, 0.1);
  color: var(--gold);
  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(--neon);
  color: #00140d;
  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(--panel);
  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(--gold);
  font-size: 12px;
}

/* MAIN */
main {
  max-width: 960px;
  margin: auto;
  padding: 24px 16px;
}

.screen { display: none; }
.screen.active { display: block; }

.eyebrow, .top span, .brain small, .panel > span {
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.screen h1 {
  font-size: clamp(34px, 7vw, 68px);
  line-height: 1.02;
  margin: 14px 0 10px;
}
.screen h1 em {
  color: var(--neon);
  font-style: normal;
  text-shadow: 0 0 35px rgba(0, 230, 160, 0.45);
}

.lead {
  font-size: 16px;
  line-height: 1.5;
  color: var(--muted);
  margin-top: 6px;
}

/* BRAIN CARD */
.brain, .panel, .card, .scenario-card, .dialogue-bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  margin: 18px 0;
  box-shadow: var(--shadow);
}

.brain {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 14px;
  align-items: center;
}
.brain > span { font-size: 28px; }
.brain b { display: block; font-size: 20px; margin-top: 2px; }

.moods {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.mood, .tabs button, .grade button, .choices button {
  border: 1px solid var(--border);
  background: #0d1412;
  color: var(--muted);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
}
.mood.active, .tabs .active {
  border-color: var(--neon);
  color: var(--text);
  box-shadow: 0 0 18px rgba(0, 230, 160, 0.22);
}

/* ACTIONS */
.continue {
  width: 100%;
  border: 1px solid rgba(0, 230, 160, 0.4);
  background: linear-gradient(135deg, rgba(0, 184, 128, 0.25), rgba(0, 230, 160, 0.12));
  color: white;
  border-radius: 18px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  margin-bottom: 12px;
}
.continue div { flex: 1; }
.continue b { display: block; font-size: 16px; }
.continue small { display: block; color: var(--muted); margin-top: 2px; font-size: 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.grid button {
  min-height: 90px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 16px;
  padding: 14px;
  font-size: 20px;
}
.grid b { font-size: 14.5px; margin-top: 6px; display: block; }
.grid small { font-size: 11.5px; color: var(--muted); margin-top: 2px; display: block; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 18px;
  text-align: center;
}
.stats div {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
}
.stats b { display: block; font-size: 24px; color: var(--gold); }
.stats small { font-size: 10px; color: var(--muted); letter-spacing: 0.08em; }

/* TOP HEADER */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.top > button {
  background: transparent;
  border: 0;
  color: white;
  font-size: 26px;
  padding: 0 4px;
}
.top h2 { margin: 2px 0; font-size: 24px; }

.head-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.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;
}

.neon-mini {
  border: 1px solid rgba(0, 230, 160, 0.4);
  background: rgba(0, 230, 160, 0.12);
  color: var(--neon);
  font-weight: 800;
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 11.5px;
}

/* WORD CARD */
.card h1 { font-size: 42px; margin: 0 0 4px; word-break: break-word; }
.translation { font-size: 22px; color: var(--neon); font-weight: 700; }
.phonetic { color: var(--gold); margin-top: 6px; font-size: 14px; }

.info { display: grid; gap: 10px; }
.info div {
  background: #0c1311;
  border-radius: 14px;
  padding: 14px;
  line-height: 1.5;
  font-size: 14px;
}
.info b {
  display: block;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 12px;
}
.tabs button { white-space: nowrap; }

.grade > small { color: var(--muted); }
.grade > div {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
}

/* CANVAS MIND MAP */
.canvas-container {
  position: relative;
  width: 100%;
  height: 520px;
  background: #040907;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  margin-top: 12px;
  box-shadow: var(--shadow);
}

#mindmapCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.mindmap-info-box {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  padding: 10px 14px;
  background: rgba(12, 20, 18, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 12px;
  pointer-events: none;
  font-size: 13px;
  line-height: 1.4;
}

/* 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(--panel);
}
.scenario-card:hover { transform: translateY(-2px); border-color: var(--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(--panel);
}
.dialogue-bubble.local {
  border-left: 4px solid var(--border);
}
.dialogue-bubble.user {
  border-left: 4px solid var(--neon);
  background: linear-gradient(90deg, rgba(0, 230, 160, 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(--gold);
}
.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: #507C6D; }
.mastery-bar.stage-2 { background: var(--gold); }
.mastery-bar.stage-3 { background: #00b880; }
.mastery-bar.stage-4 { background: var(--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(255, 90, 95, 0.12);
  border: 1px solid rgba(255, 90, 95, 0.3);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text);
}

/* SRS & BLURT & HUNT */
.big-number { font-size: 64px; color: var(--neon); font-weight: 900; }
.panel.center { text-align: center; }
.panel textarea, .form-input, .form-textarea {
  width: 100%;
  background: #08100e;
  color: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  font-size: 14px;
}
.panel textarea { min-height: 160px; margin: 14px 0; resize: vertical; line-height: 1.5; }
.form-input { height: 44px; }
.form-textarea { min-height: 80px; resize: vertical; }

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}
.choices button {
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
}

/* MODAL */
.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(--panel);
  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(--gold);
  letter-spacing: 0.08em;
}

/* BOTTOM NAV — 7 TABS PERFECT FIT FOR IPHONE & ANDROID */
nav.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(7, 11, 10, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  box-sizing: border-box;
}

nav.bottom-nav button {
  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.bottom-nav button small {
  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.bottom-nav button.active {
  color: var(--neon);
  background: rgba(0, 230, 160, 0.15);
}

.hidden { display: none !important; }

/* RESPONSIVE */
@media (max-width: 650px) {
  main { padding: 18px 12px; }
  .screen h1 { font-size: 38px; }
  .grade > div { grid-template-columns: 1fr 1fr; }
  .choices { grid-template-columns: 1fr; }
  .canvas-container { height: 420px; }
  .form-grid { grid-template-columns: 1fr; }
}