:root {
  color-scheme: dark;
  --bg: #101113;
  --panel: #181a1d;
  --panel-strong: #202327;
  --line: #363b42;
  --text: #f1f3f5;
  --muted: #aeb6c0;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --danger: #ef4444;
  --ok: #22c55e;
  --tile: #0b0d10;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.shell {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  align-items: stretch;
}

.brand-block {
  padding: clamp(32px, 8vw, 96px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(120deg, rgba(56, 189, 248, .12), transparent 42%),
    linear-gradient(180deg, #141619, #101113);
}

.mark {
  margin: 0 0 18px;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 760px;
  font-size: clamp(44px, 6vw, 82px);
  line-height: .95;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
}

.subcopy {
  max-width: 560px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.5;
}

.login-form {
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  background: var(--panel);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #0f1114;
  color: var(--text);
  padding: 0 14px;
  outline: none;
}

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

button {
  cursor: pointer;
}

.login-form button,
.text-button {
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: var(--accent-strong);
  color: #061016;
  font-weight: 800;
}

.error {
  min-height: 20px;
  margin: 0;
  color: #fca5a5;
}

.call-view {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 20px;
  padding: 18px 28px;
  background: #15171a;
  border-bottom: 1px solid var(--line);
}

.topbar .mark {
  margin-bottom: 6px;
}

.status-group {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 14px;
}

.metric {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  background: #101215;
}

.status {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-left: 3px solid var(--line);
  padding-left: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.status.ready {
  border-color: var(--ok);
  color: var(--ok);
}

.text-button {
  padding: 0 16px;
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.stage {
  min-height: 0;
  height: 100%;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(56, 189, 248, .04), transparent 220px),
    #0e0f11;
  overflow: hidden;
}

.participant-grid,
.peer-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  height: 100%;
  min-height: 0;
  place-items: center;
}

.peer-grid {
  display: contents;
}

.participant,
.peer {
  position: relative;
  width: 100%;
  height: auto;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  min-width: 0;
  min-height: 0;
  border: 1px solid #2d333a;
  background:
    linear-gradient(135deg, rgba(56, 189, 248, .1), transparent 34%),
    var(--tile);
  overflow: hidden;
  transition: border-color .12s ease, box-shadow .12s ease;
  cursor: pointer;
}

.participant.speaking,
.peer.speaking {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px rgba(56, 189, 248, .32),
    0 0 24px rgba(56, 189, 248, .34);
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, .025) 1px, transparent 1px),
    #06080a;
  background-size: 32px 32px;
}

.audio-badge {
  position: absolute;
  top: 18px;
  left: 18px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(16, 17, 19, .86);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.identity {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  text-shadow: 0 1px 10px rgba(0, 0, 0, .65);
}

.identity span {
  color: var(--muted);
  font-size: 13px;
}

.peer.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  border: 1px dashed #3a414a;
  padding: 32px;
  color: var(--muted);
  text-align: center;
  background: #121519;
  cursor: default;
}

.peer-name {
  position: absolute;
  left: 18px;
  bottom: 18px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(16, 17, 19, .82);
  font-weight: 800;
}

.header-controls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.control-button {
  width: 46px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #121417;
  color: var(--text);
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.control-button:hover,
.control-button:focus-visible {
  border-color: var(--accent);
  background: #18212a;
  color: var(--accent);
  outline: none;
}

.control-button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.control-button.danger {
  border-color: rgba(239, 68, 68, .6);
}

.control-button svg {
  width: 21px;
  height: 21px;
  stroke-width: 2;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(5, 7, 10, .72);
}

.modal-panel {
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  display: grid;
  grid-template-rows: auto auto 1fr;
  border: 1px solid var(--line);
  background: #15171a;
  overflow: hidden;
}

.compact-panel {
  width: min(430px, 100%);
  grid-template-rows: auto 1fr;
}

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

.modal-header .mark {
  margin-bottom: 5px;
}

h3 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.admin-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 14px;
  align-items: end;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.admin-form button {
  height: 48px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: var(--accent-strong);
  color: #061016;
  font-weight: 800;
}

.admin-form button.secondary,
.user-row button.secondary {
  border-color: var(--line);
  background: transparent;
  color: var(--text);
}

input[readonly] {
  color: var(--muted);
  background: #14171b;
}

.user-list-wrap {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.list-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 20px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

#adminMessage {
  color: var(--muted);
  font-size: 13px;
}

#adminMessage.error {
  color: #fca5a5;
}

.user-list {
  min-height: 0;
  overflow: auto;
}

.user-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 13px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.user-actions {
  display: flex;
  gap: 8px;
}

.user-row strong {
  overflow-wrap: anywhere;
}

.user-row button {
  min-height: 36px;
  border: 1px solid rgba(239, 68, 68, .55);
  border-radius: 2px;
  background: transparent;
  color: #fca5a5;
  font-weight: 800;
  padding: 0 12px;
}

.camera-list {
  display: grid;
  gap: 10px;
  padding: 18px 20px 20px;
}

.camera-list button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #101215;
  color: var(--text);
  font-weight: 800;
  text-align: left;
  padding: 0 12px;
}

.camera-list button.selected {
  border-color: var(--accent);
  color: var(--accent);
}

.empty-message {
  margin: 0;
  color: var(--muted);
}

.participant-grid.focused {
  display: block;
  position: relative;
}

.participant-grid.focused .participant,
.participant-grid.focused .peer {
  display: none;
}

.participant-grid.focused .focused-tile {
  display: block;
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
}

@media (max-width: 1180px) {
  .participant-grid,
  .peer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overscroll-behavior: none;
  }

  .login-view {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100svh;
  }

  .brand-block {
    min-height: 0;
    padding: 28px 22px 22px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand-block .mark {
    margin-bottom: 10px;
  }

  h1 {
    font-size: 30px;
    line-height: 1;
  }

  .subcopy {
    margin-top: 12px;
    font-size: 15px;
    line-height: 1.35;
  }

  .login-form {
    justify-content: start;
    gap: 14px;
    padding: 18px 20px 22px;
  }

  input {
    height: 44px;
  }

  .login-form button {
    min-height: 44px;
  }

  .call-view {
    position: fixed;
    inset: 0;
    min-height: 100svh;
    height: 100dvh;
    grid-template-rows: 1fr;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .topbar {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(84.375vw + 4px);
    z-index: 20;
    display: flex;
    justify-content: center;
    padding: 0 16px;
    border: 0;
    background: transparent;
    pointer-events: none;
  }

  .title-block,
  .status-group {
    display: none;
  }

  .stage {
    min-height: 0;
    height: 100%;
    padding: 8px;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .participant-grid,
  .peer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, auto);
    gap: 8px;
    width: 100%;
    height: 100%;
    max-height: calc(84.375vw - 4px);
    min-height: 0;
    align-content: start;
    place-items: stretch;
    overflow: hidden;
  }

  .participant,
  .peer {
    max-height: none;
  }

  .header-controls {
    pointer-events: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: min(330px, calc(100vw - 24px));
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, .12);
    background: rgba(15, 17, 20, .9);
    backdrop-filter: blur(14px);
  }

  .control-button {
    width: 44px;
    height: 40px;
    background: #171b20;
  }

  .control-button svg {
    width: 20px;
    height: 20px;
  }

  .modal {
    padding: 10px;
    place-items: end center;
  }

  .modal-panel {
    max-height: calc(100svh - 20px);
  }

  .admin-form {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px;
  }

  .user-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .user-actions {
    justify-content: stretch;
  }

  .user-actions button {
    flex: 1;
  }

  .modal-header,
  .list-heading,
  .user-row {
    padding-left: 16px;
    padding-right: 16px;
  }

  .identity,
  .peer-name {
    left: 8px;
    right: 8px;
    bottom: 8px;
    font-size: 12px;
  }

  .identity span,
  .audio-badge,
  .peer.empty {
    font-size: 11px;
  }

  .audio-badge {
    top: 8px;
    left: 8px;
    padding: 5px 7px;
  }

  .peer.empty {
    padding: 12px;
  }

  .participant-grid.focused {
    height: 100%;
  }

  .participant-grid.focused .focused-tile {
    height: auto;
    max-height: 100%;
    aspect-ratio: 16 / 9;
  }
}
