:root {
  --bg: #0e0f13;
  --surface: #171920;
  --surface-2: #20232c;
  --border: #2b2f3b;
  --text: #ecedf1;
  --muted: #9aa0ae;
  --accent: #6d7cff;
  --accent-text: #ffffff;
  --good: #3ecf8e;
  --warn: #f5b942;
  --bad: #ff6b6b;
  --radius: 12px;
  --gutter: 16px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

a {
  color: inherit;
}

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

.small {
  font-size: 13px;
}

.error {
  color: var(--bad);
  margin: 8px 0 0;
  font-size: 14px;
}

.icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
  flex: none;
}

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.08s;
}

.btn:hover {
  background: #292d38;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
  font-weight: 600;
}

.btn.primary:hover {
  background: #7d8bff;
}

.btn.wide {
  width: 100%;
}

.icon-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
}

.icon-btn.big {
  width: 64px;
  height: 64px;
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

.icon-btn.big .icon {
  width: 30px;
  height: 30px;
}

.icon-btn.small {
  width: 36px;
  height: 36px;
  min-height: 36px;
}

.icon-btn.small .icon {
  width: 18px;
  height: 18px;
}

input:not([type='range']) {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 16px; /* keeps iOS from zooming in on focus */
}

input:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--muted);
}

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

/* ---------- home ---------- */

.home {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--gutter);
}

.home-card {
  width: 100%;
  max-width: 420px;
  padding: 28px 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand.small {
  font-size: 17px;
  gap: 8px;
}

.tagline {
  margin: 8px 0 24px;
  color: var(--muted);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- room ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) var(--gutter) 8px;
  border-bottom: 1px solid var(--border);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 14px;
  cursor: pointer;
}

.chip .icon {
  width: 16px;
  height: 16px;
}

.connection {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.connection::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.connection[data-state='online']::before {
  background: var(--good);
}

.connection[data-state='offline']::before {
  background: var(--bad);
}

.stage {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.player-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

.player,
.player iframe,
.player video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.player video {
  background: #000;
}

.player-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: var(--gutter);
  background: radial-gradient(circle at 50% 40%, #1d2030, #000 70%);
}

.player-empty p {
  margin: 2px 0;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 10px var(--gutter) 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  font-size: 14px;
}

.banner[data-tone='bad'] {
  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
  background: color-mix(in srgb, var(--bad) 12%, var(--surface));
}

.banner p {
  margin: 0;
  flex: 1 1 220px;
}

.now {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px var(--gutter) 0;
}

.now-text {
  flex: 1;
  min-width: 0;
}

.now-title {
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.now-meta {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-chip {
  flex: none;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
  background: var(--surface-2);
}

.sync-chip[data-tone='good'] {
  color: var(--good);
  background: color-mix(in srgb, var(--good) 14%, transparent);
}

.sync-chip[data-tone='warn'] {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
}

.sync-chip[data-tone='bad'] {
  color: var(--bad);
  background: color-mix(in srgb, var(--bad) 14%, transparent);
}

.seekbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px var(--gutter) 0;
}

.seekbar input {
  flex: 1;
  min-width: 0;
  height: 28px;
  accent-color: var(--accent);
}

.time {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  min-width: 38px;
}

.time:last-child {
  text-align: right;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 4px var(--gutter) 12px;
}

.panel {
  padding: var(--gutter);
  border-bottom: 1px solid var(--border);
}

.panel h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 15px;
}

.count {
  color: var(--muted);
  font-weight: 500;
}

.add-form {
  display: grid;
  gap: 8px;
}

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

.add-buttons .btn {
  flex: 1;
  padding: 0 8px;
}

.add-form.busy {
  opacity: 0.6;
  pointer-events: none;
}

.queue,
.members {
  list-style: none;
  margin: 0;
  padding: 0;
}

.queue li {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

.queue li + li {
  border-top: 1px solid var(--border);
}

.q-thumb {
  width: 96px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-2);
}

.q-thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.q-text {
  min-width: 0;
}

.q-title {
  font-size: 14px;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.q-meta {
  font-size: 12px;
  color: var(--muted);
}

.q-actions {
  display: flex;
  gap: 4px;
}

.members li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.members li[data-tone='good'] .dot {
  background: var(--good);
}

.members li[data-tone='warn'] .dot {
  background: var(--warn);
}

.members li[data-tone='bad'] .dot {
  background: var(--bad);
}

.m-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-state {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- join sheet & toast ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  background: rgb(0 0 0 / 0.6);
  backdrop-filter: blur(6px);
}

.sheet-card {
  width: 100%;
  max-width: 440px;
  padding: 22px 20px max(22px, env(safe-area-inset-bottom));
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  background: var(--surface);
}

.sheet-card h2 {
  margin: 0 0 16px;
  font-size: 20px;
}

.sheet-card h2 span {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color: var(--accent);
}

.sheet-card .muted {
  margin: 12px 0 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  max-width: calc(100% - 2 * var(--gutter));
  padding: 10px 16px;
  border-radius: 10px;
  background: #2c3040;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.4);
  font-size: 14px;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- larger screens ---------- */

@media (min-width: 600px) {
  .sheet {
    place-items: center;
  }

  .sheet-card {
    border-radius: 18px;
  }
}

/* Phones in landscape: don't pin the player, there's no room for anything else. */
@media (max-height: 500px) {
  .stage {
    position: static;
  }
}

@media (min-width: 960px) {
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 20px;
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px;
  }

  .stage {
    position: static;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    overflow: hidden;
    align-self: start;
  }

  .side {
    display: grid;
    gap: 16px;
    align-content: start;
  }

  .panel {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
  }
}
