* {
    box-sizing: border-box;
}

:root {
    --page-bg: #08111f;
    --page-glow: rgba(92, 193, 255, 0.2);
    --panel-bg: rgba(8, 18, 34, 0.8);
    --panel-border: rgba(141, 173, 201, 0.18);
    --panel-strong: rgba(255, 255, 255, 0.06);
    --panel-soft: rgba(255, 255, 255, 0.03);
    --text-main: #eef6ff;
    --text-soft: #99abc3;
    --text-faint: #6f8098;
    --accent: #ff9e57;
    --accent-strong: #ffb980;
    --accent-cool: #59d1ff;
    --success: #7fe1a2;
    --warning: #ffd56f;
    --danger: #ff8575;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.38);
    --shadow-sm: 0 12px 32px rgba(0, 0, 0, 0.18);
    --mono: "IBM Plex Mono", "SFMono-Regular", monospace;
    --sans: "IBM Plex Sans", "Segoe UI", sans-serif;
}

body.theme-light {
    --page-bg: #f2ede2;
    --page-glow: rgba(199, 113, 37, 0.14);
    --panel-bg: rgba(255, 251, 244, 0.86);
    --panel-border: rgba(113, 76, 43, 0.14);
    --panel-strong: rgba(113, 76, 43, 0.08);
    --panel-soft: rgba(113, 76, 43, 0.04);
    --text-main: #1e242d;
    --text-soft: #6a7077;
    --text-faint: #8c8376;
    --accent: #b65c20;
    --accent-strong: #d17a3c;
    --accent-cool: #0f7a95;
    --success: #2b8451;
    --warning: #9f6c00;
    --danger: #b4443f;
    --shadow-lg: 0 24px 70px rgba(92, 74, 53, 0.16);
    --shadow-sm: 0 12px 26px rgba(92, 74, 53, 0.08);
}

html {
    background: var(--page-bg);
    color-scheme: dark;
    scroll-behavior: smooth;
}

body.theme-light {
    color-scheme: light;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--sans);
    background:
        radial-gradient(circle at top left, var(--page-glow), transparent 34%),
        radial-gradient(circle at bottom right, rgba(255, 158, 87, 0.08), transparent 28%),
        linear-gradient(160deg, rgba(255, 255, 255, 0.03), transparent 20%),
        var(--page-bg);
    color: var(--text-main);
    overflow-x: hidden;
    -webkit-tap-highlight-color: rgba(255, 158, 87, 0.2);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(circle at center, black 34%, transparent 90%);
    opacity: 0.18;
}

.skip-link {
    position: absolute;
    top: 1rem;
    left: 1rem;
    transform: translateY(-160%);
    padding: 0.85rem 1rem;
    border-radius: 999px;
    background: var(--accent);
    color: #111;
    text-decoration: none;
    z-index: 10;
}

.skip-link:focus-visible {
    transform: translateY(0);
}

#app {
    min-height: 100vh;
}

.page-shell {
    width: min(1500px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 24px 0 40px;
}

.hero {
    display: grid;
    grid-template-columns: 1.45fr 0.95fr;
    gap: 20px;
    margin-bottom: 20px;
}

.hero-copy,
.hero-card,
.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
}

.hero-copy {
    padding: 28px;
    position: relative;
    overflow: hidden;
}

.hero-copy::after {
    content: "websocket";
    position: absolute;
    right: -8px;
    bottom: -18px;
    font-family: var(--mono);
    font-size: clamp(2.4rem, 8vw, 7rem);
    line-height: 0.88;
    color: rgba(255, 255, 255, 0.05);
    pointer-events: none;
}

.eyebrow,
.panel-kicker {
    margin: 0 0 12px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.74rem;
    color: var(--accent-cool);
}

.hero h1,
.panel h2,
.panel h3 {
    margin: 0;
    text-wrap: balance;
}

.hero h1 {
    font-size: clamp(2.4rem, 4vw, 4.7rem);
    line-height: 0.95;
    max-width: 10ch;
}

.hero-text {
    max-width: 58ch;
    margin: 18px 0 0;
    color: var(--text-soft);
    font-size: 1.02rem;
}

.hero-pills,
.chip-row,
.command-list,
.users-list,
.frame-list,
.timeline {
    margin: 0;
    padding: 0;
    list-style: none;
}

.hero-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

.hero-pills li,
.meta-chip {
    padding: 0.5rem 0.7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    font-size: 0.82rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.hero-card {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.status-wrap {
    display: grid;
    gap: 12px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-width: 128px;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-variant-numeric: tabular-nums;
    background: rgba(255, 255, 255, 0.08);
}

.status-badge.connected {
    background: rgba(127, 225, 162, 0.18);
    color: var(--success);
}

.status-badge.warning {
    background: rgba(255, 213, 111, 0.16);
    color: var(--warning);
}

.status-badge.error {
    background: rgba(255, 133, 117, 0.18);
    color: var(--danger);
}

.status-badge.idle {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-soft);
}

.status-detail {
    margin: 0;
    color: var(--text-soft);
}

.hero-actions,
.form-actions,
.split-field,
.panel-head,
.frame-head,
.timeline-header,
.form-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.hero-actions,
.chip-row,
.form-actions {
    flex-wrap: wrap;
}

.transport-grid,
.detail-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 0;
}

.transport-grid div,
.detail-list div {
    min-width: 0;
    padding: 14px;
    border-radius: var(--radius-md);
    background: var(--panel-soft);
    border: 1px solid var(--panel-border);
}

dt {
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-faint);
    margin-bottom: 6px;
}

dd {
    margin: 0;
    font-family: var(--mono);
    font-size: 0.9rem;
    color: var(--text-main);
    word-break: break-word;
}

.main-content {
    display: grid;
    gap: 16px;
}

.dashboard-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dashboard-note {
    margin: 0;
    color: var(--text-soft);
    font-size: 0.92rem;
}

.dashboard {
    display: grid;
    grid-template-columns: minmax(280px, 320px) minmax(420px, 1fr) minmax(300px, 360px);
    gap: 20px;
    align-items: start;
    grid-auto-flow: row dense;
}

.dashboard-block {
    min-width: 0;
}

.dashboard-block-center {
    grid-column: 2;
}

.panel {
    padding: 22px;
}

.panel-head {
    margin-bottom: 18px;
    align-items: start;
    cursor: grab;
}

.panel-head button {
    cursor: pointer;
}

.panel-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* ── Drag-and-drop indicator line ── */
.drop-indicator {
    position: absolute;
    top: 0;
    left: 0;
    height: 4px;
    border-radius: 2px;
    background: var(--accent, rgba(89, 209, 255, 0.8));
    box-shadow: 0 0 10px rgba(89, 209, 255, 0.45);
    pointer-events: none;
    z-index: 100;
    opacity: 0;
    transform: scaleX(0.3);
    transition: opacity 0.15s ease, transform 0.15s ease;
    will-change: transform, opacity;
}

.drop-indicator.visible {
    opacity: 1;
    transform: scaleX(1);
}

.drop-indicator::before,
.drop-indicator::after {
    content: "";
    position: absolute;
    top: -4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent, rgba(89, 209, 255, 0.8));
}

.drop-indicator::before {
    left: -6px;
}

.drop-indicator::after {
    right: -6px;
}

/* ── Block drag transitions ── */
.dashboard-block[draggable="true"] {
    transition: box-shadow 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.dashboard-block.is-dragging {
    opacity: 0.35;
    border-color: var(--accent, rgba(89, 209, 255, 0.3));
    border-style: dashed;
    box-shadow: none;
}

.dashboard.is-reordering .dashboard-block:not(.is-dragging) {
    transition: box-shadow 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.dashboard-block.is-dragging .panel-head,
.panel-head:active {
    cursor: grabbing;
}

.dashboard-block.drop-before,
.dashboard-block.drop-after {
    border-color: rgba(89, 209, 255, 0.32);
    box-shadow: 0 0 0 1px rgba(89, 209, 255, 0.15);
}

.drag-ghost {
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

.dashboard-block.layout-flash {
    animation: layout-flash 0.34s ease;
}

.panel-count {
    min-width: 44px;
    padding: 0.55rem 0.7rem;
    border-radius: 999px;
    background: var(--panel-strong);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.stack-form {
    display: grid;
    gap: 10px;
}

label {
    font-size: 0.86rem;
    color: var(--text-main);
    font-weight: 600;
}

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

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    padding: 0.9rem 0.95rem;
    transition: border-color 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

select {
    appearance: none;
}

textarea {
    resize: vertical;
    min-height: 140px;
}

button {
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.82rem 1.05rem;
    cursor: pointer;
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
    font-weight: 600;
    transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

button:hover {
    transform: translateY(-1px);
}

button.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #1d1308;
}

button.secondary {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--panel-border);
}

button.ghost {
    background: transparent;
    border-color: var(--panel-border);
    color: var(--text-soft);
}

button:hover,
button:active {
    background-color: rgba(255, 255, 255, 0.12);
}

button.primary:hover,
button.primary:active {
    background: linear-gradient(135deg, var(--accent-strong), var(--accent));
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
.skip-link:focus-visible {
    outline: 2px solid var(--accent-cool);
    outline-offset: 3px;
}

.split-field {
    align-items: stretch;
}

.split-field input {
    flex: 1;
}

.hint,
.form-meta,
.timeline-meta,
.metric-label,
.frame-size,
.timeline-time {
    color: var(--text-soft);
}

.hint,
.form-meta {
    font-size: 0.82rem;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.metric-card {
    min-width: 0;
    padding: 16px;
    border-radius: var(--radius-md);
    background: var(--panel-soft);
    border: 1px solid var(--panel-border);
}

.metric-label {
    display: block;
    margin-bottom: 10px;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

.metric-value {
    display: block;
    font-family: var(--mono);
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
}

.users-list {
    display: grid;
    gap: 10px;
}

.users-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--panel-soft);
    border: 1px solid transparent;
}

.users-list li:hover {
    border-color: var(--panel-border);
}

.user-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.user-name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.timeline-panel,
.frames-panel {
    min-height: 0;
}

.timeline,
.frame-list {
    display: grid;
    gap: 12px;
    max-height: 720px;
    overflow-y: auto;
    padding-right: 4px;
}

.timeline-item,
.frame-card,
.empty-state {
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--panel-border);
    background: var(--panel-soft);
    min-width: 0;
}

.timeline-item.chat {
    border-color: rgba(89, 209, 255, 0.24);
}

.timeline-item.self {
    border-color: rgba(127, 225, 162, 0.28);
}

.timeline-item.error {
    border-color: rgba(255, 133, 117, 0.3);
}

.timeline-item.presence {
    border-color: rgba(255, 213, 111, 0.28);
}

.timeline-item.telemetry,
.timeline-item.outbound,
.timeline-item.system,
.timeline-item.action {
    border-color: rgba(255, 255, 255, 0.12);
}

.timeline-label,
.frame-title {
    font-size: 0.82rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-cool);
}

.timeline-time,
.frame-size {
    font-family: var(--mono);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.timeline-body {
    margin: 10px 0 0;
    overflow-wrap: anywhere;
}

.timeline-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.composer-panel {
    position: relative;
    overflow: hidden;
}

.chip-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.command-list,
.detail-list,
.users-list,
.frame-list,
.timeline,
.metric-grid {
    min-width: 0;
}

.command-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.command-list li {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--panel-soft);
    border: 1px solid var(--panel-border);
    font-family: var(--mono);
    overflow-wrap: anywhere;
}

.frame-card.out {
    border-color: rgba(255, 158, 87, 0.22);
}

.frame-card.in {
    border-color: rgba(89, 209, 255, 0.22);
}

pre {
    margin: 12px 0 0;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-family: var(--mono);
    font-size: 0.84rem;
    line-height: 1.55;
    color: var(--text-main);
}

.empty-state {
    color: var(--text-soft);
}

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.22);
}

@media (max-width: 1240px) {
    .dashboard {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-block-center {
        grid-column: auto;
    }
}

@media (max-width: 980px) {
    .page-shell {
        width: min(100vw - 20px, 100%);
    }

    .hero,
    .dashboard {
        grid-template-columns: 1fr;
    }

    .dashboard-block-center {
        grid-column: auto;
    }

    .timeline,
    .frame-list {
        max-height: none;
    }
}

@media (max-width: 640px) {
    .page-shell {
        width: calc(100vw - 16px);
        padding-top: 12px;
    }

    .hero-copy,
    .hero-card,
    .panel {
        padding: 18px;
        border-radius: 20px;
    }

    .transport-grid,
    .detail-list,
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .split-field,
    .dashboard-toolbar,
    .hero-actions,
    .form-actions,
    .panel-head,
    .panel-tools,
    .frame-head,
    .timeline-header,
    .form-meta {
        flex-direction: column;
        align-items: stretch;
    }
}

@keyframes layout-flash {
    0% {
        box-shadow: 0 0 0 2px rgba(89, 209, 255, 0.5);
    }

    100% {
        box-shadow: 0 0 0 2px transparent;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}