:root {
  --bg: #0f1419;
  --panel: #18202a;
  --panel-2: #212c39;
  --line: #2c3948;
  --text: #e8edf2;
  --muted: #93a1b0;
  --accent: #2f9e7a;
  --accent-ink: #06231a;
  --danger: #d9534f;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ------------------------------ düğmeler ------------------------------ */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn:focus-visible, .ctl:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* -------------------------------- giriş ------------------------------- */
.lobby {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 30px; height: 30px; fill: var(--accent); flex: none; }
.brand h1 { font-size: 21px; margin: 0; }
.lead { color: var(--muted); margin: 4px 0 10px; font-size: 15px; }
label { font-size: 14px; font-weight: 600; margin-top: 8px; }
input[type="text"] {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.hint { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.hint.center { text-align: center; margin-top: 6px; }
.error {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(217, 83, 79, .15);
  border: 1px solid rgba(217, 83, 79, .5);
  font-size: 14px;
}
.card .btn.primary { margin-top: 14px; }

/* --------------------------------- oda -------------------------------- */
.room {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.status, .top-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.muted { color: var(--muted); }
.badge.locked { background: rgba(217, 83, 79, .18); border-color: rgba(217, 83, 79, .5); }
.badge.e2e { color: #7fd8b8; border-color: rgba(47, 158, 122, .5); }

.stage { flex: 1; min-height: 0; display: flex; position: relative; }

.grid {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  overflow: hidden;
}
.grid[data-count="2"] { grid-template-rows: 1fr 1fr; }
.grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="5"], .grid[data-count="6"] { grid-template-columns: 1fr 1fr; }
@media (min-width: 760px) {
  .grid[data-count="2"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
  .grid[data-count="5"], .grid[data-count="6"] { grid-template-columns: 1fr 1fr 1fr; }
}

.tile {
  position: relative;
  background: #05080b;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.local video { transform: scaleX(-1); }
.tile.local.screen video { transform: none; object-fit: contain; }
.tile .label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  padding: 3px 9px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .6);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile[data-state="connecting"]::after,
.tile[data-state="new"]::after,
.tile[data-state="disconnected"]::after,
.tile[data-state="failed"]::after {
  content: "Bağlanıyor…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(5, 8, 11, .7);
  font-size: 14px;
}

/* ------------------------------- sohbet ------------------------------- */
.chat {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
}
@media (max-width: 759px) {
  .chat { position: absolute; inset: 0; width: auto; border-left: 0; z-index: 5; }
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg {
  max-width: 88%;
  padding: 7px 11px;
  border-radius: 12px;
  background: var(--panel-2);
  align-self: flex-start;
  overflow-wrap: anywhere;
}
.msg.mine { align-self: flex-end; background: rgba(47, 158, 122, .28); }
.msg .who { display: block; font-size: 11px; color: var(--muted); }
.msg p { margin: 0; white-space: pre-wrap; }
.msg.system {
  align-self: center;
  background: none;
  color: var(--muted);
  font-size: 12px;
  padding: 0;
}
.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.chat-form input { flex: 1; }

/* ------------------------------ kontroller ---------------------------- */
.controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 8px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.ctl {
  position: relative;
  flex: 1;
  max-width: 96px;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.ctl .ico { font-size: 20px; line-height: 1; }
.ctl[aria-pressed="false"] { background: var(--bg); color: var(--muted); }
.ctl[aria-pressed="false"] .ico { opacity: .45; text-decoration: line-through; }
#screenBtn[aria-pressed="true"] { border-color: var(--accent); }
.ctl.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl:disabled { opacity: .4; cursor: default; }
.dot {
  position: absolute;
  top: 6px;
  right: 14px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #000;
  border: 1px solid var(--line);
  font-size: 14px;
  z-index: 20;
}
