:root {
    color-scheme: dark;
    --page: #101217;
    --surface: #191c22;
    --surface-raised: #20242c;
    --surface-soft: #15181e;
    --border: #30353f;
    --border-strong: #454c59;
    --text: #f6f7f9;
    --muted: #9da4af;
    --accent: #82d49a;
    --accent-strong: #9be2ad;
    --accent-ink: #102016;
    --accent-soft: #21382a;
    --danger: #f17d86;
    --danger-soft: #382126;
    --warning: #e6b85f;
    --focus: #a9c7ff;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
    color-scheme: light;
    --page: #f3f4f6;
    --surface: #ffffff;
    --surface-raised: #f8f9fb;
    --surface-soft: #f0f2f5;
    --border: #dfe2e7;
    --border-strong: #c5cad2;
    --text: #17191e;
    --muted: #68707d;
    --accent: #3d9c5d;
    --accent-strong: #34864f;
    --accent-ink: #ffffff;
    --accent-soft: #e4f3e9;
    --danger: #c54855;
    --danger-soft: #f9e8ea;
    --warning: #9b6a17;
    --focus: #255ea8;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--page);
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    overflow-x: hidden;
    color: var(--text);
    background: var(--page);
    font-size: 15px;
    line-height: 1.5;
}

button,
input,
select {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font: inherit;
}

button {
    padding: 0.75rem 1rem;
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
    font-weight: 720;
    cursor: pointer;
    transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease, transform 140ms ease;
}

button:hover {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
}

button:active {
    transform: scale(0.985);
}

button:disabled {
    cursor: wait;
    opacity: 0.55;
}

button.secondary {
    border-color: var(--border);
    color: var(--text);
    background: var(--surface-raised);
}

button.secondary:hover {
    border-color: var(--border-strong);
    background: var(--surface-soft);
}

button.danger {
    border-color: var(--danger-soft);
    color: var(--danger);
    background: var(--danger-soft);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

input,
select {
    padding: 0.75rem 0.85rem;
    border-color: var(--border);
    color: var(--text);
    background: var(--surface-soft);
}

input:hover,
select:hover {
    border-color: var(--border-strong);
}

input[type="range"] {
    min-height: 32px;
    padding: 0;
    accent-color: var(--accent);
}

label,
legend {
    color: var(--text);
    font-weight: 640;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    max-width: 100%;
    margin-bottom: 0;
    overflow-wrap: anywhere;
    font-size: clamp(1.75rem, 6vw, 2.35rem);
    font-weight: 760;
    line-height: 1.12;
    letter-spacing: -0.04em;
}

h2 {
    margin-bottom: 0.35rem;
    font-size: clamp(1.25rem, 4.5vw, 1.55rem);
    font-weight: 740;
    line-height: 1.2;
    letter-spacing: -0.025em;
}

h3 {
    margin-bottom: 0.9rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 760;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.app-shell {
    display: grid;
    align-content: center;
    width: min(100% - 1.5rem, 600px);
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    padding:
        max(2rem, env(safe-area-inset-top))
        max(0rem, env(safe-area-inset-right))
        max(2rem, env(safe-area-inset-bottom))
        max(0rem, env(safe-area-inset-left));
}

.app-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
    text-align: center;
}

.brand-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 48px;
    height: 48px;
    margin-bottom: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 15px;
    color: var(--accent);
    background: var(--surface);
}

.brand-wave {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.brand-wave span {
    display: block;
    width: 4px;
    border-radius: 3px;
    background: currentColor;
}

.brand-wave span:nth-child(1),
.brand-wave span:nth-child(3) {
    height: 12px;
}

.brand-wave span:nth-child(2) {
    height: 22px;
}

.server-icon {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 14px;
    object-fit: cover;
}

.eyebrow {
    margin-bottom: 0.35rem;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 720;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.muted,
.field-help {
    color: var(--muted);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 34px;
    margin-top: 0.9rem;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface);
    font-size: 0.78rem;
    font-weight: 650;
}

.status-dot {
    width: 0.5rem;
    height: 0.5rem;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #707784;
}

.status-pill.authenticated .status-dot,
.status-pill.connected .status-dot {
    background: var(--accent);
}

.status-pill.connecting .status-dot {
    background: var(--warning);
}

.status-pill.error .status-dot {
    background: var(--danger);
}

.view {
    display: grid;
    gap: 0.85rem;
}

.card,
.notice,
.dialog-card {
    border: 1px solid var(--border);
    background: var(--surface);
}

.card {
    width: 100%;
    padding: clamp(1.25rem, 5vw, 2rem);
    border-radius: 20px;
    box-shadow: 0 16px 38px rgb(0 0 0 / 14%);
}

.card-intro {
    max-width: 430px;
    margin: 0 auto 1.25rem;
    text-align: center;
}

.card-intro p:last-child {
    margin-bottom: 0;
}

form {
    display: grid;
    gap: 0.75rem;
}

#pairingForm {
    max-width: 410px;
    margin: 0 auto;
}

.code-input {
    height: 72px;
    padding: 0.4rem;
    border-color: var(--border-strong);
    border-radius: 14px;
    letter-spacing: 0.38em;
    text-align: center;
    text-indent: 0.38em;
    font-size: clamp(1.75rem, 10vw, 2.35rem);
    font-variant-numeric: tabular-nums;
    font-weight: 760;
}

.field-help {
    margin: -0.2rem 0 0.25rem;
    font-size: 0.82rem;
    line-height: 1.45;
}

#pairingHelp {
    text-align: center;
}

.button-stack {
    display: grid;
    gap: 0.65rem;
}

.legacy {
    max-width: 410px;
    margin: 1.2rem auto 0;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

.legacy summary,
.chat-panel summary,
#diagnosticsPanel summary {
    min-height: 44px;
    padding: 0.75rem 0;
    font-weight: 650;
    cursor: pointer;
}

.legacy form {
    padding-top: 0.65rem;
    text-align: left;
}

.notice {
    margin-bottom: 0.85rem;
    padding: 1rem 1.1rem;
    border-left: 3px solid var(--danger);
    border-radius: 12px;
    text-align: center;
}

.notice p {
    margin: 0.3rem 0 0;
    color: var(--muted);
}

.notice button {
    margin-top: 0.75rem;
}

.permission-card {
    text-align: center;
}

.permission-symbol {
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    margin: 0 auto 1.2rem;
    border-radius: 50%;
    color: var(--accent);
    background: var(--accent-soft);
}

.permission-symbol > span,
.mic-symbol > span {
    position: relative;
    display: block;
    width: 18px;
    height: 28px;
    border: 3px solid currentColor;
    border-radius: 10px;
}

.permission-symbol > span::after,
.mic-symbol > span::after {
    position: absolute;
    left: 50%;
    bottom: -9px;
    width: 24px;
    height: 13px;
    border-right: 3px solid currentColor;
    border-bottom: 3px solid currentColor;
    border-left: 3px solid currentColor;
    border-radius: 0 0 13px 13px;
    content: "";
    transform: translateX(-50%);
}

.connected-heading,
.dialog-heading,
.meter-label,
.range-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.connected-heading {
    position: relative;
    justify-content: center;
    min-height: 46px;
    text-align: center;
}

.connected-heading h2,
.connected-heading p {
    margin-bottom: 0;
}

.connected-heading .compact-button {
    position: absolute;
    right: 0;
}

.compact-button {
    width: auto;
    min-height: 40px;
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
}

.icon-button {
    width: 44px;
    min-height: 44px;
    flex: 0 0 44px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.2rem;
}

.voice-control {
    display: grid;
    place-items: center;
    margin: 1.8rem 0 1.6rem;
}

.mic-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.2rem;
    width: 168px;
    height: 168px;
    padding: 1rem;
    border: 1px solid var(--accent);
    border-radius: 50%;
    color: var(--accent-ink);
    background: var(--accent);
    box-shadow: 0 0 0 10px var(--accent-soft);
}

.mic-button:hover {
    transform: translateY(-2px);
}

.mic-button:active {
    transform: scale(0.98);
}

.mic-symbol {
    display: grid;
    place-items: center;
    height: 40px;
}

.mic-button.muted {
    border-color: var(--danger);
    color: var(--danger);
    background: var(--danger-soft);
    box-shadow: 0 0 0 10px color-mix(in srgb, var(--danger-soft), transparent 15%);
}

.meter-block {
    width: min(100%, 390px);
    margin: 0 auto 1.25rem;
}

.meter-label {
    margin-bottom: 0.55rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 620;
}

.transmit-indicator.active {
    color: var(--accent);
}

.meter {
    position: relative;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-soft);
}

.meter > div {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 80ms linear;
}

.meter-threshold {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--text);
    opacity: 0.7;
}

.mic-test {
    display: grid;
    gap: 0.65rem;
    margin-top: 0.25rem;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: min(100%, 390px);
    margin: 0 auto 1rem;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-soft);
}

.segmented label {
    min-width: 0;
    cursor: pointer;
}

.segmented input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.segmented span {
    display: grid;
    place-items: center;
    min-height: 44px;
    padding: 0.45rem;
    border-radius: 9px;
    color: var(--muted);
    text-align: center;
    font-size: 0.82rem;
}

.segmented input:checked + span {
    color: var(--text);
    background: var(--surface-raised);
    box-shadow: 0 2px 7px rgb(0 0 0 / 10%);
}

.segmented input:focus-visible + span {
    outline: 3px solid var(--focus);
    outline-offset: -1px;
}

.ptt-button {
    width: min(100%, 390px);
    min-height: 72px;
    margin: 0 auto 1rem;
    touch-action: none;
    user-select: none;
}

.ptt-button.active {
    border-color: var(--danger);
    color: #ffffff;
    background: var(--danger);
}

.chat-panel {
    width: min(100%, 440px);
    margin: 1rem auto;
    border-top: 1px solid var(--border);
}

.chat-log {
    max-height: 180px;
    overflow-y: auto;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--muted);
    background: var(--surface-soft);
    text-align: left;
    white-space: pre-wrap;
}

.chat-form {
    grid-template-columns: 1fr auto;
    margin-top: 0.65rem;
}

.chat-form button {
    width: auto;
}

.disconnect-button {
    display: block;
    width: min(100%, 390px);
    margin: 1.1rem auto 0;
}

dialog {
    width: min(100% - 1rem, 620px);
    max-height: calc(100dvh - 1rem);
    padding: 0;
    border: 0;
    color: var(--text);
    background: transparent;
}

dialog::backdrop {
    background: rgb(0 0 0 / 70%);
}

.dialog-card {
    display: grid;
    gap: 0;
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
    padding:
        1.25rem
        max(1.25rem, env(safe-area-inset-right))
        max(1.35rem, env(safe-area-inset-bottom))
        max(1.25rem, env(safe-area-inset-left));
    border-radius: 20px;
}

.dialog-card h2,
.dialog-card .eyebrow {
    margin-bottom: 0;
}

.dialog-heading {
    padding-bottom: 1.1rem;
    border-bottom: 1px solid var(--border);
}

.settings-section {
    display: grid;
    gap: 0.7rem;
    padding: 1.15rem 0;
    border-bottom: 1px solid var(--border);
}

.settings-section h3 {
    margin-bottom: 0.15rem;
}

.settings-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
    padding-top: 1.15rem;
}

.check-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 44px;
    font-weight: 580;
}

.check-row input {
    width: 22px;
    min-height: 22px;
    flex: 0 0 22px;
    accent-color: var(--accent);
}

.range-label output {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.capture-status {
    margin: 0;
}

.capture-status.warning {
    color: var(--warning);
}

pre {
    max-height: 220px;
    overflow: auto;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 0.72rem;
    white-space: pre-wrap;
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.noscript {
    padding: 1rem;
    color: #ffffff;
    background: #8c1f2f;
    text-align: center;
}

@media (min-width: 560px) {
    .button-stack {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 520px) {
    .app-shell {
        align-content: start;
    }

    .connected-heading {
        padding-top: 3rem;
    }

    .connected-heading .compact-button {
        top: 0;
        right: 50%;
        transform: translateX(50%);
    }

    .connected-heading .compact-button:active {
        transform: translateX(50%) scale(0.985);
    }

    .settings-actions {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 400px) {
    .card {
        padding: 1.1rem;
        border-radius: 16px;
    }

    .mic-button {
        width: 150px;
        height: 150px;
    }

    .segmented span {
        font-size: 0.76rem;
    }
}

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