:root {
  --ink: #1a1814;
  --ink-soft: #5c564c;
  --paper: #f7f3ec;
  --paper-2: #efe8dc;
  --line: #d9cfc0;
  --accent: #0f6e56;
  --accent-2: #0a4f3d;
  --danger: #9b2c2c;
  --tile: #12100e;
  --glow: rgba(15, 110, 86, 0.18);
  --font: "DM Sans", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
}

body {
  min-height: 100vh;
  position: relative;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, var(--glow), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 110%, rgba(26, 24, 20, 0.08), transparent 50%),
    linear-gradient(165deg, #faf7f1 0%, #efe6d8 45%, #e8dfd0 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.1rem;
  background: var(--accent);
  color: #f4fff9;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.15s ease;
}

button:hover {
  background: var(--accent-2);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: var(--ink);
}

button.secondary:hover {
  background: #000;
}

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

button.ghost:hover {
  background: var(--paper-2);
  color: var(--ink);
}

button.share.active {
  background: var(--danger);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.lobby {
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 4.5rem) 1.25rem 3rem;
  animation: rise 0.55s ease both;
}

.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(3.5rem, 10vw, 5.5rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 0.95;
}

.brand p {
  margin: 0.75rem 0 2.25rem;
  color: var(--ink-soft);
  font-size: 1.05rem;
  max-width: 28rem;
}

.lobby.invite .panels {
  grid-template-columns: minmax(260px, 28rem);
  justify-content: start;
}

.lobby.invite #create-form {
  display: none;
}

.panels {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.35rem 1.25rem 1.4rem;
  background: color-mix(in srgb, white 72%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(8px);
}

.panel h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-soft);
}

input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  background: #fffdf9;
  color: var(--ink);
  outline: none;
}

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

input.code {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
}

.error {
  margin-top: 1.25rem;
  color: var(--danger);
  font-size: 0.92rem;
}

.room {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  gap: 0;
  animation: rise 0.4s ease both;
}

.room-bar {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, white 80%, transparent);
  backdrop-filter: blur(10px);
}

.room-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.65rem 1rem;
}

.room-title {
  font-family: var(--display);
  font-size: 1.55rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 500;
}

.chip strong {
  color: var(--ink);
  letter-spacing: 0.12em;
  font-family: ui-monospace, monospace;
}

.room-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.share-opt {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.share-opt select {
  min-width: 9.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #fffdf9;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.share-hint {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--ink-soft);
  max-width: 36rem;
}

.people {
  padding: 1.1rem 1rem;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-2) 70%, white);
}

.people h3 {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

#peer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

#peer-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  font-size: 0.92rem;
}

#peer-list li.self {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

#peer-list .badge {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.stage {
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-content: start;
  background:
    linear-gradient(180deg, transparent, rgba(18, 16, 14, 0.03)),
    var(--paper);
}

.room.screen-focus {
  grid-template-columns: 1fr;
}

.room.screen-focus .room-bar,
.room.screen-focus .people {
  display: none;
}

.room.screen-focus .stage {
  grid-column: 1 / -1;
  min-height: 100vh;
  padding: 0;
  gap: 0;
  grid-template-columns: 1fr;
  background: #000;
}

.stage.focused .tile {
  display: none;
}

.stage.focused .tile.is-focused {
  display: block;
  aspect-ratio: auto;
  height: 100vh;
  border-radius: 0;
  box-shadow: none;
  cursor: zoom-out;
}

.empty-stage {
  grid-column: 1 / -1;
  min-height: 50vh;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--ink-soft);
  padding: 2rem;
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.empty-stage[hidden] {
  display: none;
}

.tile {
  position: relative;
  overflow: hidden;
  margin: 0;
  border-radius: 14px;
  background: var(--tile);
  aspect-ratio: 16 / 10;
  box-shadow: 0 12px 40px rgba(18, 16, 14, 0.12);
  animation: fade-in 0.35s ease both;
  cursor: zoom-in;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

.tile figcaption {
  position: absolute;
  left: 0.65rem;
  bottom: 0.65rem;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  background: rgba(18, 16, 14, 0.72);
  color: #f5f0e8;
  font-size: 0.78rem;
  font-weight: 500;
  backdrop-filter: blur(4px);
  pointer-events: none;
}

.tile.local video {
  transform: none;
}

.tile.invite {
  cursor: pointer;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 70% 60% at 50% 40%, rgba(15, 110, 86, 0.28), transparent 70%),
    var(--tile);
}

.tile.invite .invite-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  color: #f5f0e8;
  text-align: center;
  padding: 1rem;
}

.tile.invite .invite-body strong {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 400;
}

.tile.invite .invite-body span {
  font-size: 0.85rem;
  color: #cfc6b8;
}

.tile-controls {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  z-index: 2;
}

.tile-controls .close-live {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  background: #d12626;
  color: #fff;
  font-size: 1.15rem;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(209, 38, 38, 0.35);
}

.tile-controls .close-live:hover {
  background: #a81c1c;
}

.vol {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: rgba(18, 16, 14, 0.72);
  color: #f5f0e8;
  font-size: 0.72rem;
}

.vol input[type="range"] {
  width: 88px;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: #7dccb0;
}

.tile.local .vol {
  display: none;
}

#peer-list li.live-link {
  cursor: pointer;
}

#peer-list li.live-link:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

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

@keyframes fade-in {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 760px) {
  .room {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }

  .people {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  #peer-list {
    flex-direction: row;
    flex-wrap: wrap;
  }
}
