:root {
    --bg: #080d13;
    --bg-soft: #0c141d;
    --panel: rgba(15, 24, 34, 0.86);
    --panel-solid: #101a24;
    --panel-raised: #152231;
    --border: rgba(124, 160, 190, 0.16);
    --border-strong: rgba(124, 160, 190, 0.28);
    --text: #e9f1fa;
    --text-soft: #a9bbcb;
    --muted: #75899d;
    --accent: #35d6a1;
    --accent-strong: #20b98a;
    --accent-soft: rgba(53, 214, 161, 0.12);
    --cyan: #58c7e8;
    --danger: #ff6b81;
    --warning: #f4bf5f;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 16px 38px rgba(0, 0, 0, 0.3);
    --font: "Segoe UI Variable Display", "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
    --mono: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(1200px 700px at 82% -10%, rgba(53, 214, 161, 0.08), transparent 60%),
        radial-gradient(1000px 600px at 8% 0%, rgba(88, 199, 232, 0.06), transparent 55%),
        linear-gradient(180deg, #0a1119 0%, #080d13 55%, #070b10 100%);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    color: inherit;
}

a {
    color: var(--accent);
}

code {
    padding: 1px 5px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
    color: #cfe7f5;
    font-family: var(--mono);
    font-size: 0.88em;
}

.svg-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

svg {
    width: 1.15em;
    height: 1.15em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}

[hidden] {
    display: none !important;
}

::selection {
    color: #052016;
    background: var(--accent);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 10px;
    background-clip: padding-box;
    background-color: rgba(146, 174, 197, 0.24);
}

/* ---------- Login ---------- */

.login-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 24px;
    overflow: hidden;
    background:
        radial-gradient(900px 600px at 50% 10%, rgba(53, 214, 161, 0.12), transparent 60%),
        linear-gradient(180deg, #081018, #070b10);
}

.login-orbit {
    position: absolute;
    width: min(900px, 90vw);
    aspect-ratio: 1;
    border: 1px solid rgba(53, 214, 161, 0.08);
    border-radius: 50%;
    box-shadow: 0 0 0 90px rgba(53, 214, 161, 0.02), 0 0 0 180px rgba(88, 199, 232, 0.015);
    animation: orbit-pulse 8s ease-in-out infinite;
    pointer-events: none;
}

@keyframes orbit-pulse {
    0%, 100% { transform: scale(1); opacity: 0.65; }
    50% { transform: scale(1.04); opacity: 1; }
}

.login-card {
    position: relative;
    width: min(440px, 100%);
    padding: 38px;
    border: 1px solid var(--border);
    border-radius: 26px;
    background: linear-gradient(180deg, rgba(21, 34, 49, 0.95), rgba(12, 20, 29, 0.98));
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
}

.login-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, rgba(53, 214, 161, 0.4), transparent 35%, transparent 65%, rgba(88, 199, 232, 0.25));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 26px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(88, 199, 232, 0.32);
    border-radius: 14px;
    background: #0a1622;
    color: var(--accent);
    box-shadow: 0 0 28px rgba(88, 199, 232, 0.12);
}

.brand-mark img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.brand-mark svg {
    width: 25px;
    height: 25px;
}

.brand-eyebrow {
    color: var(--accent);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.16em;
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 28px;
    font-weight: 650;
    letter-spacing: -0.02em;
}

.login-card h1 .version-tag {
    height: 20px;
    padding: 0 7px;
    margin-left: 4px;
    font-size: 10px;
    vertical-align: middle;
}

.login-lead {
    margin: 0 0 28px;
    color: var(--text-soft);
    font-size: 14px;
}

.login-foot {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 26px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
}

.login-foot span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ---------- Shell ---------- */

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    height: 72px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(8, 13, 19, 0.82);
    backdrop-filter: blur(18px);
}

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

.brand-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

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

.brand-copy strong {
    overflow: hidden;
    font-size: 15px;
    font-weight: 650;
    letter-spacing: 0.01em;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.version-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 16px;
    padding: 0 5px;
    border: 1px solid rgba(53, 214, 161, 0.28);
    border-radius: 4px;
    background: rgba(53, 214, 161, 0.08);
    color: var(--accent);
    font-family: var(--mono);
    font-size: 8px;
    font-weight: 600;
    letter-spacing: 0.03em;
    line-height: 1;
    white-space: nowrap;
    vertical-align: middle;
}

.brand-copy span {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.warning-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 11px;
    border: 1px solid rgba(244, 191, 95, 0.28);
    border-radius: 999px;
    background: rgba(244, 191, 95, 0.08);
    color: var(--warning);
    font-size: 11px;
    white-space: nowrap;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.025);
    color: var(--text-soft);
    font-size: 12px;
    white-space: nowrap;
}

.status-pill i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    box-shadow: 0 0 0 3px rgba(117, 137, 157, 0.12);
}

.status-pill.online {
    border-color: rgba(53, 214, 161, 0.32);
    color: #bdf8e1;
}

.status-pill.online i {
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(53, 214, 161, 0.15), 0 0 12px rgba(53, 214, 161, 0.65);
}

.status-pill.busy i {
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.35; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.1); }
}

.layout {
    width: min(1760px, 100%);
    margin: 0 auto;
    padding: 22px 28px 30px;
    display: grid;
    grid-template-columns: 336px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    flex: 1 0 auto;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(17, 28, 40, 0.92), rgba(11, 18, 26, 0.9));
    box-shadow: var(--shadow-md);
}

.connect-panel,
.devices-panel,
.help-panel {
    padding: 18px;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.panel-head.compact {
    align-items: center;
    margin-bottom: 12px;
}

.panel-head h2 {
    margin: 0 0 2px;
    font-size: 15px;
    font-weight: 650;
}

.panel-head p {
    margin: 0;
    color: var(--muted);
    font-size: 11.5px;
}

.step-badge {
    display: grid;
    place-items: center;
    min-width: 32px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10px;
}

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

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 14px;
}

.field > span {
    color: var(--text-soft);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    background: rgba(5, 10, 15, 0.55);
    color: var(--text);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input,
select {
    height: 42px;
    padding: 0 12px;
}

textarea {
    padding: 12px;
    resize: vertical;
    min-height: 120px;
}

input::placeholder,
textarea::placeholder {
    color: #5f7386;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(53, 214, 161, 0.6);
    background: rgba(5, 10, 15, 0.8);
    box-shadow: 0 0 0 3px rgba(53, 214, 161, 0.1);
}

input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.55;
}

.input-with-icon {
    position: relative;
}

.input-with-icon svg {
    position: absolute;
    top: 50%;
    left: 12px;
    width: 16px;
    height: 16px;
    color: var(--muted);
    transform: translateY(-50%);
    pointer-events: none;
}

.input-with-icon input {
    padding-left: 37px;
}

.input-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto 78px;
    align-items: center;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: rgba(5, 10, 15, 0.55);
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.input-split:focus-within {
    border-color: rgba(53, 214, 161, 0.6);
    box-shadow: 0 0 0 3px rgba(53, 214, 161, 0.1);
}

.input-split input {
    border: 0;
    background: transparent;
    box-shadow: none;
}

.input-split input:focus {
    box-shadow: none;
    background: transparent;
}

.port-sep {
    color: var(--muted);
    font-family: var(--mono);
}

.input-split input[type="number"] {
    padding-left: 8px;
    text-align: center;
    font-family: var(--mono);
    font-size: 12.5px;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.advanced {
    margin: 4px 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.018);
}

.advanced summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 12px;
    color: var(--text-soft);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

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

.advanced summary .chevron {
    width: 13px;
    height: 13px;
    margin-left: auto;
    color: var(--muted);
    transition: transform 0.18s ease;
}

.advanced[open] summary .chevron {
    transform: rotate(90deg);
}

.advanced-body {
    padding: 0 12px 12px;
    border-top: 1px solid var(--border);
}

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

.pair-grid .field {
    margin-bottom: 0;
}

.hint {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.5;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 42px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    user-select: none;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, #44e0ad, #23bf8d);
    color: #042016;
    box-shadow: 0 10px 24px rgba(35, 191, 141, 0.2);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #58e7b8, #2ccb98);
    box-shadow: 0 12px 28px rgba(35, 191, 141, 0.28);
}

.btn-secondary {
    border-color: var(--border-strong);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    border-color: rgba(53, 214, 161, 0.35);
    background: rgba(53, 214, 161, 0.08);
}

.btn-ghost {
    background: transparent;
    color: var(--text-soft);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.btn-block {
    width: 100%;
}

.btn.loading {
    pointer-events: none;
}

.btn.loading::after {
    content: "";
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.icon-btn {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

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

.form-error {
    margin: 10px 0 0;
    padding: 9px 11px;
    border: 1px solid rgba(255, 107, 129, 0.22);
    border-radius: 8px;
    background: rgba(255, 107, 129, 0.07);
    color: #ffb2bd;
    font-size: 11.5px;
    line-height: 1.5;
}

/* ---------- Device list ---------- */

.btn-scan {
    width: 100%;
    height: 36px;
    margin-bottom: 11px;
    border-color: rgba(88, 199, 232, 0.2);
    background: rgba(88, 199, 232, 0.045);
    color: #a8e4f4;
    font-size: 11px;
}

.btn-scan:hover:not(:disabled) {
    border-color: rgba(88, 199, 232, 0.4);
    background: rgba(88, 199, 232, 0.09);
}

.btn-scan svg {
    width: 15px;
    height: 15px;
}

.device-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 348px;
    overflow-y: auto;
    padding-right: 2px;
}

.device-card {
    position: relative;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    width: 100%;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.018);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.device-card:hover {
    border-color: var(--border-strong);
    background: rgba(255, 255, 255, 0.04);
    transform: translateY(-1px);
}

.device-card.selected {
    border-color: rgba(53, 214, 161, 0.5);
    background: rgba(53, 214, 161, 0.07);
    box-shadow: inset 0 0 0 1px rgba(53, 214, 161, 0.12);
}

.device-card.offline {
    opacity: 0.66;
}

.device-icon {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(5, 10, 15, 0.4);
    color: var(--text-soft);
}

.device-icon svg {
    width: 17px;
    height: 17px;
}

.device-card.selected .device-icon {
    border-color: rgba(53, 214, 161, 0.3);
    color: var(--accent);
}

.device-info {
    min-width: 0;
}

.device-name {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    font-size: 12.5px;
    font-weight: 650;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.device-name .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    flex: none;
}

.device-name .dot.online {
    background: var(--accent);
    box-shadow: 0 0 8px rgba(53, 214, 161, 0.7);
}

.device-meta {
    overflow: hidden;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 9.5px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.device-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--muted);
    font-size: 10px;
    white-space: nowrap;
}

.device-card.selected .device-action {
    color: var(--accent);
}

.device-action svg {
    width: 12px;
    height: 12px;
}

.device-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: 5px;
    background: rgba(244, 191, 95, 0.1);
    color: var(--warning);
    font-family: var(--mono);
    font-size: 8.5px;
    letter-spacing: 0.03em;
}

.mini-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px 12px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    color: var(--muted);
    text-align: center;
}

.mini-empty svg {
    width: 28px;
    height: 28px;
    opacity: 0.55;
}

.mini-empty p {
    margin: 0;
    max-width: 230px;
    font-size: 11px;
}

/* ---------- Help ---------- */

.help-steps {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.help-steps li {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 10px;
}

.help-steps li > span {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 9px;
}

.help-steps strong {
    display: block;
    margin-bottom: 2px;
    font-size: 11.5px;
    font-weight: 650;
}

.help-steps p {
    margin: 0;
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.55;
}

.help-note {
    display: flex;
    gap: 8px;
    margin-top: 15px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: rgba(88, 199, 232, 0.04);
    color: var(--muted);
    font-size: 10px;
    line-height: 1.5;
}

.help-note svg {
    width: 14px;
    height: 14px;
    margin-top: 1px;
    color: var(--cyan);
}

/* ---------- Viewer ---------- */

.workspace {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.viewer {
    overflow: hidden;
}

.viewer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.device-title {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.device-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--muted);
    box-shadow: 0 0 0 4px rgba(117, 137, 157, 0.1);
    flex: none;
}

.device-dot.online {
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(53, 214, 161, 0.12), 0 0 16px rgba(53, 214, 161, 0.55);
}

.device-dot.busy {
    background: var(--warning);
    animation: pulse 1.2s ease-in-out infinite;
}

.device-title h1 {
    margin: 0;
    overflow: hidden;
    font-size: 15px;
    font-weight: 650;
    letter-spacing: 0.01em;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.device-title p {
    margin: 1px 0 0;
    overflow: hidden;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 9.5px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.viewer-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.chip {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--muted);
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.chip.live {
    border-color: rgba(53, 214, 161, 0.25);
    background: var(--accent-soft);
    color: var(--accent);
}

.quality-field {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 26px;
    padding: 0 7px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--muted);
}

.quality-field svg {
    width: 12px;
    height: 12px;
}

.quality-field select {
    width: auto;
    height: 24px;
    padding: 0 15px 0 0;
    border: 0;
    background: transparent;
    color: var(--text-soft);
    font-size: 10px;
    cursor: pointer;
}

.quality-field select:focus {
    box-shadow: none;
}

.stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: clamp(380px, 61vh, 780px);
    padding: 22px;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 50% 50%, rgba(53, 214, 161, 0.05), transparent 60%),
        #05080c;
}

.stage-grid {
    position: absolute;
    inset: 0;
    opacity: 0.55;
    background-image:
        linear-gradient(rgba(124, 160, 190, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(124, 160, 190, 0.045) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: radial-gradient(ellipse at center, black 20%, transparent 72%);
    pointer-events: none;
}

.stage::after {
    content: "";
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 90px 20px rgba(0, 0, 0, 0.55);
    pointer-events: none;
}

.stage:fullscreen {
    width: 100vw;
    height: 100vh;
    padding: 18px;
    border-radius: 0;
    background: #000;
}

.stage:fullscreen .stage-grid,
.stage:fullscreen .stage-badge {
    display: none;
}

.stage:fullscreen #screenCanvas {
    max-height: calc(100vh - 36px);
    max-width: calc(100vw - 36px);
    border-radius: 6px;
}

#screenCanvas {
    position: relative;
    z-index: 2;
    display: none;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    border-radius: 10px;
    background: #000;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.08);
    outline: none;
    touch-action: none;
    cursor: crosshair;
}

.stage.has-frame #screenCanvas {
    display: block;
}

.stage.has-frame .stage-empty {
    display: none;
}

.stage-empty {
    position: relative;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 440px;
    padding: 24px;
    text-align: center;
}

.empty-art {
    position: relative;
    width: 150px;
    height: 116px;
    margin-bottom: 20px;
}

.empty-phone {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 64px;
    height: 104px;
    border: 1px solid rgba(124, 160, 190, 0.32);
    border-radius: 13px;
    background: linear-gradient(160deg, rgba(22, 36, 50, 0.9), rgba(8, 14, 20, 0.95));
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
    transform: translate(-50%, -50%) rotate(-7deg);
}

.empty-phone::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    width: 18px;
    height: 3px;
    border-radius: 3px;
    background: rgba(124, 160, 190, 0.35);
    transform: translateX(-50%);
}

.empty-phone span {
    position: absolute;
    inset: 14px 6px 10px;
    border-radius: 6px;
    background:
        radial-gradient(circle at 70% 20%, rgba(53, 214, 161, 0.28), transparent 45%),
        linear-gradient(145deg, rgba(53, 214, 161, 0.08), rgba(88, 199, 232, 0.03));
}

.empty-signal {
    position: absolute;
    right: 6px;
    bottom: 10px;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 34px;
}

.empty-signal i {
    display: block;
    width: 4px;
    border-radius: 3px;
    background: var(--accent);
    box-shadow: 0 0 10px rgba(53, 214, 161, 0.45);
}

.empty-signal i:nth-child(1) { height: 10px; opacity: 0.35; }
.empty-signal i:nth-child(2) { height: 20px; opacity: 0.6; }
.empty-signal i:nth-child(3) { height: 32px; opacity: 0.95; }

.stage-empty h3 {
    margin: 0 0 6px;
    font-size: 17px;
    font-weight: 600;
}

.stage-empty p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.empty-badges {
    display: flex;
    gap: 6px;
    margin-top: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.empty-badges span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--muted);
    font-size: 9.5px;
}

.empty-badges svg {
    width: 12px;
    height: 12px;
    color: var(--text-soft);
}

.stage-overlay {
    position: absolute;
    z-index: 8;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 24px;
    background: rgba(4, 7, 10, 0.74);
    backdrop-filter: blur(4px);
    text-align: center;
}

.stage-overlay h3 {
    margin: 8px 0 0;
    font-size: 16px;
    font-weight: 600;
}

.stage-overlay p {
    max-width: 420px;
    margin: 0;
    color: var(--text-soft);
    font-size: 12px;
    line-height: 1.6;
}

.stage-overlay .btn {
    margin-top: 12px;
}

.spinner {
    width: 34px;
    height: 34px;
    border: 2px solid rgba(53, 214, 161, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.85s linear infinite;
}

.spinner.hidden {
    display: none;
}

.stage-badge {
    position: absolute;
    z-index: 6;
    top: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border: 1px solid rgba(53, 214, 161, 0.2);
    border-radius: 6px;
    background: rgba(5, 10, 15, 0.72);
    color: var(--accent);
    font-family: var(--mono);
    font-size: 8px;
    letter-spacing: 0.07em;
    backdrop-filter: blur(8px);
}

.stage-badge.snapshot {
    border-color: rgba(244, 191, 95, 0.24);
    color: var(--warning);
}

.touch-indicator {
    position: absolute;
    z-index: 5;
    width: 26px;
    height: 26px;
    margin: -13px 0 0 -13px;
    border: 1px solid rgba(53, 214, 161, 0.7);
    border-radius: 50%;
    background: rgba(53, 214, 161, 0.14);
    box-shadow: 0 0 22px rgba(53, 214, 161, 0.35);
    pointer-events: none;
    opacity: 0;
    transform: scale(0.5);
}

.touch-indicator.show {
    animation: touch-ripple 0.42s ease-out forwards;
}

@keyframes touch-ripple {
    0% { opacity: 1; transform: scale(0.4); }
    100% { opacity: 0; transform: scale(1.4); }
}

/* ---------- Controls ---------- */

.controlbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 16px;
    border-top: 1px solid var(--border);
    background: rgba(8, 14, 20, 0.42);
    overflow-x: auto;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: none;
}

.control-group.grow {
    flex: 1 1 auto;
}

.control-divider {
    width: 1px;
    height: 24px;
    margin: 0 3px;
    background: var(--border);
    flex: none;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-soft);
    font-size: 10.5px;
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

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

.tool-btn:hover {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.tool-btn:active {
    background: var(--accent-soft);
    color: var(--accent);
}

.workspace-footer {
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 0 6px;
    color: var(--muted);
    font-size: 10px;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-family: var(--mono);
    white-space: nowrap;
}

.stat span {
    color: #5d7286;
    font-family: var(--font);
    font-size: 9.5px;
    letter-spacing: 0.04em;
}

.stat strong {
    color: var(--text-soft);
    font-size: 10.5px;
    font-weight: 500;
}

.shortcut-hint {
    margin-left: auto;
    color: #5d7286;
    font-size: 9.5px;
}

.site-footer {
    border-top: 1px solid var(--border);
    background: rgba(6, 10, 15, 0.45);
}

.site-footer-inner {
    width: min(1760px, 100%);
    margin: 0 auto;
    padding: 15px 28px 17px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    flex-wrap: wrap;
    color: #617487;
    font-size: 10px;
    line-height: 1.6;
}

.site-footer a {
    color: var(--text-soft);
    text-decoration: none;
    transition: color 0.15s ease;
}

.site-footer a:hover {
    color: var(--accent);
}

.site-footer .version-tag {
    height: 15px;
    margin: 0 2px;
    font-size: 7.5px;
}

@media (max-width: 720px) {
    .site-footer-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 13px 16px 15px;
    }
}

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(3, 6, 9, 0.72);
    backdrop-filter: blur(7px);
}

.modal-card {
    width: min(540px, 100%);
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: linear-gradient(180deg, #131f2c, #0d161f);
    box-shadow: var(--shadow-lg);
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.modal-head h2 {
    margin: 0 0 3px;
    font-size: 17px;
    font-weight: 650;
}

.modal-head p {
    margin: 0;
    color: var(--muted);
    font-size: 11px;
}

.check-row {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin: 4px 0 18px;
    color: var(--text-soft);
    font-size: 11px;
    cursor: pointer;
}

.check-row input {
    width: 16px;
    height: 16px;
    margin: 1px 0 0;
    accent-color: var(--accent);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- Toasts ---------- */

.toast-stack {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    max-width: min(380px, calc(100vw - 32px));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 11px 13px;
    border: 1px solid var(--border-strong);
    border-radius: 11px;
    background: rgba(17, 28, 40, 0.96);
    box-shadow: var(--shadow-md);
    color: var(--text);
    font-size: 11.5px;
    line-height: 1.5;
    pointer-events: auto;
    animation: toast-in 0.22s ease-out;
}

.toast svg {
    width: 15px;
    height: 15px;
    margin-top: 1px;
    color: var(--accent);
}

.toast.error {
    border-color: rgba(255, 107, 129, 0.32);
}

.toast.error svg {
    color: var(--danger);
}

.toast.warn {
    border-color: rgba(244, 191, 95, 0.3);
}

.toast.warn svg {
    color: var(--warning);
}

.toast.out {
    animation: toast-out 0.2s ease-in forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateY(5px); }
}

.noscript {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    background: var(--bg);
    color: var(--text);
}

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
    .layout {
        grid-template-columns: 300px minmax(0, 1fr);
        padding: 18px 20px 26px;
    }

    .viewer-meta .chip:nth-child(2) {
        display: none;
    }

    .shortcut-hint {
        display: none;
    }
}

@media (max-width: 980px) {
    .topbar {
        height: 64px;
        padding: 0 18px;
    }

    .brand-copy span,
    .warning-chip {
        display: none;
    }

    .layout {
        grid-template-columns: minmax(0, 1fr);
        padding: 14px 14px 24px;
    }

    .sidebar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .help-panel {
        grid-column: 1 / -1;
    }

    .stage {
        height: clamp(340px, 56vh, 680px);
        padding: 14px;
    }

    .viewer-head {
        padding: 14px 16px;
    }

    .controlbar {
        padding: 10px 12px;
    }
}

@media (max-width: 720px) {
    body {
        font-size: 13.5px;
    }

    .topbar {
        padding: 0 12px;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
    }

    .brand-copy strong {
        font-size: 13.5px;
    }

    .status-pill {
        max-width: 118px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar {
        display: flex;
    }

    .layout {
        padding: 10px 10px 20px;
        gap: 12px;
    }

    .connect-panel,
    .devices-panel,
    .help-panel {
        padding: 15px;
    }

    .viewer-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .viewer-meta {
        width: 100%;
        justify-content: flex-start;
    }

    .viewer-meta .chip:nth-child(2) {
        display: inline-flex;
    }

    .stage {
        height: 54vh;
        min-height: 300px;
        padding: 8px;
    }

    .stage-empty p {
        display: none;
    }

    .empty-badges {
        margin-top: 12px;
    }

    .empty-art {
        transform: scale(0.85);
        margin-bottom: 10px;
    }

    .controlbar {
        gap: 4px;
        padding: 8px;
    }

    .control-divider {
        display: none;
    }

    .tool-btn {
        width: 38px;
        height: 36px;
        justify-content: center;
        padding: 0;
    }

    .tool-btn span {
        display: none;
    }

    .tool-btn svg {
        width: 18px;
        height: 18px;
    }

    .workspace-footer {
        gap: 12px;
        padding: 0;
    }

    .workspace-footer .stat:nth-child(4) {
        display: none;
    }

    .login-card {
        padding: 26px 22px;
    }

    .login-foot {
        flex-direction: column;
        gap: 6px;
    }

    .toast-stack {
        right: 12px;
        bottom: 12px;
    }

    .modal-card {
        padding: 18px;
    }
}

@media (max-width: 520px) {
    .topbar-right {
        gap: 6px;
    }

    .status-pill {
        width: 30px;
        height: 30px;
        justify-content: center;
        padding: 0;
    }

    .status-pill span {
        display: none;
    }

    .brand-copy strong {
        max-width: 170px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

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