[x-cloak] {
    display: none !important;
}

/* ---- tokens: dark is the default, light is a straight override of every colour ---- */

:root {
    color-scheme: dark light;

    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --bg: #0a0d12;
    --bg-panel: #10141b;
    --bg-raised: #171c25;
    --bg-hover: #1f2530;
    --bg-inset: #06080b;
    --border: #232a35;
    --border-strong: #354051;
    --text: #e7eaf0;
    --text-dim: #a6afbd;
    --text-faint: #727c8b;
    --accent: #57a9ff;
    --accent-dim: rgba(87, 169, 255, 0.14);
    --accent-text: #06080b;
    --danger: #ff6b6b;
    --danger-bg: rgba(255, 107, 107, 0.10);
    --warn: #ffc857;
    --warn-bg: rgba(255, 200, 87, 0.10);
    --online: #3ddc84;
    --offline: #59636f;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.5);

    --topbar-h: 52px;
    --drawer-w: 340px;
    --radius: 8px;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #eef1f5;
        --bg-panel: #ffffff;
        --bg-raised: #f5f7fa;
        --bg-hover: #e9edf4;
        --bg-inset: #dfe4eb;
        --border: #d8dee7;
        --border-strong: #b9c2cf;
        --text: #14181f;
        --text-dim: #4a5462;
        --text-faint: #79828f;
        --accent: #1668dc;
        --accent-dim: rgba(22, 104, 220, 0.10);
        --accent-text: #ffffff;
        --danger: #c62f2f;
        --danger-bg: rgba(198, 47, 47, 0.07);
        --warn: #9a6b00;
        --warn-bg: rgba(255, 193, 7, 0.16);
        --online: #188a4c;
        --offline: #98a2b0;
        --shadow: 0 14px 32px rgba(15, 23, 42, 0.14);
    }
}

/* ---- page ---- */

*,
*:before,
*:after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.vnc-cockpit {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--bg);
}

/* ---- top bar ---- */

.vnc-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    min-height: var(--topbar-h);
    padding: 7px 12px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

.vnc-home {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 9px;
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 13px;
    text-decoration: none;
    white-space: nowrap;
}

.vnc-home:hover {
    background-color: var(--bg-hover);
    color: var(--text);
}

.vnc-home svg {
    width: 15px;
    height: 15px;
}

.vnc-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 31px;
    height: 31px;
    padding: 0;
    cursor: pointer;
    background-color: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
}

.vnc-icon-btn:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-strong);
    color: var(--text);
}

.vnc-icon-btn svg {
    width: 16px;
    height: 16px;
}

.vnc-topbar-spacer {
    flex: 1 1 auto;
    min-width: 0;
}

.vnc-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.vnc-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 3px 10px;
    background-color: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-dim);
    font-size: 12px;
    white-space: nowrap;
}

.vnc-status:before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--offline);
}

.vnc-status[data-status="connecting"]:before {
    background-color: var(--warn);
    animation: vnc-blink 1.2s ease-in-out infinite;
}

.vnc-status[data-status="connected"]:before {
    background-color: var(--online);
}

.vnc-status[data-status="error"]:before {
    background-color: var(--danger);
}

@keyframes vnc-blink {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

.vnc-current {
    min-width: 0;
    overflow: hidden;
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- body split ---- */

.vnc-body {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
}

.vnc-drawer {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 0 0 var(--drawer-w);
    width: var(--drawer-w);
    max-width: 100%;
    padding: 16px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
}

.vnc-drawer > * + * {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.vnc-scrim {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 25;
    background-color: rgba(0, 0, 0, 0.55);
}

.vnc-stage {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    background-color: var(--bg-inset);
}

.vnc-screen {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background-color: var(--bg-inset);
}

/* noVNC injects its canvas here; keep it from overflowing the frame */
.vnc-screen canvas {
    display: block;
}

/* ---- overlays on the stage: well below noVNC's capture layer at z-index 10000 ---- */

.vnc-float {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    width: min(520px, calc(100% - 32px));
    box-shadow: var(--shadow);
}

.vnc-idle {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    background-color: var(--bg-inset);
    text-align: center;
}

.vnc-idle-icon {
    width: 42px;
    height: 42px;
    color: var(--border-strong);
}

.vnc-idle-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.vnc-idle-text {
    margin: 0;
    max-width: 46ch;
    font-size: 13px;
    color: var(--text-faint);
}

/* ---- drawer: saved targets ---- */

.vnc-section-title {
    margin: 0 0 4px;
    color: var(--text-faint);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.vnc-section-hint {
    margin: 0 0 10px;
    color: var(--text-faint);
    font-size: 11px;
    line-height: 1.6;
}

.vnc-targets {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vnc-target {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 10px;
    padding: 10px 12px;
    cursor: pointer;
    text-align: left;
    background-color: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.vnc-target:hover:not([disabled]) {
    background-color: var(--bg-hover);
    border-color: var(--accent);
}

.vnc-target[disabled] {
    cursor: not-allowed;
    opacity: 0.45;
}

.vnc-target-name {
    font-weight: 600;
    color: var(--text);
}

.vnc-target-addr {
    grid-column: 1 / -1;
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 11px;
    word-break: break-all;
}

.vnc-target-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    grid-row: 1;
    grid-column: 2;
}

.vnc-target-desc {
    grid-column: 1 / -1;
    color: var(--text-dim);
    font-size: 11px;
    line-height: 1.6;
}

.vnc-badge {
    padding: 1px 7px;
    background-color: var(--accent-dim);
    border-radius: 999px;
    color: var(--accent);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.vnc-empty {
    margin: 0;
    padding: 12px;
    background-color: transparent;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-faint);
    font-size: 12px;
}

.vnc-empty a {
    color: var(--accent);
}

/* ---- drawer: custom address ---- */

.vnc-custom {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vnc-mode {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vnc-mode-btn {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 9px 12px;
    cursor: pointer;
    text-align: left;
    background-color: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.vnc-mode-btn:hover {
    border-color: var(--border-strong);
}

.vnc-mode-btn[aria-pressed="true"] {
    background-color: var(--accent-dim);
    border-color: var(--accent);
}

.vnc-mode-name {
    font-size: 13px;
    font-weight: 600;
}

.vnc-mode-desc {
    color: var(--text-faint);
    font-size: 11px;
}

.vnc-mode-btn[aria-pressed="true"] .vnc-mode-desc {
    color: var(--text-dim);
}

/* the drawer is narrow, so the fields stack instead of sharing a row */
.vnc-custom-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.vnc-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.vnc-field label {
    color: var(--text-dim);
    font-size: 12px;
}

.vnc-field input,
.vnc-cred input {
    width: 100%;
    padding: 8px 10px;
    background-color: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    line-height: 18px;
}

.vnc-field input:focus,
.vnc-cred input:focus {
    border-color: var(--accent);
    outline: none;
}

.vnc-field input::placeholder {
    color: var(--text-faint);
}

.vnc-field-hint {
    color: var(--text-faint);
    font-size: 11px;
    line-height: 1.5;
}

.vnc-advanced {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.vnc-advanced summary {
    cursor: pointer;
    color: var(--text-dim);
    font-size: 12px;
}

.vnc-advanced[open] summary {
    margin-bottom: 10px;
}

.vnc-bridge {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.vnc-bridge-note {
    margin: 0;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.7;
}

.vnc-preview {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    margin: 0;
    padding: 8px 10px;
    background-color: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-faint);
    font-size: 11px;
}

.vnc-preview code {
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 12px;
    word-break: break-all;
}

/* ---- buttons ---- */

.vnc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 13px;
    cursor: pointer;
    background-color: var(--accent);
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--accent-text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
    /* also worn by an <a> */
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, filter 0.15s ease;
}

.vnc-btn:hover:not([disabled]) {
    filter: brightness(1.1);
}

.vnc-btn[disabled] {
    cursor: not-allowed;
    opacity: 0.4;
    filter: none;
}

.vnc-btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.vnc-btn-alert {
    background-color: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
}

.vnc-btn-alert:hover:not([disabled]) {
    background-color: var(--danger);
    border-color: var(--danger);
    color: var(--bg-panel);
    filter: none;
}

.vnc-btn-ghost {
    background-color: transparent;
    border-color: var(--border);
    color: var(--text-dim);
}

.vnc-btn-ghost:hover:not([disabled]) {
    background-color: var(--bg-hover);
    color: var(--text);
    filter: none;
}

.vnc-btn-ghost[aria-pressed="true"] {
    background-color: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.vnc-btn:focus-visible,
.vnc-icon-btn:focus-visible,
.vnc-target:focus-visible,
.vnc-mode-btn:focus-visible,
.vnc-field input:focus-visible,
.vnc-cred input:focus-visible,
.vnc-home:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---- overlays: credentials and errors ---- */

.vnc-cred {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background-color: var(--bg-panel);
    border: 1px solid var(--warn);
    border-radius: var(--radius);
}

.vnc-cred label {
    flex: 1 1 100%;
    color: var(--text);
    font-size: 12px;
}

.vnc-cred input {
    flex: 1 1 180px;
    width: auto;
}

.vnc-error {
    padding: 12px 14px;
    background-color: var(--bg-panel);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
}

.vnc-error-text {
    margin: 0;
}

.vnc-error-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

/* ---- drawer: tutorial ---- */

.vnc-help summary {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-dim);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    list-style: none;
}

.vnc-help summary::-webkit-details-marker {
    display: none;
}

.vnc-help summary:before {
    content: "";
    width: 6px;
    height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
}

.vnc-help[open] summary:before {
    transform: rotate(45deg);
}

.vnc-help-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 12px;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.75;
}

.vnc-help-body h3 {
    margin: 0 0 4px;
    color: var(--text);
    font-size: 13px;
}

.vnc-help-body .vnc-guide-sub {
    margin: 4px 0 8px;
    color: var(--text-faint);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.vnc-help-body p {
    margin: 0;
}

.vnc-help-body strong {
    color: var(--text);
}

.vnc-steps {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 0;
    padding-left: 20px;
}

.vnc-steps-flat {
    list-style: none;
    padding-left: 0;
}

.vnc-code,
.vnc-bridge-cmd {
    margin: 8px 0 0;
    padding: 10px 12px;
    overflow-x: auto;
    background-color: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.7;
}

.vnc-code code {
    padding: 0;
    background-color: transparent;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
}

/* ---- narrow screens: the drawer floats over the picture ---- */

@media (max-width: 930px) {
    .vnc-drawer {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 30;
        flex: 0 0 auto;
        width: min(88vw, var(--drawer-w));
        box-shadow: var(--shadow);
    }

    .vnc-scrim {
        display: block;
    }

    .vnc-current {
        display: none;
    }

    .vnc-float {
        top: 12px;
        width: calc(100% - 24px);
    }
}

@media (max-width: 560px) {
    .vnc-home-text {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .vnc-status[data-status="connecting"]:before {
        animation: none;
    }
}
