*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #07080d;
  --panel: #0e1020;
  --panel2: #14162a;
  --panel3: #191c35;
  --border: #242846;
  --text: #ececf5;
  --muted: #8486a3;
  --quiet: #5d607c;
  --home: #7eb8ff;
  --t1: #7affb8;
  --t2: #ffc96e;
  --t3: #ff7eb8;
  --gold: #ffd700;
  --danger: #ff6f91;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 18% 12%, rgba(126,184,255,0.08), transparent 36%),
    radial-gradient(ellipse at 88% 4%, rgba(255,126,184,0.06), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(10, 12, 24, 0.86);
  padding: 1.4rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.sidebar-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.brand {
  min-width: 0;
}

.eyebrow,
.field span {
  color: var(--quiet);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: 'Playfair Display', serif;
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 2.8rem;
  line-height: 0.95;
  background: linear-gradient(135deg, #7eb8ff, #c3a6ff 52%, #ff7eb8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 { font-size: clamp(2rem, 4vw, 3rem); color: var(--home); }
h3 { font-size: 1.5rem; color: var(--home); }

.workspace {
  padding: 1.6rem;
  max-width: 1440px;
  width: 100%;
}

.workspace-header,
.song-meta-panel,
.section-toolbar,
.song-section,
.chord-dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(14, 16, 32, 0.82);
}

.workspace-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem;
  margin-bottom: 1rem;
}

.header-actions {
  display: flex;
  align-items: end;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.header-actions .primary-btn {
  width: auto;
}

.song-meta-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.8fr) minmax(150px, 0.4fr);
  gap: 0.8rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.compact-field {
  min-width: 150px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0d0f1e;
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 2.45rem;
  padding: 0 0.75rem;
}

textarea {
  resize: vertical;
  padding: 0.8rem;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--home);
  box-shadow: 0 0 0 3px rgba(126,184,255,0.12);
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.icon-btn {
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel2);
  min-height: 2.45rem;
  padding: 0 0.95rem;
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, #1a3d68, #302456);
  border-color: rgba(126,184,255,0.5);
}

.secondary-btn {
  background: #162039;
  border-color: rgba(126,184,255,0.28);
}

.ghost-btn {
  background: transparent;
}

.menu-wrap {
  position: relative;
  flex: 0 0 auto;
}

.menu-trigger[aria-expanded="true"] {
  border-color: rgba(126,184,255,0.48);
  background: #162039;
}

.action-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 20;
  width: max-content;
  min-width: 11rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101225;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  padding: 0.35rem;
}

.action-menu button {
  width: 100%;
  min-height: 2.25rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  display: block;
  padding: 0 0.7rem;
  text-align: left;
}

.action-menu button:hover,
.action-menu button:focus {
  background: var(--panel3);
  outline: none;
}

.action-menu button.danger {
  color: var(--danger);
}

.danger {
  color: var(--danger);
}

.sidebar-actions {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(14, 16, 32, 0.78);
  margin-bottom: 0.9rem;
  padding: 0.75rem;
}

.sidebar-actions .secondary-btn {
  width: 100%;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.song-search {
  margin: 0.8rem 0;
}

.song-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.song-list-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.4rem;
  gap: 0.35rem;
  padding: 0.35rem;
}

.song-list-item.active {
  border-color: var(--home);
  background: #121d37;
}

.song-open-btn {
  min-width: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.4rem;
  text-align: left;
}

.song-open-btn:hover,
.song-open-btn:focus {
  background: rgba(126,184,255,0.08);
  outline: none;
}

.song-menu-wrap {
  align-self: center;
}

.song-row-menu {
  right: 0;
}

.song-list-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-list-meta {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

.section-toolbar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.sections-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.reading-panel {
  max-width: 920px;
  margin: 0 auto;
}

.song-sheet {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(14, 16, 32, 0.86);
  color: var(--text);
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

.sheet-artist {
  margin: 0;
  padding: 1.25rem 2rem 0;
  color: var(--muted);
  font-size: 1rem;
}

.sheet-sections {
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  padding: 1.6rem 2rem 2rem;
}

.sheet-section {
  padding-bottom: 1.6rem;
  border-bottom: 1px solid var(--border);
}

.sheet-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.sheet-section h4 {
  margin: 0 0 0.8rem;
  color: var(--home);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sheet-chords {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.sheet-chord-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
}

.sheet-chord {
  min-height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.86rem;
}

.sheet-chord small {
  color: var(--muted);
  font-size: 0.68rem;
}

.empty-chord {
  color: var(--quiet);
}

.sheet-lyrics {
  white-space: pre-wrap;
  color: var(--text);
  font-size: 1.06rem;
  line-height: 1.72;
}

.muted-lyrics,
.empty-reading {
  color: var(--muted);
  font-style: italic;
}

.song-section {
  padding: 1rem;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.section-name {
  font-weight: 700;
  color: var(--home);
}

.lyrics-input {
  min-height: 11rem;
  margin-bottom: 0.9rem;
}

.grids-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.chord-grid-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 2.45rem;
  gap: 0.5rem;
  align-items: start;
}

.section-menu-wrap,
.row-menu-wrap {
  align-self: start;
}

.add-grid-btn,
.add-section-end {
  margin-top: 0.75rem;
}

.add-section-end {
  width: 100%;
}

.chord-cell {
  min-height: 3.2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 0.75rem;
}

.cell-roman {
  color: var(--muted);
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
}

.cell-name {
  font-family: 'DM Mono', monospace;
  font-size: 0.9rem;
}

.empty-cell {
  color: var(--quiet);
}

.chord-dialog {
  width: min(980px, calc(100vw - 2rem));
  max-height: min(780px, calc(100vh - 2rem));
  color: var(--text);
  padding: 1rem;
}

.chord-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.icon-btn {
  width: 2.4rem;
  padding: 0;
}

.menu-trigger {
  font-size: 1.2rem;
  line-height: 1;
}

.tier-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 0.8rem;
}

.tier-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.tier-header {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.tier-title {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
}

.tier-meta,
.tier-count {
  color: var(--quiet);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tier-count {
  font-family: 'DM Mono', monospace;
  font-size: 1.3rem;
}

.picker-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.75rem;
}

.chord-picker {
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--panel2);
  color: var(--text);
  display: grid;
  grid-template-columns: 6px 2.8rem 1fr;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.35rem;
  padding: 0 0.65rem;
}

.chord-picker:hover {
  background: var(--panel3);
}

.chord-picker.is-dim {
  opacity: 0.45;
  cursor: default;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
}

.card-home { border-top: 2px solid var(--home); }
.card-t1 { border-top: 2px solid var(--t1); }
.card-t2 { border-top: 2px solid var(--t2); }
.card-t3 { border-top: 2px solid var(--t3); }
.card-home .tier-title, .card-home .tier-count { color: var(--home); }
.card-t1 .tier-title, .card-t1 .tier-count { color: var(--t1); }
.card-t2 .tier-title, .card-t2 .tier-count { color: var(--t2); }
.card-t3 .tier-title, .card-t3 .tier-count { color: var(--t3); }
.card-home .dot { background: var(--home); }
.card-t1 .dot { background: var(--t1); }
.card-t2 .dot { background: var(--t2); }
.card-t3 .dot { background: var(--t3); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .song-meta-panel,
  .workspace-header {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }
  .tier-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .workspace { padding: 0.9rem; }
  .song-meta-panel,
  .section-toolbar,
  .section-head {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }
  .header-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .sheet-sections {
    padding: 1.2rem 1.4rem 1.4rem;
  }
  .chord-grid-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) 2.45rem;
  }
  .sheet-chord-row {
    grid-template-columns: 1fr;
  }
  .tier-grid { grid-template-columns: 1fr; }
}
