:root {
  --bg: #0a0806;
  --bg-raised: #16120d;
  --amber: #ffb400;
  --amber-dim: #7a5900;
  --red: #ff3b1f;
  --grey: #a39c8c;
  --grey-dim: #7d7666;
  --text: #ded6c6;
  --danger: #c0392b;
  --perf-brightness: 0.8;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", "Consolas", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

input, textarea {
  font-family: inherit;
  user-select: text;
  -webkit-user-select: text;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* Fallback so the browser's default white canvas can never show through at an edge
     while a screen is still settling in — every screen we have is black or near-black
     except the panel theme's faceplate, so black is the safest universal backstop. */
  background: #000;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
}
.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* ===================== SPLASH SCREEN ===================== */

#splash-screen {
  background: var(--bg);
  align-items: center;
  justify-content: center;
}

.splash-wordmark {
  font-size: 42px;
  font-weight: 700;
  color: var(--amber);
  text-align: center;
  padding: 0 20px;
  animation: splash-fade-in 500ms ease;
}
@keyframes splash-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.splash-hint {
  position: absolute;
  left: 50%;
  bottom: calc(32px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  color: var(--grey-dim);
  font-size: 14px;
}

/* ===================== SETLIST SCREEN ===================== */

#setlist-screen {
  background: var(--bg);
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
}

.setlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 16px;
}
.setlist-header h1 {
  font-size: 26px;
  margin: 0;
  color: var(--text);
  font-weight: 600;
}

.icon-btn {
  background: var(--bg-raised);
  color: var(--text);
  font-size: 22px;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state {
  padding: 40px 16px;
  color: var(--grey);
  font-size: 17px;
  line-height: 1.5;
}
.empty-state p { margin: 0 0 8px; }

.tune-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tune-row-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
}
.tune-row-wrap.dragging {
  z-index: 20;
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
}

.tune-row-delete-bg {
  position: absolute;
  inset: 0;
  background: var(--danger);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.tune-row-delete-action {
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  width: 84px;
  height: 100%;
  flex-shrink: 0;
}

.tune-row {
  position: relative;
  background: var(--bg-raised);
  border-radius: 10px;
  padding: 14px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  touch-action: pan-y;
}

.tune-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}
.tune-row-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tune-row-meta {
  font-size: 14px;
  color: var(--grey);
  font-variant-numeric: tabular-nums;
}
.tune-row-note {
  font-size: 13px;
  color: var(--grey-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tune-row-drag-handle {
  background: transparent;
  color: var(--grey);
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.tune-row-drag-handle svg {
  width: 22px;
  height: 22px;
}

.setlist-toolbar {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.perform-bar {
  margin-top: 12px;
}

.btn {
  font-size: 17px;
  font-weight: 600;
  padding: 16px 18px;
  border-radius: 10px;
  min-height: 52px;
}
.btn-primary {
  background: var(--amber);
  color: #1a1200;
  flex: 1;
}
.btn-secondary {
  background: var(--bg-raised);
  color: var(--text);
  border: 2px solid var(--grey-dim);
  flex: 1;
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 2px solid var(--danger);
}
.btn-perform {
  background: var(--red);
  color: #1a0400;
  width: 100%;
}
.btn-perform:disabled {
  background: var(--bg-raised);
  color: var(--grey-dim);
}

/* ===================== MODALS ===================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.modal-panel {
  background: var(--bg-raised);
  width: 100%;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-panel h2 {
  margin: 0 0 16px;
  color: var(--text);
  font-size: 20px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--grey);
  margin: 14px 0 6px;
}

.text-input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--grey-dim);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 17px;
}
.text-input:focus {
  outline: none;
  border-color: var(--amber);
}
.textarea {
  resize: none;
}

.bpm-editor {
  display: flex;
  align-items: center;
  gap: 14px;
}
.btn-nudge {
  background: var(--bg);
  color: var(--amber);
  width: 56px;
  height: 56px;
  border-radius: 10px;
  font-size: 26px;
  flex-shrink: 0;
}
.bpm-value {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 40px;
  color: var(--text);
}

.tap-tempo-btn {
  width: 100%;
  margin-top: 10px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

#brightness-slider {
  width: 100%;
  height: 44px;
  accent-color: var(--amber);
}

.settings-backup-row {
  display: flex;
  gap: 10px;
}

.settings-summary-row {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--grey-dim);
  border-radius: 10px;
  padding: 14px 16px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  text-align: left;
}
.settings-summary-chevron {
  color: var(--grey);
  font-size: 20px;
  flex-shrink: 0;
}

.segmented-row {
  display: flex;
  gap: 10px;
}
.segmented-option {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--grey-dim);
  border-radius: 10px;
  padding: 12px 14px;
  min-height: 48px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.segmented-option.selected {
  background: var(--amber);
  color: #1a1200;
  border-color: var(--amber);
}

.settings-hint {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--grey);
}

.option-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.option-row {
  background: var(--bg);
  color: inherit;
  border: 2px solid var(--grey-dim);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}
.option-row.selected {
  border-color: var(--amber);
}
.option-row-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.option-row-desc {
  font-size: 13px;
  color: var(--grey);
}

.jump-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}
.jump-row-btn {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--grey-dim);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.jump-row-btn.current {
  border-color: var(--amber);
}
.jump-row-bpm {
  font-size: 14px;
  font-weight: 400;
  color: var(--grey);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ===================== PERFORMANCE SCREEN ===================== */

#performance-screen {
  background: #000;
  filter: brightness(var(--perf-brightness));
  align-items: stretch;
  justify-content: flex-start;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  position: relative;
  overflow: hidden;
}

.exit-btn {
  position: absolute;
  top: env(safe-area-inset-top);
  right: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  min-width: 64px;
  min-height: 56px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  z-index: 10;
}

.perf-top {
  text-align: center;
  padding: 34px 40px 0;
  min-height: 92px;
}
.perf-title {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  color: var(--amber);
  line-height: 1.2;
  overflow-wrap: break-word;
}
.perf-note {
  margin: 8px 0 0;
  font-size: 18px;
  color: var(--grey);
  line-height: 1.35;
}

.perf-bpm-wrap {
  text-align: center;
  margin: 6px 0 4px;
  flex-shrink: 0;
}
.perf-bpm {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 108px;
  font-weight: 700;
  color: var(--amber);
  line-height: 1;
}

.pulse-area {
  position: relative;
  flex: 1;
  min-height: 160px;
  margin: 10px 0;
  display: flex;
  align-items: center;
}

.stop {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  background: var(--amber-dim);
  border-radius: 4px;
}
.stop-left { left: 0; }
.stop-right { right: 0; }

.marker {
  position: absolute;
  top: 8%;
  bottom: 8%;
  width: 34px;
  margin-left: -17px;
  left: 17px;
  background: var(--amber);
  border-radius: 8px;
  box-shadow: 0 0 24px 4px rgba(255,180,0,0.55);
  opacity: 0;
}
.marker.live {
  opacity: 1;
}

.beat-counter {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  color: var(--text);
}

.pulse-hint {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  color: var(--text);
  font-size: 14px;
}

.perf-nav {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.btn-nav {
  flex: 1;
  background: var(--bg-raised);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  padding: 20px 10px;
  border-radius: 10px;
  min-height: 64px;
}
.btn-nav:active {
  background: #221b10;
}

.up-next {
  text-align: center;
  margin-top: 10px;
  font-size: 14px;
  color: var(--grey-dim);
  min-height: 18px;
  flex-shrink: 0;
}

/* Respect reduced motion everywhere except the marker, which is the app's core function. */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
