:root {
  color-scheme: dark;
  --bg: #07090d;
  --surface: #101319;
  --surface-raised: #171b22;
  --surface-soft: #1c212a;
  --line: #2a303a;
  --line-strong: #3b4350;
  --text: #f5f7fa;
  --muted: #9aa3b2;
  --faint: #697383;
  --red: #ff2d3f;
  --red-dark: #c91426;
  --green: #41d17d;
  --amber: #ffbd4a;
  --blue: #55a7ff;
  --radius: 18px;
  --shadow: 0 28px 80px rgb(0 0 0 / 35%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -10%, rgb(255 45 63 / 16%), transparent 34rem),
    radial-gradient(circle at 100% 30%, rgb(85 167 255 / 8%), transparent 30rem),
    var(--bg);
}

button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 36px;
  display: flex;
  flex-direction: column;
}

.host-controls-visible .shell { padding-bottom: 132px; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -.03em;
  text-decoration: none;
}

.brand-mark {
  padding: 5px 8px;
  border-radius: 7px;
  color: white;
  background: var(--red);
  font-size: .9rem;
  font-style: italic;
  letter-spacing: -.08em;
}

.header-actions,
.button-group,
.primary-actions,
.room-hero-actions,
.room-footer,
.playback-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.connection-pill,
.room-connection-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .85rem;
}

.latency { color: var(--faint); font-variant-numeric: tabular-nums; }

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 4px rgb(105 115 131 / 12%);
}

.status-dot.ok { background: var(--green); box-shadow: 0 0 0 4px rgb(65 209 125 / 13%); }
.status-dot.busy, .status-dot.warn { background: var(--amber); box-shadow: 0 0 0 4px rgb(255 189 74 / 13%); }
.status-dot.error, .status-dot.bad { background: var(--red); box-shadow: 0 0 0 4px rgb(255 45 63 / 13%); }

.progress {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 28px 0 0;
}

.progress span {
  padding: 10px 12px;
  border-top: 2px solid var(--line);
  color: var(--faint);
  font-size: .76rem;
  font-weight: 800;
}

.progress span.active { border-color: var(--red); color: var(--text); }
.progress span.complete { border-color: var(--green); color: var(--muted); }
.progress em { margin-left: 6px; font-style: normal; text-transform: uppercase; letter-spacing: .08em; }

.flow-step {
  width: 100%;
  margin: auto;
  padding: 70px 0 80px;
  animation: enter .26s ease-out;
}

.flow-step.narrow { max-width: 620px; }
.flow-step.room-step { padding-top: 52px; }

@keyframes enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.step-copy { max-width: 760px; margin-bottom: 36px; }
.step-copy.centered { margin-inline: auto; text-align: center; }

.eyebrow,
.section-number,
.label {
  margin: 0 0 8px;
  color: var(--red);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  max-width: 820px;
  margin-bottom: 18px;
  font-size: clamp(2.4rem, 7vw, 5rem);
  line-height: .98;
  letter-spacing: -.06em;
}

h2 { margin-bottom: 0; font-size: 1.55rem; letter-spacing: -.03em; }
h3 { margin-bottom: 0; font-size: 1.25rem; letter-spacing: -.02em; }

.lede {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  line-height: 1.65;
}

.instruction-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 0 0 34px;
  padding: 0;
  list-style: none;
}

.instruction-list li {
  min-height: 170px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgb(255 255 255 / 3%), transparent), var(--surface);
}

.instruction-list > li > span,
.role-icon {
  display: grid;
  width: 34px;
  height: 34px;
  margin-bottom: 30px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--red);
  font-size: .8rem;
  font-weight: 900;
}

.instruction-list strong { display: block; margin-bottom: 8px; }
.instruction-list p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }

.button,
.icon-button,
.text-button,
.ready-button {
  border: 0;
  cursor: pointer;
  transition: border-color .16s, background .16s, color .16s, transform .16s;
}

.button {
  min-height: 44px;
  padding: 0 17px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-raised);
  font-weight: 800;
}

.button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.role-card:hover { transform: translateY(-1px); border-color: #5b6472; }
.button.primary { border-color: var(--red); background: var(--red); color: white; }
.button.primary:hover { border-color: #ff5363; background: #ff4051; }
.button.subtle { background: transparent; }
.button.danger { color: #ff7b86; }
.button.compact { min-height: 36px; padding: 0 12px; font-size: .78rem; }
.header-connect-button { white-space: nowrap; }
.button.large { min-height: 52px; padding-inline: 22px; }
.button:disabled { cursor: not-allowed; opacity: .42; }

.hint {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.5;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  max-width: 820px;
  margin: 0 auto 24px;
}

.role-card {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  text-align: left;
}

.role-card strong { display: block; margin-bottom: 10px; font-size: 1.4rem; }
.role-card small { display: block; min-height: 52px; color: var(--muted); line-height: 1.5; }
.role-link { display: block; margin-top: 30px; color: var(--red); font-weight: 800; }

.text-button {
  display: block;
  margin: 24px auto 0;
  padding: 8px;
  color: var(--muted);
  background: transparent;
}
.text-button:hover { color: var(--text); }

.setup-form,
.readiness-card,
.participants-card,
.detail-section {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.setup-form { display: grid; gap: 20px; }

.field { display: grid; gap: 8px; }
.field > span, .transport legend { color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.field small { color: var(--faint); font-size: .78rem; line-height: 1.45; }
.form-status {
  margin: -4px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: .86rem;
  line-height: 1.45;
}
.form-status.busy { border-color: #8d762a; color: #f1da84; background: rgb(211 170 45 / 10%); }
.form-status.error { border-color: #8f3840; color: #ff9aa3; background: rgb(255 45 63 / 10%); }

input, select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  color: var(--text);
  background: #0b0e13;
}

input:focus, select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgb(255 45 63 / 12%); }
.code-input { font-size: 1.35rem; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }

.room-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}
.room-hero h1 { margin-bottom: 12px; font-size: clamp(2rem, 5vw, 3.8rem); }

.readiness-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 18px;
  border-color: #3a424e;
}
.readiness-card strong { display: block; margin-bottom: 6px; font-size: 1.45rem; }
.readiness-card p { margin: 0; color: var(--muted); }

.ready-button {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 170px;
  min-height: 56px;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-soft);
  font-weight: 900;
}
.ready-button[aria-pressed="true"] { border-color: var(--green); background: rgb(65 209 125 / 14%); color: #8ff0b6; }
.ready-check {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.participants-card { box-shadow: none; }
.participants-heading, .detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
.ready-summary { text-align: right; }
.ready-summary strong { display: block; font-size: 1.25rem; }
.ready-summary span { color: var(--muted); font-size: .78rem; text-transform: uppercase; }

.participants-list { display: grid; gap: 10px; }
.participant {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0c0f14;
}
.participant-name { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 800; }
.participant-name small { padding: 3px 6px; border-radius: 5px; color: var(--red); background: rgb(255 45 63 / 12%); font-size: .62rem; }
.participant-meta { color: var(--muted); font-size: .8rem; }
.ready-badge { padding: 6px 10px; border-radius: 999px; color: var(--muted); background: var(--surface-soft); font-size: .72rem; font-weight: 900; text-transform: uppercase; }
.ready-badge.ready { color: #8ff0b6; background: rgb(65 209 125 / 14%); }

.room-footer {
  justify-content: space-between;
  margin-top: 16px;
  padding: 0 4px;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: .76rem;
}
footer p { margin: 0; }

.details-modal {
  width: min(980px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  color: var(--text);
  background: var(--bg);
  box-shadow: 0 35px 120px rgb(0 0 0 / 70%);
}
.details-modal::backdrop { background: rgb(0 0 0 / 72%); backdrop-filter: blur(5px); }
.modal-shell { min-height: 0; }
.modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: rgb(7 9 13 / 94%);
  backdrop-filter: blur(14px);
}
.modal-content { display: grid; gap: 16px; padding: 18px; }
.detail-section { box-shadow: none; }
.section-number { margin-bottom: 6px; color: var(--faint); }

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-raised);
  font-size: 1.3rem;
}

.settings-grid, .sync-settings {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, .6fr);
  gap: 16px;
  margin-bottom: 18px;
}

.transport { display: flex; align-items: center; gap: 10px; margin: 0; padding: 0; border: 0; }
.transport legend { margin-bottom: 8px; }
.transport label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .78rem; }
.transport input { width: auto; min-height: 0; }
.transport small { display: none; }
.disabled-option { opacity: .45; }

.player-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0;
  padding: 20px;
  border-radius: 12px;
  background: #0b0e13;
}
.player-summary p { margin-bottom: 6px; color: var(--muted); font-size: .78rem; font-weight: 800; }
.player-summary strong { font: 700 clamp(1.6rem, 5vw, 2.6rem)/1 ui-monospace, SFMono-Regular, Consolas, monospace; }

.state-pill { padding: 7px 10px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: .72rem; font-weight: 900; }
.state-pill.ok { color: #8ff0b6; background: rgb(65 209 125 / 14%); }
.state-pill.busy { color: #ffd485; background: rgb(255 189 74 / 12%); }

.telemetry {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
  margin: 0 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--line);
}
.telemetry div { min-width: 0; padding: 12px; background: #0b0e13; }
.telemetry dt { margin-bottom: 5px; color: var(--faint); font-size: .65rem; text-transform: uppercase; letter-spacing: .06em; }
.telemetry dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 .78rem ui-monospace, SFMono-Regular, Consolas, monospace; }

.playback-controls { flex-wrap: wrap; }
.seek-form { display: flex; flex: 1 1 260px; gap: 8px; }
.seek-form input { min-width: 150px; }

.host-controls-dock {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-strong);
  background: rgb(7 9 13 / 94%);
  box-shadow: 0 -18px 50px rgb(0 0 0 / 48%);
  backdrop-filter: blur(18px);
}

.host-controls-inner {
  display: flex;
  width: min(1120px, 100%);
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
}

.host-controls-summary {
  display: grid;
  min-width: 190px;
  gap: 3px;
}

.host-controls-summary strong { font-size: .9rem; }
.host-controls-summary > span:last-child {
  color: var(--muted);
  font: 700 .82rem ui-monospace, SFMono-Regular, Consolas, monospace;
}

.host-controls-dock .playback-controls {
  flex: 1;
  justify-content: flex-end;
}

.host-controls-dock .button { min-height: 46px; }
.host-controls-dock .seek-form { max-width: 340px; }

.technical-overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.technical-overview div, .sync-settings > div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b0e13;
}
.technical-overview strong, .sync-settings strong { display: block; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.sync-settings small { display: block; margin-top: 6px; color: var(--faint); }

.technical-participants { margin-top: 20px; }
.technical-row {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr .8fr .7fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}
.technical-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.technical-row .good { color: var(--green); }
.technical-row .warn { color: var(--amber); }
.technical-row .bad { color: var(--red); }

.diagnostic-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
}
.diagnostic-summary p { margin: 0; }

#logOutput {
  min-height: 180px;
  max-height: 360px;
  margin: 0;
  padding: 15px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #b9c2cf;
  background: #05070a;
  white-space: pre-wrap;
  word-break: break-word;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
}

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 1120px); padding-top: 14px; }
  .host-controls-visible .shell { padding-bottom: 218px; }
  .room-hero, .readiness-card, .room-footer, footer { align-items: stretch; flex-direction: column; }
  .app-header { align-items: center; }
  .header-actions { justify-content: flex-end; flex-wrap: wrap; }
  .connection-pill { flex-wrap: wrap; }
  .progress em { display: none; }
  .flow-step { padding: 48px 0; }
  .instruction-list, .role-grid, .settings-grid, .sync-settings { grid-template-columns: 1fr; }
  .instruction-list li { min-height: 0; }
  .instruction-list > li > span { margin-bottom: 18px; }
  .primary-actions, .room-hero-actions { align-items: stretch; flex-direction: column; }
  .button.large { width: 100%; }
  .ready-button { width: 100%; }
  .telemetry, .technical-overview { grid-template-columns: repeat(2, 1fr); }
  .technical-row { grid-template-columns: 1fr 1fr; }
  .modal-content { padding: 10px; }
  .detail-section { padding: 18px; }
  .host-controls-dock { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .host-controls-inner { display: grid; gap: 10px; }
  .host-controls-summary {
    grid-template-columns: auto 1fr auto;
    min-width: 0;
    align-items: center;
    gap: 8px;
  }
  .host-controls-summary strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .host-controls-dock .playback-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  .host-controls-dock .button { min-width: 0; padding-inline: 8px; }
  .host-controls-dock .seek-form {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: 1fr auto;
    max-width: none;
  }
}
