:root {
  color-scheme: dark;
  /* Shared visual language with The Listening Room: warm + dark + intimate,
     here in a warm navy-blue key (cream text + copper accent on deep blue). */
  --bg: #16212c;
  --bg2: #1e2b38;
  --panel: #243341;
  --field: #0f1822;
  --cream: #f3ead9;
  --muted: #d0c7ad;
  --faint: #a39b83;
  --accent: #e6d2a3;
  --accent-soft: rgba(230, 210, 163, 0.16);
  --accent-line: rgba(230, 210, 163, 0.42);
  --danger: #cf7d68;
  --line: rgba(243, 234, 217, 0.1);
  --line-strong: rgba(243, 234, 217, 0.18);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.4);
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-family: var(--sans);
}

* {
  box-sizing: border-box;
}

/* `hidden` must win over component display rules (buttons set display:inline-flex). */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 820px at 50% -12%, #26384a 0%, var(--bg) 56%) no-repeat;
  background-attachment: fixed;
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 auto 16px;
  max-width: 1500px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 2px;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.topbar-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

/* ---------- Cloud-sync sign-in dialog ---------- */
.auth-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  color: var(--cream);
  max-width: 380px;
  padding: 22px;
  width: calc(100vw - 40px);
}

.auth-dialog::backdrop {
  background: rgba(11, 16, 22, 0.7);
}

.auth-status {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin-bottom: 16px;
}

.auth-dialog label {
  margin-bottom: 12px;
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.1em;
  margin-bottom: 8px;
}

.auth-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin-top: 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: var(--serif);
  font-size: clamp(2rem, 6.5vw, 3.4rem);
  font-weight: 400;
  letter-spacing: 0.5px;
  line-height: 1;
  text-shadow: 0 2px 26px rgba(0, 0, 0, 0.45);
}

h2 {
  font-family: var(--serif);
  font-size: 1.18rem;
  font-weight: 400;
}

/* ---------- View tabs ---------- */
.view-tabs {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, 1fr);
  margin: 0 auto 16px;
  max-width: 1500px;
  padding: 6px;
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 5;
}

.view-tab {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--faint);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 1px;
  min-height: 42px;
  padding: 0 10px;
  text-transform: uppercase;
  transition: color 0.3s, background 0.3s, border-color 0.3s;
}

.view-tab:hover {
  color: var(--cream);
}

.view-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

/* ---------- Workspace + panels ---------- */
.workspace {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.25fr) minmax(280px, 0.85fr);
  margin: 0 auto;
  max-width: 1500px;
}

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

.workspace.focused .panel:not(.active-view) {
  display: none;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.018), rgba(0, 0, 0, 0.14)), var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  min-height: 76vh;
  overflow: hidden;
}

.panel-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 18px 18px 16px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.songbook-header {
  align-items: stretch;
  flex-direction: column;
}

.panel-title-block {
  align-items: baseline;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-width: 0;
}

.songbook-header .header-actions {
  display: grid;
  gap: 8px;
}

.header-actions-secondary {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel-header p {
  color: var(--faint);
  flex: 0 0 auto;
  font-size: 0.86rem;
  margin-top: 4px;
}

.search-row,
.builder-controls {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 140px;
  padding: 14px 18px;
}

/* ---------- Form fields ---------- */
input,
select,
textarea {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--cream);
  min-width: 0;
  padding: 11px 13px;
  -webkit-appearance: none;
  appearance: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(230, 210, 163, 0.6);
  outline: none;
}

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--faint) 50%), linear-gradient(135deg, var(--faint) 50%, transparent 50%);
  background-position: calc(100% - 18px) 1.1em, calc(100% - 13px) 1.1em;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
  padding-right: 32px;
}

select option {
  background: var(--bg2);
  color: var(--cream);
}

textarea {
  line-height: 1.5;
  resize: vertical;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.8rem;
  font-weight: 600;
  gap: 6px;
}

/* ---------- Buttons ---------- */
.primary-button,
.secondary-button,
.icon-button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 44px;
  padding: 0 15px;
  transition: color 0.3s, background 0.3s, border-color 0.3s;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #1d1713;
  letter-spacing: 0.3px;
}

.primary-button:hover {
  background: #efdcb2;
  border-color: #efdcb2;
}

.secondary-button {
  background: rgba(243, 234, 217, 0.02);
  border-color: var(--line);
  color: var(--cream);
}

.secondary-button:hover {
  background: rgba(230, 210, 163, 0.1);
  border-color: var(--accent-line);
  color: var(--accent);
}

.icon-button {
  aspect-ratio: 1;
  background: rgba(243, 234, 217, 0.02);
  border-color: var(--line);
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0;
  width: 44px;
}

.icon-button:hover {
  border-color: var(--accent-line);
  color: var(--accent);
}

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

.danger:hover {
  border-color: rgba(207, 125, 104, 0.5);
  color: var(--danger);
}

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

.danger-text:hover {
  border-color: rgba(207, 125, 104, 0.5);
  color: var(--danger);
}

/* ---------- Song + set lists ---------- */
.song-list,
.setlist {
  display: grid;
  gap: 8px;
  max-height: calc(76vh - 130px);
  overflow: auto;
  padding: 0 18px 18px;
}

.song-row,
.set-row {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.012), rgba(0, 0, 0, 0.08));
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  transition: transform 0.3s, border-color 0.3s, box-shadow 0.3s;
  width: 100%;
}

.song-row {
  align-items: stretch;
  grid-template-columns: 1fr auto;
  overflow: hidden;
}

.song-main {
  background: transparent;
  border: 0;
  color: inherit;
  display: grid;
  gap: 9px;
  min-width: 0;
  padding: 13px 14px;
  text-align: left;
}

.song-add {
  align-self: stretch;
  background: transparent;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--faint);
  font-size: 1.5rem;
  line-height: 1;
  transition: color 0.3s, background 0.3s;
  width: 50px;
}

.song-add:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.song-add.in {
  color: var(--accent);
}

.song-row:hover {
  border-color: var(--accent-line);
  transform: translateY(-1px);
}

.song-row.active {
  border-color: rgba(230, 210, 163, 0.6);
  box-shadow: inset 3px 0 0 var(--accent);
}

.song-row h3,
.set-row h3 {
  color: var(--cream);
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 400;
  margin: 0;
  transition: color 0.3s;
}

.song-row:hover h3 {
  color: var(--accent);
}

.song-row p,
.set-row p {
  color: var(--faint);
  font-size: 0.84rem;
}

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

.pill {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--faint);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 3px 9px;
  text-transform: uppercase;
}

.pill.memorized {
  border-color: rgba(174, 191, 142, 0.38);
  color: #b1c191;
}

.pill.learning {
  border-color: rgba(216, 176, 106, 0.42);
  color: #d8b06a;
}

.pill.chords {
  border-color: rgba(159, 185, 194, 0.36);
  color: #a3bcc4;
}

.pill.chart-pill {
  border-color: var(--accent-line);
  color: var(--accent);
}

/* ---------- Empty states ---------- */
.empty-state {
  align-content: center;
  color: var(--muted);
  display: grid;
  justify-items: center;
  min-height: 76vh;
  padding: 36px;
  text-align: center;
}

.empty-state h2 {
  color: var(--cream);
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  line-height: 1.6;
  max-width: 34ch;
}

.empty-mark {
  align-items: center;
  background: rgba(230, 210, 163, 0.08);
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  color: var(--accent);
  display: flex;
  font-size: 2rem;
  height: 76px;
  justify-content: center;
  margin-bottom: 16px;
  width: 76px;
}

/* ---------- Song detail form ---------- */
.song-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.hidden {
  display: none;
}

.form-topline {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 44px;
}

.title-input {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 400;
}

.form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, 1fr);
}

.form-actions,
.set-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.chart-box {
  align-items: center;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  padding: 13px 14px;
}

.field-label {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.chart-box p {
  color: var(--cream);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.chart-actions {
  display: flex;
  gap: 8px;
}

.visually-hidden {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

/* ---------- Set builder ---------- */
.builder-controls {
  grid-template-columns: 92px 1fr;
}

.setlist {
  max-height: calc(76vh - 196px);
}

.set-row {
  align-items: center;
  gap: 10px;
  grid-template-columns: 24px 1fr auto;
  padding: 9px 12px;
}

.set-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

.set-controls .icon-button {
  font-size: 1.15rem;
  min-height: 36px;
  width: 36px;
}

.set-controls .icon-button:disabled {
  cursor: default;
  opacity: 0.3;
}

.set-song-button {
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: inherit;
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 7px;
  text-align: left;
}

.set-song-button.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.set-number {
  color: var(--faint);
  font-family: var(--serif);
  font-size: 1.1rem;
  font-style: italic;
}

.set-actions {
  border-top: 1px solid var(--line);
  padding: 18px;
}

/* ---------- Live mode ---------- */
.live-dialog {
  background: var(--bg);
  border: 0;
  color: var(--cream);
  height: 100dvh;
  max-height: none;
  max-width: none;
  padding: 0;
  width: 100vw;
}

.live-dialog::backdrop {
  background: #0b1016;
}

.live-stage {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
}

.live-toolbar {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 52px;
}

.live-toolbar .icon-button {
  background: rgba(243, 234, 217, 0.04);
  border-color: var(--line);
  color: var(--cream);
  min-height: 52px;
  width: 52px;
}

.live-counter {
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 1.5px;
  text-align: center;
}

.live-card {
  overflow: auto;
  padding: 18px min(6vw, 56px) 50px;
}

.live-kicker {
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.live-card h2 {
  font-family: var(--serif);
  font-size: clamp(2.3rem, 8vw, 6rem);
  font-weight: 400;
  line-height: 1.02;
  margin-bottom: 14px;
}

.live-card p {
  color: var(--muted);
  font-size: clamp(1.1rem, 3vw, 1.7rem);
  line-height: 1.4;
  margin-bottom: 18px;
}

.live-card pre {
  color: var(--cream);
  font-family: var(--sans);
  font-size: clamp(1.4rem, 4.4vw, 2.8rem);
  line-height: 1.45;
  margin: 0;
  white-space: pre-wrap;
}

.live-card pre[hidden] {
  display: none;
}

.live-chart {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0 0 20px;
  overflow: hidden;
}

.live-chart-header {
  align-items: center;
  background: var(--bg2);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 11px 14px;
}

.live-chart-header strong {
  color: var(--cream);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.live-chart-header a {
  color: var(--accent);
  flex: 0 0 auto;
  font-weight: 700;
  text-decoration: none;
}

.live-chart-header a:hover {
  text-decoration: underline;
}

.live-chart iframe {
  background: white;
  border: 0;
  display: block;
  height: min(72vh, 780px);
  width: 100%;
}

.live-chart pre {
  background: #0c131b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(1.15rem, 3vw, 2rem);
  max-height: 72vh;
  overflow: auto;
  padding: 16px;
}

.live-bottom-nav {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  padding-top: 12px;
}

.live-nav-button {
  align-items: center;
  background: rgba(243, 234, 217, 0.03);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--cream);
  display: flex;
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  font-weight: 700;
  justify-content: center;
  min-height: 64px;
  transition: color 0.3s, background 0.3s, border-color 0.3s;
}

.live-nav-button:hover {
  border-color: var(--accent-line);
  color: var(--accent);
}

.live-nav-button:active {
  background: rgba(230, 210, 163, 0.14);
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 320px 1fr;
  }

  .set-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }

  .setlist {
    max-height: 320px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .view-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .overview-tab {
    display: none;
  }

  .workspace:not(.focused) .panel:not(.active-view) {
    display: none;
  }

  .panel {
    min-height: auto;
  }

  .song-list,
  .setlist {
    max-height: none;
  }

  .form-grid,
  .search-row,
  .builder-controls {
    grid-template-columns: 1fr 1fr;
  }

  .detail-panel {
    order: 2;
  }

  .set-panel {
    order: 3;
  }

  /* iOS zooms the page when focusing an input under 16px — pin them. */
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 430px) {
  .view-tab {
    min-height: 44px;
    padding: 0 6px;
  }

  .form-grid,
  .search-row,
  .builder-controls {
    grid-template-columns: 1fr;
  }

  .chart-box {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .set-actions {
    grid-template-columns: 1fr 1fr;
  }

  .chart-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .header-actions-secondary {
    grid-template-columns: 1fr 1fr;
  }

  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions,
  .songbook-header .header-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
