:root {
  color-scheme: dark;
  --bg: #0f0f0f;
  --surface: #212121;
  --surface-2: #272727;
  --surface-3: #3f3f3f;
  --border: #303030;
  --border-strong: #4d4d4d;
  --text: #f1f1f1;
  --muted: #aaaaaa;
  --faint: #909090;
  --accent: #ff0000;
  --accent-strong: #cc0000;
  --accent-hover: #a80000;
  --focus: #3ea6ff;
  --danger: #ff8a8a;
  --danger-bg: #2a1215;
  --danger-border: #5c1f24;
  --radius-card: 12px;
  --radius-control: 8px;
  --radius-pill: 999px;
  --font: "Roboto", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-family: var(--font);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

h1,
h2 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

button,
input {
  font: inherit;
}

::selection {
  background: rgba(255, 0, 0, 0.35);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Лендинг */

.landing {
  display: grid;
  place-items: center;
  padding: 56px 20px;
}

.lobby {
  width: min(880px, 100%);
  display: grid;
  gap: 16px;
}

.lobby__brand {
  text-align: center;
  margin-bottom: 8px;
}

.logo {
  position: relative;
  display: inline-block;
  width: 56px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
}

.logo::after {
  content: "";
  position: absolute;
  left: 22px;
  top: 10px;
  border-left: 14px solid #fff;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
}

h1 {
  margin-top: 18px;
  font-size: clamp(28px, 4.5vw, 38px);
  line-height: 1.1;
}

.tagline {
  margin: 12px auto 0;
  max-width: 520px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.card {
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.card h2 {
  font-size: 16px;
  font-weight: 500;
}

.card form {
  display: grid;
  gap: 12px;
}

.card .primary,
.card .secondary {
  width: 100%;
}

label {
  font-size: 12px;
  color: var(--muted);
}

input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #121212;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background-color 0.15s;
}

input::placeholder {
  color: var(--faint);
}

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

input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 1px var(--focus);
}

button {
  height: 42px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.08s;
}

button:hover {
  background: var(--surface-3);
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.primary {
  background: var(--accent-strong);
  color: #fff;
}

.primary:hover {
  background: var(--accent-hover);
}

.primary:active:not(:disabled) {
  background: #8f0000;
}

.secondary {
  border-color: var(--border);
  background: var(--surface-2);
}

.secondary:hover {
  background: var(--surface-3);
}

.ghost {
  border-color: var(--border);
  background: transparent;
}

.ghost:hover {
  background: var(--surface-2);
}

.ghost:active:not(:disabled) {
  background: var(--surface-3);
}

.ghost[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--surface-2);
  color: #fff;
}

.error {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-control);
  background: var(--danger-bg);
  color: var(--danger);
}

@media (min-width: 720px) {
  .lobby {
    grid-template-columns: 1fr 1fr;
  }

  .lobby__brand,
  .error {
    grid-column: 1 / -1;
  }
}

/* Оболочка комнаты */

body.room {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.room-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.room-header__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
}

.brand-mark::after {
  content: "";
  position: absolute;
  left: 14px;
  top: 7px;
  border-left: 10px solid #fff;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

.room-header__code {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.room-code {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

.room-header__media {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pill {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.room-header .ghost {
  height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.banner {
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.banner[data-kind="error"] {
  border-bottom-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

.banner[data-kind="warning"] {
  background: var(--surface-2);
}

.room-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
  padding: 16px 24px 24px;
}

.stage-column {
  display: grid;
  gap: 12px;
  min-width: 0;
  /* Плеер целиком помещается в экран: ширина ограничена доступной высотой */
  width: min(100%, calc((100vh - 170px) * 16 / 9));
  width: min(100%, calc((100dvh - 170px) * 16 / 9));
  margin-inline: auto;
}

.stage-toolbar {
  display: flex;
  gap: 8px;
}

.stage-toolbar input {
  flex: 1;
}

.error--inline {
  margin: 0;
}

input[type="range"] {
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="range"]:hover,
input[type="range"]:focus {
  border-color: transparent;
  box-shadow: none;
}

input[type="range"].controls__volume,
.tile__controls input[type="range"] {
  accent-color: var(--text);
}

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: #000;
}

.player {
  position: absolute;
  inset: 0;
}

.player iframe,
.player > div {
  width: 100%;
  height: 100%;
}

.stage iframe {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.stage-click {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

.stage-click:hover,
.stage-click:active:not(:disabled) {
  background: transparent;
  transform: none;
}

.stage-click:focus-visible {
  outline-offset: -4px;
}

.stage__placeholder {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 6px;
  padding: 20px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.stage__placeholder[hidden],
.resume-overlay[hidden] {
  display: none;
}

.stage__placeholder p {
  margin: 0;
  color: var(--text);
  font-size: 17px;
}

.stage__placeholder span {
  font-size: 13px;
}

.resume-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.65);
  cursor: pointer;
}

.resume-overlay button {
  pointer-events: none;
}

.controls {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  display: grid;
  gap: 0;
  padding: 4px 0 0;
  border-top: 1px solid var(--border);
  background: rgba(15, 15, 15, 0.92);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.stage:hover .controls,
.stage:focus-within .controls {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

@media (hover: none) {
  .controls {
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }
}

.controls__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px 4px;
}

.controls__play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}

.controls__play:hover {
  background: rgba(255, 255, 255, 0.1);
}

.controls__play:active:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
  transform: scale(0.96);
}

.controls__time {
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.controls__spacer {
  flex: 1;
}

.controls__progress {
  position: relative;
  width: 100%;
  height: 14px;
}

.progress__input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

input[type="range"].progress__input {
  height: 100%;
}

.progress__track {
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.32);
  transform: translateY(-50%);
  transition: height 0.12s ease;
  pointer-events: none;
}

.controls:hover .progress__track,
.progress__input:focus-visible + .progress__track {
  height: 5px;
}

.progress__fill {
  width: 0;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
}

.progress__thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  margin-left: -6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.stage:hover .progress__thumb,
.progress__input:focus-visible + .progress__track .progress__thumb {
  opacity: 1;
}

.controls__volume {
  width: 90px;
}

.controls__cc {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.stage--empty .player,
.stage--empty iframe {
  visibility: hidden;
}

.controls__fullscreen,
.controls .ghost {
  height: 32px;
  padding: 0 10px;
}

.controls__fullscreen {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 640px) {
  .controls__row {
    gap: 8px;
    padding: 0 10px 2px;
  }

  .controls__play {
    width: 32px;
    height: 32px;
  }

  .controls__time {
    font-size: 11px;
  }

  .controls__volume {
    display: none;
  }

  .controls__progress {
    height: 12px;
  }

  .controls__fullscreen {
    padding: 0 8px;
  }
}

/* Правая колонка */

.side {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.tiles:empty {
  display: none;
}

.tile {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: #000;
  transition: border-color 0.15s;
}

.tile:hover {
  border-color: var(--border-strong);
}

.tile video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile--cam-off video {
  visibility: hidden;
}

.tile__overlay {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  padding: 7px 10px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile--cam-off .tile__overlay {
  top: 0;
  bottom: 0;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.tile__controls {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.75);
}

.tile__controls input {
  flex: 1;
  min-width: 0;
  accent-color: var(--text);
}

.tile__mute {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
}

.tile__mute:hover {
  background: var(--surface-3);
}

.tile__mute svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Панели */

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

.panel h2 {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.participants {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.participant {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius-control);
}

.participant:hover {
  background: var(--surface-2);
}

.participant--self {
  background: var(--surface-2);
}

.participant__name {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.participant__badges {
  display: flex;
  gap: 6px;
  color: var(--muted);
}

.participant__badges svg {
  display: block;
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.panel--chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 340px;
}

.chat-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  max-height: 42vh;
  padding-right: 4px;
  overflow-y: auto;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13.5px;
  line-height: 1.4;
}

.chat-message:hover {
  background: var(--surface-2);
}

.chat-message__author {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.chat-message__text {
  color: var(--text);
  overflow-wrap: anywhere;
}

.chat-message--system {
  color: var(--faint);
  font-size: 12px;
}

.chat-message--error {
  color: var(--danger);
  font-size: 12px;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  flex: 1;
  height: 38px;
}

.chat-form button {
  height: 38px;
  padding: 0 16px;
}

/* Оверлеи */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.8);
}

.overlay[hidden] {
  display: none;
}

.overlay__card {
  width: min(400px, 100%);
}

.muted {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.5;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.15s;
}

.button-link:hover {
  background: var(--surface-3);
}

@media (max-width: 980px) {
  .room-layout {
    grid-template-columns: 1fr;
  }

  .panel--chat {
    min-height: 280px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
