:root {
  color-scheme: dark;
  --bg: #12100f;
  --surface: #211d1a;
  --surface-strong: #2b2520;
  --ink: #f6f1e8;
  --muted: #b8aa9a;
  --line: #514239;
  --accent: #d6402f;
  --accent-dark: #a92e23;
  --accent-hot: #f2b84b;
  --cool: #0f766e;
  --danger: #f04438;
  --stage: #101418;
  --stage-panel: #192026;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(214, 64, 47, 0.16), transparent 220px),
    radial-gradient(circle at 14% 0%, rgba(242, 184, 75, 0.18), transparent 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 4px;
}

button {
  min-height: 40px;
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary {
  background: #181513;
  color: var(--accent-hot);
}

button.danger {
  border-color: var(--danger);
  background: #211312;
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  background: #171412;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

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

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid rgba(242, 184, 75, 0.24);
  background: linear-gradient(90deg, rgba(18, 16, 15, 0.96), rgba(43, 37, 32, 0.78));
  padding: 22px clamp(16px, 4vw, 48px) 18px;
}

.app-header h1 {
  margin: 4px 0 0;
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1.05;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0;
  color: var(--accent-hot);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  display: block;
  width: clamp(92px, 9vw, 132px);
  aspect-ratio: 1 / 1;
  height: auto;
  max-height: 132px;
  object-fit: contain;
  filter: drop-shadow(0 14px 26px rgba(0, 0, 0, 0.42));
}

.brand-mark {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border: 2px solid var(--accent-hot);
  background: linear-gradient(135deg, #2b2520 0%, #12100f 58%, #d6402f 100%);
  box-shadow: 0 0 0 4px rgba(214, 64, 47, 0.14), 0 12px 30px rgba(0, 0, 0, 0.35);
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 900;
}

.brand-mark span {
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  padding: 4px 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  width: auto;
}

.header-actions select {
  width: 92px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.user-badge button {
  min-height: 34px;
  padding: 0 10px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  background: #171412;
  border-bottom: 1px solid rgba(81, 66, 57, 0.8);
  padding: 14px clamp(16px, 4vw, 48px);
}

.tab {
  background: #211d1a;
  color: var(--muted);
  border-color: var(--line);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent-hot);
  color: white;
}

main {
  padding: 22px clamp(16px, 4vw, 48px) 48px;
}

body:not(.is-authenticated) .tabs,
body:not(.is-authenticated) main > .view {
  display: none;
}

body.is-authenticated #authView {
  display: none;
}

.auth-view {
  display: grid;
  min-height: calc(100vh - 190px);
  place-items: center;
}

.auth-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(43, 37, 32, 0.96), rgba(24, 21, 19, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  padding: 24px;
}

.auth-panel h2 {
  margin: 4px 0 4px;
  color: var(--ink);
  font-size: 2rem;
  line-height: 1.05;
  text-transform: uppercase;
}

.auth-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.google-button {
  width: 100%;
}

.link-button {
  min-height: 0;
  justify-self: start;
  border: 0;
  background: transparent;
  color: var(--accent-hot);
  padding: 0;
}

.link-button:hover {
  background: transparent;
  color: var(--ink);
}

.auth-note {
  min-height: 1.2em;
  margin: 10px 0 0;
  text-align: center;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

#performView {
  margin-top: -22px;
  margin-right: calc(-1 * clamp(16px, 4vw, 48px));
  margin-bottom: -48px;
  margin-left: calc(-1 * clamp(16px, 4vw, 48px));
}

.grid {
  display: grid;
  gap: 18px;
}

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

#songsView .two-columns {
  grid-template-columns: minmax(680px, 1.7fr) minmax(320px, 0.85fr);
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.22);
  padding: 18px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
  color: var(--accent-hot);
  text-transform: uppercase;
}

.stack {
  display: grid;
  gap: 12px;
}

.song-editor-panel {
  position: sticky;
  top: 12px;
}

.song-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.song-meta-grid .span-2 {
  grid-column: span 2;
}

.transpose-editor-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.transpose-tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(244, 177, 68, 0.06);
  padding: 8px;
}

.transpose-tool-group span {
  flex: 1;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.transpose-tool-group button {
  min-height: 34px;
  padding: 0 10px;
}

.lyrics-editor-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.lyrics-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lyrics-search-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(244, 177, 68, 0.22);
  border-radius: 6px;
  background: rgba(244, 177, 68, 0.06);
}

.lyrics-search-tools button {
  min-height: 36px;
  padding: 0 12px;
}

.format-button {
  width: 40px;
  min-height: 36px;
  padding: 0;
}

.color-apply-button {
  min-height: 36px;
  padding: 0 10px;
}

.lyrics-tag-button {
  min-height: 36px;
  padding: 0 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.color-tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #181513;
}

.color-tool input {
  width: 34px;
  height: 28px;
  border: 0;
  padding: 0;
  background: transparent;
}

.rich-lyrics-editor {
  min-height: clamp(420px, 48vh, 760px);
  max-height: 70vh;
  overflow: auto;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #141211;
  color: var(--ink);
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.02rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.rich-lyrics-editor:focus {
  outline: 2px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.rich-lyrics-editor p,
.perform-lyrics p {
  margin: 0 0 0.72em;
}

.field-row,
.actions,
.section-header,
.add-song-row,
.perform-topbar {
  display: flex;
  gap: 10px;
}

.field-row > * {
  flex: 1;
}

.actions {
  flex-wrap: wrap;
}

.actions.compact {
  align-items: center;
}

.section-header {
  align-items: center;
  justify-content: space-between;
}

.list,
.setlist-items {
  display: grid;
  gap: 10px;
}

.scroll-list,
.detail-scroll-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.scroll-list {
  max-height: min(58vh, 640px);
}

.detail-scroll-list {
  max-height: min(62vh, 720px);
}

.scroll-list::-webkit-scrollbar,
.detail-scroll-list::-webkit-scrollbar {
  width: 10px;
}

.scroll-list::-webkit-scrollbar-thumb,
.detail-scroll-list::-webkit-scrollbar-thumb {
  background: #725642;
  border: 3px solid var(--surface);
  border-radius: 999px;
}

.search-field {
  margin: 0 0 12px;
}

.search-field input {
  background: #171412;
}

.item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: var(--surface-strong);
}

.item-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.item h3 {
  margin: 0;
  font-size: 1rem;
}

.item p {
  margin: 5px 0 0;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.item-actions button {
  min-height: 32px;
  padding: 0 10px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px 120px auto;
  gap: 10px;
  align-items: center;
}

.user-row strong {
  display: block;
}

.user-row select {
  min-width: 0;
}

.user-active-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
}

.user-active-control input {
  width: auto;
}

.pill {
  display: inline-grid;
  min-width: 34px;
  min-height: 28px;
  place-items: center;
  border-radius: 999px;
  background: rgba(242, 184, 75, 0.16);
  color: var(--accent-hot);
  padding: 2px 10px;
  font-weight: 750;
}

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

.detail-panel {
  margin-top: 18px;
}

.add-song-row {
  align-items: center;
  margin: 14px 0;
}

.add-song-row select {
  flex: 1;
}

.add-song-row input {
  flex: 1.5;
}

.setlist-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.order-controls {
  display: grid;
  gap: 4px;
}

.order-controls button {
  min-height: 30px;
  padding: 0;
}

.perform-shell {
  height: calc(100vh - 120px);
  min-height: 68vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  background: var(--stage);
  color: #f8fafc;
  border-radius: 0;
  padding: 18px;
}

.perform-topbar {
  align-items: center;
  flex-wrap: wrap;
}

.perform-topbar select {
  max-width: 360px;
  background: var(--stage-panel);
  color: #f8fafc;
  border-color: #334155;
}

.perform-song-nav {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.perform-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.perform-tool-group,
.perform-speed-tool,
.perform-metronome,
.wait-countdown {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  min-height: 40px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: var(--stage-panel);
  color: #cbd5e1;
  padding: 0 10px;
}

.perform-tool-group button {
  min-height: 30px;
  padding: 0 10px;
}

.transpose-live-tool > span:first-child {
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 800;
}

.perform-speed-tool input {
  width: 160px;
  padding: 0;
}

.perform-tool-value {
  min-width: 54px;
  color: #f8fafc;
  font-size: 0.9rem;
  font-weight: 750;
  text-align: center;
}

.perform-speed-tool .perform-tool-value {
  min-width: 150px;
  text-align: right;
}

.perform-metronome .perform-tool-value {
  min-width: 72px;
}

.metronome-dot {
  width: 18px;
  height: 18px;
  border: 2px solid #94a3b8;
  border-radius: 999px;
  background: #1f2937;
}

.metronome-dot.active {
  animation: metronomePulse var(--beat-duration, 0.667s) steps(2, end) infinite;
}

.wait-countdown {
  border-color: #f59e0b;
  color: #fde68a;
}

.wait-countdown strong {
  min-width: 34px;
  color: #ffffff;
  font-size: 1.05rem;
  text-align: right;
}

@keyframes metronomePulse {
  0%,
  45% {
    background: #f8fafc;
    border-color: #f8fafc;
    box-shadow: 0 0 18px rgba(248, 250, 252, 0.85);
  }
  46%,
  100% {
    background: #1f2937;
    border-color: #94a3b8;
    box-shadow: none;
  }
}

.perform-card {
  min-height: 0;
  overflow: auto;
  background: var(--stage-panel);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 18px 0 0;
}

.perform-card h2 {
  margin: 6px 18px 18px;
  font-size: clamp(2rem, 5vw, 4rem);
}

.perform-card > .muted {
  margin-left: 18px;
  margin-right: 18px;
}

.perform-lyrics {
  margin: 0;
  font-size: var(--perform-font-size, 1.89rem);
  line-height: 1.55;
  white-space: pre-wrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.modal-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 14px;
  padding: 0 0 14px;
}

.modal-header h2 {
  margin: 4px 0 0;
  color: var(--accent-hot);
  text-transform: uppercase;
}

.lyrics-import-modal {
  display: flex;
  flex-direction: column;
  width: min(860px, calc(100vw - 32px));
  overflow: hidden;
}

.lyrics-import-body {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.import-tools {
  margin: 0 0 10px;
}

.lyrics-import-text {
  min-height: min(28vh, 280px);
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.45;
}

.import-preview-field {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.lyrics-import-preview {
  min-height: 120px;
  max-height: 22vh;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #141211;
  color: var(--ink);
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.45;
  white-space: pre-wrap;
}

.import-guidance {
  margin: 0 0 12px;
}

.lyrics-import-actions {
  position: sticky;
  bottom: 0;
  margin: 14px -18px -18px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 -12px 24px rgba(0, 0, 0, 0.18);
}

.pending-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pending-list li {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  padding: 12px;
}

.pending-list li.current {
  border-color: var(--accent-hot);
  background: rgba(242, 184, 75, 0.12);
}

.pending-index {
  display: grid;
  min-height: 34px;
  place-items: center;
  border-radius: 999px;
  background: rgba(214, 64, 47, 0.24);
  color: #ffffff;
  font-weight: 850;
}

.pending-list strong {
  color: #ffffff;
}

.pending-list p {
  margin: 4px 0 0;
}

#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(360px, calc(100vw - 32px));
  border: 1px solid rgba(242, 184, 75, 0.55);
  border-radius: 8px;
  background: #171412;
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48);
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: 180ms ease;
  pointer-events: none;
}

#toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  .app-header {
    align-items: start;
    flex-direction: column;
  }

  .header-actions,
  .user-badge {
    flex-wrap: wrap;
  }

  .two-columns,
  #songsView .two-columns {
    grid-template-columns: 1fr;
  }

  #performView {
    margin-top: -22px;
    margin-right: calc(-1 * clamp(16px, 4vw, 48px));
    margin-bottom: -48px;
    margin-left: calc(-1 * clamp(16px, 4vw, 48px));
  }

  .song-editor-panel {
    position: static;
  }

  .song-meta-grid {
    grid-template-columns: 1fr;
  }

  .song-meta-grid .span-2 {
    grid-column: auto;
  }

  .transpose-editor-tools {
    grid-template-columns: 1fr;
  }

  .rich-lyrics-editor {
    min-height: 360px;
    max-height: 60vh;
  }

  .field-row,
  .add-song-row,
  .section-header,
  .perform-topbar,
  .perform-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .perform-song-nav {
    margin-left: 0;
  }

  .perform-song-nav button {
    flex: 1;
  }

  .perform-tool-group,
  .perform-speed-tool,
  .perform-metronome,
  .wait-countdown {
    justify-content: space-between;
    width: 100%;
  }

  .perform-shell {
    height: auto;
    min-height: 72vh;
  }

  .perform-card {
    max-height: 58vh;
  }

  .perform-speed-tool input {
    flex: 1;
  }

  .setlist-item {
    grid-template-columns: 1fr;
  }

  .user-row {
    grid-template-columns: 1fr;
  }

  .scroll-list,
  .detail-scroll-list {
    max-height: 52vh;
  }
}
