:root{
  --bg: #18120f;
  --bg-soft: #231a16;
  --panel: rgba(32, 24, 20, 0.92);
  --panel-strong: rgba(42, 31, 24, 0.98);
  --line: rgba(248, 221, 191, 0.14);
  --line-strong: rgba(248, 221, 191, 0.22);
  --text: #f4e7d5;
  --muted: #c9b7a6;
  --faint: #8c7666;
  --accent: #d79a44;
  --accent-2: #efc97c;
  --accent-3: #8b6a3d;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.34);
  --radius: 14px;
  --font-size: 1.15rem;
}

*{ box-sizing:border-box; }
html,body{ min-height:100%; }
body{
  margin:0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color:var(--text);
  background:
    radial-gradient(circle at top left, rgba(215,154,68,0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(239,201,124,0.08), transparent 24%),
    linear-gradient(180deg, #140f0d 0%, var(--bg) 100%);
  letter-spacing:0;
  font-size:16px;
}

body[data-dark="false"]{
  --bg: #e7dac8;
  --bg-soft: #f4eadc;
  --panel: rgba(249, 244, 236, 0.96);
  --panel-strong: rgba(255, 250, 244, 0.99);
  --line: rgba(84, 57, 36, 0.14);
  --line-strong: rgba(84, 57, 36, 0.22);
  --text: #201812;
  --muted: #5b493b;
  --faint: #7c6758;
  --shadow: 0 18px 40px rgba(55, 35, 19, 0.12);
  background:
    radial-gradient(circle at top left, rgba(215,154,68,0.20), transparent 28%),
    radial-gradient(circle at top right, rgba(255,220,154,0.24), transparent 24%),
    linear-gradient(180deg, #f6f0e7 0%, #e8dccb 100%);
}

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

button{
  border:1px solid var(--line-strong);
  border-radius:12px;
  background:linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
  cursor:pointer;
}

button:hover{ border-color: rgba(215,154,68,0.55); }
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible{
  outline:2px solid rgba(215,154,68,0.9);
  outline-offset:2px;
}

.panel{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
}

.app-shell{
  width:min(1560px, calc(100vw - 24px));
  margin:12px auto 24px;
  display:grid;
  gap:12px;
}

.topbar{
  display:flex;
  justify-content:space-between;
  gap:16px;
  padding:16px;
  align-items:flex-start;
}

.brand{
  display:flex;
  gap:14px;
  align-items:flex-start;
  min-width:0;
}

.brand-mark{
  width:68px;
  height:68px;
  border-radius:18px;
  overflow:hidden;
  background:linear-gradient(180deg, rgba(215,154,68,0.98), rgba(140,98,39,0.98));
  border:1px solid rgba(255, 236, 197, 0.36);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.38), 0 10px 20px rgba(0,0,0,0.18);
  flex:0 0 auto;
}

.brand-mark img{ width:100%; height:100%; display:block; }

.brand-copy{ min-width:0; }
.eyebrow{
  margin:0 0 4px;
  text-transform:uppercase;
  letter-spacing:0.14em;
  color:var(--accent-2);
  font-size:0.74rem;
  font-weight:700;
}
h1{
  margin:0;
  font-size:2.7rem;
  line-height:0.98;
  font-weight:700;
}
.lede{
  margin:8px 0 0;
  color:var(--muted);
  max-width:62ch;
  line-height:1.45;
}

.topbar-meta{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:10px;
}

.mode-switch{
  display:inline-flex;
  gap:6px;
  padding:5px;
  border-radius:999px;
  background:rgba(255,255,255,0.04);
  border:1px solid var(--line);
}

.segmented{
  padding:10px 14px;
  border-radius:999px;
  border:1px solid transparent;
  background:transparent;
  color:var(--muted);
  font-weight:700;
}
.segmented.active{
  color:var(--text);
  background:linear-gradient(180deg, rgba(215,154,68,0.22), rgba(215,154,68,0.12));
  border-color:rgba(215,154,68,0.35);
}

.topbar-actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.ghost-button,
.primary-button,
.control-button,
.remote-button{
  min-height:44px;
  padding:10px 14px;
}

.ghost-button.small{ min-height:38px; padding:8px 12px; }
.ghost-button{
  color:var(--text);
  background:rgba(255,255,255,0.04);
}
.ghost-button.danger{
  border-color:rgba(220,112,98,0.24);
}
.primary-button{
  background:linear-gradient(180deg, rgba(215,154,68,0.96), rgba(160,110,36,0.96));
  color:#1e1408;
  border-color:rgba(255,231,176,0.22);
  font-weight:700;
}

.hero{
  display:flex;
  justify-content:space-between;
  gap:16px;
  padding:14px 16px;
  align-items:flex-end;
}

.hero-stats{
  display:flex;
  gap:18px;
  flex-wrap:wrap;
  align-items:flex-end;
}
.stat-label{
  margin:0 0 4px;
  font-size:0.74rem;
  color:var(--faint);
  text-transform:uppercase;
  letter-spacing:0.12em;
  font-weight:700;
}
.stat-value{
  margin:0;
  font-size:1.6rem;
  font-weight:700;
  line-height:1;
}
.hero-chip-stack{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}
.hero-chip,
.status-pill,
.meta-chip{
  border-radius:999px;
  border:1px solid var(--line-strong);
  padding:7px 10px;
  background:rgba(255,255,255,0.03);
  color:var(--muted);
  font-size:0.84rem;
  font-weight:700;
}
.hero-callout{
  text-align:right;
  max-width:38ch;
}
.hero-next{
  margin:0;
  font-size:1.08rem;
  line-height:1.42;
  color:var(--text);
}

.workspace{
  display:grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr) minmax(320px, 420px);
  gap:12px;
  align-items:start;
}

.sidebar,
.stage-panel{
  padding:14px;
}

.panel-head{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:10px;
}

.panel-label{
  margin:0 0 4px;
  font-size:0.74rem;
  color:var(--faint);
  text-transform:uppercase;
  letter-spacing:0.12em;
  font-weight:700;
}
h2{
  margin:0;
  font-size:1.25rem;
  line-height:1.14;
}
h3{
  margin:0;
  font-size:1rem;
  line-height:1.2;
}

.search-field input,
.field input,
.field textarea,
.field select{
  width:100%;
  border:1px solid var(--line-strong);
  border-radius:12px;
  padding:12px 12px;
  background:var(--panel-strong);
  color:var(--text);
}

.search-field{
  display:block;
  margin:14px 0;
}

.song-list-wrap{
  min-height:200px;
}

.song-list{
  display:grid;
  gap:8px;
}

.song-item{
  border:1px solid var(--line);
  border-radius:12px;
  background:rgba(255,255,255,0.03);
  padding:11px 12px;
  cursor:pointer;
  text-align:left;
}
.song-item.active{
  border-color:rgba(215,154,68,0.65);
  background:linear-gradient(180deg, rgba(215,154,68,0.14), rgba(215,154,68,0.06));
}
.song-item-title{
  margin:0;
  font-weight:700;
}
.song-item-meta{
  margin:5px 0 0;
  color:var(--muted);
  font-size:0.92rem;
  line-height:1.35;
}

.empty-state{
  padding:16px 0;
  color:var(--muted);
}
.empty-title{
  margin:0;
  font-weight:700;
  color:var(--text);
}
.empty-copy{
  margin:6px 0 0;
  line-height:1.5;
}

.stage-panel{
  display:grid;
  gap:14px;
  position:relative;
}

.mode-rescue{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  justify-content:flex-end;
  align-items:center;
  position:sticky;
  top:10px;
  z-index:3;
  justify-self:end;
  width:fit-content;
  max-width:100%;
  padding:6px;
  border:1px solid var(--line);
  border-radius:999px;
  background:rgba(18, 12, 9, 0.62);
  box-shadow:0 12px 28px rgba(0,0,0,0.22);
  backdrop-filter:blur(14px) saturate(130%);
  -webkit-backdrop-filter:blur(14px) saturate(130%);
}

.rescue-button{
  min-height:38px;
  padding:8px 12px;
  border-radius:999px;
  border:1px solid transparent;
  background:transparent;
  color:var(--text);
  font-weight:700;
  white-space:nowrap;
}

.rescue-button.accent,
.rescue-button.active{
  background:linear-gradient(180deg, rgba(215,154,68,0.22), rgba(215,154,68,0.10));
  border-color:rgba(215,154,68,0.44);
}

.stage-head{
  align-items:flex-start;
}
.song-artist{
  margin:6px 0 0;
  color:var(--muted);
  font-size:1rem;
  line-height:1.35;
}

.meta-pills{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

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

.control-button{
  color:var(--text);
  background:rgba(255,255,255,0.04);
}
.control-button.accent{
  background:linear-gradient(180deg, rgba(215,154,68,0.26), rgba(215,154,68,0.10));
  border-color:rgba(215,154,68,0.34);
}

.chart-surface{
  min-height:360px;
  padding:18px 16px 14px;
  border-radius:16px;
  border:1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.01)),
    rgba(255,255,255,0.02);
}

.song-page{
  font-size:var(--font-size);
  line-height:1.55;
}

.song-page h3{
  margin:0 0 10px;
  font-size:1.05rem;
  color:var(--accent-2);
}

.chart-line{
  margin:0 0 2px;
  white-space:pre-wrap;
}

.lyric-line{
  margin:0 0 3px;
}

.lyric-token{
  display:inline-grid;
  grid-template-rows:auto auto;
  justify-items:start;
  vertical-align:bottom;
  margin-right:0.18em;
}

.lyric-chord{
  color:var(--accent-2);
  font-weight:700;
  font-size:0.78em;
  line-height:1;
  min-height:1em;
}

.lyric-text{
  white-space:pre-wrap;
}

.section-divider{
  margin:16px 0 10px;
  padding-top:10px;
  border-top:1px solid var(--line);
  text-transform:uppercase;
  letter-spacing:0.12em;
  color:var(--accent);
  font-size:0.74rem;
  font-weight:700;
}

.meta-line{
  color:var(--muted);
  font-size:0.95rem;
  line-height:1.45;
}

.notes-panel{
  padding:14px;
  border:1px solid var(--line);
  border-radius:16px;
  background:rgba(255,255,255,0.03);
}
.notes-body{
  margin-top:10px;
  color:var(--text);
  line-height:1.55;
  white-space:pre-wrap;
}

.remote-panel{
  display:grid;
  gap:14px;
  padding:6px 0 0;
}
.remote-note{
  margin:6px 0 0;
  color:var(--muted);
  line-height:1.45;
}
.remote-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
}
.remote-button{
  min-height:70px;
  font-size:1rem;
  font-weight:700;
  background:rgba(255,255,255,0.05);
}

.editor-panel{
  padding:14px;
  display:none;
  gap:14px;
}
.hidden-panel{ display:none; }

.import-box,
.setlist-box{
  border:1px solid var(--line);
  border-radius:14px;
  padding:12px;
  background:rgba(255,255,255,0.03);
}
.section-head{
  margin-bottom:10px;
}

.field{
  display:grid;
  gap:6px;
  margin-bottom:10px;
}
.field span{
  color:var(--muted);
  font-size:0.84rem;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:0.1em;
}
.field textarea{
  resize:vertical;
  min-height:88px;
}
.field-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
}
.action-row{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}
.field-help{
  margin:8px 0 0;
  color:var(--muted);
  line-height:1.45;
  font-size:0.92rem;
}

.setlist-summary{
  display:grid;
  gap:8px;
}
.setlist-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:8px;
  color:var(--muted);
  font-size:0.92rem;
}
.setlist-item{
  display:flex;
  justify-content:space-between;
  gap:8px;
  align-items:center;
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px 12px;
  background:rgba(255,255,255,0.03);
}
.setlist-item.active{
  border-color:rgba(215,154,68,0.62);
  background:linear-gradient(180deg, rgba(215,154,68,0.12), rgba(215,154,68,0.05));
}
.setlist-item-copy{
  min-width:0;
}
.setlist-item-title{
  margin:0;
  font-weight:700;
}
.setlist-item-sub{
  margin:4px 0 0;
  color:var(--muted);
  font-size:0.92rem;
}
.setlist-actions{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
}
.tiny-button{
  min-height:34px;
  padding:6px 9px;
  border-radius:10px;
  font-size:0.84rem;
}

.status-bar{
  position:fixed;
  left:50%;
  bottom:18px;
  transform:translateX(-50%);
  max-width:min(820px, calc(100vw - 24px));
  padding:10px 14px;
  border-radius:999px;
  background:rgba(24,18,14,0.92);
  border:1px solid rgba(255,255,255,0.08);
  color:var(--text);
  box-shadow:var(--shadow);
  opacity:0;
  pointer-events:none;
  transition:opacity .2s ease, transform .2s ease;
}
.status-bar.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}

.blackout{
  position:fixed;
  inset:0;
  z-index:50;
  background:#000;
  display:grid;
  place-items:end center;
  padding:clamp(18px, 5vw, 48px);
}

.blackout[hidden]{
  display:none;
}

.blackout-reveal{
  min-height:48px;
  padding:12px 18px;
  border-radius:999px;
  border:1px solid rgba(239,201,124,0.32);
  background:rgba(24,18,14,0.82);
  color:#f4e7d5;
  font-weight:800;
  box-shadow:0 14px 32px rgba(0,0,0,0.42);
}

body.mode-presentation .topbar,
body.mode-presentation .hero,
body.mode-presentation .library-panel,
body.mode-presentation .editor-panel,
body.mode-remote .topbar,
body.mode-remote .hero,
body.mode-remote .library-panel,
body.mode-remote .editor-panel{
  display:none;
}

body.mode-presentation .workspace,
body.mode-remote .workspace{
  grid-template-columns:1fr;
}

body.mode-presentation .stage-panel{
  min-height:calc(100vh - 36px);
  background:rgba(18, 12, 9, 0.92);
}

body.mode-presentation .performance-controls,
body.mode-presentation .notes-panel,
body.mode-remote .performance-controls,
body.mode-remote .notes-panel,
body.mode-remote .chart-surface{
  display:none;
}

body.mode-remote .remote-panel{
  display:grid;
}

body.editing .editor-panel{
  display:grid;
}

body.editing .editor-panel.hidden-panel{
  display:grid;
}

body:not(.editing) .editor-panel{
  opacity:0.82;
}

body.mode-remote .stage-panel{
  min-height:calc(100vh - 36px);
}

body.mode-remote .song-page{
  display:none;
}

@media (max-width: 1180px){
  .workspace{
    grid-template-columns:minmax(0,1fr);
  }
  .editor-panel{
    order:3;
  }
}

@media (max-width: 780px){
  .topbar,
  .hero{
    flex-direction:column;
    align-items:stretch;
  }
  .topbar-meta{
    align-items:stretch;
  }
  .performance-controls{
    grid-template-columns:repeat(2, minmax(0,1fr));
  }
  .field-grid{
    grid-template-columns:1fr;
  }
  h1{
    font-size:2.2rem;
  }
}

@media (max-width: 540px){
  body{
    font-size:15px;
  }
  .app-shell{
    width:calc(100vw - 16px);
    margin:8px auto 18px;
  }
  .topbar,
  .hero,
  .sidebar,
  .stage-panel,
  .editor-panel{
    padding:12px;
  }
  .brand-mark{
    width:58px;
    height:58px;
    border-radius:16px;
  }
  .remote-grid{
    grid-template-columns:1fr;
  }

  .mode-rescue{
    justify-content:center;
    top:8px;
    width:100%;
    border-radius:18px;
  }
}
