/* Алло — «ночное радио»: глубокий индиго + янтарный сигнал «в эфире» */
:root {
  --night: #15172a;     /* фон */
  --deck: #1f2238;      /* панели */
  --raised: #2b2f4b;    /* кнопки, поля */
  --well: #0f1120;      /* подложка видео */
  --ink: #eeebf7;       /* текст */
  --haze: #9396b2;      /* второстепенный текст */
  --signal: #ffb938;    /* янтарный: говорит / главное действие */
  --signal-ink: #2a1c00;
  --stop: #f0544f;      /* выключено / выйти */
  --display: "Unbounded", "Segoe UI", system-ui, sans-serif;
  --text: "Manrope", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--night); color: var(--ink); font: 500 15px/1.5 var(--text); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Главная и вход ---------- */
.screen { position: relative; min-height: 100%; display: flex; align-items: center; padding: 48px max(24px, 8vw); overflow: hidden; }
.waves {
  position: absolute; right: -30vmax; bottom: -30vmax; width: 90vmax; height: 90vmax; border-radius: 50%; pointer-events: none;
  background: repeating-radial-gradient(circle, transparent 0 46px, rgba(255, 185, 56, .07) 46px 48px);
  -webkit-mask-image: radial-gradient(circle, #000 20%, transparent 70%); mask-image: radial-gradient(circle, #000 20%, transparent 70%);
}
.intro { position: relative; max-width: 34rem; }
.wordmark { font: 900 clamp(48px, 11vw, 120px)/.92 var(--display); letter-spacing: -.04em; margin: 0 0 28px; color: var(--ink); white-space: nowrap; }
.wordmark::after { content: ""; display: inline-block; width: .16em; height: .16em; margin-left: .06em; border-radius: 50%; background: var(--signal); box-shadow: 0 0 .3em var(--signal); }
.wordmark.small { font-size: 22px; margin-bottom: 40px; }
.lead { font-size: 18px; line-height: 1.6; color: var(--haze); margin: 0 0 36px; max-width: 30rem; }
.room-name { font: 700 clamp(26px, 5vw, 36px)/1.15 var(--display); margin: 0 0 28px; letter-spacing: -.02em; }
.room-name span { color: var(--signal); overflow-wrap: anywhere; }
.field { display: block; margin: 0 0 16px; max-width: 22rem; }
.field span { display: block; font-size: 14px; color: var(--haze); margin-bottom: 8px; }
.field input { width: 100%; background: var(--deck); border: 1.5px solid var(--raised); border-radius: 14px; padding: 14px 16px; font-size: 17px; }
.field input:focus { border-color: var(--signal); outline: none; }
.err { color: var(--stop); min-height: 1.5em; margin: 14px 0 0; }

.btn { display: inline-flex; align-items: center; gap: 10px; border: 0; border-radius: 999px; padding: 15px 28px; font-weight: 700; font-size: 16px; cursor: pointer; text-decoration: none; transition: transform .12s, background .12s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--signal); color: var(--signal-ink); }
.btn.primary:hover { background: #ffc85e; }
.btn.ghost { background: var(--raised); color: var(--ink); padding: 9px 16px; font-size: 14px; font-weight: 600; }
.btn.ghost:hover { background: #363a5a; }
.btn.ghost svg { width: 18px; height: 18px; }

/* ---------- Комната ---------- */
#room { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px 6px; }
.where { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 700; }
.where #roomTitle { font-family: var(--display); font-weight: 500; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 10px var(--signal); flex: none; }
.count { color: var(--haze); font-weight: 500; white-space: nowrap; }

.body { flex: 1; display: flex; min-height: 0; }
#stage { flex: 1; display: flex; gap: 12px; padding: 12px 18px; min-width: 0; min-height: 0; }
#focus { display: none; flex: 1; min-width: 0; }
#focus .tile { width: 100%; height: 100%; aspect-ratio: auto; }
#grid { flex: 1; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-content: center; overflow: auto; padding: 4px; }
#stage.has-focus #focus { display: block; }
#stage.has-focus #grid { flex: 0 0 240px; grid-template-columns: 1fr; align-content: start; }

/* Плитка участника */
.tile { --lvl: 0; position: relative; background: var(--deck); border-radius: 20px; overflow: hidden; aspect-ratio: 16 / 10; cursor: pointer; transition: box-shadow .12s; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: var(--well); }
.tile.novideo video { visibility: hidden; position: absolute; }
.tile .avatar {
  display: none; position: absolute; inset: 0; margin: auto; width: 96px; height: 96px; border-radius: 50%;
  background: hsl(var(--hue, 250) 60% 70%); color: hsl(var(--hue, 250) 50% 14%);
  font: 700 38px/1 var(--display); align-items: center; justify-content: center; transition: box-shadow .12s;
}
.tile.novideo .avatar { display: flex; }
/* Главное: янтарное «в эфире», дышит вместе с голосом */
.tile.speaking { box-shadow: inset 0 0 0 3px var(--signal); }
.tile.speaking .avatar { box-shadow: 0 0 0 calc(4px + var(--lvl) * 14px) rgba(255, 185, 56, .35), 0 0 0 3px var(--signal); }

.tile .label { position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 6px; max-width: calc(100% - 24px); padding: 5px 11px; border-radius: 999px; background: rgba(15, 17, 32, .72); font-size: 13px; font-weight: 600; white-space: nowrap; }
.tile .label .name { overflow: hidden; text-overflow: ellipsis; }
.tile .label svg { width: 15px; height: 15px; }
.tile .label .muted-ic { color: var(--stop); display: none; }
.tile.mic-off .label .muted-ic { display: block; }
.tile .label .screen-ic { color: var(--signal); }
.tile .tools { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; align-items: center; padding: 4px; border-radius: 999px; background: rgba(15, 17, 32, .72); opacity: 0; transition: opacity .15s; }
.tile:hover .tools, .tile:focus-within .tools { opacity: 1; }
.tile .tools button { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.tile .tools button:hover { background: var(--raised); }
.tile .tools svg { width: 17px; height: 17px; }
.tile .tools input[type=range] { width: 90px; accent-color: var(--signal); margin: 0 4px 0 8px; }
.tile.mine video.cam { transform: scaleX(-1); }

/* Панель управления */
.dock { align-self: center; display: flex; align-items: center; gap: 10px; margin: 6px auto 18px; padding: 10px; border-radius: 999px; background: var(--deck); box-shadow: 0 10px 30px rgba(5, 6, 15, .45); }
.ctl { display: grid; place-items: center; width: 52px; height: 52px; border: 0; border-radius: 50%; background: var(--raised); color: var(--ink); cursor: pointer; transition: background .12s, transform .12s; }
.ctl:hover { background: #363a5a; }
.ctl:active { transform: scale(.94); }
.ctl.on { background: var(--signal); color: var(--signal-ink); }
.ctl.off { background: rgba(240, 84, 79, .18); color: var(--stop); }
.ctl.leave { background: var(--stop); color: #fff; width: 64px; }
.ctl.leave:hover { background: #ff6a65; }
.screen-group { display: flex; align-items: center; gap: 4px; background: var(--raised); border-radius: 999px; padding-right: 6px; }
.screen-group .ctl { background: transparent; }
.screen-group .ctl.on { background: var(--signal); }
/* Режим показа экрана: своя кнопка и меню вместо системного списка */
.mode-btn { display: flex; align-items: center; gap: 4px; background: transparent; border: 0; padding: 8px 6px 8px 4px; font-size: 13px; font-weight: 700; color: var(--haze); cursor: pointer; border-radius: 999px; }
.mode-btn:hover, .mode-btn[aria-expanded="true"] { color: var(--ink); }
.mode-btn svg { width: 16px; height: 16px; transition: transform .15s; }
.mode-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.pop.menu { width: min(320px, calc(100% - 32px)); padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.menu button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; background: transparent; border: 0; border-radius: 14px; padding: 11px 14px 11px 40px; cursor: pointer; position: relative; }
.menu button:hover { background: var(--raised); }
.menu button b { font-size: 15px; }
.menu button span { font-size: 13px; color: var(--haze); }
.menu button::before { content: ""; position: absolute; left: 14px; top: 15px; width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--raised); }
.menu button[aria-checked="true"]::before { background: var(--signal); box-shadow: 0 0 8px rgba(255, 185, 56, .6); }
.sep { width: 1px; height: 28px; background: var(--raised); margin: 0 4px; }

/* Чат */
#chat { width: 320px; margin: 12px 18px 12px 0; background: var(--deck); border-radius: 20px; display: flex; flex-direction: column; overflow: hidden; }
.chat-head { padding: 16px 18px 8px; font: 500 14px var(--display); }
#chatLog { flex: 1; overflow-y: auto; padding: 8px 18px; display: flex; flex-direction: column; gap: 10px; }
.chat-empty { color: var(--haze); font-size: 14px; margin: 0; }
#chatLog .msg { overflow-wrap: anywhere; line-height: 1.45; }
#chatLog .msg b { display: block; font-size: 13px; color: var(--signal); font-weight: 700; }
#chatLog .msg a { color: #9fb4ff; }
#chatForm { padding: 12px; }
#chatInput { width: 100%; background: var(--raised); border: 0; border-radius: 999px; padding: 12px 16px; }
#chatInput:focus { outline: 2px solid var(--signal); }

#toast { position: fixed; left: 50%; top: 18px; transform: translate(-50%, -8px); max-width: min(560px, calc(100% - 32px)); background: var(--ink); color: var(--night); font-weight: 600; padding: 12px 18px; border-radius: 16px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Проверка микрофона в лобби и в настройках */
.mic-check { max-width: 22rem; margin: 0 0 24px; }
.mic-row { display: flex; align-items: center; gap: 10px; background: var(--deck); border: 1.5px solid var(--raised); border-radius: 14px; padding: 4px 6px 4px 14px; }
.mic-row svg { color: var(--haze); width: 20px; height: 20px; }
.mic-row select, .pop select { flex: 1; min-width: 0; background: transparent; border: 0; padding: 10px 4px; font-size: 15px; cursor: pointer; }
.mic-row select option, .pop select option { background: var(--deck); color: var(--ink); }
.meter { height: 6px; margin: 10px 2px 0; border-radius: 999px; background: var(--raised); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--signal); transform-origin: left; transform: scaleX(0); transition: transform 60ms linear; }
.mic-hint { font-size: 14px; color: var(--haze); margin: 10px 2px 0; }
.mic-hint.bad { color: var(--stop); }
.link-btn { background: none; border: 0; padding: 6px 2px; color: var(--signal); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* Окно настроек звука над панелью */
.pop { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); width: min(360px, calc(100% - 32px)); background: var(--deck); border-radius: 20px; padding: 18px; box-shadow: 0 16px 40px rgba(5, 6, 15, .6); z-index: 6; }
.pop .field { margin: 0 0 6px; max-width: none; }
.pop .field + .meter { margin-bottom: 18px; }
.pop select { width: 100%; background: var(--raised); border-radius: 12px; padding: 11px 12px; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--signal); }

/* Статус соединения на плитке */
.tile .conn { position: absolute; left: 12px; top: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(15, 17, 32, .8); color: var(--signal); font-size: 12px; font-weight: 700; }

#unmute { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 8; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(5, 6, 15, .5); }

@media (max-width: 760px) {
  .topbar { padding: 12px 16px 4px; }
  .btn.ghost span { display: none; }
  #stage { flex-direction: column; padding: 8px 16px; }
  #grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-content: start; }
  #stage.has-focus #grid { flex: 0 0 auto; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .tile .avatar { width: 64px; height: 64px; font-size: 26px; }
  .tile.speaking .avatar { box-shadow: 0 0 0 calc(3px + var(--lvl) * 6px) rgba(255, 185, 56, .35), 0 0 0 3px var(--signal); }
  .dock { gap: 6px; padding: 8px; margin-bottom: max(12px, env(safe-area-inset-bottom)); }
  .ctl { width: 46px; height: 46px; }
  .ctl.leave { width: 54px; }
  .mode-btn, .sep { display: none; }
  .screen-group { padding: 0; }
  #chat { position: fixed; inset: 60px 16px 90px; width: auto; margin: 0; z-index: 5; box-shadow: 0 10px 40px rgba(5, 6, 15, .6); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Своя демонстрация: вместо живого превью — значок (меньше нагрузки во время игры) */
.tile.self-share .avatar { font-size: 0; background: var(--raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffb938' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='12' rx='2'/%3E%3Cpath d='M8 20h8M12 16v4'/%3E%3C/svg%3E") center / 44% no-repeat; }
#stage.has-focus #grid .avatar { width: 60px; height: 60px; font-size: 24px; margin-top: 18px; }
#stage.has-focus #grid .tile.speaking .avatar { box-shadow: 0 0 0 calc(3px + var(--lvl) * 6px) rgba(255, 185, 56, .35), 0 0 0 3px var(--signal); }
