:root {
  --bg: #0d0b12;
  --surface: #171420;
  --surface-2: #1f1b2c;
  --border: rgba(244, 241, 250, 0.09);
  --text: #f4f1fa;
  --text-dim: rgba(244, 241, 250, 0.58);
  --accent: #ffb648;
  --accent-bright: #ffc86b;
  --accent-ink: #2a1c04;
  --accent-focus: rgba(255, 182, 72, 0.55);
  --accent-ring: rgba(255, 182, 72, 0.5);
  --accent-glow: rgba(255, 182, 72, 0.13);
  --accent-tint: rgba(255, 182, 72, 0.14);
  --accent-tint-soft: rgba(255, 182, 72, 0.12);
  --accent-tint-strong: rgba(255, 182, 72, 0.28);
  --accent-title-1: #ffd58a;
  --accent-title-2: #ffb648;
  --accent-now-1: rgba(255, 182, 72, 0.16);
  --accent-now-2: rgba(255, 182, 72, 0.04);
  --accent-now-3: rgba(255, 182, 72, 0.4);
  --danger: #ff9c9c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

html {
  overscroll-behavior-y: contain;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font-family: inherit;
}

[hidden] {
  display: none !important;
}

#app {
  height: 100vh;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.screen-center {
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 24px;
  position: relative;
}

.screen-center::before {
  content: "";
  position: absolute;
  top: -30%;
  left: 0;
  right: 0;
  height: 90%;
  background: radial-gradient(
    ellipse at center,
    var(--accent-glow),
    transparent 65%
  );
  pointer-events: none;
}

.screen-center form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
}

.app-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
  background: linear-gradient(120deg, var(--accent-title-1), var(--accent-title-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  color: var(--text-dim);
  font-size: 15px;
  text-align: center;
}

.field-label {
  margin-left: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.code-input {
  width: 100%;
  min-height: 62px;
  text-align: center;
  text-indent: 0.3em;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  -webkit-appearance: none;
  appearance: none;
}

.code-input::placeholder {
  color: rgba(244, 241, 250, 0.32);
}

.code-input:focus {
  outline: none;
  border-color: var(--accent-focus);
}

.rule-input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  -webkit-appearance: none;
  appearance: none;
}

.rule-input:focus {
  outline: none;
  border-color: var(--accent-focus);
}

.rule-input:disabled {
  opacity: 0.45;
}

.field-help {
  margin: -8px 4px 0;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

.rules-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rules-row .rule-input {
  flex: 1;
}

.rules-per {
  flex: 0 0 auto;
  color: var(--text-dim);
  font-size: 14px;
}

/* The invisible checkbox input stretches over the whole 44px row (the real
   touch target) while the track/knob spans render the visible switch. */
.switch-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}

.switch-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  flex: 0 0 auto;
  display: block;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.switch-knob {
  display: block;
  width: 26px;
  height: 26px;
  margin: 2px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s ease, background 0.15s ease;
}

.switch-input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch-input:checked + .switch-track .switch-knob {
  transform: translateX(20px);
  background: var(--accent-ink);
}

.switch-row:focus-within .switch-track {
  border-color: var(--accent-focus);
}

.switch-text {
  color: var(--text);
  font-size: 14px;
}

.btn-primary {
  min-height: 50px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 800;
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-primary:disabled {
  opacity: 0.55;
}

.inline-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}

.muted-note {
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  line-height: 1.5;
}

.room-chip {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 18px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
}

.ready-actions {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 22px;
}

.ready-actions .btn-primary {
  width: 100%;
}

.screen-extras {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 18px;
}

.screen-extras .btn-row .btn-primary {
  flex: 1;
}

.btn-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn-row .btn-primary {
  flex: 1;
}

/* Framework-registered <google-cast-launcher>; hidden until the sender SDK
   is configured with a castAppId. display:inline-block is required for the
   width/height to apply. */
.btn-cast {
  flex: 0 0 auto;
  display: inline-block;
  width: 50px;
  min-height: 50px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  --disconnected-color: var(--text);
  --connected-color: var(--accent);
}

.btn-cast.is-connected {
  border-color: var(--accent-focus);
}

.player-url {
  font-size: 12px;
  line-height: 1.4;
  word-break: break-all;
  text-align: center;
}

.link-btn {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 2px 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  text-decoration: underline;
}

.copy-text {
  color: var(--accent);
  user-select: all;
  -webkit-user-select: all;
}

.control-bar {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  padding: 12px 24px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-buttons {
  display: flex;
  gap: 8px;
}

.ctrl-btn {
  flex: 1;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.ctrl-btn:active {
  transform: translateY(1px);
}

.ctrl-btn:disabled {
  opacity: 0.55;
}

.queue-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  overflow-y: auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.queue-overlay-close {
  position: absolute;
  top: 12px;
  right: 12px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.queue-overlay-heading {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 18px;
  background: linear-gradient(120deg, var(--accent-title-1), var(--accent-title-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.queue-overlay-list {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.queue-overlay-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.queue-overlay-art,
.queue-overlay-art-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  flex: 0 0 auto;
  object-fit: cover;
}

.queue-overlay-art-placeholder {
  background: var(--surface-2);
}

.queue-overlay-meta {
  min-width: 0;
}

.queue-overlay-name {
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-overlay-artist,
.queue-overlay-requester {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-overlay-empty {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 0;
  text-align: center;
  color: var(--text-dim);
}

/* --------------------------------- ready screen cards (playback + rules) */

/* The ready screen carries more content than the others — let it scroll
   instead of clipping when the two cards push it past the viewport. */
#screen-ready {
  justify-content: flex-start;
  overflow-y: auto;
  padding-bottom: 32px;
}

.ready-cards {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
}

.host-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.host-card-heading {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.segment-btn {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
}

.segment-btn.is-active {
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  color: var(--accent-ink);
}

.app-branch {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-secondary {
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.btn-secondary:active {
  transform: translateY(1px);
}

.app-status {
  min-height: 20px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  color: var(--text-dim);
}

.app-status.is-stalled {
  color: var(--danger);
}

/* PIN entry card — shown on each screen while the server demands a host
   PIN and none is stored for the session (hostPinRequired from /host/config). */
.pin-card {
  width: 100%;
  max-width: 360px;
  gap: 8px;
}

.pin-row {
  display: flex;
  gap: 8px;
}

.pin-row .rule-input {
  flex: 1;
  min-width: 0;
  text-align: left;
  text-indent: 12px;
}

.pin-row .pin-save {
  flex: 0 0 auto;
  min-width: 88px;
}

.host-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1100;
  max-width: min(88vw, 360px);
  padding: 12px 18px;
  border: 1px solid var(--accent-focus);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

/* ----------------------------------------- default song card (idle track) */

.idle-search-input {
  text-align: left;
  text-indent: 12px;
}

.idle-search-input::placeholder {
  color: rgba(244, 241, 250, 0.32);
}

.idle-search-input:focus {
  outline: none;
  border-color: var(--accent-focus);
}

.idle-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.idle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
}

.idle-art {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--surface);
  flex: 0 0 auto;
  overflow: hidden;
}

.idle-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.idle-meta {
  min-width: 0;
}

.idle-name {
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.idle-artist {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.idle-duration {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--text-dim);
}

.idle-set-btn {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--accent-focus);
  border-radius: 12px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.idle-set-btn:active {
  transform: translateY(1px);
}

.idle-set-btn:disabled {
  opacity: 0.55;
}

/* ------------------------------------------------------------- theme card */

/* Swatch row for the room theme. Buttons are rendered from
   window.JUKEBOX_THEMES by js/app.js — nothing theme-id-specific lives in
   the markup or this sheet except the override blocks below. */
.theme-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-option {
  flex: 1 1 140px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 12px 6px 6px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-align: left;
}

.theme-option:hover {
  border-color: var(--accent-focus);
}

.theme-option:active {
  transform: translateY(1px);
}

.theme-option:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

.theme-option.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  box-shadow: 0 0 0 1px var(--accent),
    0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}

.theme-chip {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.theme-option-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------- TV display card */

/* Layout mini-mockup row. Buttons are rendered from
   window.JUKEBOX_DISPLAYS by js/app.js and reuse the .theme-option shell
   (hover/focus/selected states come free) restacked into a column with the
   mockup above the label. Only the generic mockup skeleton is styled here —
   the per-layout arrangement keys off data-mock, whose values live in the
   registry (displays.js), never in app.js. Strokes/fills use the accent so
   the mockups re-theme with the room. */
.display-option {
  flex: 1 1 100%;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px;
}

.display-option-hint {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.display-mockup {
  position: relative;
  display: block;
  width: 100%;
  height: 40px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  color: var(--accent);
  overflow: hidden;
}

.display-mockup-art {
  display: block;
  background: currentColor;
}

.display-mockup-lines {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.display-mockup-line {
  display: block;
  width: 100%;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
}

.display-mockup-line:last-child {
  width: 62%;
}

/* Artwork layout: art fills the screen, overlay text lines sit over its
   bottom-left corner (ink-on-accent for contrast). */
.display-mockup[data-mock="overlay"] .display-mockup-art {
  position: absolute;
  inset: 4px;
  border-radius: 4px;
}

.display-mockup[data-mock="overlay"] .display-mockup-lines {
  position: absolute;
  left: 9px;
  bottom: 9px;
}

.display-mockup[data-mock="overlay"] .display-mockup-line {
  width: 26px;
  background: var(--accent-ink);
}

.display-mockup[data-mock="overlay"] .display-mockup-line:last-child {
  width: 17px;
}

/* Split layout: tilted art block left, detail lines right. */
.display-mockup[data-mock="split"] {
  display: flex;
  align-items: stretch;
  gap: 5px;
  padding: 4px;
}

.display-mockup[data-mock="split"] .display-mockup-art {
  flex: 0 0 38%;
  border-radius: 4px;
  transform: rotate(-7deg) scale(0.92);
}

.display-mockup[data-mock="split"] .display-mockup-lines {
  flex: 1;
  min-width: 0;
}

.display-mockup[data-mock="split"] .display-mockup-line {
  opacity: 0.55;
}

/* ------------------------------------------------------------ theme variants
   Registered in js/themes.js + the backend allow-list; those three move
   together. Same palette values as the joiner stylesheet; :root above IS the
   classic palette. Borders follow midnight's accent-tinted rgba form. */

[data-theme="midnight"] {
  --bg: #060a14;
  --surface: #0d1526;
  --surface-2: #14203a;
  --border: rgba(125, 211, 252, 0.14);
  --accent: #7dd3fc;
  --accent-bright: #bae6fd;
  --accent-ink: #052738;
  --accent-focus: rgba(125, 211, 252, 0.55);
  --accent-ring: rgba(125, 211, 252, 0.5);
  --accent-glow: rgba(125, 211, 252, 0.13);
  --accent-tint: rgba(125, 211, 252, 0.14);
  --accent-tint-soft: rgba(125, 211, 252, 0.12);
  --accent-tint-strong: rgba(125, 211, 252, 0.28);
  --accent-title-1: #bae6fd;
  --accent-title-2: #7dd3fc;
  --accent-now-1: rgba(125, 211, 252, 0.16);
  --accent-now-2: rgba(125, 211, 252, 0.04);
  --accent-now-3: rgba(125, 211, 252, 0.4);
}

[data-theme="sunset"] {
  --bg: #16090f;
  --surface: #241019;
  --surface-2: #331825;
  --border: rgba(251, 113, 133, 0.14);
  --accent: #fb7185;
  --accent-bright: #fda4af;
  --accent-ink: #4c0519;
  --accent-focus: rgba(251, 113, 133, 0.55);
  --accent-ring: rgba(251, 113, 133, 0.5);
  --accent-glow: rgba(251, 113, 133, 0.13);
  --accent-tint: rgba(251, 113, 133, 0.14);
  --accent-tint-soft: rgba(251, 113, 133, 0.12);
  --accent-tint-strong: rgba(251, 113, 133, 0.28);
  --accent-title-1: #fda4af;
  --accent-title-2: #fb7185;
  --accent-now-1: rgba(251, 113, 133, 0.16);
  --accent-now-2: rgba(251, 113, 133, 0.04);
  --accent-now-3: rgba(251, 113, 133, 0.4);
}

[data-theme="mono"] {
  --bg: #0a0a0c;
  --surface: #17181b;
  --surface-2: #222327;
  --border: rgba(229, 231, 235, 0.14);
  --accent: #e5e7eb;
  --accent-bright: #f9fafb;
  --accent-ink: #1f2023;
  --accent-focus: rgba(229, 231, 235, 0.55);
  --accent-ring: rgba(229, 231, 235, 0.5);
  --accent-glow: rgba(229, 231, 235, 0.13);
  --accent-tint: rgba(229, 231, 235, 0.14);
  --accent-tint-soft: rgba(229, 231, 235, 0.12);
  --accent-tint-strong: rgba(229, 231, 235, 0.28);
  --accent-title-1: #f9fafb;
  --accent-title-2: #e5e7eb;
  --accent-now-1: rgba(229, 231, 235, 0.16);
  --accent-now-2: rgba(229, 231, 235, 0.04);
  --accent-now-3: rgba(229, 231, 235, 0.4);
}
