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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-surface: #1e2a4a;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --accent-secondary: #533483;
  --phrase-colors-0: #4ecdc4;
  --phrase-colors-1: #f7d354;
  --phrase-colors-2: #e17055;
  --phrase-colors-3: #a29bfe;
  --phrase-colors-4: #fd79a8;
  --phrase-colors-5: #55efc4;
  --cursor-color: #e94560;
  --border-color: rgba(255, 255, 255, 0.1);
  --radius: 6px;
  --font-mono: 'Consolas', 'Monaco', monospace;
  --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
}

/* ===== Layout ===== */
body {
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 4px 16px;
  gap: 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.app-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.song-info {
  font-size: 13px;
  color: var(--text-secondary);
}

.app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.app-footer {
  height: 28px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.autosave-status {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}


/* ===== Buttons ===== */
.btn {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--text-muted);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.btn-full {
  width: 100%;
  margin-top: 8px;
}

.btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== Editor Area ===== */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.toolbar-label input[type="range"] {
  width: 80px;
  accent-color: var(--accent);
}

.time-display {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 140px;
}

.zoom-display {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Timeline (3 rows) ===== */
.timeline-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.timeline-row {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Row 0: Metadaten */
.meta-row {
  flex-shrink: 0;
  border-bottom: 2px solid var(--border-color);
  background: var(--bg-secondary);
  overflow: hidden;
}

.meta-fields {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  flex-wrap: wrap;
}

.meta-fields-audio {
  padding: 4px 12px;
}

.meta-field {
  display: flex;
  align-items: center;
  gap: 4px;
}

.meta-field label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.meta-field input,
.meta-field select {
  padding: 3px 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-sans);
}

.meta-field input[type="text"] {
  width: 140px;
}

.meta-field input[type="number"] {
  width: 70px;
}

.meta-field select {
  width: 100px;
}

.meta-field input:focus,
.meta-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.meta-badge {
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}
.meta-badge[data-level="excellent"] { color: #55efc4; border-color: #55efc4; }
.meta-badge[data-level="good"] { color: #4ecdc4; border-color: #4ecdc4; }
.meta-badge[data-level="ok"] { color: #f7d354; border-color: #f7d354; }
.meta-badge[data-level="poor"] { color: #e94560; border-color: #e94560; }

.meta-transcode {
  background: rgba(233, 69, 96, 0.15);
  color: #e94560;
  border-color: #e94560;
  font-weight: 700;
  animation: transcode-pulse 1.5s ease-in-out 3;
}
.meta-transcode[hidden] {
  display: none;
}
@keyframes transcode-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.meta-separator {
  color: var(--border-color);
  font-size: 16px;
  margin: 0 4px;
}

/* Karaoke Lauftext */
.karaoke-row {
  flex-shrink: 0;
  height: 118px;
  border-bottom: 2px solid var(--border-color);
  background: #000000;
  overflow: hidden;
}

/* Row 1: Waveform */
.waveform-row {
  flex: 2;
  min-height: 0;
  max-height: 106px;
  border-bottom: 2px solid var(--border-color);
  overflow: hidden;
}

.waveform-wrap {
  position: relative;
  width: 100%;
  height: 80px;
}
.waveform-row .waveform {
  width: 100%;
  height: 80px;
}
.audio-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(22, 33, 62, 0.92);
  z-index: 5;
  pointer-events: none;
}
.audio-hint[hidden] {
  display: none;
}
.audio-hint-icon {
  font-size: 22px;
  color: var(--accent);
}
.audio-hint-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.audio-hint-file {
  color: var(--text-primary);
  font-weight: 600;
}
.audio-hint-detail {
  font-size: 11px;
  color: var(--text-muted);
}

/* Row 2: Overview minimap */
.overview-row {
  flex: 1;
  min-height: 0;
  max-height: 68px;
  border-bottom: 2px solid var(--border-color);
  background: var(--bg-secondary);
  overflow: hidden;
}

/* Row 3: Phrase blocks */
.phrases-row {
  flex: 2;
  min-height: 0;
  max-height: 116px;
  border-bottom: 2px solid var(--border-color);
  background: var(--bg-secondary);
}

/* Row 4: Syllable detail */
.syllables-row {
  flex: 2;
  min-height: 0;
  max-height: 106px;
  background: var(--bg-primary);
  border-bottom: 2px solid var(--border-color);
}

/* Row 5: Silbeneditor (Split/Merge) */
.silbeneditor-row {
  flex: 2;
  min-height: 0;
  max-height: 116px;
  border-bottom: 2px solid var(--border-color);
  background: var(--bg-secondary);
  overflow: hidden;
}

.row-canvas {
  display: block;
}

/* Row headers */
.row-header {
  position: sticky;
  left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px;
  background: var(--bg-tertiary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  z-index: 10;
  border-bottom: 1px solid var(--border-color);
}

.row-header-title {
  white-space: nowrap;
}

.row-header-sub {
  font-weight: 400;
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  flex: 1;
}

.btn-close-row {
  width: 24px;
  height: 24px;
  font-size: 14px;
  padding: 0;
  flex-shrink: 0;
}

/* ===== Tap Timing ===== */
.tap-status {
  font-size: 13px;
  color: var(--accent);
}

.tap-status.hidden {
  display: none;
}


/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Export Overlay ===== */
/* ===== Save/Load dropdown ===== */
.save-load-group {
  position: relative;
}
.load-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  min-width: 280px;
  max-height: 360px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.load-dropdown[hidden] {
  display: none;
}
.load-dropdown-header {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}
.load-dropdown-list {
  overflow-y: auto;
  flex: 1;
}
.load-dropdown-empty {
  padding: 16px 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
.load-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
}
.load-item:hover {
  background: var(--bg-tertiary);
}
.load-item-info {
  flex: 1;
  min-width: 0;
}
.load-item-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.load-item-date {
  font-size: 10px;
  color: var(--text-muted);
}
.load-item-delete {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.load-item-delete:hover {
  background: var(--accent);
  color: white;
}

/* ===== Karaoke style dropdown ===== */
.karaoke-style-select {
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  font-size: 10px;
  padding: 1px 4px;
  height: 18px;
  cursor: pointer;
  outline: none;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.karaoke-style-select:hover {
  border-color: var(--text-muted);
}
.karaoke-style-select:focus {
  border-color: var(--accent);
}

.export-overlay[hidden] {
  display: none;
}
.export-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.export-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 10px;
  padding: 32px 48px;
  text-align: center;
  min-width: 340px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.export-dialog-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}
.export-progress-wrap {
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}
.export-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.15s ease;
}
.export-progress-text {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-variant-numeric: tabular-nums;
}
.at-confirm { padding: 16px 0 8px; }
.at-confirm-text { margin: 0 0 10px; font-size: 14px; line-height: 1.5; color: var(--text-primary); text-align: center; }
.at-confirm-sub { font-size: 12px; color: var(--text-secondary); }
#btn-at-start { margin-top: 4px; font-size: 14px; }
.at-log {
  text-align: left;
  font-size: 12px;
  font-family: monospace;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 16px;
  max-height: 160px;
  overflow-y: auto;
  line-height: 1.6;
}
.at-log .at-ok { color: #4ec970; }
.at-log .at-warn { color: #e8a838; }
.at-log .at-err { color: #e84848; }
