/* Цундере-тема: пастельно-розовая днём, вишнёво-тёмная ночью. */
:root {
  --bg: #fff3f6;
  --bg-dots: #ffd9e3;
  --panel: #ffffff;
  --panel-2: #ffe8ee;
  --line: #f7c4d2;
  --text: #3b1f2b;
  --muted: #a06a80;
  --accent: #ff4d7d;
  --accent-2: #e6336a;
  --accent-soft: #ffd1de;
  --green: #2fbf71;
  --red: #e5484d;
  --yellow: #ffb020;
  --shadow: 0 8px 28px #ff4d7d22;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1219;
    --bg-dots: #2a1823;
    --panel: #281a23;
    --panel-2: #33212d;
    --line: #4a2c3d;
    --text: #ffe9f0;
    --muted: #c493a8;
    --accent-soft: #4a2238;
    --shadow: 0 8px 28px #0007;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg) radial-gradient(var(--bg-dots) 1.5px, transparent 1.5px) 0 0 / 22px 22px;
  color: var(--text);
  font: 15px/1.45 "M PLUS Rounded 1c", system-ui, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 999px; padding: 8px 16px; background: var(--panel-2); font-weight: 700; }
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-2); }
button.primary:active { box-shadow: 0 2px 0 var(--accent-2); transform: translateY(2px); }
button.secondary { background: var(--accent-soft); color: var(--accent-2); }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--accent); background: var(--panel-2); }
.link { background: none; color: var(--muted); text-decoration: underline dotted; padding: 4px; font-weight: 400; font-size: 13px; }
.link:hover { color: var(--accent); }
button.small { padding: 6px 14px; }
input:not([type=range]):not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=range], input[type=checkbox] { accent-color: var(--accent); }
input[type=range] { width: 100%; }
label { display: block; margin: 10px 0; color: var(--muted); font-size: 13px; font-weight: 700; }
label > input, label > select { margin-top: 5px; color: var(--text); font-size: 15px; font-weight: 400; }
label output { color: var(--text); float: right; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; font-weight: 400; }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 10px; }
.error { color: var(--red); background: #e5484d18; padding: 8px 12px; border-radius: 12px; border: 2px dashed #e5484d55; }

.card { background: var(--panel); border-radius: 22px; box-shadow: var(--shadow); border: 2px solid var(--line); }

/* Аватарки */
.avatar, .avatar-pick {
  border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800;
  background-size: cover; background-position: center; flex: none;
}
.avatar-pick {
  width: 58px; height: 58px; padding: 0; font-size: 22px; border: 3px dashed var(--accent);
  margin-top: 8px;
}
.avatar-pick.big { width: 84px; height: 84px; font-size: 32px; margin: 0; }

/* Вход */
.screen { height: 100%; }
#auth { display: grid; place-items: center; padding: 16px; overflow: auto; }
.join-wrap { display: flex; flex-direction: column; align-items: center; width: min(400px, 100%); }
.mascot-box { position: relative; display: flex; align-items: flex-end; gap: 4px; margin-bottom: -18px; z-index: 1; }
.mascot { width: 130px; height: 130px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-2deg); } }
.bubble {
  position: relative; background: var(--panel); border: 2px solid var(--line); border-radius: 18px;
  padding: 10px 14px; font-size: 14px; max-width: 220px; margin-bottom: 70px; box-shadow: var(--shadow);
}
.bubble::before {
  content: ""; position: absolute; left: -9px; bottom: 14px; width: 14px; height: 14px; background: var(--panel);
  border-left: 2px solid var(--line); border-bottom: 2px solid var(--line); transform: rotate(45deg);
}
.join-card { width: 100%; padding: 26px; display: flex; flex-direction: column; }
.join-card h1 { margin: 0; font-size: 28px; font-weight: 800; color: var(--accent); text-align: center; }
.heart { display: inline-block; animation: beat 1.2s infinite; }
@keyframes beat { 15% { transform: scale(1.25); } 30% { transform: scale(1); } }
.join-profile { display: flex; gap: 12px; align-items: center; }
.grow { flex: 1; }
.join-card .primary { margin-top: 8px; padding: 11px; font-size: 16px; }
.join-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; }
.tabs { justify-content: center; margin: 14px 0 4px; }
.tabs label { flex: 1; text-align: center; }

/* Приложение: комнаты слева, комната справа */
.app { display: flex; }
.sidebar {
  width: 260px; flex: none; display: flex; flex-direction: column; background: var(--panel);
  border-right: 2px solid var(--line); min-height: 0;
}
.side-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; color: var(--accent); font-size: 18px; border-bottom: 2px solid var(--line); }
.rooms-head {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 4px;
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.rooms-head .mini { font-size: 18px; color: var(--accent-2); }
.room-list, .member-list { list-style: none; margin: 0; padding: 0; }
.room-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.room-row { display: flex; align-items: center; gap: 2px; border-radius: 12px; }
.room-row:hover { background: var(--panel-2); }
.room-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: none; border-radius: 12px; text-align: left; color: var(--text);
}
.room-btn svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.room-btn span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-btn small { color: var(--muted); font-weight: 400; }
.room-row .mini { width: 26px; height: 26px; font-size: 12px; background: none; color: var(--muted); visibility: hidden; }
.room-row:hover .mini, .room-row:focus-within .mini { visibility: visible; }
.room-row .mini:hover { background: var(--accent-soft); color: var(--accent-2); }
.room-item.current .room-row { background: var(--accent-soft); }
.room-item.current .room-btn, .room-item.current .room-btn svg { color: var(--accent-2); }
.member-list { padding: 2px 0 6px 30px; }
.member-list li { display: flex; align-items: center; gap: 8px; padding: 3px 6px; font-size: 13.5px; }
.member-list .avatar { width: 22px; height: 22px; font-size: 11px; }
.member-list span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-list i { display: flex; align-items: center; gap: 3px; color: var(--red); font-style: normal; }
.member-list i svg { width: 14px; height: 14px; }
.live { background: var(--red); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 6px; text-transform: uppercase; }
.me-panel { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 2px solid var(--line); background: var(--panel-2); }
.me-panel .avatar { width: 36px; height: 36px; font-size: 15px; }
.me-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.me-text b, .me-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text span { font-size: 12px; color: var(--muted); }
.me-panel .mini { background: var(--panel); color: var(--accent-2); }

.room-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lobby { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px; text-align: center; color: var(--muted); }
.lobby p { font-size: 17px; max-width: 360px; }
.menu-btn { display: none; }

dialog.small-dialog { width: min(380px, calc(100vw - 32px)); padding: 20px; }
.small-dialog h2 { margin: 0 0 12px; font-size: 18px; color: var(--accent-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Комната */
.room { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 2px solid var(--line);
}
.room-title { font-weight: 800; display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--accent-2); }
.room-title .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); flex: none; }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }
.badge { background: var(--accent); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 12px; }

.layout { flex: 1; display: flex; min-height: 0; }
.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 16px; gap: 16px; overflow: auto; }

.stage { display: flex; flex-direction: column; gap: 10px; }
.screen-view {
  max-height: 62vh; position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9; border: 3px solid var(--accent-soft); background-size: contain; background-position: center; background-repeat: no-repeat;
}
.screen-view.loading video { opacity: 0; }
.screen-view.loading::after {
  content: "Подключаюсь к стриму…"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-weight: 800; background: #0008;
}
.screen-view video { width: 100%; height: 100%; object-fit: contain; display: block; }
.screen-view .label {
  position: absolute; left: 8px; bottom: 8px; background: #000a; color: #fff; padding: 3px 10px; border-radius: 999px; font-size: 13px;
}
.view-actions { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; z-index: 1; }
.view-actions button { background: #000a; color: #fff; padding: 4px 10px; font-size: 13px; }
.view-actions .unwatch:hover { background: var(--red); }

.stream-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.stream-card {
  position: relative; width: 240px; aspect-ratio: 16 / 9; padding: 0; overflow: hidden;
  border-radius: 14px; background: #000; border: 3px solid var(--accent-soft); font-weight: 400;
}
.stream-card:hover { border-color: var(--accent); }
.stream-card img, .stream-card video { width: 100%; height: 100%; object-fit: contain; display: block; }
.stream-card.no-preview::before {
  content: "Превью скоро будет…"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff9; font-size: 13px;
}
.stream-card .live { position: absolute; top: 6px; left: 6px; }
.stream-card .label {
  position: absolute; left: 6px; bottom: 6px; max-width: calc(100% - 12px); background: #000a; color: #fff;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stream-card .watch {
  position: absolute; inset: 0; display: grid; place-items: center; background: #0007; color: #fff;
  font-weight: 800; opacity: 0; transition: opacity .12s;
}
.stream-card:hover .watch, .stream-card:focus-visible .watch { opacity: 1; }

.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); align-content: start; }
.tile {
  position: relative; background: var(--panel); border-radius: var(--radius);
  padding: 22px 12px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 3px solid var(--line); transition: border-color .12s, transform .12s;
}
.tile.speaking { border-color: var(--accent); transform: translateY(-2px); }
.tile-media { width: 100%; display: grid; place-items: center; }
.tile .avatar {
  width: 72px; height: 72px; font-size: 28px; transition: box-shadow .12s;
  box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--line);
}
.tile.speaking .avatar { box-shadow: 0 0 0 3px var(--panel), 0 0 0 6px var(--accent); }
.tile video { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; background: #000; display: block; }
.tile.self video { transform: scaleX(-1); }
.tile.has-video { padding-top: 10px; }
.tile-name { font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-icons { position: absolute; top: 6px; right: 10px; display: flex; gap: 4px; color: var(--red); z-index: 1; }
.tile-icons svg { width: 18px; height: 18px; }
.tile-icons .mine { color: var(--muted); }
.tile-ping { position: absolute; top: 6px; left: 12px; font-size: 11px; color: var(--muted); z-index: 1; }
.tile-actions { width: 100%; display: flex; align-items: center; gap: 6px; }
.tile.self .tile-actions { visibility: hidden; }
.mini { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; flex: none; background: var(--panel-2); font-size: 14px; }
.mini svg { width: 16px; height: 16px; }
.mini.active { background: var(--red); color: #fff; }
.tile.connecting { opacity: .55; }
.tile.local-muted .avatar { filter: grayscale(.8); }

.alone { text-align: center; color: var(--muted); margin: 10px auto; }
.alone img { animation: bob 3s ease-in-out infinite; }

.chat { width: 320px; display: flex; flex-direction: column; background: var(--panel); border-left: 2px solid var(--line); }
.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 8px; }
.msg .avatar { width: 32px; height: 32px; font-size: 14px; }
.msg-body { min-width: 0; }
.msg .meta { font-size: 12px; color: var(--muted); }
.msg .meta b { color: var(--accent-2); margin-right: 6px; }
.msg .text { white-space: pre-wrap; word-wrap: break-word; }
.msg .text a { color: var(--accent); }
.msg.system { color: var(--muted); font-size: 13px; font-style: italic; justify-content: center; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 2px solid var(--line); align-items: flex-end; }
.chat-form textarea { resize: none; max-height: 120px; }
.chat-form button { width: 42px; height: 42px; padding: 0; flex: none; }

.controls {
  display: flex; justify-content: center; gap: 10px; padding: 12px; background: var(--panel);
  border-top: 2px solid var(--line); flex-wrap: wrap;
}
.ctrl { width: 52px; height: 48px; display: grid; place-items: center; padding: 0; border-radius: 16px; background: var(--panel-2); color: var(--accent-2); }
.ctrl svg { width: 22px; height: 22px; }
.ctrl.off { background: var(--red); color: #fff; }
.ctrl.on { background: var(--accent); color: #fff; }
.ctrl.danger { background: var(--red); color: #fff; }
.ctrl.ptt { width: auto; padding: 0 18px; user-select: none; touch-action: none; }
.ctrl.ptt.active { background: var(--green); color: #fff; }

/* Всплывашки */
.toasts { position: fixed; left: 16px; bottom: 84px; display: flex; flex-direction: column; gap: 8px; z-index: 20; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 2px solid var(--accent);
  border-radius: 18px; padding: 6px 14px 6px 6px; box-shadow: var(--shadow); max-width: 360px; font-size: 14px;
  animation: pop .25s ease-out;
}
.toast img { width: 36px; height: 36px; flex: none; }
@keyframes pop { from { transform: translateY(10px) scale(.9); opacity: 0; } }

/* Настройки и выбор экрана */
dialog { color: var(--text); padding: 0; }
dialog.settings { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: #3b1f2b88; }
.settings-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.settings-head h2 { margin: 0; font-size: 20px; color: var(--accent-2); }
.settings-body { padding: 0 20px 20px; overflow-y: auto; }
.settings-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin: 22px 0 6px; }
.profile-row { display: flex; gap: 16px; align-items: center; }
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented label { margin: 0; padding: 7px 14px; border-radius: 999px; background: var(--panel-2); color: var(--text); cursor: pointer; font-size: 14px; }
.segmented label:has(input:checked) { background: var(--accent); color: #fff; }
.segmented input { display: none; }
.meter-wrap { position: relative; margin-top: 8px; }
.meter { position: relative; height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; margin: 6px 0; }
.meter-fill { height: 100%; width: 0; background: var(--muted); transition: width 60ms linear; }
.meter-fill.open { background: var(--green); }
.meter-mark { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.keybind { min-width: 140px; margin-top: 5px; font-family: ui-monospace, monospace; border-radius: 10px; }
.keybind.listening { background: var(--yellow); color: #000; }
.test-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.test-row .hint { margin: 0; }
#s-test.on { background: var(--green); color: #fff; }

dialog.picker { width: min(760px, calc(100vw - 32px)); }
.picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; padding: 16px 20px; max-height: 60vh; overflow: auto; }
.picker-list button { border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 6px; font-weight: 400; font-size: 13px; text-align: left; }
.picker-list button:hover { outline: 3px solid var(--accent); }
.picker-list img { width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #0002; border-radius: 8px; }
.picker-list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-audio { padding: 0 20px 16px; }

@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 10; box-shadow: var(--shadow); transform: translateX(-102%); transition: transform .2s; }
  .app.side-open .sidebar { transform: none; }
  .menu-btn { display: inline-block; }
  .lobby .menu-btn { position: absolute; top: 12px; left: 12px; }
  .room-row .mini { visibility: visible; }
  .chat { position: fixed; inset: 56px 0 74px 0; width: auto; z-index: 5; }
  .layout:not(.chat-open) .chat { display: none; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .stream-card { width: calc(50% - 5px); }
  .ctrl { width: 44px; }
  .mascot { width: 100px; height: 100px; }
}
@media (min-width: 761px) {
  .layout.chat-hidden .chat { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
