:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #191d21;
  --panel-strong: #20262b;
  --line: #303841;
  --text: #f4f6f8;
  --muted: #9aa7b2;
  --accent: #2fbf8f;
  --accent-dark: #16835f;
  --danger: #d8534f;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.join-panel {
  width: min(520px, calc(100vw - 32px));
  margin: 0 auto;
  padding-top: 18vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 15px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #06120e;
  font-weight: 800;
}

.join-form {
  display: grid;
  gap: 18px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d0f11;
  color: var(--text);
  padding: 13px 14px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
}

.primary-action,
.danger-button,
.controls button,
.message-form button,
.icon-button {
  border: 0;
  border-radius: 6px;
  color: var(--text);
  padding: 12px 16px;
  font-weight: 700;
}

.primary-action {
  background: var(--accent);
  color: #06120e;
}

.primary-action:hover {
  background: #45d0a3;
}

.call-view {
  display: grid;
  min-height: 100vh;
  grid-template-rows: 76px minmax(0, 1fr) 76px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  background: #121619;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 750;
}

h2 {
  font-size: 15px;
  margin-bottom: 12px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.icon-button {
  background: var(--panel-strong);
}

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

.workspace {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) 340px;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  grid-auto-rows: minmax(240px, 1fr);
  gap: 12px;
  min-height: 0;
  padding: 12px;
  overflow: auto;
}

.tile {
  position: relative;
  overflow: hidden;
  min-height: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #08090a;
}

.tile-media {
  width: 100%;
  height: 100%;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #08090a;
}

.tile.screen-share video {
  object-fit: contain;
}

.tile-name {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  padding: 7px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.62);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.panel-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

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

.participant-list li {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 14px;
}

.chat-section {
  display: grid;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-bottom: 0;
}

.messages {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
}

.message {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 6px;
  background: var(--panel-strong);
  font-size: 14px;
}

.message strong {
  color: var(--accent);
  font-size: 12px;
}

.message-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.message-form button {
  background: var(--accent-dark);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: #121619;
}

.controls button {
  min-width: 130px;
  background: var(--panel-strong);
}

.controls button.active {
  background: var(--accent);
  color: #06120e;
}

@media (max-width: 959px) {
  .join-panel {
    width: min(440px, calc(100vw - 28px));
    padding-top: 10vh;
  }

  .join-form {
    padding: 22px;
  }

  .call-view {
    min-height: 100dvh;
    grid-template-rows: auto auto auto;
  }

  .topbar {
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
  }

  .top-actions {
    flex-shrink: 0;
  }

  .top-actions button {
    padding: 10px 12px;
    font-size: 14px;
  }

  h1 {
    max-width: 46vw;
    font-size: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace {
    display: block;
    min-height: auto;
    overflow: visible;
  }

  .video-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
    padding: 8px;
    overflow: visible;
  }

  .tile {
    min-height: 0;
    aspect-ratio: 16 / 9;
  }

  .side-panel {
    display: block;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .panel-section {
    padding: 12px 14px;
  }

  .participant-list {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }

  .participant-list li {
    padding: 9px 10px;
    font-size: 14px;
  }

  .chat-section {
    display: grid;
    min-height: 180px;
    grid-template-rows: auto minmax(72px, 1fr) auto;
  }

  .controls {
    flex-wrap: nowrap;
    gap: 6px;
    padding: 8px;
    position: sticky;
    bottom: 0;
    z-index: 5;
  }

  .controls button {
    min-width: 0;
    flex: 1 1 0;
    padding: 10px 6px;
    font-size: 12px;
    white-space: nowrap;
  }

  .controls #micButton.active {
    background: #2fbf8f;
    color: #06120e;
  }

  .controls #cameraButton.active {
    background: #4f8cff;
    color: #061020;
  }

  .controls #switchCameraButton {
    background: #f0b84f;
    color: #1f1300;
  }
}

@media (max-width: 520px) {
  .brand {
    margin-bottom: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }

  h1 {
    max-width: 100%;
  }

  .video-grid {
    gap: 8px;
  }

  .tile-name {
    left: 8px;
    bottom: 8px;
    padding: 6px 8px;
    font-size: 12px;
  }

  .message-form {
    grid-template-columns: 1fr;
  }

  .video-grid.mobile-call-layout {
    position: relative;
    display: block;
    width: 100%;
    height: calc(100dvh - 178px);
    min-height: 460px;
    padding: 0;
    overflow: hidden;
    background: #050607;
  }

  .video-grid.mobile-call-layout .tile {
    border: 0;
    border-radius: 0;
    background: #050607;
  }

  .video-grid.mobile-call-layout .primary-tile {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
  }

  .video-grid.mobile-call-layout .self-preview {
    position: absolute;
    right: 10px;
    bottom: 18px;
    z-index: 4;
    width: min(24vw, 104px);
    height: min(34vw, 136px);
    min-height: 0;
    aspect-ratio: auto;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
    touch-action: none;
    user-select: none;
  }

  .video-grid.mobile-call-layout .self-preview .tile-name {
    display: none;
  }

  .video-grid.mobile-call-layout + .side-panel {
    display: none;
  }
}
