:root {
  color-scheme: dark;
  --window: #0c1115;
  --panel: #141c21;
  --panel-alt: #1b272d;
  --edit: #10171b;
  --accent: #38c4b0;
  --accent-dark: #103838;
  --text: #f4f7f6;
  --muted: #9cabb0;
  --line: #34464d;
  --amber: #e3b24f;
  --danger: #d25750;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--window); color: var(--text); }
button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }
svg { display: block; }

.appbar {
  display: grid; min-height: 64px; grid-template-columns: 1fr auto 40px; align-items: center;
  gap: 16px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: #0e1519;
}
.brand { display: inline-flex; width: max-content; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 18px; font-weight: 800; }
.brand img { width: 42px; height: 42px; }
.brand small { padding: 3px 6px; border: 1px solid var(--accent); color: var(--accent); font-size: 9px; }
.connection { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgb(227 178 79 / 12%); }
.connection.online { color: #dff7f1; }
.connection.online .connection-dot { background: var(--accent); box-shadow: 0 0 0 3px rgb(56 196 176 / 14%); }

.app-shell { height: calc(100% - 64px); }
.lobby-view { display: grid; height: 100%; grid-template-columns: minmax(260px, .72fr) minmax(360px, 1.15fr) minmax(280px, .82fr); }
.room-view { display: grid; height: 100%; grid-template-columns: minmax(420px, 1fr) minmax(300px, 380px); }
.pane { min-width: 0; overflow: auto; scrollbar-color: var(--accent) var(--panel); scrollbar-width: auto; }
.pane + .pane { border-left: 1px solid var(--line); }
.identity-pane, .preview-pane, .voice-pane { padding: 24px; background: var(--panel); }
.rooms-pane, .room-main { display: flex; flex-direction: column; padding: 24px; }
.pane-heading { margin-bottom: 20px; }
.pane-heading p, .room-titlebar p { margin: 0 0 7px; color: var(--accent); font-size: 10px; font-weight: 800; }
.pane-heading h1, .pane-heading h2, .room-titlebar h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.pane-heading > span { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }
.row-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

.field-label { display: block; margin: 12px 0 6px; color: #c4d0d2; font-size: 11px; }
input, select {
  width: 100%; height: 42px; padding: 0 11px; border: 1px solid var(--line); border-radius: 4px;
  outline: 0; background: var(--edit); color: var(--text);
}
input:focus, select:focus, button:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 2px rgb(56 196 176 / 14%); }
.pin-input { max-width: 132px; }
.section-label { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--amber); font-size: 10px; font-weight: 800; }

.icon-picker { position: relative; }
.icon-picker-button { display: grid; width: 100%; height: 52px; grid-template-columns: 1fr 32px; align-items: center; padding: 4px 7px; border: 1px solid var(--line); border-radius: 4px; background: var(--edit); cursor: pointer; }
.icon-picker-button > span { display: grid; place-items: center; }
.icon-picker-button > svg { width: 20px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 140ms ease; }
.icon-picker-button[aria-expanded="true"] > svg { transform: rotate(180deg); }
.icon-menu { position: absolute; z-index: 20; top: calc(100% + 4px); right: 0; left: 0; max-height: 260px; overflow-y: auto; border: 1px solid var(--line); background: #111a1f; box-shadow: 0 14px 32px rgb(0 0 0 / 42%); scrollbar-color: var(--accent) #111a1f; }
.icon-option { display: grid; width: 100%; height: 52px; place-items: center; border: 0; border-bottom: 1px solid #26363d; background: transparent; cursor: pointer; }
.icon-option:hover, .icon-option[aria-selected="true"] { background: var(--accent-dark); }
.fighter-icon { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 50%; }
.fighter-icon img { display: block; width: 100%; height: 100%; border-radius: 50%; }
.icon-option[aria-selected="true"] .fighter-icon { box-shadow: 0 0 0 2px var(--accent); }

.create-room .command { width: 100%; margin-top: 16px; }
.command { min-height: 42px; padding: 0 15px; border: 1px solid transparent; border-radius: 4px; font-weight: 700; cursor: pointer; }
.command:disabled { cursor: default; opacity: .42; }
.command.primary { background: var(--accent); color: #092326; }
.command.secondary { border-color: var(--line); background: var(--panel-alt); color: var(--text); }
.command.danger { border-color: #6e3b3c; background: #2a1c1e; color: #ffb8b4; }
.icon-button { display: grid; width: 40px; height: 40px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-alt); cursor: pointer; }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.room-list { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 5px; overflow-y: auto; padding-right: 8px; scrollbar-color: var(--accent) var(--panel); }
.room-row { display: grid; min-height: 58px; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 4px; background: #10171b; text-align: left; cursor: pointer; }
.room-row:hover { border-color: #5b737c; }
.room-row.selected { border-color: var(--accent); background: var(--accent-dark); }
.room-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.room-row small { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.room-count { color: var(--amber); font-size: 12px; font-weight: 800; }
.room-lock { margin-right: 7px; color: var(--amber); font-size: 9px; }
.empty-state { display: grid; min-height: 220px; flex: 1; place-content: center; text-align: center; }
.empty-state span { margin-top: 6px; color: var(--muted); font-size: 12px; }

.member-list { display: flex; flex-direction: column; gap: 5px; }
.preview-members { max-height: 280px; overflow-y: auto; }
.member-row { display: grid; min-height: 52px; grid-template-columns: 5px 42px minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 5px 8px; border-bottom: 1px solid var(--line); background: #10171b; }
.member-level { position: relative; width: 5px; height: 34px; overflow: hidden; background: #26363d; }
.member-level span { position: absolute; right: 0; bottom: 0; left: 0; height: var(--level, 0%); background: var(--accent); transition: height 90ms linear; }
.member-row .fighter-icon { width: 36px; height: 36px; }
.member-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.member-name small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.member-state { color: var(--muted); font-size: 9px; }
.member-mix { display: grid; width: 220px; grid-template-columns: minmax(80px, 1fr) 38px auto; align-items: center; gap: 7px; }
.member-mix input[type="range"] { min-width: 0; }
.member-mix output { color: var(--accent); text-align: right; font-size: 9px; }
.member-mute { display: inline-flex; min-height: 28px; align-items: center; gap: 5px; color: var(--muted); font-size: 9px; cursor: pointer; }
.member-mute input { width: 16px; height: 16px; accent-color: var(--danger); }
.preview-members .member-mix { display: none; }
.member-row.speaking { border-color: var(--accent); background: #122a2b; }
.member-row.speaking .fighter-icon { box-shadow: 0 0 0 2px var(--accent); }
.join-command { width: 100%; margin-top: 14px; }

.audio-settings { padding-bottom: 16px; }
.range-row { display: flex; justify-content: space-between; gap: 12px; margin: 14px 0 2px; color: #c4d0d2; font-size: 11px; }
.range-row output { color: var(--accent); }
input[type="range"] { height: 22px; padding: 0; border: 0; background: transparent; accent-color: var(--accent); box-shadow: none; }
.toggle-row { display: flex; min-height: 38px; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid #2a3a41; color: #d4dddf; font-size: 11px; cursor: pointer; }
.toggle-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle-row i { position: relative; width: 34px; height: 18px; flex: none; border-radius: 9px; background: #405158; }
.toggle-row i::after { position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: #d7e0e1; content: ""; transition: transform 120ms ease; }
.toggle-row input:checked + i { background: var(--accent); }
.toggle-row input:checked + i::after { background: #082527; transform: translateX(16px); }
.ptt-key-row { display: flex; min-height: 42px; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; }
.ptt-key-row button { min-width: 70px; height: 30px; border: 1px solid var(--line); border-radius: 3px; background: var(--edit); cursor: pointer; }
.mic-test { display: inline-flex; width: 100%; align-items: center; justify-content: center; gap: 8px; margin-top: 14px; }
.mic-test svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.test-level { height: 5px; margin-top: 7px; overflow: hidden; background: #26363d; }
.test-level span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 70ms linear; }

.room-titlebar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.room-titlebar > div > span { color: var(--muted); font-size: 11px; }
.room-members { min-height: 0; flex: 1; overflow-y: auto; padding-top: 12px; }
.room-members .member-row { min-height: 64px; grid-template-columns: 6px 48px minmax(0, 1fr) minmax(150px, 220px) auto; padding: 7px 10px; }
.room-members .fighter-icon { width: 44px; height: 44px; }
.room-identity { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.room-identity .field-label { margin-top: 0; }
.room-identity > div { display: grid; grid-template-columns: minmax(0, 1fr) 108px; gap: 7px; }
.room-identity .command { min-height: 42px; padding-inline: 8px; font-size: 11px; }
.voice-control { display: grid; grid-template-columns: 7px 1fr; gap: 12px; align-items: stretch; }
.local-level { position: relative; overflow: hidden; background: #26363d; }
.local-level span { position: absolute; right: 0; bottom: 0; left: 0; height: 0; background: var(--accent); transition: height 70ms linear; }
.mute-button { display: flex; min-height: 58px; align-items: center; justify-content: center; gap: 10px; border: 1px solid var(--accent); border-radius: 4px; background: var(--accent); color: #092326; font-weight: 800; cursor: pointer; }
.mute-button.muted { border-color: #7e4242; background: #351f21; color: #ffc4bf; }
.mute-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ptt-state { grid-column: 2; padding: 6px; border: 1px solid var(--line); color: var(--amber); text-align: center; font-size: 10px; }
.voice-pane .audio-settings { margin-top: 18px; }
body.room-active .mic-test, body.room-active .test-level { display: none; }

.pin-dialog { width: min(390px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }
.pin-dialog::backdrop { background: rgb(3 7 9 / 74%); backdrop-filter: blur(4px); }
.pin-dialog form { padding: 24px; }
.pin-dialog p { margin: 0 0 7px; color: var(--accent); font-size: 10px; font-weight: 800; }
.pin-dialog h2 { margin: 0 0 18px; font-size: 20px; }
.pin-dialog input { text-align: center; font-size: 22px; letter-spacing: 4px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.toast { position: fixed; z-index: 50; right: 18px; bottom: 18px; max-width: min(390px, calc(100% - 36px)); padding: 12px 15px; border: 1px solid var(--amber); border-radius: 4px; background: #241f16; color: #ffe4ad; box-shadow: 0 12px 38px rgb(0 0 0 / 38%); font-size: 12px; }

@media (max-width: 1040px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: calc(100% - 64px); }
  .lobby-view { height: auto; min-height: calc(100vh - 64px); grid-template-columns: minmax(250px, .8fr) minmax(360px, 1.2fr); }
  .preview-pane { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(250px, .7fr) minmax(320px, 1.3fr); gap: 22px; border-top: 1px solid var(--line); border-left: 0 !important; }
  .preview-pane > .pane-heading, .preview-pane > .member-list, .preview-pane > .join-command { grid-column: 1; }
  .preview-pane > .settings-host { grid-column: 2; grid-row: 1 / span 4; }
}

@media (max-width: 720px) {
  .appbar { grid-template-columns: 1fr auto 40px; padding-inline: 12px; }
  .connection #connectionText { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand { font-size: 16px; }
  .brand img { width: 38px; height: 38px; }
  .lobby-view, .room-view { display: block; min-height: 0; }
  .pane { overflow: visible; padding: 18px; border-left: 0 !important; border-top: 1px solid var(--line); }
  .identity-pane { border-top: 0; }
  .rooms-pane { min-height: 420px; }
  .room-list { max-height: 430px; }
  .preview-pane { display: block; }
  .preview-pane > * { margin-bottom: 14px; }
  .preview-members { max-height: 350px; }
  .room-main { min-height: 480px; }
  .voice-pane { min-height: 300px; }
  .room-titlebar h1 { max-width: 210px; overflow-wrap: anywhere; }
  .room-members .member-row { grid-template-columns: 6px 44px minmax(0, 1fr) auto; }
  .room-members .member-mix { width: 100%; grid-column: 3 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
