:root {
  --bg: #0f1117;
  --card: #1a1d27;
  --card-2: #232735;
  --line: #2c3142;
  --text: #e7e9ef;
  --muted: #8a90a2;
  --accent: #ff7a18;
  --accent-2: #ffb347;
  --primary: #4f8cff;
  --primary-d: #3a6fd8;
  --active: #2a3550;
  --done: #1d3326;
  --warn: #b58900;
  --error: #e0533c;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
}

html[data-theme="light"] {
  --bg: #f3f5fa;
  --card: #ffffff;
  --card-2: #f0f2f7;
  --line: #d8dde7;
  --text: #1c2030;
  --muted: #6b7280;
  --accent: #d35400;
  --accent-2: #b7541b;
  --primary: #2a6df4;
  --primary-d: #1e54c4;
  --active: #dfe9ff;
  --done: #d8f5df;
  --warn: #8a6d00;
  --error: #c0392b;
  --shadow: 0 8px 24px rgba(20,30,60,.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 50% -200px, color-mix(in srgb, var(--primary) 15%, var(--bg)), var(--bg));
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app { max-width: 900px; margin: 0 auto; padding: 24px 16px 80px; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 24px;
  gap: 8px;
}
.topbar-title { text-align: center; }
.topbar-actions { display: flex; gap: 8px; }
.topbar-actions.left { justify-content: flex-start; }
.topbar-actions.right { justify-content: flex-end; }
.topbar h1 {
  margin: 0;
  font-size: 2.2rem;
  letter-spacing: -.5px;
  color: var(--accent);
}
.topbar h1 span { color: var(--text); }
.tagline { color: var(--muted); margin: 4px 0 0; font-size: .92rem; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: .15s;
}
.icon-btn:hover { border-color: var(--primary); transform: translateY(-1px); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.step { display: none; }
.step.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h2 { margin: 0 0 18px; font-size: 1.25rem; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
  margin-bottom: 16px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .82rem; color: var(--muted); }

input[type=text], input[type=number], textarea, select {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .95rem;
  font-family: inherit;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
}
textarea { resize: vertical; line-height: 1.7; }

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 14px 0;
  font-size: .9rem;
  color: var(--muted);
}
.options label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  align-items: center;
}

.btn {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  font-family: inherit;
  transition: .15s;
}
.btn:hover:not(:disabled) { border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-d); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1rem; padding: 14px 20px; }
.btn.small { padding: 6px 10px; font-size: .82rem; }
.btn kbd, kbd {
  background: rgba(0,0,0,.25);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: .75rem;
  margin-left: 4px;
  font-family: "Cascadia Code", monospace;
}
html[data-theme="light"] kbd { background: rgba(0,0,0,.08); }
.file-btn { display: inline-flex; align-items: center; }

.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .82rem; }

/* LYRIC SEARCH */
.lyric-search {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 18px;
}
.search-row { display: flex; gap: 10px; }
.search-row input { flex: 1; }
.search-hint { margin: 8px 0 0; font-size: .82rem; }
.search-status { margin-top: 10px; font-size: .88rem; color: var(--muted); }
.search-results { list-style: none; margin: 12px 0 0; padding: 0; max-height: 280px; overflow-y: auto; }
.search-results li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--card);
  cursor: pointer;
  transition: .15s;
}
.search-results li:hover { border-color: var(--primary); }
.search-results .res-main { min-width: 0; }
.search-results .res-title { font-weight: 600; }
.search-results .res-sub { font-size: .82rem; color: var(--muted); }
.search-results .res-tags { display: flex; gap: 6px; flex-shrink: 0; }
.res-badge {
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.res-badge.synced { background: var(--done); color: var(--accent-2); }
.res-badge.plain { background: var(--active); color: var(--text); }

/* SYNC */
.audio-loader { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
#player { width: 100%; margin-bottom: 10px; }
#player-video { width: 100%; max-height: 360px; margin-bottom: 10px; background: #000; border-radius: 8px; }

.waveform {
  width: 100%;
  height: 64px;
  display: block;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  cursor: crosshair;
}

.sync-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.speed { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.speed label { color: var(--muted); font-size: .85rem; }
.speed select { width: auto; padding: 6px 8px; }

.sync-settings {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.sync-settings summary {
  cursor: pointer;
  font-size: .9rem;
  color: var(--muted);
  -webkit-user-select: none;
  user-select: none;
}
.sync-settings[open] summary { color: var(--text); margin-bottom: 10px; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 16px;
}
.setting {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .85rem;
  color: var(--muted);
}
.setting input[type=number] { width: 100px; padding: 6px 8px; }
.setting.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  cursor: pointer;
}

.stamp-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.advanced-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
  padding: 10px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.adv-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.adv-label { font-size: .82rem; color: var(--muted); margin-right: 4px; }

.lines {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.lines li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.lines li:last-child { border-bottom: none; }
.lines li.current { background: var(--active); }
.lines li.tagged { background: var(--done); }
.lines li.current.tagged { background: var(--active); }
.lines li.playing { box-shadow: inset 4px 0 0 var(--accent); }
.lines .time {
  flex: 0 0 86px;
  font-variant-numeric: tabular-nums;
  font-family: "Cascadia Code", monospace;
  color: var(--accent-2);
  font-size: .88rem;
}
.lines .time.empty { color: var(--muted); opacity: .5; }
.lines .text { flex: 1; min-width: 0; word-break: break-word; }
.lines .text.blank { color: var(--muted); font-style: italic; }
.lines .row-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .15s;
}
.lines li:hover .row-actions,
.lines li.current .row-actions { opacity: 1; }
.row-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: .8rem;
  border-radius: 4px;
  font-family: inherit;
}
.row-btn:hover { background: var(--card-2); border-color: var(--line); color: var(--text); }

.word-tag {
  display: inline-block;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--accent-2);
  font-family: "Cascadia Code", monospace;
  font-size: .72rem;
  padding: 1px 4px;
  border-radius: 3px;
  margin: 0 2px;
  vertical-align: middle;
}

/* VALIDATION */
.validation {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--warn) 15%, var(--card-2));
  border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line));
  color: var(--text);
  font-size: .88rem;
}
.validation.error {
  background: color-mix(in srgb, var(--error) 15%, var(--card-2));
  border-color: color-mix(in srgb, var(--error) 40%, var(--line));
}
.validation ul { margin: 6px 0 0; padding-left: 22px; }
.validation li { margin: 2px 0; }
.validation strong { color: var(--accent-2); }

/* PREVIEW SECTION */
.preview-section {
  margin-top: 20px;
  padding: 16px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.preview-section h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--accent-2);
}
#live-preview, #lrc-output {
  font-family: "Cascadia Code", monospace;
  font-size: .85rem;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 12px;
  width: 100%;
  line-height: 1.6;
}
.preview-stats {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  font-size: .82rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.preview-stats span {
  padding: 4px 10px;
  background: var(--card);
  border-radius: 6px;
}
.preview-stats #stats-warn { background: color-mix(in srgb, var(--warn) 30%, var(--card)); color: var(--text); }

.export-format-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: .9rem;
}
.export-format-bar select { width: auto; }

.foot { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 8px; }
.foot a { color: var(--primary); text-decoration: none; }
.foot a:hover { text-decoration: underline; }

/* KARAOKE */
.karaoke {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, #1b1f2e, #050608);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.karaoke-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.15);
  color: #fff;
  z-index: 2;
}
.karaoke-stage {
  width: 100%;
  max-width: 1100px;
  text-align: center;
  color: #fff;
}
.karaoke-prev, .karaoke-next {
  font-size: clamp(1rem, 2.5vw, 1.6rem);
  opacity: .35;
  margin: 12px 0;
  min-height: 2em;
  transition: opacity .3s;
}
.karaoke-current {
  font-size: clamp(2rem, 6vw, 4.5rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--accent-2);
  text-shadow: 0 0 24px color-mix(in srgb, var(--accent) 40%, transparent);
  min-height: 1.2em;
  transition: transform .3s;
}
.karaoke-current.flash { transform: scale(1.04); }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 998;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade .15s ease;
}
.modal-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 620px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
}
.shortcuts {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.shortcuts td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.shortcuts td:first-child { width: 160px; white-space: nowrap; }
.tips { padding-left: 22px; font-size: .9rem; color: var(--muted); }
.tips li { margin: 4px 0; }

.projects-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
}
.projects-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
}
.projects-list .proj-info { flex: 1; min-width: 0; }
.projects-list .proj-title { font-weight: 600; }
.projects-list .proj-sub { font-size: .8rem; color: var(--muted); }

/* SNACKBAR */
.snackbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: .9rem;
  animation: slide-up .2s ease;
}
@keyframes slide-up { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.snackbar-action {
  background: transparent;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: .9rem;
}
.snackbar-action:hover { text-decoration: underline; }

@media (max-width: 600px) {
  .app { padding: 14px 10px 80px; }
  .topbar { grid-template-columns: auto 1fr auto; }
  .topbar h1 { font-size: 1.6rem; }
  .meta-grid { grid-template-columns: 1fr; }
  .speed { margin-left: 0; }
  .lines .time { flex: 0 0 70px; font-size: .78rem; }
  .lines .row-actions { opacity: 1; }
  .btn { padding: 9px 12px; font-size: .85rem; }
  .btn.big { padding: 16px 16px; font-size: 1rem; width: 100%; }
  .stamp-bar { position: sticky; bottom: 0; padding: 8px; background: var(--card); margin: 0 -22px -22px; border-top: 1px solid var(--line); }
  .modal-card { max-height: 95vh; }
}

