:root {
  color-scheme: light;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #f7f8fb;
  color: #161b28;
  --bg: #f7f8fb;
  --panel: #fff;
  --soft: #f3f5f9;
  --text: #161b28;
  --muted: #576376;
  --line: #dce2ed;
  --accent: #364bcd;
  --accent-hover: #2839a9;
  --accent-soft: #e9edff;
  --accent-ink: #2e43b6;
  --danger: #b52b48;
  --danger-soft: #fae8ed;
  --green: #147350;
  --shadow: 0 16px 40px #202c4b0b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #131722;
    --panel: #1a202e;
    --soft: #212839;
    --text: #f3f5fc;
    --muted: #abb6cb;
    --line: #364158;
    --accent: #8e9dff;
    --accent-hover: #aebaff;
    --accent-soft: #293564;
    --accent-ink: #b9c4ff;
    --danger: #ff9aaf;
    --danger-soft: #462535;
    --green: #73d3a7;
    --shadow: 0 16px 40px #090c1670;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131722;
  --panel: #1a202e;
  --soft: #212839;
  --text: #f3f5fc;
  --muted: #abb6cb;
  --line: #364158;
  --accent: #8e9dff;
  --accent-hover: #aebaff;
  --accent-soft: #293564;
  --accent-ink: #b9c4ff;
  --danger: #ff9aaf;
  --danger-soft: #462535;
  --green: #73d3a7;
  --shadow: 0 16px 40px #090c1670;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; min-height: 100vh; color: var(--text); background: var(--bg); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1, h2 { line-height: 1.16; letter-spacing: -.035em; }
h1 { font-size: clamp(1.65rem, 3.2vw, 2.35rem); }
h2 { font-size: 1.07rem; }
p { line-height: 1.55; }
img { object-fit: contain; display: block; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.site-header { background: var(--panel); border-bottom: 1px solid var(--line); }
.header-inner { width: min(100% - 64px, 1500px); min-height: 72px; margin: 0 auto; display: flex; align-items: center; gap: 44px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 750; font-size: 1.16rem; letter-spacing: -.045em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); }
#unread-count, .room-unread { padding: 2px 6px; border-radius: 9px; background: var(--accent); color: var(--panel); font-size: .72rem; }
.room-unread { margin-inline-start: auto; }
.navigation, .header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions { margin-inline-start: auto; }
.header-user { margin-inline: 5px; color: var(--muted); font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 18ch; }
.nav-tab, .theme-button { min-height: 38px; padding: 8px 12px; border: 1px solid transparent; border-radius: 9px; color: var(--muted); background: transparent; font-weight: 620; font-size: .89rem; }
.nav-tab:hover, .theme-button:hover { background: var(--soft); }
.nav-tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
.theme-button { width: 39px; padding: 0; border-color: var(--line); display: grid; place-items: center; }
.theme-icon { width: 15px; height: 15px; border: 1.6px solid currentColor; border-radius: 50%; background: linear-gradient(90deg, currentColor 50%, transparent 50%); }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 13px; min-height: 39px; border: 1px solid transparent; border-radius: 9px; font-size: .86rem; font-weight: 650; line-height: 1.2; white-space: nowrap; }
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); }
:root[data-theme="dark"] .button.primary { color: #10162d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .button.primary { color: #10162d; } }
.button.subtle { color: var(--text); background: var(--panel); border-color: var(--line); }
.button.subtle:hover:not(:disabled) { background: var(--soft); }
.button[aria-pressed="true"] { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.button.danger { color: var(--danger); background: var(--danger-soft); }
.button.danger:hover:not(:disabled) { border-color: var(--danger); }
.link-button { border: 0; padding: 5px 0; color: var(--accent-ink); background: transparent; font-size: .84rem; font-weight: 650; }
.link-button:hover { text-decoration: underline; }

.auth-shell { display: grid; place-items: center; min-height: calc(100vh - 73px); min-height: calc(100svh - 73px); padding: 32px 18px 84px; background: radial-gradient(ellipse at 50% 0%, var(--accent-soft), transparent 58%); }
.auth-card { width: min(100%, 432px); padding: clamp(24px, 6vw, 40px); border: 1px solid var(--line); border-radius: 21px; background: var(--panel); box-shadow: var(--shadow); }
.auth-card h1 { font-size: clamp(1.7rem, 5vw, 2.05rem); }
.auth-description { margin: 10px 0 26px; font-size: .94rem; color: var(--muted); }
.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: var(--text); font-size: .85rem; font-weight: 650; min-width: 0; }
input, select, textarea { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--text); padding: 11px 12px; min-height: 44px; font-size: 1rem; font-weight: 400; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.password-field { position: relative; }
.password-field input { padding-inline-end: 89px; }
.password-field button { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); }
.auth-submit { min-height: 44px; margin-top: 5px; }
.arrow { font-size: 1.05rem; }
.back { justify-self: center; }
.enrollment { padding: 11px; border-radius: 9px; background: var(--soft); color: var(--muted); font-size: .82rem; }
.secret-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 5px; margin-top: 8px; }
.secret-row code { overflow-wrap: anywhere; color: var(--text); user-select: all; font-size: .8rem; }
.error { color: var(--danger); font-size: .85rem; overflow-wrap: anywhere; }
.auth-card > .error { margin-top: 15px; }

.workspace { width: min(100% - 64px, 1500px); margin: 29px auto; display: grid; grid-template-columns: minmax(174px, 215px) minmax(0, 1fr) minmax(274px, 340px); align-items: start; gap: 20px; }
.lesson-list, .lesson, .chat, .empty-lesson { background: var(--panel); border: 1px solid var(--line); border-radius: 15px; min-width: 0; }
.lesson-list { padding: 16px 12px; }
.lesson-list h2 { margin: 0 7px 13px; }
.rooms { display: grid; gap: 5px; }
.room-button { display: flex; align-items: center; gap: 9px; min-width: 0; width: 100%; text-align: left; padding: 8px; background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 9px; }
.room-button:hover { background: var(--soft); }
.room-button[aria-current="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.room-button span { display: grid; min-width: 0; gap: 3px; }
.room-button strong, .room-button small { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.room-button strong { font-size: .86rem; }
.room-button small { color: var(--muted); font-size: .73rem; }
.avatar { flex: none; }
.theme-icon-image { filter: grayscale(1) brightness(.8); }
:root[data-theme="dark"] .theme-icon-image, .stage-image img { filter: grayscale(1) invert(.9); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-icon-image { filter: grayscale(1) invert(.9); }
}
.room-button[data-hand="true"] { background: var(--soft); border-color: var(--green); color: var(--green); }
.room-button[data-hand="true"] small, .hand-status { color: var(--green); }
.empty-lesson { grid-column: 2 / -1; min-height: 460px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; padding: 30px; }
.empty-lesson p { color: var(--muted); }
.lesson { padding: 17px; }
.lesson-header { display: flex; justify-content: space-between; align-items: center; gap: 13px; margin: 1px 0 16px; }
.lesson-header h1 { font-size: clamp(1.3rem, 2.5vw, 1.85rem); overflow-wrap: anywhere; margin-top: 3px; }
.eyebrow, .presence, .chat-status { font-size: .77rem; color: var(--muted); }
.presence { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.presence::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.presence[data-online="true"] { color: var(--green); }
.peer-media, .peer-mic, .peer-link { display: inline-flex; align-items: center; gap: 6px; }
.peer-media { flex-wrap: wrap; font-size: .77rem; color: var(--muted); }
.peer-mic[data-state="on"] { color: var(--green); }
.peer-mic meter { width: 40px; height: 9px; accent-color: var(--green); }
.peer-link { align-items: flex-end; gap: 2px; height: 14px; color: var(--green); }
.peer-link i { display: block; width: 3px; height: 4px; border-radius: 1px; background: currentColor; opacity: .24; }
.peer-link i:nth-child(2) { height: 7px; }
.peer-link i:nth-child(3) { height: 10px; }
.peer-link i:nth-child(4) { height: 13px; }
.peer-link[data-bars="1"] { color: var(--danger); }
.peer-link[data-bars="0"] { color: var(--muted); }
.peer-link[data-bars="1"] i:first-child,
.peer-link[data-bars="2"] i:nth-child(-n+2),
.peer-link[data-bars="3"] i:nth-child(-n+3),
.peer-link[data-bars="4"] i { opacity: 1; }
.stage { display: grid; place-items: center; position: relative; min-height: 290px; aspect-ratio: 16 / 10; overflow: hidden; border-radius: 11px; background: #171d2d; color: #fff; text-align: center; }
.stage-placeholder { padding: 19px 18px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.stage-placeholder strong { font-size: 1.23rem; letter-spacing: -.027em; }
.stage-placeholder p { color: #c3cce0; max-width: 28ch; font-size: .88rem; }
.stage-placeholder > .button, .stage-placeholder > .control-row { margin-top: 7px; }
.stage-image { display: grid; place-items: center; width: 70px; height: 70px; border: 1px solid #404a67; border-radius: 17px; background: #262f47; margin-bottom: 4px; }
.stage .button.primary { color: #111632; background: #b4bfff; }
.stage .button.primary:hover:not(:disabled) { background: #d1d8ff; }
.stage .button.stage-button { background: #303a53; border-color: #47516b; color: #fff; }
.stage video { background: #101420; object-fit: contain; }
.stage video:not([hidden]) { display: block; }
#remote-video { position: absolute; width: 100%; height: 100%; inset: 0; }
#remote-video[hidden] { display: block !important; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
#local-video { width: 100%; height: 100%; }
.local-preview { position: absolute; bottom: 12px; right: 12px; width: min(30%, 160px); aspect-ratio: 4 / 3; overflow: hidden; border: 1px solid #69718b; border-radius: 8px; }
.remote-fullscreen, .local-fullscreen { position: absolute; top: 8px; right: 8px; }
.local-fullscreen { top: 3px; right: 3px; min-height: 30px; min-width: 30px; padding: 0; font-size: 1rem; }
.screen-audio { padding-inline: 3px; color: var(--muted); }
.screen-preview { display: block; width: 100%; max-height: 42vh; background: #101420; border-radius: 8px; }
.video-viewer { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #101420; }
.video-viewer::backdrop { background: #101420; }
.video-viewer video { width: 100%; height: 100%; object-fit: contain; }
.video-viewer-actions { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; flex-wrap: wrap; gap: 8px; }
.stage video:fullscreen { width: 100%; height: 100%; object-fit: contain; }
.stage video:-webkit-full-screen { width: 100%; height: 100%; object-fit: contain; }
.play-media { position: absolute; left: 12px; bottom: 12px; }
.device-bar, .control-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.device-bar { justify-content: space-between; margin-top: 13px; }
.call-status { margin: 9px 0 0; font-size: .8rem; color: var(--muted); }

.chat { height: clamp(540px, calc(100dvh - 132px), 850px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.chat-header { min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.chat-scroll { overflow: auto; padding: 13px 14px; overscroll-behavior: contain; }
.messages { display: grid; gap: 12px; min-width: 0; }
.message-item { min-width: 0; border-radius: 10px; padding: 9px 10px; background: var(--soft); }
.message-item.own { background: var(--accent-soft); }
.message-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: .76rem; margin-bottom: 6px; }
.message-meta strong { min-width: 0; overflow-wrap: anywhere; }
.message-meta time { color: var(--muted); flex: none; font-size: .7rem; }
.delete-message { padding: 0; color: var(--danger); font-size: .7rem; }
.edit-message { padding: 0; font-size: .7rem; }
.message-meta { flex-wrap: wrap; }
.message-time { display: inline-flex; align-items: baseline; gap: 5px; color: var(--muted); }
.message-body { display: grid; gap: 7px; min-width: 0; font-size: .88rem; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.history-button { display: block; margin: 0 auto 12px; }
.history-notice { margin-bottom: 12px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); font-size: .79rem; }
.history-notice .link-button { font-size: inherit; }
.history-notice summary { cursor: pointer; }
.history-notice ul { list-style: none; margin: 6px 0 0; padding: 0; }
.history-notice li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 9px; padding: 5px 0; border-top: 1px solid var(--line); }
.empty-chat { height: 100%; min-height: 185px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 8px; }
.empty-chat strong { font-size: .92rem; }
.empty-chat p { font-size: .81rem; color: var(--muted); }
.composer { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 8px; }
.composer textarea { min-height: 76px; max-height: 42vh; resize: vertical; background: var(--soft); }
.composer-actions { display: flex; justify-content: space-between; gap: 6px; }
.voice-preview { display: grid; gap: 6px; }
.voice-preview .control-row { justify-content: space-between; }
.voice-player { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; min-width: 0; padding: 4px 8px 4px 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; }
.voice-toggle { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 6px; color: var(--accent-ink); background: var(--accent-soft); }
.voice-toggle:hover { outline: 1px solid var(--accent); }
.voice-toggle svg { width: 15px; height: 15px; fill: currentColor; }
.voice-player .voice-position { min-height: 26px; height: 26px; padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
.voice-time { font-size: .73rem; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.voice-player-error { grid-column: 1 / -1; color: var(--danger); padding: 0 4px 3px; font-size: .74rem; }
.code-button span { color: var(--accent-ink); font-family: ui-monospace, monospace; }
.code-block { min-width: 0; background: #1b2234; color: #e6eaf5; border-radius: 8px; overflow: hidden; }
.code-heading { display: flex; justify-content: space-between; align-items: center; gap: 5px; padding: 3px 9px; background: #283149; color: #e3e7f7; font-size: .73rem; }
.code-heading .link-button { color: #d0d8ff; font-size: .73rem; }
.code-block pre { max-height: 28rem; overflow: auto; margin: 0; padding: 10px; tab-size: 4; font: .79rem/1.55 ui-monospace, Consolas, monospace; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal { color: #d8aaff; }
.hljs-string, .hljs-regexp, .hljs-symbol { color: #a5e4af; }
.hljs-title, .hljs-name, .hljs-section, .hljs-built_in { color: #9bc7ff; }
.hljs-number, .hljs-attr, .hljs-attribute, .hljs-variable { color: #ffc78f; }
.hljs-comment, .hljs-quote { color: #a6afc4; font-style: italic; }
.hljs-meta, .hljs-type, .hljs-tag { color: #ffa8c0; }

.admin { width: min(100% - 64px, 1120px); margin: 42px auto; }
.admin-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.admin-header p, .dialog p:not(.error) { margin-top: 6px; color: var(--muted); font-size: .9rem; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 15px; }
.settings-card { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 18px; }
.settings-card h3 { margin: 8px 0 0; font-size: .95rem; }
.settings-card form + form { border-top: 1px solid var(--line); padding-top: 12px; }
.settings-card p { color: var(--muted); font-size: .86rem; }
.settings-card p.error { color: var(--danger); }
.settings-card .button { width: fit-content; }
.settings-card input[type="range"] { padding: 0; min-height: 24px; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; min-height: 0; accent-color: var(--accent); }
#mic-meter { width: 100%; }
.admin > .error { margin-bottom: 12px; }
.audit-sections { margin-bottom: 15px; }
.audit-pages { margin-top: 14px; }
.audit-pages span, .audit-empty, .audit-detail { color: var(--muted); font-size: .82rem; }
.audit-detail { display: block; margin-top: 4px; }
.audit-address, .audit-date { white-space: nowrap; }
.audit-actions { text-align: end; }
.audit-actions .button { white-space: normal; }
.audit-actions .button:disabled { opacity: 1; color: var(--muted); }
.accounts-table { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: .86rem; }
th, td { padding: 12px 14px; text-align: start; border-bottom: 1px solid var(--line); }
th { background: var(--soft); color: var(--muted); font-size: .78rem; font-weight: 650; }
tr:last-child td { border-bottom: 0; }
.person { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.person span { display: grid; gap: 4px; }
.person small { color: var(--muted); }
.factor-active { color: var(--green); }
.table-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.table-actions .link-button { white-space: nowrap; }
.table-actions .delete { color: var(--danger); }
.dialog { width: min(calc(100% - 30px), 435px); max-height: calc(100% - 30px); border: 1px solid var(--line); border-radius: 15px; padding: 22px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: #0c102bb0; }
.dialog h2 { font-size: 1.35rem; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.toast { position: fixed; z-index: 2; bottom: 18px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); border-radius: 9px; padding: 10px 15px; background: var(--text); color: var(--panel); box-shadow: var(--shadow); font-size: .87rem; text-align: center; }
.wake-notice { position: fixed; z-index: 3; inset: auto 16px 18px auto; width: min(350px, calc(100vw - 32px)); padding: 14px; border: 1px solid var(--accent); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.wake-notice p { margin-bottom: 10px; font-weight: 650; }
.noscript { margin: 2rem; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(264px, 32%); }
  .lesson-list { grid-column: 1 / -1; }
  .rooms { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .empty-lesson { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .settings-grid { grid-template-columns: 1fr; }
  .workspace, .admin, .header-inner { width: calc(100% - 28px); }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 12px; margin-block: 13px; }
  .header-inner { gap: 14px; min-height: 60px; flex-wrap: wrap; padding-block: 8px; }
  .header-user { display: none; }
  .auth-shell { min-height: calc(100svh - 61px); }
  .chat { height: clamp(420px, 66dvh, 670px); }
  .lesson { padding: 12px; }
  .stage { min-height: 245px; }
  .admin { margin-block: 20px; }
}

@media (max-width: 470px) {
  .navigation { order: 3; width: 100%; gap: 4px; }
  .nav-tab { min-height: 34px; }
  .lesson-header { align-items: flex-start; flex-direction: column; gap: 7px; }
  .room-button { padding: 6px; }
  .rooms { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
  .button { padding-inline: 9px; }
  .stage { aspect-ratio: auto; }
}
