:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #07111f;
  color: var(--text);
  font-synthesis: none;
  --blue: #58a6ff;
  --blue-bright: #8bc5ff;
  --ink: #07111f;
  --stage: #03080f;
  --surface-input: rgba(5, 14, 25, 0.76);
  --surface-header: rgba(7, 17, 31, 0.88);
  --surface-chat: rgba(9, 23, 39, 0.66);
  --surface-editor: rgba(18, 40, 66, 0.7);
  --surface-toast: #12263d;
  --text: #edf6ff;
  --text-strong: #f5f9ff;
  --text-soft: #b9cce0;
  --line: rgba(155, 202, 255, 0.14);
  --line-strong: rgba(155, 202, 255, 0.28);
  --muted: #8aa4bf;
  --subtle: #647f9b;
  --radius-control: 0.65rem;
  --radius-stage: 0.8rem;
  --header-height: 4.5rem;
  --motion-fast: 150ms ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(circle at 15% -10%, rgba(40, 126, 220, 0.16), transparent 34rem),
    var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--blue-bright);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.login {
  width: min(32rem, calc(100% - 3rem));
  min-height: 100svh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  animation: rise 500ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.login-mark {
  width: 5rem;
  height: 2.5rem;
  display: flex;
  align-items: end;
  gap: 0.45rem;
  margin-bottom: 2.25rem;
}

.login-mark span {
  width: 0.55rem;
  border-radius: 99px;
  background: var(--blue);
  box-shadow: 0 0 1.5rem rgba(88, 166, 255, 0.45);
  animation: equalize 1.8s ease-in-out infinite alternate;
}

.login-mark span:nth-child(1) { height: 45%; }
.login-mark span:nth-child(2) { height: 100%; animation-delay: -600ms; }
.login-mark span:nth-child(3) { height: 68%; animation-delay: -1.1s; }

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--blue-bright);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.login h1 {
  margin: 0;
  font-size: clamp(3.25rem, 11vw, 5.75rem);
  font-weight: 740;
  line-height: 0.92;
  letter-spacing: -0.065em;
}

.login-copy {
  margin: 1.25rem 0 3.5rem;
  color: var(--muted);
  font-size: 1.05rem;
}

.login-form label,
.name-form label {
  display: block;
  margin-bottom: 0.6rem;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 650;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-input);
  color: var(--text-strong);
  transition: background var(--motion-fast), border-color var(--motion-fast);
}

input {
  min-height: 3rem;
  padding: 0 0.9rem;
}

textarea {
  resize: none;
  padding: 0.75rem 0.85rem;
}

input:hover,
textarea:hover {
  border-color: var(--line-strong);
}

.primary-button,
.secondary-button {
  min-height: 2.75rem;
  border-radius: var(--radius-control);
  padding: 0 1rem;
  font-weight: 750;
  transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}

.primary-button {
  background: var(--blue);
  color: #04101c;
}

.secondary-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-soft);
}

.login-form .primary-button {
  min-width: 6rem;
  padding: 0 1.2rem;
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-bright);
  transform: translateY(-1px);
}

.secondary-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: rgba(88, 166, 255, 0.08);
  color: var(--text);
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

.form-error {
  min-height: 1.25rem;
  margin: 0.75rem 0 0;
  color: #ff9eaa;
  font-size: 0.84rem;
}

.app {
  min-height: 100svh;
  animation: fade 350ms ease both;
}

.app-header {
  height: var(--header-height);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface-header);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  justify-self: start;
  width: max-content;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.035em;
  text-decoration: none;
}

.brand span {
  color: var(--blue);
}

.room-status {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text-soft);
  font-size: 0.8rem;
}

.status-dot {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  background: #687b91;
}

.status-dot.live {
  background: #64d6a2;
  box-shadow: 0 0 0 0.3rem rgba(100, 214, 162, 0.1), 0 0 1rem rgba(100, 214, 162, 0.4);
}

.status-dot.connecting {
  background: #efc572;
  animation: breathe 1s ease-in-out infinite alternate;
}

.presence {
  color: #718ba5;
}

.text-button,
.name-button {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  transition: color var(--motion-fast);
}

.text-button {
  justify-self: end;
}

.name-button {
  flex: none;
}

.text-button:hover,
.name-button:hover {
  color: var(--text-strong);
}

.workspace {
  min-height: calc(100svh - var(--header-height));
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 23rem);
  transition: grid-template-columns 180ms ease;
}

.workspace.chat-collapsed {
  grid-template-columns: minmax(0, 1fr) 3.5rem;
}

.watch-area {
  min-width: 0;
  padding: clamp(1rem, 3vw, 2.5rem);
}

.stage {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius-stage);
  background: var(--stage);
  box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.3);
}

.player-shell,
.provider-mount,
.player-shell iframe,
#youtube-player,
#twitch-player,
#stream-player {
  width: 100%;
  height: 100%;
}

.player-shell {
  position: relative;
}

.stage[data-provider="twitch"] {
  aspect-ratio: auto;
}

.stage[data-provider="twitch"] .player-shell {
  height: auto;
}

.stage[data-provider="stream"] {
  aspect-ratio: var(--stream-aspect-ratio, 16 / 9);
}

.stream-mount,
#stream-player {
  background: #000;
}

#stream-player {
  display: block;
  object-fit: contain;
}

.provider-mount {
  overflow: hidden;
}

.twitch-mount,
.twitch-mount iframe {
  min-width: 0;
}

.player-shell iframe {
  opacity: 1;
  transition: opacity 120ms ease;
}

.player-shell::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--stage);
  color: var(--muted);
  content: "Syncing paused frame";
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.player-shell[data-provider="youtube"].preparing-frame iframe {
  opacity: 0;
}

.player-shell[data-provider="youtube"].preparing-frame::after {
  opacity: 1;
}

.stage-notice {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  background:
    linear-gradient(150deg, rgba(24, 80, 138, 0.18), transparent 42%),
    #07111d;
  animation: fade 240ms ease both;
}

.stage-notice h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.4rem);
  letter-spacing: -0.04em;
}

.stage-notice > p:last-child {
  margin: 0.8rem 0 0;
  color: var(--muted);
}

.signal {
  height: 3.5rem;
  display: flex;
  align-items: end;
  gap: 0.35rem;
  margin-bottom: 1.6rem;
}

.signal i {
  display: block;
  width: 0.45rem;
  border-radius: 99px;
  background: #38506a;
}

.signal i:nth-child(1) { height: 30%; }
.signal i:nth-child(2) { height: 60%; }
.signal i:nth-child(3) { height: 100%; }

.ad-pulse {
  width: 3.25rem;
  height: 3.25rem;
  margin-bottom: 1.75rem;
  border: 0.4rem solid rgba(88, 166, 255, 0.16);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 1.1s linear infinite;
}

.watch-meta {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 2rem;
  padding-top: 1.5rem;
}

.watch-meta > div {
  min-width: 0;
}

.watch-meta h2 {
  max-width: 54rem;
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.65rem);
  line-height: 1.3;
  letter-spacing: -0.025em;
}

#join-button {
  flex: none;
}

.volume-note {
  margin: 0.65rem 0 0;
  color: var(--subtle);
  font-size: 0.78rem;
}

.chat {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
  background: var(--surface-chat);
}

.chat-header {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.chat-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-right: -0.5rem;
}

.chat-toggle {
  min-width: 2.75rem;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--muted);
  transition: background var(--motion-fast), color var(--motion-fast);
}

.chat-toggle:hover {
  background: rgba(88, 166, 255, 0.08);
  color: var(--text-strong);
}

.chat-toggle-label {
  display: none;
}

.chat-toggle-icon {
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 180ms ease;
}

.chat-toggle[aria-expanded="false"] .chat-toggle-icon {
  transform: rotate(135deg);
}

.chat-body {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  animation: fade 180ms ease both;
}

.chat.collapsed {
  grid-template-rows: auto;
}

.chat.collapsed .chat-header {
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0.5rem 0.375rem;
  border-bottom: 0;
}

.chat.collapsed .chat-heading,
.chat.collapsed .name-button {
  display: none;
}

.chat.collapsed .chat-header-actions {
  justify-content: center;
  margin: 0;
}

.name-form {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-editor);
  animation: reveal 180ms ease both;
}

.name-fields {
  display: grid;
  gap: 0.65rem;
}

.name-fields input {
  min-height: 2.75rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.form-actions button {
  min-width: 4.75rem;
}

.messages {
  grid-row: 2;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  scrollbar-color: #25405e transparent;
}

.message {
  margin: 0 0 1.1rem;
  animation: message-in 180ms ease both;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.55rem;
  margin-bottom: 0.25rem;
}

.message-name {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 750;
}

.message.host .message-name {
  color: var(--blue-bright);
}

.message-time {
  color: #5d7894;
  font-size: 0.68rem;
  white-space: nowrap;
}

.message-body {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.empty-chat {
  margin: 0;
  color: #607c98;
  font-size: 0.82rem;
  text-align: center;
}

.chat-form {
  grid-row: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
}

.chat-form button {
  padding: 0 0.9rem;
}

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 10;
  max-width: min(24rem, calc(100% - 2.5rem));
  padding: 0.85rem 1rem;
  border: 1px solid rgba(139, 197, 255, 0.2);
  border-radius: var(--radius-control);
  background: var(--surface-toast);
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 0.82rem;
  animation: toast-in 220ms ease both;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(1rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(-0.4rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(0.35rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(0.7rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes breathe {
  to { opacity: 0.4; }
}

@keyframes equalize {
  to { transform: scaleY(0.45); opacity: 0.65; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 860px) {
  .app-header {
    height: 5.25rem;
    grid-template-columns: 1fr auto;
    padding-block: 0.65rem;
  }

  .room-status {
    order: 3;
    grid-column: 1 / -1;
    justify-self: start;
    margin-top: -0.55rem;
  }

  .workspace {
    min-height: calc(100svh - 5.25rem);
    grid-template-columns: 1fr;
  }

  .workspace.chat-collapsed {
    grid-template-columns: 1fr;
    align-content: start;
  }

  .chat {
    min-height: 32rem;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .chat.collapsed {
    min-height: 0;
  }

  .chat.collapsed .chat-header {
    min-height: 3.5rem;
    justify-content: flex-end;
    padding: 0.375rem 1rem;
  }

  .chat.collapsed .chat-toggle {
    width: auto;
    gap: 0.55rem;
    padding: 0 0.75rem;
  }

  .chat.collapsed .chat-toggle-label {
    display: inline;
  }
}

@media (max-width: 520px) {
  .login {
    width: min(100% - 2rem, 32rem);
  }

  .login-copy {
    margin-bottom: 2.25rem;
  }

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

  .login-form .primary-button {
    min-height: 3rem;
  }

  .form-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .watch-area {
    padding: 0.75rem;
  }

  .stage {
    border-radius: 0.55rem;
  }

  .stage-notice > p:last-child {
    display: none;
  }

  .stage-notice {
    padding: 0.65rem;
  }

  .stage-notice h2 {
    font-size: 1.05rem;
    line-height: 1.15;
  }

  .stage-notice .signal {
    display: none;
  }

  .watch-meta {
    align-items: center;
    gap: 1rem;
  }

  #join-button {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
