/* ─── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0d0d0d;
  --bg2:          #111111;
  --bg3:          #181818;
  --border:       rgba(0, 191, 255, 0.15);
  --border-sub:   rgba(255, 255, 255, 0.05);
  --text:         #e2e2e2;
  --text-dim:     #888;
  --text-dimmer:  #555;
  --primary:      #00bfff;
  --primary-dim:  rgba(0, 191, 255, 0.10);
  --primary-glow: rgba(0, 191, 255, 0.30);
  --orange:       #ffa657;
  --purple:       #d2a8ff;
  --red:          #f85149;
  --yellow:       #e3b341;
  --cursor-bg:    #00bfff;
  --cursor-text:  #000;
  --search-bg:    #b58900;
  --visual-bg:    #0d2a3a;
  --line-hl:      #0a1a22;
  --sidebar-w:    220px;
  --header-h:     52px;
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-ui:      'Inter', system-ui, -apple-system, sans-serif;
  --radius:       8px;
  --transition:   0.15s ease;
}

html, body { height: 100%; font-family: var(--font-ui); background: var(--bg); color: var(--text); }
body { overflow: hidden; }

/* ─── Screens ───────────────────────────────────────────────────────────────── */
.screen { display: none; height: 100vh; }
.screen.active { display: flex; flex-direction: column; }
#trainer-screen { display: none; flex-direction: column; }
#trainer-screen.active { display: flex; }

/* ─── Welcome Screen ────────────────────────────────────────────────────────── */
#welcome-screen {
  background: radial-gradient(ellipse at 50% 40%, #001a26 0%, var(--bg) 70%);
  align-items: center; justify-content: center;
  position: relative;
}

.welcome-content {
  text-align: center;
  max-width: 520px;
  padding: 2rem;
  animation: fadeInUp 0.6s ease;
}

.welcome-logo {
  font-family: var(--font-mono);
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}
.vim-logo { color: var(--primary); text-shadow: 0 0 20px var(--primary-glow); }
.trainer-text { color: var(--text-dim); font-size: 2rem; font-weight: 300; }

.welcome-subtitle {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin-bottom: 2rem;
}

.welcome-features {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 2.5rem;
}
.feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.feature-icon { font-size: 1.5rem; }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: #000;
  border: none;
  padding: 0.75rem 2.5rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity var(--transition), box-shadow var(--transition), transform var(--transition);
}
.btn-primary:hover {
  opacity: 0.88;
  box-shadow: 0 0 18px var(--primary-glow);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg3);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.btn-secondary:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-dim);
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: rgba(17, 17, 17, 0.96);
  border-bottom: 1px solid var(--border-sub);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  flex-shrink: 0;
  z-index: 10;
}

.nav-back {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dimmer);
  text-decoration: none;
  transition: color var(--transition);
  white-space: nowrap;
}
.nav-back:hover { color: var(--primary); }

.nav-divider {
  width: 1px;
  height: 18px;
  background: var(--border-sub);
  flex-shrink: 0;
}

.header-logo {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.logo-vim { color: var(--primary); text-shadow: 0 0 10px var(--primary-glow); }
.logo-trainer { color: var(--text-dim); font-weight: 300; }

#progress-container {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 280px;
}

#progress-bar {
  flex: 1;
  height: 5px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border-sub);
}

#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, #7ee8ff 100%);
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}

#progress-text {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* ─── Main content ──────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border-sub);
  overflow-y: auto;
  flex-shrink: 0;
}

#lesson-list { padding: 0.5rem 0; }

.lesson-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--transition), border-color var(--transition);
  user-select: none;
}
.lesson-item:hover { background: var(--bg3); }
.lesson-item.active {
  background: var(--primary-dim);
  border-left-color: var(--primary);
}
.lesson-item.done { border-left-color: rgba(0, 191, 255, 0.4); }
.lesson-item.done .lesson-item-icon { color: var(--primary); }

.lesson-item-icon {
  font-size: 1rem;
  width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}
.lesson-item-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.lesson-item-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lesson-item-sub {
  font-size: 0.72rem;
  color: var(--text-dimmer);
  font-family: var(--font-mono);
}

/* ─── Editor area ───────────────────────────────────────────────────────────── */
#editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 1rem;
  gap: 0.75rem;
  min-width: 0;
}

/* ─── Task panel ────────────────────────────────────────────────────────────── */
#task-panel {
  background: var(--bg2);
  border: 1px solid var(--border-sub);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
}

#task-number {
  font-size: 0.7rem;
  color: var(--text-dimmer);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#task-instruction {
  font-size: 1rem;
  color: var(--text);
  line-height: 1.5;
}
#task-instruction kbd {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1em 0.45em;
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--yellow);
}
#task-instruction strong { color: var(--primary); }

#task-hint {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.hint-label { color: var(--yellow); font-weight: 600; }

/* ─── Vim wrapper ───────────────────────────────────────────────────────────── */
#vim-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  border: 1px solid var(--border-sub);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
  position: relative;
  background: var(--bg);
}

#vim-editor {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
  outline: none;
  cursor: text;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.6;
  background: var(--bg);
}
#vim-editor:focus { outline: none; }
#vim-wrapper:focus-within {
  border-color: var(--border);
  box-shadow: 0 0 0 1px rgba(0, 191, 255, 0.12);
}

/* Lines */
.vim-line {
  display: flex;
  white-space: pre;
  min-height: 1.6em;
}
.vim-line-active { background: var(--line-hl); }

.line-num {
  width: 2.5rem;
  text-align: right;
  padding-right: 0.75rem;
  color: var(--text-dimmer);
  user-select: none;
  flex-shrink: 0;
}
.vim-line-active .line-num { color: var(--text-dim); }

.line-content { flex: 1; }

/* Cursor characters */
.char-cursor {
  background: var(--cursor-bg);
  color: var(--cursor-text);
  border-radius: 1px;
}
.char-cursor-insert {
  background: transparent;
  border-left: 2px solid var(--primary);
  animation: blink 1s step-end infinite;
}
.char-search { background: var(--search-bg); color: #fff; border-radius: 2px; }
.char-visual { background: var(--visual-bg); }

/* ─── Status bar ────────────────────────────────────────────────────────────── */
#vim-statusbar {
  background: var(--bg3);
  border-top: 1px solid var(--border-sub);
  display: flex;
  align-items: center;
  padding: 0 0.5rem;
  height: 1.6rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  gap: 0.5rem;
  flex-shrink: 0;
}

#mode-indicator {
  padding: 0 0.5rem;
  font-weight: 700;
  border-radius: 2px;
  letter-spacing: 0.05em;
}
.mode-normal  { background: var(--primary); color: #000; }
.mode-insert  { background: #00e676;        color: #000; }
.mode-visual  { background: var(--purple);  color: #000; }
.mode-command { background: var(--orange);  color: #000; }
.mode-search  { background: var(--yellow);  color: #000; }

#file-name { flex: 1; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#cursor-position { color: var(--text-dimmer); white-space: nowrap; }

/* ─── Command line ──────────────────────────────────────────────────────────── */
#vim-cmdline {
  background: var(--bg2);
  border-top: 1px solid var(--border-sub);
  padding: 0.2rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  height: 1.8rem;
  display: flex;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
}
#cmdline-prefix { color: var(--orange); font-weight: 700; }
#cmdline-content { color: var(--text); }
#cmdline-cursor { color: var(--text); animation: blink 1s step-end infinite; }
#cmdline-prefix, #cmdline-content, #cmdline-cursor { visibility: hidden; }

/* ─── Task success overlay ──────────────────────────────────────────────────── */
#task-success {
  position: absolute;
  inset: 0;
  background: rgba(0, 191, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: successFlash 0.9s ease;
  z-index: 20;
  border-radius: var(--radius);
}
#task-success.hidden { display: none; }

.success-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg2);
  border: 2px solid var(--primary);
  box-shadow: 0 0 20px var(--primary-glow);
  border-radius: var(--radius);
  padding: 0.75rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary);
}
.success-icon { font-size: 1.5rem; }

/* ─── Quick reference ───────────────────────────────────────────────────────── */
#quick-ref {
  background: var(--bg2);
  border: 1px solid var(--border-sub);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  flex-shrink: 0;
}
#quick-ref h3 {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dimmer);
  margin-bottom: 0.4rem;
}
#quick-ref-content {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
}
.ref-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
}
.ref-item kbd {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--yellow);
  white-space: nowrap;
}
.ref-item span { color: var(--text-dim); }

/* ─── Modal base ────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: slideUp 0.25s ease;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg3); color: var(--text); }

/* ─── Cheatsheet modal ──────────────────────────────────────────────────────── */
#cheatsheet-modal .modal-content {
  max-width: 760px;
  width: 100%;
}
#cheatsheet-modal h2 {
  font-size: 1.1rem;
  margin-bottom: 1.25rem;
  font-family: var(--font-mono);
  color: var(--primary);
}

.cheatsheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
}

.cheat-category h3 {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dimmer);
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-sub);
}

.cheat-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}
.cheat-item kbd {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--yellow);
  white-space: nowrap;
  flex-shrink: 0;
}
.cheat-item span { color: var(--text-dim); }

/* ─── Lesson complete modal ─────────────────────────────────────────────────── */
.celebration {
  text-align: center;
  padding: 2.5rem;
  max-width: 420px;
}
.celebration-icon { font-size: 3.5rem; margin-bottom: 0.75rem; }
.celebration h2 { font-size: 1.5rem; margin-bottom: 0.75rem; color: var(--primary); }
.celebration p {
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

/* ─── Animations ────────────────────────────────────────────────────────────── */
@keyframes blink {
  50% { opacity: 0; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes successFlash {
  0%   { opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dimmer); }

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  #sidebar { width: 160px; }
  .lesson-item-sub { display: none; }
  #editor-area { padding: 0.5rem; gap: 0.5rem; }
  #quick-ref { display: none; }
}
@media (max-width: 520px) {
  #sidebar { display: none; }
}
