/* =============================================
   Song Co-Writing — Styles
   ============================================= */

/* ---- TOAST NOTIFICATIONS ---- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #2a2a4a;
  color: #e0e0ff;
  border-left: 4px solid #7c5cbf;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateX(40px);
  animation: toastIn 0.3s forwards;
  pointer-events: auto;
  max-width: 360px;
}
.toast.toast-error { border-left-color: #e74c3c; }
.toast.toast-success { border-left-color: #2ecc71; }
.toast.toast-out { animation: toastOut 0.3s forwards; }
@keyframes toastIn { to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(40px); } }

/* ---- TUTORIAL OVERLAY ---- */
.tutorial-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.tutorial-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(6px);
}
.tutorial-card {
  position: relative; z-index: 1;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 40px 28px;
  max-width: 480px; width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px var(--accent-glow);
  animation: tutorialIn 0.35s ease-out;
}
@keyframes tutorialIn {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.tutorial-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 24px;
}
.tutorial-header .tutorial-icon {
  font-size: 28px; color: var(--accent);
}
.tutorial-header h2 {
  font-size: 20px; font-weight: 700; color: var(--text);
}
.tutorial-steps { position: relative; min-height: 140px; }
.tutorial-step {
  display: none; animation: stepFade 0.3s ease;
}
.tutorial-step.active { display: block; }
@keyframes stepFade {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}
.tutorial-step-icon {
  font-size: 32px; margin-bottom: 8px;
}
.tutorial-step h3 {
  font-size: 16px; font-weight: 600; color: var(--accent); margin-bottom: 8px;
}
.tutorial-step p {
  font-size: 13.5px; color: var(--text-dim); line-height: 1.65;
}
.tutorial-step kbd {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; font-size: 12px;
  font-family: var(--font-mono); color: var(--text);
}
.tutorial-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border);
}
.tutorial-dots { display: flex; gap: 6px; }
.tutorial-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border); transition: all 0.2s;
}
.tutorial-dot.active {
  background: var(--accent); box-shadow: 0 0 6px var(--accent-glow);
}
.tutorial-buttons { display: flex; gap: 8px; }
.btn-tutorial-skip {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  padding: 7px 16px; border-radius: 8px; cursor: pointer; font-size: 12.5px;
  transition: all 0.15s;
}
.btn-tutorial-skip:hover { color: var(--text); border-color: var(--text-muted); }
.btn-tutorial-next {
  background: var(--accent); border: none; color: white;
  padding: 7px 20px; border-radius: 8px; cursor: pointer; font-size: 12.5px;
  font-weight: 600; transition: all 0.15s;
}
.btn-tutorial-next:hover { background: var(--accent-hover); }

:root {
  --bg-dark: #0f0f1a;
  --bg-panel: #16162a;
  --bg-card: #1c1c35;
  --bg-input: #22223a;
  --bg-hover: #2a2a4a;
  --accent: #7c5cfc;
  --accent-hover: #9b7fff;
  --accent-glow: rgba(124, 92, 252, 0.3);
  --text: #e8e6f0;
  --text-dim: #8888aa;
  --text-muted: #555577;
  --border: #2a2a45;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --love: #f472b6;
  --sad: #60a5fa;
  --angry: #ef4444;
  --happy: #fbbf24;
  --confident: #a78bfa;
  --nostalgic: #c084fc;
  --dark: #6b7280;
  --spiritual: #34d399;
  --party: #fb923c;
  --lonely: #94a3b8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- TOOLBAR ---- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
  flex-shrink: 0;
}

.toolbar-left, .toolbar-center, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  -webkit-app-region: no-drag;
}

.app-logo { font-size: 22px; margin-right: 4px; }
.app-title { font-weight: 700; font-size: 14px; color: var(--accent); letter-spacing: 0.5px; }

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 8px;
}

.toolbar-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border);
}
.toolbar-btn .icon { font-size: 14px; }

.song-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  width: 300px;
  padding: 4px 12px;
  border-radius: var(--radius);
  transition: all 0.15s;
}
.song-title-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-input);
}
.song-title-input::placeholder { color: var(--text-muted); }

.stat-badge {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-card);
  padding: 3px 8px;
  border-radius: 10px;
}

.save-indicator {
  font-size: 10px;
  color: var(--success);
  transition: color 0.3s;
}
.save-indicator.unsaved { color: var(--warning); }

/* ---- MAIN LAYOUT ---- */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- SIDEBARS ---- */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
  width: 300px;
}

.sidebar-section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 6px;
}

.sidebar-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 700;
}

.sidebar-label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin: 6px 0 3px;
}

.sidebar-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
}
.sidebar-input:focus { outline: none; border-color: var(--accent); }

.section-select {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: var(--radius);
  font-size: 12px;
}

.add-section-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* Structure list */
.structure-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.structure-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg-input);
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
}
.structure-item:hover { border-color: var(--border); background: var(--bg-hover); }
.structure-item.active { border-color: var(--accent); background: var(--accent-glow); }

.structure-item-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-verse { background: #2563eb33; color: #60a5fa; }
.badge-chorus { background: #7c3aed33; color: #a78bfa; }
.badge-pre-chorus { background: #db277733; color: #f472b6; }
.badge-bridge { background: #059669aa; color: #34d399; }
.badge-hook { background: #d9770633; color: #fbbf24; }
.badge-intro { background: #6b728033; color: #9ca3af; }
.badge-outro { background: #6b728033; color: #9ca3af; }
.badge-ad-lib { background: #f4347233; color: #fb923c; }
.badge-spoken { background: #374151aa; color: #d1d5db; }

.structure-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.structure-item:hover .structure-actions { opacity: 1; }

.btn-struct-action {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 12px;
  border-radius: 3px;
}
.btn-struct-action:hover { color: var(--text); background: var(--bg-dark); }

/* Buttons */
.btn-small {
  padding: 5px 10px;
  border: none;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-accent {
  background: var(--accent);
  color: white;
}
.btn-accent:hover { background: var(--accent-hover); }

.template-grid {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 4px;
}

.btn-template {
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
  width: 100%;
  text-align: left;
  flex-shrink: 0;
}
.btn-template:hover { color: var(--text); border-color: var(--accent); }

/* ---- EDITOR AREA ---- */
.editor-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sections-editor {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.section-block {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color 0.2s;
}
.section-block:focus-within {
  border-color: var(--accent);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.section-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-section-action {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  opacity: 0.4;
}
.section-block:hover .btn-section-action {
  opacity: 1;
}
.btn-section-action:hover {
  border-color: var(--border);
  color: var(--text);
  background: var(--bg-input);
}
.btn-section-delete:hover {
  color: #ff6b6b;
  border-color: #ff6b6b44;
  background: #ff6b6b11;
}

.section-title-edit {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  width: 140px;
}
.section-title-edit:focus {
  outline: none;
  border-bottom: 1px solid var(--accent);
}

.section-syllable-avg {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-dark);
  padding: 2px 8px;
  border-radius: 8px;
}

.section-textarea {
  width: 100%;
  min-height: 120px;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 2;
  resize: vertical;
  user-select: text;
}
.section-textarea:focus { outline: none; }
.section-textarea::placeholder { color: var(--text-muted); }

/* Suggestion bar inside each section */
.suggestion-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}

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

.suggestion-bar-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.suggestion-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.suggestion-chip {
  font-size: 12.5px;
  padding: 6px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: text;
  line-height: 1.4;
}
.suggestion-chip:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-glow);
}

.btn-generate-line {
  font-size: 11px;
  padding: 4px 12px;
  background: var(--accent);
  border: none;
  color: white;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s;
}
.btn-generate-line:hover { background: var(--accent-hover); }

.btn-new-suggestions {
  font-size: 11px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-new-suggestions:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}
.empty-state-icon { font-size: 48px; opacity: 0.3; }
.empty-state-text { font-size: 14px; }
.empty-state-hint { font-size: 12px; color: var(--text-muted); max-width: 400px; line-height: 1.6; }

/* ---- TOOLS (right sidebar) ---- */
.tool-input-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.tool-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
}
.tool-input:focus { outline: none; border-color: var(--accent); }

.tool-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
}

.tool-tab {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px;
  font-size: 10px;
  text-align: center;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.12s;
}
.tool-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.tool-results {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
  padding: 2px 0;
}

.tool-word {
  font-size: 11px;
  padding: 3px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.12s;
}
.tool-word:hover {
  border-color: var(--accent);
  color: var(--text);
}
.tool-word.inserted {
  border-color: var(--success);
  color: var(--success);
}

.syllable-display {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 0;
}
.syllable-count-big {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  font-family: var(--font-mono);
}
.syllable-label { font-size: 12px; color: var(--text-dim); }

.syllable-breakdown {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  padding: 4px 0;
  line-height: 1.6;
}
.syllable-word {
  display: inline-block;
  margin-right: 6px;
}
.syllable-word-count {
  color: var(--accent);
  font-weight: 700;
}

/* Mood buttons */
.mood-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.mood-btn {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.12s;
}
.mood-btn:hover { border-color: var(--accent); color: var(--text); }
.mood-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.mood-results {
  max-height: 150px;
}

/* Scratch pad */
.scratch-pad {
  width: 100%;
  min-height: 80px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
  resize: vertical;
  user-select: text;
}
.scratch-pad:focus { outline: none; border-color: var(--accent); }

/* Chord Progressions tool */
.chord-key-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.chord-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}
.chord-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.chord-card:hover {
  border-color: var(--accent);
}
.chord-card-name {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 3px;
}
.chord-card-chords {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
}
.chord-card-genre {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Verse Gen tool */
.versegen-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.versegen-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}
.versegen-line {
  font-size: 12px;
  padding: 5px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}
.versegen-line:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-glow);
}
.versegen-line.inserted {
  border-color: var(--success);
  color: var(--success);
}
.versegen-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
}

/* Animations */
@keyframes chipSlideIn {
  from { opacity: 0; transform: translateY(8px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.suggestion-chip {
  animation: chipSlideIn 0.3s ease backwards;
}
.suggestion-chip:nth-child(1) { animation-delay: 0ms; }
.suggestion-chip:nth-child(2) { animation-delay: 50ms; }
.suggestion-chip:nth-child(3) { animation-delay: 100ms; }
.suggestion-chip:nth-child(4) { animation-delay: 150ms; }
.suggestion-chip:nth-child(5) { animation-delay: 200ms; }
.suggestion-chip:nth-child(6) { animation-delay: 250ms; }

/* Mood Indicator */
.mood-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; margin-bottom: 8px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 10px; border-left: 3px solid var(--accent);
  transition: border-color 0.3s, background 0.3s;
}
.mood-indicator-emoji { font-size: 18px; }
.mood-indicator-label {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
}

/* Tool Icons */
.tool-icon { margin-right: 4px; font-size: 14px; }

/* Mobile toggle — hidden on desktop */
.mobile-toggle { display: none !important; }

/* Collapsible panel header (mobile only) */
.mobile-panel-header {
  display: none;
}

/* Responsive — tablet */
@media (max-width: 1100px) {
  .sidebar-left { width: 220px; }
  .sidebar-right { width: 240px; }
}

/* =============================================
   Responsive — mobile (≤ 860px)
   Single scrollable column layout.
   Both sidebars become collapsible panels
   stacked with the editor.
   ============================================= */
@media (max-width: 860px) {
  .mobile-toggle { display: flex !important; }

  /* Body: allow scrolling */
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto;
  }

  /* Toolbar: sticky at top, compact */
  .toolbar {
    position: sticky;
    top: 0;
    z-index: 200;
    padding: 0 10px;
    height: 44px;
    flex-wrap: nowrap;
  }
  .toolbar-left {
    flex: 0 0 auto;
    overflow: hidden;
    gap: 2px;
  }
  .toolbar-left .toolbar-btn span:not(.icon) { display: none; }
  .toolbar-left .toolbar-btn { padding: 5px 7px; }
  .toolbar-left .app-title { display: none; }
  .toolbar-left .toolbar-divider { margin: 0 4px; }
  .toolbar-center { flex: 1; min-width: 0; }
  .song-title-input { width: 100%; font-size: 14px; }

  /* Main layout: single column, scrollable */
  .main-layout {
    flex-direction: column;
    overflow: visible;
  }

  /* Sidebars: full width, inline in the flow */
  .sidebar-left,
  .sidebar-right {
    width: 100%;
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  /* Collapsible panel headers */
  .mobile-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-panel-header:active {
    background: var(--bg-hover);
  }
  .mobile-panel-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
  }
  .mobile-panel-arrow {
    font-size: 12px;
    color: var(--text-dim);
    transition: transform 0.2s;
  }
  .sidebar.collapsed .mobile-panel-arrow {
    transform: rotate(-90deg);
  }

  /* Collapsed sidebar: hide inner content */
  .sidebar.collapsed .sidebar-section {
    display: none;
  }

  /* Editor: full width, no fixed height */
  .editor-area {
    padding: 12px 10px;
    overflow: visible;
    min-height: 50vh;
  }
  .sections-editor {
    max-width: 100%;
  }

  /* Section blocks: tighter on mobile */
  .section-header { padding: 6px 10px; }
  .section-textarea {
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.9;
  }

  /* Suggestion bar */
  .suggestion-bar { padding: 8px 10px; }
  .suggestion-header { flex-wrap: wrap; gap: 6px; }
  .suggestion-chips { gap: 5px; }
  .suggestion-chip { white-space: normal; word-break: break-word; }

  /* Template grid */
  .template-grid { max-height: 260px; }

  /* Tutorial */
  .tutorial-card { max-width: 90vw; padding: 28px 24px 22px; }

  /* Structure actions always visible (no hover on touch) */
  .structure-actions { opacity: 1; }
  .btn-section-action { opacity: 1; }
}

/* Responsive — phone */
@media (max-width: 540px) {
  .toolbar {
    height: 42px;
    padding: 0 6px;
    gap: 0;
  }
  .toolbar-left { gap: 1px; }
  .toolbar-left .toolbar-btn { padding: 4px 5px; font-size: 11px; }
  .toolbar-left .app-logo { font-size: 18px; margin-right: 2px; }
  .toolbar-left .toolbar-divider { display: none; }
  .toolbar-right { gap: 4px; }
  .toolbar-right .stat-badge { display: none; }
  .song-title-input { font-size: 13px; padding: 3px 6px; }

  /* Editor */
  .editor-area { padding: 8px 6px; gap: 12px; }
  .section-block { border-radius: var(--radius); }
  .section-textarea {
    font-size: 13px;
    padding: 10px 12px;
    min-height: 100px;
    line-height: 1.8;
  }
  .section-header { padding: 6px 8px; }
  .section-header-left { gap: 5px; }
  .section-title-edit { width: 90px; font-size: 12px; }
  .section-badge { font-size: 8px; padding: 1px 5px; }
  .section-syllable-avg { font-size: 9px; padding: 1px 6px; }
  .suggestion-bar { padding: 8px; gap: 6px; }
  .suggestion-chip { font-size: 11.5px; padding: 5px 10px; }

  /* Mood indicator */
  .mood-indicator { padding: 5px 10px; margin-bottom: 6px; }
  .mood-indicator-emoji { font-size: 16px; }
  .mood-indicator-label { font-size: 11px; }

  /* Empty state */
  .empty-state-icon { font-size: 36px; }
  .empty-state-text { font-size: 13px; }
  .empty-state-hint { font-size: 11px; max-width: 90vw; }

  /* Mood buttons */
  .mood-btn { padding: 5px 10px; font-size: 12px; }
  .mood-selector { gap: 5px; }

  /* Tool results */
  .tool-results { max-height: 100px; }
  .tool-word { font-size: 12px; padding: 4px 10px; }

  /* Chord cards */
  .chord-card { padding: 10px; }
  .chord-card-chords { font-size: 12px; }

  /* Verse gen */
  .versegen-line { font-size: 12px; padding: 6px 10px; }

  /* Scratch pad */
  .scratch-pad { min-height: 60px; font-size: 13px; }

  /* Tutorial */
  .tutorial-card { padding: 20px 16px 16px; max-width: 95vw; }
  .tutorial-header h2 { font-size: 17px; }
  .tutorial-step h3 { font-size: 14px; }
  .tutorial-step p { font-size: 12.5px; }

  /* Sidebar panels: tighter padding */
  .sidebar { padding: 8px; }
  .mobile-panel-header { padding: 10px 12px; }
}

/* Responsive — very small phones (< 360px) */
@media (max-width: 360px) {
  .toolbar-left .toolbar-btn:nth-child(n+5) { display: none; }
  .toolbar-left .app-logo { display: none; }
  .section-title-edit { width: 70px; font-size: 11px; }
  .suggestion-actions { flex-wrap: wrap; }
  .btn-generate-line,
  .btn-new-suggestions { font-size: 10px; padding: 3px 8px; }
}

/* ---- Touch device optimizations ---- */
@media (pointer: coarse) {
  .toolbar-btn { min-height: 36px; min-width: 36px; justify-content: center; }
  .btn-small { min-height: 36px; padding: 6px 12px; font-size: 12px; }
  .mood-btn { min-height: 36px; }
  .tool-tab { min-height: 36px; font-size: 11px; }
  .structure-item { padding: 8px 10px; }
  .btn-struct-action { width: 28px; height: 28px; font-size: 14px; }
  .structure-actions { opacity: 1; }
  .section-block:hover .btn-section-action,
  .btn-section-action { opacity: 1; }
  .btn-section-action { width: 30px; height: 30px; }
  .tool-input, .sidebar-input, .section-select { min-height: 36px; font-size: 13px; }
  .suggestion-chip { padding: 8px 14px; }
  .scratch-pad { min-height: 100px; font-size: 13px; }
  .btn-generate-line,
  .btn-new-suggestions { min-height: 32px; padding: 6px 14px; font-size: 12px; }
  .btn-template { min-height: 36px; padding: 8px 10px; font-size: 12px; }
  .tool-word { min-height: 30px; padding: 5px 10px; font-size: 12px; display: inline-flex; align-items: center; }
  .versegen-line { padding: 8px 12px; font-size: 13px; }
  .chord-card { padding: 10px 12px; }
  .mobile-panel-header { min-height: 44px; }
}

/* ---- Landscape phone ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .toolbar { height: 36px; }
  .toolbar-btn { padding: 3px 6px; font-size: 11px; }
  .song-title-input { font-size: 12px; padding: 2px 8px; }
  .editor-area { padding: 6px 8px; gap: 8px; }
  .section-textarea { min-height: 80px; line-height: 1.6; }
  .mood-indicator { padding: 3px 8px; margin-bottom: 4px; }
}
