:root {
  --bg: #160d09;
  --card: #221711;
  --card-2: #2d211b;
  --line: #4d3327;
  --text: #fff7ed;
  --muted: #c8afa0;
  --accent: #ffb380;
  --accent-2: #f4d3bd;
  --primary: #993300;
  --primary-d: #b84a12;
  --active: #3a251b;
  --done: #4a2f20;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  background: radial-gradient(1400px 700px at 50% -200px, #993300 0%, #663018 30%, #2b1710 58%, var(--bg) 88%);
  color: var(--text);
  line-height: 1.5;
}

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

.topbar { text-align: center; margin-bottom: 24px; }
.topbar h1 {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: 1px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 2px 14px rgba(255, 179, 128, .28);
}
.topbar h1 span { color: var(--accent-2); font-weight: 700; }
.tagline {
  color: var(--accent-2);
  margin: 6px 0 0;
  font-weight: 600;
  letter-spacing: 1.5px;
  font-size: .92rem;
  text-transform: uppercase;
}

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

.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);
}
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 { border-color: var(--primary); }
.btn:focus-visible, .search-result:focus-visible, .lines li:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff7ed; font-weight: 600; }
.btn.primary:hover { background: var(--primary-d); border-color: var(--primary-d); color: #fff7ed; }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1rem; padding: 14px 20px; }
.btn.compact { padding: 7px 10px; font-size: .82rem; }
.btn.danger { color: #ffcfb0; }
.btn kbd {
  background: rgba(0,0,0,.3);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: .75rem;
  margin-left: 6px;
}
.file-btn { display: inline-flex; align-items: center; }

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

/* 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-result {
  display: flex;
  width: 100%;
  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;
  color: var(--text);
  text-align: left;
  font: inherit;
}
.search-result:hover { border-color: var(--primary); }
.search-results .res-main { min-width: 0; }
.search-results .res-title, .search-results .res-sub { display: block; }
.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; }
.media-empty { margin: -6px 0 14px; color: var(--muted); font-size: .82rem; }
#player { width: 100%; margin-bottom: 14px; }
#player-video { width: 100%; max-height: 360px; margin-bottom: 14px; background: #000; border-radius: 8px; }

.waveform-wrap {
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.waveform {
  width: 100%;
  min-height: 80px;
  cursor: crosshair;
}
.waveform-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font-size: .78rem;
  flex-wrap: wrap;
}
.waveform-time {
  font-family: "Cascadia Code", monospace;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}
.waveform-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  color: var(--muted);
  font-size: .85rem;
}
@media (max-width: 600px) {
  .waveform { min-height: 64px; }
  .waveform-meta { font-size: .72rem; }
}

.sync-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px;
  background: rgba(0, 0, 0, .08);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
}
.speed, .delay { display: flex; align-items: center; gap: 6px; }
.speed { margin-left: auto; }
.speed label, .delay label { color: var(--muted); font-size: .85rem; }
.speed select, .delay select { width: auto; padding: 6px 8px; }

.stamp-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  grid-template-areas: "stamp nav";
  gap: 8px 10px;
  align-items: stretch;
  margin-bottom: 10px;
}
.stamp-bar #stamp {
  grid-area: stamp;
  width: 100%;
  min-height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.edit-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  padding: 8px;
  background: rgba(0, 0, 0, .08);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
}
.line-nav-group { grid-area: nav; justify-self: stretch; }
.button-group {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, .08);
}
.button-group .btn {
  border: 0;
  border-radius: 0;
  white-space: nowrap;
}
.button-group .btn + .btn { border-left: 1px solid var(--line); }
.button-group .btn:not(:disabled):hover { background: rgba(153, 51, 0, .18); }
.timestamp-clear-group { margin-left: auto; }
.timestamp-clear-group .btn:not(:disabled):hover { background: rgba(153, 51, 0, .22); }

.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: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.lines .line-number {
  flex: 0 0 28px;
  color: var(--muted);
  font-size: .78rem;
  text-align: right;
}
.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 .time {
  flex: 0 0 86px;
  font-variant-numeric: tabular-nums;
  font-family: "Cascadia Code", monospace;
  color: var(--accent-2);
  font-size: .9rem;
}
.lines .time.empty { color: var(--muted); opacity: .5; }
.lines .text { flex: 1; }
.lines .text.blank { color: var(--muted); font-style: italic; }
.line-editor {
  margin-top: 12px;
  padding: 12px;
  background: var(--card-2);
  border-radius: 8px;
}
.line-editor label { display: block; color: var(--muted); font-size: .82rem; margin-bottom: 6px; }
.line-editor-row { display: flex; gap: 8px; }
.line-editor-row input { flex: 1; }

/* 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);
}

/* Karaoke stage — chữ chạy theo nhạc */
.karaoke-preview {
  background: linear-gradient(180deg, rgba(153, 51, 0, .16), rgba(255, 179, 128, .05));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  height: 260px;
  overflow: hidden;
  position: relative;
  mask-image: linear-gradient(180deg, transparent 0, #000 18%, #000 82%, transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 18%, #000 82%, transparent 100%);
}
.karaoke-stage {
  height: 100%;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 100px 18px;
  text-align: center;
  scrollbar-width: none;
}
.karaoke-stage::-webkit-scrollbar { display: none; }
.karaoke-empty {
  color: var(--muted);
  font-style: italic;
  margin: 0;
  padding: 30px 10px;
}
.karaoke-line {
  display: block;
  margin: 14px 0;
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--muted);
  opacity: .45;
  transition: opacity .35s ease, color .35s ease, transform .35s ease, text-shadow .35s ease, font-size .35s ease;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: .2px;
}
.karaoke-line.past {
  opacity: .28;
  font-size: .92rem;
}
.karaoke-line.upcoming {
  opacity: .55;
}
.karaoke-line.current {
  color: var(--accent);
  opacity: 1;
  font-size: 1.42rem;
  font-weight: 700;
  text-shadow: 0 0 24px rgba(255, 179, 128, .45);
  transform: scale(1.02);
  letter-spacing: .4px;
}
.karaoke-line.unsynced {
  font-style: italic;
  opacity: .35;
}
.karaoke-line.blank::before { content: '♪'; opacity: .4; }

.raw-preview {
  margin-top: 14px;
}
.raw-preview summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .85rem;
  padding: 6px 0;
  user-select: none;
}
.raw-preview summary:hover { color: var(--accent-2); }
.raw-preview[open] summary { margin-bottom: 8px; }

#live-preview {
  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: 16px;
  margin-top: 10px;
  font-size: .85rem;
  color: var(--muted);
}
.preview-stats span {
  padding: 4px 10px;
  background: var(--card);
  border-radius: 6px;
}
.validation { margin-top: 10px; color: var(--muted); font-size: .85rem; }
.validation.warning, .export-warning, .error { color: #ffcfb0; }
.validation.success { color: #f4d3bd; }
.export-warning {
  background: rgba(153, 51, 0, .16);
  border: 1px solid rgba(255, 179, 128, .24);
  border-radius: 8px;
  padding: 10px 12px;
}
.review-player {
  padding: 16px;
  margin-bottom: 16px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.review-player-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.review-time {
  font-family: "Cascadia Code", monospace;
  font-size: clamp(2rem, 7vw, 4rem);
  line-height: 1;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.review-duration {
  color: var(--muted);
  font-size: .45em;
}
.review-seek {
  width: 100%;
  accent-color: var(--primary);
}
.review-media-status {
  margin-top: 8px;
}
.project-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.project-actions { display: flex; gap: 8px; }

#lrc-output { font-family: "Cascadia Code", monospace; font-size: .9rem; }

.foot { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 8px; }
.foot p { margin: 4px 0; }
.foot p:last-child {
  color: var(--accent);
  font-weight: 600;
  letter-spacing: .5px;
}
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 6, 4, .72);
  backdrop-filter: blur(5px);
}
.confirm-overlay[hidden] { display: none; }
.confirm-box {
  width: min(420px, 100%);
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .42);
}
.confirm-box h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--accent-2);
}
.confirm-box p {
  margin: 0;
  color: var(--text);
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

@media (max-width: 600px) {
  .meta-grid { grid-template-columns: 1fr; }
  .speed { margin-left: 0; }
  .card { padding: 16px; }
  .search-row, .project-bar { align-items: stretch; flex-direction: column; }
  .project-actions { flex-wrap: wrap; }
  .sync-controls { align-items: stretch; }
  .sync-controls .btn { flex: 1; }
  .speed, .delay { flex: 1 1 160px; }
  .speed select, .delay select { flex: 1; }
  .lines .line-number { display: none; }
  .lines li { padding: 10px; gap: 8px; }
  .lines .time { flex-basis: 82px; font-size: .82rem; }
  .preview-stats { flex-wrap: wrap; gap: 8px; }
  .review-player-main { align-items: stretch; flex-direction: column; }
  .review-actions .btn { flex: 1; }
  .review-time { text-align: left; }
  .karaoke-preview { height: 200px; }
  .karaoke-stage { padding: 70px 12px; }
  .karaoke-line { font-size: .95rem; }
  .karaoke-line.current { font-size: 1.2rem; }
}

@media (max-width: 460px) {
  .stamp-bar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "stamp"
      "nav";
  }
  .stamp-bar .btn.big { width: 100%; min-height: auto; }
  .line-editor-row { align-items: stretch; flex-direction: column; }
  .button-group { width: 100%; }
  .button-group .btn { flex: 1; min-width: 0; }
  .timestamp-clear-group { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
