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

:root {
  --bg:           #0d0d0d;
  --bg2:          #111111;
  --bg3:          #181818;
  --bg4:          #1f1f1f;
  --border:       rgba(0, 191, 255, 0.15);
  --border-sub:   rgba(255, 255, 255, 0.05);
  --text:         #e2e2e2;
  --text-dim:     #9a9a9a;
  --text-dimmer:  #9a9a9a;
  --primary:      #00bfff;
  --primary-dim:  rgba(0, 191, 255, 0.10);
  --primary-glow: rgba(0, 191, 255, 0.30);
  --orange:       #ffa657;
  --purple:       #d2a8ff;
  --green:        #00e676;
  --red:          #f85149;
  --yellow:       #e3b341;
  --cursor-bg:    #00bfff;
  --cursor-text:  #000;
  --search-bg:    #b58900;
  --visual-bg:    #1c3a52;
  --line-hl:      #0a1a22;
  --sidebar-w:    240px;
  --header-h:     52px;
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-ui:      system-ui, -apple-system, sans-serif;
  --radius:       6px;
  --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: var(--bg);
  align-items: center; justify-content: center;
  position: relative;
}

.welcome-content {
  text-align: center;
  max-width: 540px;
  padding: 2rem;
  animation: none;
}

.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: none; }
.trainer-text { color: var(--text-dim); font-size: 2rem; font-weight: 300; }

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

.welcome-features {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 2.25rem;
}
.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; }

.welcome-hint {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--text-dimmer);
  font-family: var(--font-mono);
}
.welcome-hint kbd {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05em 0.4em;
  color: var(--yellow);
}

/* ─── 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.82rem;
  font-family: var(--font-mono);
  border-radius: var(--radius); cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.btn-secondary:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-dim); }

.btn-icon {
  background: var(--bg3); color: var(--text-dim);
  border: 1px solid var(--border-sub);
  width: 32px; height: 32px;
  border-radius: var(--radius); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.btn-icon:hover { color: var(--primary); border-color: var(--border); }
.btn-icon.active { color: var(--primary); border-color: var(--primary); background: var(--primary-dim); }
.btn-icon.btn-danger:hover { color: var(--red); border-color: var(--red); background: rgba(248, 81, 73, 0.1); }

.btn-danger-solid {
  background: var(--red); color: #fff; border: none;
  padding: 0.5rem 1.25rem; font-size: 0.9rem; font-weight: 600;
  border-radius: var(--radius); cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
}
.btn-danger-solid:hover { opacity: 0.88; transform: translateY(-1px); }

.btn-ghost {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border-sub);
  width: 28px; height: 28px; border-radius: 6px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.btn-ghost:hover:not(:disabled) { color: var(--primary); border-color: var(--border); background: var(--primary-dim); }
.btn-ghost:disabled { opacity: 0.35; cursor: not-allowed; }

/* ─── Header ────────────────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: rgba(17, 17, 17, 0.96);
  border-bottom: 1px solid var(--border-sub);
  backdrop-filter: none;
  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);
  flex-shrink: 0;
  display: flex; flex-direction: column;
}

#sidebar-header {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dimmer);
  padding: 0.75rem 1rem 0.5rem;
  font-weight: 600;
}

#lesson-list {
  padding: 0.25rem 0;
  overflow-y: auto;
  flex: 1;
}

/* ─── Chapters ─────────────────────────────────────────────────────────── */
.chapter {
  border-bottom: 1px solid var(--border-sub);
}
.chapter:last-child { border-bottom: none; }

.chapter-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.55rem 0.75rem 0.55rem 0.6rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
  transition: background var(--transition), color var(--transition);
}
.chapter-header:hover { background: var(--bg3); color: var(--text); }
.chapter.done .chapter-header { color: var(--primary); }

.chapter-chevron {
  font-size: 0.75rem;
  transition: transform 0.2s ease;
  opacity: 0.6;
}
.chapter.collapsed .chapter-chevron { transform: rotate(-90deg); }

.chapter-icon { font-size: 0.95rem; }
.chapter-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-count {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  background: var(--bg3);
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: none;
  letter-spacing: 0;
}
.chapter.done .chapter-count { background: var(--primary-dim); color: var(--primary); }

.chapter-lessons {
  overflow: hidden;
  max-height: 1000px;
  transition: max-height 0.25s ease;
}
.chapter.collapsed .chapter-lessons { max-height: 0; }

#sidebar-footer {
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border-sub);
}
.hint-small {
  font-size: 0.7rem;
  color: var(--text-dimmer);
  font-family: var(--font-mono);
}

.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; flex: 1;
}
.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.7rem; color: var(--text-dimmer); font-family: var(--font-mono);
}
.lesson-item-count {
  font-size: 0.68rem;
  color: var(--text-dimmer);
  font-family: var(--font-mono);
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}
.lesson-item.active .lesson-item-count { background: var(--primary-dim); color: var(--primary); }
.lesson-item.locked { opacity: 0.45; cursor: not-allowed; }
.lesson-item.locked:hover { background: transparent; }
.lesson-item.locked .lesson-item-title,
.lesson-item.locked .lesson-item-sub { color: var(--text-dimmer); }
.lesson-item.locked .lesson-item-icon { filter: grayscale(1); }

/* ─── Editor area ──────────────────────────────────────────────────────── */
#editor-area {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; padding: 0.85rem; gap: 0.65rem;
  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-header {
  display: flex; align-items: center; gap: 0.75rem;
}
#task-lesson {
  font-size: 0.72rem;
  color: var(--primary);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  font-weight: 600;
}
#task-number {
  font-size: 0.7rem; color: var(--text-dimmer);
  font-family: var(--font-mono);
  text-transform: uppercase; letter-spacing: 0.08em;
}
#task-controls {
  margin-left: auto;
  display: flex; gap: 0.35rem;
}

#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.95rem; line-height: 1.55;
  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);
}

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

.line-num {
  min-width: 3ch;
  text-align: right;
  padding: 0 0.75rem;
  color: var(--text-dimmer);
  user-select: none;
  flex-shrink: 0;
  position: relative;
}
.vim-line-active .line-num { color: var(--yellow); font-weight: 600; }

.mark-label {
  position: absolute;
  left: 1px;
  color: var(--purple);
  font-weight: 700;
}

.line-content { flex: 1; }

.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: none;
}
.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.6rem; font-weight: 700;
  border-radius: 2px; letter-spacing: 0.05em;
}
.mode-normal  { background: var(--primary); color: #000; }
.mode-insert  { background: var(--green);   color: #000; }
.mode-visual  { background: var(--purple);  color: #000; }
.mode-vline   { background: #b88cff;        color: #000; }
.mode-vblock  { background: #9e73e8;        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.88rem;
  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(--primary); animation: none; }
#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.8s ease;
  z-index: 20; border-radius: var(--radius);
  pointer-events: none;
}
#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 28px var(--primary-glow);
  border-radius: var(--radius);
  padding: 0.85rem 1.75rem;
  font-size: 1.1rem; font-weight: 600; color: var(--primary);
}
.success-icon { font-size: 1.5rem; }

/* ─── Quick reference panel ───────────────────────────────────────────── */
#quick-ref {
  background: var(--bg2);
  border: 1px solid var(--border-sub);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  flex: 1; min-width: 0;
}

#quick-ref h3 {
  font-size: 0.66rem; 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.35rem 0.85rem;
}
.ref-item { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; }
.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.76rem;
  color: var(--yellow); white-space: nowrap;
}
.ref-item span { color: var(--text-dim); }

/* ─── :set toggleable view options ──────────────────────────────────── */
#vim-editor.cursorline .vim-line-active {
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
#vim-editor.nohlsearch .char-search { background: transparent !important; color: inherit !important; }
#vim-editor.show-list .line-content { white-space: pre; }

/* ─── Modal base ──────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: none;
  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); }

.modal-footer {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dimmer);
  font-family: var(--font-mono);
}
.modal-footer kbd {
  background: var(--bg3); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 4px;
  padding: 0.05em 0.4em; color: var(--yellow);
}

.modal-hint {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-dimmer);
  font-family: var(--font-mono);
}

/* ─── Cheatsheet modal ─────────────────────────────────────────────────── */
#cheatsheet-modal .modal-content { max-width: 860px; width: 100%; }
#cheatsheet-modal h2 {
  font-size: 1.15rem; margin-bottom: 1.25rem;
  font-family: var(--font-mono); color: var(--primary);
  display: flex; align-items: center; gap: 0.5rem;
}

.cheatsheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 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.75rem;
  color: var(--yellow); white-space: nowrap; flex-shrink: 0;
}
.cheat-item span { color: var(--text-dim); }

/* ─── Reset modal ──────────────────────────────────────────────────────── */
.reset-dialog {
  text-align: center;
  padding: 2rem;
  max-width: 400px;
}
.reset-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.reset-dialog h2 {
  font-size: 1.15rem;
  color: var(--red);
  margin-bottom: 0.5rem;
}
.reset-dialog p {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.55;
  margin-bottom: 1.25rem;
}
.reset-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

/* ─── Lesson complete modal ────────────────────────────────────────────── */
.celebration { text-align: center; padding: 2.5rem; max-width: 440px; }
.celebration-icon { font-size: 3.5rem; margin-bottom: 0.75rem; animation: pop 0.5s ease; }
.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; transform: scale(0.98); }
  20%  { opacity: 1; transform: scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes pop {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
/* ─── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dimmer); }

/* ─── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #sidebar { width: 180px; }
  .lesson-item-sub { display: none; }
  .lesson-item-count { display: none; }
}
@media (max-width: 620px) {
  #sidebar { display: none; }
  #editor-area { padding: 0.5rem; gap: 0.4rem; }
  .welcome-features { flex-wrap: wrap; gap: 1rem; }
  #task-controls { display: none; }
  #progress-container { display: none; }
}

:root { color-scheme: dark; --border-sub: #2a2a2a; --border: #666; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.welcome-logo { font-weight: 500; font-size: clamp(32px, 8vw, 48px); }
.welcome-features { flex-wrap: wrap; }
.feature { flex: 1 1 100px; }
.btn-primary, .btn-secondary, .btn-icon, .btn-ghost { min-height: 44px; }
#welcome-screen { min-height: 100svh; height: auto; }
.welcome-content { padding: 80px 24px 32px; }
@media (max-width: 540px) {
  #header { height: auto; min-height: var(--header-h); flex-wrap: wrap; padding: 8px; gap: 8px; }
  #sidebar { width: 120px; min-width: 120px; }
  #task-panel { padding: 12px; } #task-header { flex-wrap: wrap; }
  #main-content { min-height: 0; } #editor-area { min-width: 0; }
  #quick-ref { max-height: 24vh; overflow: auto; }
  #welcome-screen { overflow: auto; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
