:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1c2321;
  --muted: #5d6763;
  --line: #dde1dc;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --danger: #b4392f;
  --danger-soft: #f8e6e3;
  --warn-soft: #fbf1d9;
  --warn-ink: #6b4d06;
  --speak: #3fae7a;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --card: #1a201d;
    --text: #e7ece9;
    --muted: #9aa5a0;
    --line: #2c3430;
    --accent: #5fb89a;
    --accent-ink: #0d1411;
    --accent-soft: #1f3129;
    --danger: #e0695e;
    --danger-soft: #3a1f1c;
    --warn-soft: #362c14;
    --warn-ink: #f0d58f;
    --speak: #5fd39b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.page { max-width: 640px; margin: 0 auto; padding: 16px 16px 120px; }
.page.room { max-width: 900px; }
.loading { text-align: center; color: var(--muted); padding: 40vh 16px 0; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .01em; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); }
.logo svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.center { text-align: center; }
h1 { font-size: 1.4rem; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .86rem; margin: 6px 0 0; }
.error { color: var(--danger); min-height: 1.5em; margin: 8px 0; font-size: .95rem; }
.error:empty { min-height: 0; margin: 0; }
.warn { background: var(--warn-soft); color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; font-size: .92rem; }
.badge { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 10px; font-size: .85rem; font-weight: 600; }

label, .label { display: block; font-weight: 600; font-size: .92rem; margin: 14px 0 6px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.field { margin-bottom: 4px; }

input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 46px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; min-height: 44px; padding: 10px 16px; }
button:disabled { opacity: .6; cursor: progress; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.secondary { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.wide { width: 100%; margin-top: 12px; }
.link { background: none; color: var(--muted); padding: 6px 8px; min-height: 0; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--danger); display: block; margin: 10px auto 0; }
.icon { display: inline-grid; place-items: center; width: 46px; min-width: 46px; height: 46px; padding: 0; background: var(--accent-soft); color: var(--accent); }
.icon svg, .ctl svg, .inline-icon svg, .tile-mic svg, .secure svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.inline-icon svg { width: 14px; height: 14px; vertical-align: -2px; }

/* сегменты */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { margin: 0; font-weight: 500; font-size: .92rem; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--bg); min-height: 42px; display: inline-flex; align-items: center; }
.seg input:checked + label { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }

.stepper { display: flex; gap: 6px; max-width: 220px; }
.stepper button { width: 46px; background: var(--accent-soft); color: var(--accent); font-size: 1.3rem; padding: 0; }
.stepper input { text-align: center; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* ссылки */
.link-row { margin: 10px 0 14px; }
.link-row.owner .link-label { color: var(--warn-ink); }
.link-label { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.link-line { display: flex; gap: 6px; }
.link-line input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
.qr-holder { margin-top: 10px; }
.qr { width: 220px; max-width: 100%; background: #fff; border-radius: 10px; padding: 6px; }
.qr svg { display: block; width: 100%; height: auto; }

.name-line { display: flex; gap: 6px; }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--speak); }

/* комната */
.room-meta { display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.secure { display: inline-flex; align-items: center; gap: 5px; color: var(--accent); font-weight: 600; }
.secure svg { width: 16px; height: 16px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 650; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.timer.soon { color: var(--danger); border-color: var(--danger); }
@media (max-width: 420px) { .secure span { display: none; } }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--warn-soft); color: var(--warn-ink); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; }
.banner button { min-height: 36px; padding: 6px 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.tile {
  position: relative;
  font: inherit; color: inherit; text-align: center; cursor: pointer; min-height: 0;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 10px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--c); color: #fff;
  display: grid; place-items: center;
  font-size: 1.6rem; font-weight: 650;
  box-shadow: 0 0 0 0 transparent;
  transition: box-shadow .15s;
}
.tile.speaking { border-color: var(--speak); }
.tile.speaking .avatar { box-shadow: 0 0 0 4px var(--card), 0 0 0 7px var(--speak); }
.tile.poor { border-style: dashed; }
.tile-name { font-weight: 600; text-align: center; overflow-wrap: anywhere; line-height: 1.25; }
.you { color: var(--muted); font-weight: 400; }
.tile-mic { position: absolute; top: 10px; right: 10px; color: var(--danger); }
.tile-mic svg { width: 18px; height: 18px; }


.controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.ctl { display: inline-flex; align-items: center; gap: 8px; background: var(--card); color: var(--text); border: 1px solid var(--line); font-weight: 600; padding: 10px 16px; min-height: 52px; border-radius: 14px; }
.ctl.off { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.ctl.danger { background: var(--danger); color: #fff; border-color: transparent; }
.ctl.danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
@media (max-width: 480px) {
  .ctl span { display: none; }
  .ctl.danger-outline span { display: inline; font-size: .85rem; }
  .ctl { min-width: 56px; justify-content: center; }
}

#toast {
  position: fixed; left: 50%; top: 16px; transform: translate(-50%, -24px); opacity: 0; visibility: hidden;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: .95rem; max-width: calc(100% - 32px);
  transition: transform .25s ease, opacity .25s ease, visibility .25s; z-index: 10; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* --- этап 2 --- */
.small { font-size: .86rem; }
button.small { min-height: 36px; padding: 6px 12px; }
.danger-btn { background: var(--danger); color: #fff; font-weight: 600; }
details.more { margin: 18px 0 4px; border-top: 1px solid var(--line); padding-top: 10px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: 6px 0; list-style-position: inside; }
input[type=range] { width: 100%; accent-color: var(--accent); min-height: 32px; }

.crown { display: inline-flex; vertical-align: -3px; margin-right: 4px; color: #c9a227; }
.crown svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.lock-mark { display: inline-flex; color: var(--danger); }
.lock-mark svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }

.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 35%); z-index: 6; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(560px, 100%); max-height: 80dvh; overflow: auto; z-index: 7;
  margin: 0; border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.sheet-actions.col { flex-direction: column; }
.sheet-actions.col > button, .sheet-actions .row > button { width: 100%; }
.sheet-actions button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.sheet-actions button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row { display: flex; gap: 8px; }

.knocks:empty { display: none; }
.knocks { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.knock { display: flex; align-items: center; gap: 10px; background: var(--accent-soft); border-radius: 12px; padding: 8px 12px; }
.knock-name { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.knock-icon svg { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 2; }

.chat-list { display: flex; flex-direction: column; gap: 6px; max-height: 45dvh; overflow-y: auto; padding: 4px 0 10px; }
.chat-list:empty::before { content: "Сообщений пока нет"; color: var(--muted); font-size: .9rem; }
.msg { background: var(--bg); border-radius: 12px; padding: 7px 11px; max-width: 85%; align-self: flex-start; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--accent-soft); }
.msg b { display: block; font-size: .8rem; color: var(--muted); font-weight: 600; }
.chat-form { display: flex; gap: 8px; }
.chat-form button { flex: none; }
.ctl { position: relative; }
.unread { position: absolute; top: 4px; right: 4px; background: var(--danger); color: #fff; border-radius: 999px; font-size: .72rem; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 5px; }

.ctl.ptt { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.ctl.ptt-on { background: var(--speak); color: #fff; border-color: transparent; }
@media (max-width: 480px) { .ctl.ptt span { display: inline; font-size: .82rem; } .ctl.ptt { flex: 1; } }

.spinner { width: 36px; height: 36px; margin: 6px auto 14px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
