:root {
    color-scheme: light;
    --bg: #f5f5f7;
    --surface: rgba(255, 255, 255, 0.82);
    --panel: rgba(246, 247, 251, 0.86);
    --panel-strong: #ffffff;
    --line: rgba(18, 24, 38, 0.1);
    --text: #111827;
    --muted: #697386;
    --accent: #0071e3;
    --accent-strong: #0066cc;
    --danger: #d92d42;
    --warn: #b7791f;
    --shadow: 0 18px 55px rgba(20, 32, 54, 0.11);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.96), transparent 34%),
        linear-gradient(135deg, #f7f8fb 0%, #ebeef4 100%);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button {
    height: 42px;
    border: 0;
    border-radius: 12px;
    color: var(--text);
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.device-table-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    align-items: center;
    gap: 12px;
}

.unregistered-device-grid {
    grid-template-columns: minmax(150px, 1fr) 120px minmax(180px, 1.2fr) auto;
    gap: 10px;
}

.devices-section-title {
    margin: 4px 0 0;
    font-size: 18px;
    letter-spacing: 0;
}

.unregistered-name-input {
    height: 38px;
}

.device-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
}

.primary-btn {
    background: var(--accent-strong);
    color: #fff;
    font-size: 16px;
    box-shadow: 0 8px 22px rgba(0, 102, 204, 0.22);
    font-weight: 500;
    transition-duration: 200ms;
    border-radius: 12px;
}

.primary-btn:hover {
    background: var(--accent);
}

.primary-btn:active {
    background: var(--accent-strong);
}

.secondary-btn:hover {
    background: #e9e9e9;
}

.secondary-btn:active {
    background: rgba(255, 255, 255, 0.86);
}

.secondary-btn {
    font-size: 16px;
    padding-left: 16px;
    transition-duration: 200ms;
    padding-right: 16px;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid var(--line);
    color: var(--text);
}

.navigation-container {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    gap: 12px;
}

.href-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.href-container.active {
    color: var(--accent-strong);
}

.href-btn {
    background: transparent;
    color: var(--secondary);
    padding: 0;
    font-weight: 500;
    margin: 0 !important;
    padding: 0 !important;
    min-width: 0 !important;
}

.href-btn.active {
    background: transparent;
    color: var(--accent-strong);
    padding: 0;
    font-weight: 500;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(100%, 390px);
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(24px);
}

.login-card .brand-mark {
    margin-bottom: 18px;
}

.login-card h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: 0;
}

.login-card p {
    margin: 8px 0 22px;
    color: var(--muted);
}

.login-input,
.text-input,
.search-input {
    width: 100%;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    padding: 0 13px;
    outline: none;
}

.search-input {
    height: 38px;
}

.login-input:focus,
.text-input:focus,
.search-input:focus,
.peer-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.14);
}

.login-btn {
    width: 100%;
    margin-top: 18px;
}

.login-error {
    margin-bottom: 16px;
    padding: 10px 12px;
    border: 1px solid rgba(217, 45, 66, 0.24);
    border-radius: 12px;
    background: rgba(217, 45, 66, 0.08);
    color: #9f1239;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    position: relative;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.74);
    backdrop-filter: blur(24px);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-btn {
    min-width: 74px;
    padding: 0 14px;
}

.topbar-link,
.row-action {
    min-width: 84px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-mark {
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: white;
    font-size: 13px;
    font-weight: 700;
}

.brand h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
    letter-spacing: 0;
}

.brand p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.status-pill {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--muted);
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 99px;
    background: var(--warn);
}

.status-pill.ready .status-dot,
.status-pill.connected .status-dot {
    background: #22c55e;
}

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

.workspace {
    min-height: 0;
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 18px;
    padding: 18px;
}

.control-panel {
    min-height: calc(100vh - 108px);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(26px);
}

.panel-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 4px 4px;
}

.eyebrow {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.panel-hero h2 {
    margin: 3px 0 0;
    font-size: 24px;
    line-height: 1.15;
    letter-spacing: 0;
}

.device-count {
    min-width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: #111827;
    color: #fff;
    font-weight: 800;
}

.link-count {
    width: auto;
    padding: 0 14px;
    text-decoration: none;
    font-size: 13px;
}

.panel-section {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.68);
}

.section-label,
.field-label {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 9px;
}

.field-gap {
    margin-top: 12px;
}

.peer-input {
    width: 100%;
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    padding: 0 14px;
    font-size: 20px;
    font-weight: 750;
    text-transform: uppercase;
    outline: none;
}

.action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 12px;
}

.action-row.three {
    grid-template-columns: 0.85fr 0.9fr 1fr;
}

.section-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.icon-text-btn {
    width: auto;
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.86);
    color: var(--muted);
    font-size: 16px;
}

.device-list {
    display: grid;
    gap: 7px;
    max-height: calc(100vh - 522px);
    min-height: 240px;
    overflow: auto;
    padding-right: 2px;
    margin-top: 10px;
}

.device-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.86);
    transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.device-item:hover {
    transform: translateY(-1px);
    border-color: rgba(0, 113, 227, 0.34);
    box-shadow: 0 8px 20px rgba(20, 32, 54, 0.08);
}

.device-main {
    height: auto;
    min-height: 50px;
    padding: 8px 11px;
    border-radius: 0;
    background: transparent;
    text-align: left;
    display: grid;
    gap: 3px;
}

.device-code,
.device-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 750;
}

.device-delete {
    width: 46px;
    height: auto;
    border-radius: 0;
    background: rgba(217, 45, 66, 0.08);
    color: #9f1239;
    font-size: 16px;
}

.page-shell {
    min-height: 100vh;
}

.devices-page {
    width: min(1180px, calc(100% - 36px));
    display: flex;
    flex-direction: column;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
    gap: 18px;
}

.devices-header-card,
.devices-table-card {
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(26px);
}

.devices-header-card {
    min-height: 132px;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.devices-header-card h2 {
    margin: 4px 0 8px;
    font-size: 30px;
    letter-spacing: 0;
}

.devices-header-card p {
    margin: 0;
    color: var(--muted);
}

.device-count.large {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    font-size: 22px;
}

.devices-table-card {
    padding: 16px;
}

.devices-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    margin-bottom: 14px;
}

.devices-table {
    display: grid;
    gap: 8px;
}

.device-table-row {
    min-height: 62px;
    display: block;
    align-items: center;
    gap: 12px;
    padding: 8px 10px 8px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.78);
}

.device-table-main {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.device-updated {
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.row-action {
    height: 38px;
    white-space: nowrap;
}

.row-delete {
    width: 54px;
    height: 38px;
    border-radius: 12px;
}

.empty-state {
    min-height: 54px;
    display: grid;
    place-items: center;
    border: 1px dashed var(--line);
    border-radius: 14px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
    padding: 10px;
}

.danger-btn {
    width: 100%;
    background: rgba(217, 45, 66, 0.08);
    color: #9f1239;
    border: 1px solid rgba(217, 45, 66, 0.24);
    font-weight: 500;
    font-size: 16px;
    transition-duration: 200ms;
    border-radius: 12px;
}

.danger-btn:hover {
    background: rgba(217, 45, 66, 0.16);
}

.metric-row {
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 14px;
}

.metric-row strong {
    color: var(--text);
    font-size: 14px;
}

.viewer-stage {
    min-width: 0;
    min-height: 0;
    background: transparent;
}

.canvas-surface {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: calc(100vh - 108px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: #05070a;
    outline: none;
    box-shadow: var(--shadow);
}

.canvas-surface.control-active {
    border-color: var(--accent);
    cursor: none;
}

#screenCanvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.viewer-toolbar {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    pointer-events: none;
}

.viewer-toolbar>* {
    pointer-events: auto;
}

.control-toggle,
.viewer-live-chip {
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.38);
    background: rgba(255, 255, 255, 0.78);
    color: #111827;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 750;
    backdrop-filter: blur(18px);
}

.viewer-quality-select,
.viewer-monitor-select {
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.38);
    background: rgba(255, 255, 255, 0.78);
    color: #111827;
    padding: 0 28px 0 14px;
    font-size: 13px;
    font-family: inherit;
    font-weight: 750;
    backdrop-filter: blur(18px);
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111827' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
    transition: background-color 120ms ease, border-color 120ms ease;
}

.viewer-quality-select:hover,
.viewer-monitor-select:hover {
    background-color: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 113, 227, 0.6);
}

.viewer-quality-select:focus,
.viewer-monitor-select:focus {
    border-color: #0071e3;
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.25);
}

.viewer-quality-select option,
.viewer-monitor-select option {
    background: #1f2937;
    color: #ffffff;
    font-weight: 500;
}

.keyboard-toggle {
    display: none !important;
}

.fullscreen-toggle {
    margin-right: auto;
}

.canvas-surface:fullscreen {
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    border-radius: 0;
    border: 0;
}

.canvas-surface:fullscreen #screenCanvas {
    width: 100vw;
    height: 100vh;
}

.control-toggle.active {
    background: rgba(0, 113, 227, 0.9);
    color: #ffffff;
}

.viewer-live-chip {
    color: #374151;
    font-weight: 650;
}

.placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 14px;
    color: rgba(255, 255, 255, 0.64);
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 45%, rgba(80, 110, 160, 0.16), transparent 28%),
        #05070a;
}

.placeholder.hidden {
    display: none;
}

.spinner {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 3px solid rgba(255, 255, 255, 0.16);
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

.control-hint {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    max-width: calc(100% - 28px);
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.38);
    color: #111827;
    font-size: 13px;
    white-space: nowrap;
    backdrop-filter: blur(18px);
}

.shared-cursor {
    position: absolute;
    z-index: 5;
    width: 18px;
    height: 18px;
    transform: translate(-2px, -2px);
    pointer-events: none;
    opacity: 0;
    transition: opacity 120ms ease;
}

.shared-cursor::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    border-left: 12px solid #ffffff;
    border-bottom: 17px solid transparent;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}

.shared-cursor::after {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 0;
    height: 0;
    border-left: 8px solid #111827;
    border-bottom: 12px solid transparent;
}

.shared-cursor.visible {
    opacity: 1;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 980px) {
    .keyboard-toggle {
        display: inline-flex !important;
    }

    .workspace {
        grid-template-columns: 340px minmax(0, 1fr);
    }

    .topbar {
        height: auto;
        min-height: 72px;
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "brand actions"
            "nav nav";
        row-gap: 12px;
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .brand {
        grid-area: brand;
    }

    .topbar-actions {
        grid-area: actions;
    }

    .navigation-container {
        grid-area: nav;
        position: static;
        transform: none;
        width: 100%;
        justify-content: center;
        padding: 6px;
        border: 1px solid var(--line);
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.62);
    }
}

@media (max-width: 820px) {
    .topbar {
        grid-template-columns: 1fr;
        grid-template-areas:
            "brand"
            "nav"
            "actions";
        padding: 16px;
    }

    .brand {
        width: 100%;
    }

    .brand>div:last-child {
        min-width: 0;
    }

    .brand h1,
    .brand p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .navigation-container {
        justify-content: stretch;
        gap: 6px;
    }

    .href-container {
        flex: 1;
        justify-content: center;
        min-height: 38px;
        padding: 0 8px;
        border-radius: 12px;
    }

    .href-container.active {
        background: rgba(0, 113, 227, 0.1);
    }

    .href-btn {
        font-size: 14px;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
        gap: 8px;
    }

    .page-shell .topbar-actions {
        justify-content: flex-end;
    }

    .topbar-actions form {
        flex: 0 0 auto;
    }

    .status-pill {
        min-width: 0;
        flex: 1;
        justify-content: center;
    }

    .status-pill span:last-child {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .workspace {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .control-panel {
        min-height: auto;
        padding: 14px;
    }

    .device-list {
        max-height: 320px;
    }

    .canvas-surface {
        min-height: 58vh;
    }

    .viewer-toolbar {
        top: 10px;
        left: 10px;
        right: 10px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .control-toggle,
    .viewer-live-chip {
        height: 36px;
        padding: 0 11px;
        font-size: 12px;
    }

    .devices-page {
        width: calc(100% - 24px);
        margin: 12px auto;
        gap: 12px;
    }

    .devices-header-card {
        align-items: flex-start;
        flex-direction: column;
        min-height: auto;
        padding: 18px;
        border-radius: 20px;
        gap: 14px;
    }

    .devices-header-card h2 {
        font-size: 24px;
        line-height: 1.15;
    }

    .devices-header-card p {
        font-size: 14px;
        line-height: 1.4;
    }

    .device-count.large {
        width: auto;
        height: 40px;
        min-width: 68px;
        padding: 0 14px;
        border-radius: 14px;
        font-size: 16px;
    }

    .devices-toolbar,
    .device-table-row {
        grid-template-columns: 1fr;
    }

    .devices-table-card {
        padding: 12px;
        border-radius: 20px;
    }

    .devices-toolbar {
        display: grid;
        gap: 10px;
        margin-bottom: 12px;
    }

    .devices-toolbar .secondary-btn {
        width: 100%;
    }

    .device-table-row {
        min-height: 0;
        padding: 12px;
        border-radius: 16px;
    }

    .device-table-grid {
        grid-template-columns: 1fr;
        align-items: stretch;
        gap: 8px;
    }

    .unregistered-device-grid {
        grid-template-columns: 1fr;
    }

    .device-table-grid .device-name {
        font-size: 16px;
    }

    .device-table-grid .device-code,
    .device-updated {
        font-size: 13px;
        color: var(--muted);
    }

    .device-buttons {
        display: grid;
        grid-template-columns: 1fr 88px;
        gap: 8px;
        justify-content: stretch;
        margin-top: 4px;
    }

    .row-action,
    .row-delete {
        width: 100%;
    }

    .row-delete {
        width: 88px;
    }
}

@media (max-width: 420px) {
    .topbar {
        padding: 12px;
    }

    .brand-mark {
        height: 38px;
        border-radius: 10px;
    }

    .brand h1 {
        font-size: 16px;
    }

    .brand p,
    .href-btn,
    .status-pill,
    .topbar-btn {
        font-size: 13px;
    }

    .topbar-btn {
        min-width: 64px;
        padding: 0 10px;
    }

    .navigation-container {
        padding: 5px;
    }

    .href-container svg {
        width: 14px;
        height: 14px;
    }

    .devices-page {
        width: calc(100% - 16px);
        margin-top: 8px;
    }

    .devices-header-card,
    .devices-table-card {
        border-radius: 18px;
    }

    .device-buttons {
        grid-template-columns: 1fr;
    }

    .row-delete {
        width: 100%;
    }
}
