/* ---------- nền tảng ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #120a0e;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.075);
  --ink: #f7ece9;
  --muted: #bda6ac;
  --line: rgba(255, 255, 255, 0.1);
  --rose: #eaa0ac;
  --gold: #f0c98b;
  --danger: #e0736f;
  --radius: 18px;
  --max: 1160px;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-weight: 300;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  background-color: var(--bg);
  background-image: radial-gradient(1100px 620px at 10% -12%, rgba(234, 160, 172, 0.22), transparent 62%),
    radial-gradient(900px 520px at 94% 2%, rgba(240, 201, 139, 0.14), transparent 64%),
    linear-gradient(180deg, #150b11 0%, #120a0e 46%, #180d14 100%);
  background-attachment: fixed;
}

h1,
h2,
h3 {
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

a {
  color: var(--gold);
  text-decoration: none;
}

code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.85em;
  background: rgba(240, 201, 139, 0.14);
  color: var(--gold);
  padding: 0.1em 0.42em;
  border-radius: 6px;
}

/* ---------- thanh trên ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px clamp(16px, 4vw, 32px);
  backdrop-filter: blur(14px);
  background: linear-gradient(180deg, rgba(18, 10, 14, 0.9), rgba(18, 10, 14, 0.35));
}

.brand {
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.brand-dot {
  color: var(--rose);
  margin: 0 2px;
}

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

.nav a {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--muted);
  transition: color 0.18s ease, background 0.18s ease;
}

.nav a:hover {
  color: var(--ink);
  background: var(--panel);
}

.nav a.is-active {
  color: var(--ink);
  background: var(--panel-strong);
}

.nav .nav-cta {
  color: #2a1017;
  background: linear-gradient(135deg, var(--rose), var(--gold));
  font-weight: 600;
  margin-left: 6px;
}

.nav .nav-cta:hover {
  color: #2a1017;
  filter: brightness(1.06);
}

/* ---------- khối hero ---------- */
#app {
  display: block;
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 40px) clamp(16px, 4vw, 32px) clamp(40px, 7vw, 80px);
}

.hero {
  max-width: 780px;
  padding: clamp(14px, 3vw, 30px) 0 clamp(24px, 4vw, 44px);
}

.hero-sub {
  padding-bottom: clamp(18px, 3vw, 30px);
}

.eyebrow {
  margin: 0 0 14px;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}

.hero-title {
  font-size: clamp(2rem, 5.4vw, 3.5rem);
  line-height: 1.08;
  background: linear-gradient(120deg, #fff4ef 12%, var(--rose) 58%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--ink);
}

.lede {
  margin: 16px 0 0;
  max-width: 60ch;
  color: var(--muted);
  font-size: 1rem;
}

.dedication {
  margin: 18px 0 0;
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
  font-style: italic;
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  color: #f2d9d4;
}

.meta {
  margin: 12px 0 0;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
}

/* ---------- nút ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: progress;
}

.btn-primary {
  color: #2a1017;
  background: linear-gradient(135deg, var(--rose), var(--gold));
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.07);
}

.btn-ghost {
  color: var(--ink);
  background: var(--panel);
  border-color: var(--line);
}

.btn-ghost:hover {
  background: var(--panel-strong);
}

.btn-danger {
  color: #ffd9d7;
  background: rgba(224, 115, 111, 0.16);
  border-color: rgba(224, 115, 111, 0.45);
}

.btn-danger:hover {
  background: rgba(224, 115, 111, 0.26);
}

/* ---------- bố cục hai cột ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 0.9fr);
  gap: clamp(18px, 2.6vw, 34px);
  align-items: start;
}

.paper {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(20px, 4vw, 46px);
  backdrop-filter: blur(8px);
  box-shadow: 0 26px 70px -50px rgba(0, 0, 0, 0.9);
}

.cover {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: clamp(20px, 3vw, 32px);
  border: 1px solid var(--line);
}

/* ---------- lời bài hát ---------- */
.ly-section {
  margin: clamp(26px, 4vw, 38px) 0 12px;
  font-size: 0.76rem;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--rose);
}

.ly-section:first-child {
  margin-top: 0;
}

.ly-line {
  margin: 0 0 6px;
  font-size: clamp(1rem, 1.5vw, 1.12rem);
  line-height: 1.95;
  color: #ece0dd;
  transition: color 0.35s ease, opacity 0.35s ease, transform 0.35s ease;
}

.ly-gap {
  height: 10px;
}

.chip-title {
  color: var(--gold);
  border-bottom: 1px dashed rgba(240, 201, 139, 0.45);
  cursor: pointer;
  padding: 0 1px;
  border-radius: 3px;
  transition: color 0.18s ease, background 0.3s ease;
}

.chip-title:hover,
.chip-title:focus-visible {
  color: #ffe9c4;
  background: rgba(240, 201, 139, 0.12);
  outline: none;
}

.chip-flash {
  background: rgba(240, 201, 139, 0.3);
  color: #fff6e6;
}

.lyrics.is-reading .ly-line,
.is-reading .ly-line {
  opacity: 0.34;
}

.is-reading .ly-line.is-active {
  opacity: 1;
  color: #fff4ef;
  transform: translateX(4px);
}

/* ---------- cột phải ---------- */
.aside {
  position: sticky;
  top: 84px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(18px, 2.4vw, 26px);
}

.aside-title {
  font-size: 1.05rem;
  margin-bottom: 6px;
}

.aside-note {
  margin: 0 0 14px;
  font-size: 0.82rem;
  color: var(--muted);
}

.aside-foot {
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 0.74rem;
  color: rgba(189, 166, 172, 0.8);
}

.title-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: min(58vh, 520px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.title-list li + li {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.title-btn {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 8px 4px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.87rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.title-btn:hover {
  background: var(--panel-strong);
  color: var(--gold);
}

.num {
  min-width: 22px;
  font-size: 0.72rem;
  color: rgba(234, 160, 172, 0.75);
  font-variant-numeric: tabular-nums;
}

.tname {
  flex: 1;
}

/* ---------- thư viện ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 168px;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.card:hover {
  transform: translateY(-3px);
  border-color: rgba(240, 201, 139, 0.4);
  background: var(--panel-strong);
}

.card-eyebrow {
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--rose);
}

.card-title {
  font-size: 1.16rem;
  line-height: 1.3;
}

.card-ded {
  margin: 0;
  flex: 1;
  font-size: 0.87rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 0.76rem;
  color: rgba(189, 166, 172, 0.85);
}

.load-wrap {
  display: flex;
  justify-content: center;
  margin-top: 26px;
}

.empty {
  padding: 32px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

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

/* ---------- khung xương ---------- */
.skeleton {
  height: 14px;
  margin-bottom: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.w40 {
  width: 40%;
}
.w60 {
  width: 60%;
}
.w70 {
  width: 70%;
}
.w80 {
  width: 80%;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* ---------- trình ghép bài ---------- */
.editor {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.85fr);
  gap: clamp(18px, 2.6vw, 32px);
  align-items: start;
}

.editor-fields,
.editor-side > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 30px);
}

.editor-side {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 84px;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.76rem;
  color: rgba(240, 201, 139, 0.75);
}

.input,
.textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(10, 5, 8, 0.55);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: rgba(240, 201, 139, 0.55);
  box-shadow: 0 0 0 3px rgba(240, 201, 139, 0.12);
}

.textarea {
  resize: vertical;
  min-height: 260px;
}

.editor-status {
  min-height: 20px;
  margin: 4px 0 14px;
  font-size: 0.84rem;
  color: var(--muted);
}

.editor-status.is-error {
  color: #ffb3b0;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.chip-btn {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid rgba(240, 201, 139, 0.28);
  background: rgba(240, 201, 139, 0.08);
  color: #f4dcb4;
  font-family: inherit;
  font-size: 0.79rem;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.chip-btn:hover {
  background: rgba(240, 201, 139, 0.2);
  border-color: rgba(240, 201, 139, 0.5);
  transform: translateY(-1px);
}

.preview-body {
  max-height: 340px;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
}

.preview-body .ly-line {
  font-size: 0.92rem;
  line-height: 1.8;
  margin-bottom: 4px;
}

.preview-body .ly-section {
  margin: 16px 0 8px;
  font-size: 0.68rem;
}

/* ---------- chân trang ---------- */
.footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 26px clamp(16px, 4vw, 32px) 44px;
  font-size: 0.76rem;
  color: rgba(189, 166, 172, 0.7);
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* ---------- đáp ứng ---------- */
@media (max-width: 1023px) {
  .layout,
  .editor {
    grid-template-columns: minmax(0, 1fr);
  }

  .aside,
  .editor-side {
    position: static;
  }

  .title-list {
    max-height: 320px;
  }
}

@media (min-width: 1024px) {
  .hero {
    max-width: 860px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 14px;
    gap: 8px;
  }

  .brand {
    font-size: 1.05rem;
  }

  .nav a {
    padding: 7px 10px;
    font-size: 0.82rem;
  }

  .nav .nav-cta {
    margin-left: 2px;
  }

  .hero-title {
    font-size: clamp(1.75rem, 8vw, 2.4rem);
  }

  .hero-actions .btn {
    flex: 1 1 auto;
  }

  .paper {
    padding: 20px 18px;
  }

  .ly-line {
    line-height: 1.85;
  }

  .grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
