:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
    --background: #090d14;
    --surface: #111824;
    --surface-raised: #182231;
    --border: #2b3849;
    --text: #f4f7fb;
    --text-muted: #a9b5c4;
    --primary: #79a7ff;
    --primary-strong: #a8c5ff;
    --primary-text: #071225;
    --danger: #ff8a8a;
    --danger-surface: #401d24;
    --success: #61d69a;
    --warning: #f6c56c;
    --focus: #b8d0ff;
    --radius: 0.75rem;
    --shadow: 0 1.5rem 4rem rgb(0 0 0 / 35%);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-size: 1rem;
    line-height: 1.5;
}

button,
input,
textarea {
    font: inherit;
}

button,
textarea,
input {
    touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 0.2rem solid var(--focus);
    outline-offset: 0.15rem;
}

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

.auth-page {
    background:
        radial-gradient(circle at 15% 10%, rgb(45 83 145 / 28%), transparent 32rem),
        var(--background);
}

.auth-layout {
    display: grid;
    min-height: 100dvh;
    place-items: center;
    padding: 1.5rem;
}

.auth-card {
    width: min(100%, 27rem);
    padding: clamp(1.5rem, 5vw, 2.5rem);
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: rgb(17 24 36 / 94%);
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.brand-mark {
    display: inline-grid;
    width: 2.25rem;
    height: 2.25rem;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 0.6rem;
    background: var(--primary);
    color: var(--primary-text);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.auth-heading {
    margin: 2.5rem 0 1.5rem;
}

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

.auth-heading h1 {
    margin-bottom: 0.35rem;
    font-size: clamp(1.8rem, 6vw, 2.25rem);
    line-height: 1.15;
}

.auth-heading p,
.privacy-note {
    color: var(--text-muted);
}

.stack {
    display: grid;
    gap: 1.15rem;
}

.field {
    display: grid;
    gap: 0.45rem;
}

.field label {
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 650;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    background: #0b111b;
    color: var(--text);
}

input {
    min-height: 2.85rem;
    padding: 0.65rem 0.75rem;
}

textarea {
    min-height: 6.5rem;
    padding: 0.7rem;
    line-height: 1.4;
    resize: vertical;
}

textarea[readonly] {
    background: #0e1520;
    color: #d7e0ec;
}

input:hover,
textarea:hover {
    border-color: #43546a;
}

.button {
    min-height: 2.75rem;
    border: 1px solid transparent;
    border-radius: 0.55rem;
    cursor: pointer;
    font-weight: 700;
}

.button {
    padding: 0.6rem 0.9rem;
}

.button:hover:not(:disabled) {
    filter: brightness(1.08);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.52;
}

.button-primary {
    background: var(--primary);
    color: var(--primary-text);
}

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

.button-danger {
    border-color: #67313b;
    background: var(--danger-surface);
    color: #ffd6d6;
}

.button-wide {
    width: 100%;
}

.privacy-note {
    margin: 1.4rem 0 0;
    font-size: 0.8rem;
    text-align: center;
}

.message {
    margin: 0;
    padding: 0.7rem 0.8rem;
    border-radius: 0.5rem;
    font-size: 0.88rem;
}

.message-error {
    border: 1px solid #71303b;
    background: #35181e;
    color: #ffd1d1;
}

.message-info {
    border: 1px solid #344967;
    background: #101d30;
    color: #cfe0ff;
}

.desktop-page {
    height: 100dvh;
    overflow: hidden;
}

.desktop-shell {
    position: relative;
    display: grid;
    width: 100%;
    height: 100%;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    background: var(--background);
}

.desktop-shell:fullscreen {
    width: 100vw;
    height: 100vh;
}

.topbar {
    display: grid;
    min-height: 4.5rem;
    grid-template-columns: minmax(12rem, 1fr) auto minmax(12rem, 1fr);
    align-items: center;
    gap: 1rem;
    padding: 0.7rem max(1rem, env(safe-area-inset-right)) 0.7rem max(1rem, env(safe-area-inset-left));
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.brand-title,
.user-label {
    display: block;
}

.user-label {
    max-width: 18rem;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.connection-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.status-dot {
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    background: #728096;
}

.status-dot[data-state="connected"] {
    background: var(--success);
}

.status-dot[data-state="connecting"] {
    background: var(--warning);
    animation: pulse 1.2s ease-in-out infinite;
}

.status-dot[data-state="error"] {
    background: var(--danger);
}

.toolbar-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.55rem;
}

.toolbar-actions .button {
    min-height: 2.5rem;
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
}

.desktop-layout {
    display: grid;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
}

.viewer-panel {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #05070b;
}

.screen {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

.screen:focus-within {
    outline: 0.2rem solid var(--focus);
    outline-offset: -0.2rem;
}

.screen canvas {
    image-rendering: auto;
}

.viewer-message {
    position: absolute;
    inset: 50% auto auto 50%;
    width: min(90%, 32rem);
    padding: 1rem 1.25rem;
    transform: translate(-50%, -50%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgb(17 24 36 / 94%);
    color: var(--text-muted);
    text-align: center;
    box-shadow: var(--shadow);
    pointer-events: none;
}

.viewer-message p {
    margin: 0;
}

.clipboard-toast {
    position: absolute;
    z-index: 5;
    right: 1rem;
    bottom: 1rem;
    max-width: min(30rem, calc(100% - 2rem));
    margin: 0;
    padding: 0.65rem 0.8rem;
    border: 1px solid #344967;
    border-radius: 0.5rem;
    background: rgb(16 29 48 / 96%);
    color: #cfe0ff;
    box-shadow: var(--shadow);
    font-size: 0.85rem;
    pointer-events: none;
}

.clipboard-toast[data-state="error"] {
    border-color: #71303b;
    background: rgb(53 24 30 / 96%);
    color: #ffd1d1;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 0.45;
    }

    50% {
        opacity: 1;
    }
}

@media (max-width: 56rem) {
    .topbar {
        grid-template-columns: 1fr auto;
    }

    .connection-state {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-content: flex-start;
    }

    .viewer-panel {
        height: 100%;
    }
}

@media (max-width: 39rem) {
    .topbar {
        grid-template-columns: 1fr;
        min-height: auto;
        padding-top: max(0.6rem, env(safe-area-inset-top));
    }

    .brand-title {
        font-size: 0.9rem;
    }

    .toolbar-actions {
        grid-column: 1;
        grid-row: 2;
        gap: 0.35rem;
        justify-content: stretch;
    }

    .toolbar-actions .button {
        flex: 1 1 0;
        min-width: 2.75rem;
        padding-inline: 0.55rem;
        font-size: 0.78rem;
    }

    .connection-state {
        grid-column: 1;
        grid-row: 3;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: more) {
    :root {
        --border: #718198;
        --text-muted: #d4dbe4;
    }
}
