:root {
    --bg: #0f172a;
    --bg-soft: #111c31;
    --panel: rgba(15, 23, 42, 0.84);
    --panel-strong: rgba(18, 30, 52, 0.96);
    --line: rgba(255, 255, 255, 0.10);
    --line-soft: rgba(255, 255, 255, 0.06);
    --text: #f8fafc;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --ok: #22c55e;
    --warn: #f59e0b;
    --danger: #f43f5e;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    color: var(--text);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    letter-spacing: 0.02em;
    background:
        radial-gradient(circle at 46% 48%, #1e293b 0%, #142238 20%, #0f172a 62%, #0b1220 100%);
}

#canvasWrap {
    position: fixed;
    inset: 0;
    z-index: 1;
}

#arena {
    display: block;
    width: 100vw;
    height: 100vh;
}

#dash {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 18px);
    left: calc(env(safe-area-inset-left) + 18px);
    z-index: 10;
    width: min(374px, 34vw);
    max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 36px);
    overflow-y: auto;
    padding: 22px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 22px 50px -28px rgba(0, 0, 0, 0.55);
}

#dash::-webkit-scrollbar {
    width: 4px;
}

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

h1 {
    margin: 0 0 4px;
    font-size: 0.98rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #d7e2f1;
}

.sub {
    margin-bottom: 18px;
    color: var(--muted);
    font-size: 0.66rem;
    font-family: "Consolas", "SFMono-Regular", monospace;
    text-transform: uppercase;
}

.grid,
.meta,
.stagegrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.grid {
    margin-bottom: 14px;
}

.meta {
    margin-bottom: 16px;
}

.card,
.mini,
.stagecard,
.modrow {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.70);
}

.card {
    padding: 14px 10px;
    text-align: center;
}

.val {
    font-size: 1.58rem;
    font-weight: 300;
    font-family: "Consolas", "SFMono-Regular", monospace;
}

.val.accent {
    color: var(--accent);
}

.val.ok {
    color: var(--ok);
}

.lbl {
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.58rem;
    text-transform: uppercase;
    letter-spacing: 0.10em;
}

.mini {
    padding: 9px 10px;
    background: rgba(248, 250, 252, 0.08);
    font-size: 0.68rem;
    font-family: "Consolas", "SFMono-Regular", monospace;
}

.mini b,
.sectionHead,
.stagecard .stagehead,
.kpi .t,
.velocity,
.modhead {
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.10em;
}

.mini b {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
}

.sectionHead {
    margin: 0 0 8px;
    color: #c9d5e6;
}

.stagegrid {
    margin-bottom: 16px;
}

.stagecard {
    padding: 9px 10px;
    background: rgba(248, 250, 252, 0.06);
}

.stagecard .stagen {
    margin: 3px 0;
    font-size: 1rem;
    font-weight: 500;
    font-family: "Consolas", "SFMono-Regular", monospace;
}

.stagecard .stagesub {
    color: var(--muted);
    font-size: 0.54rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.modgrid {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.modrow {
    padding: 12px;
    background: rgba(248, 250, 252, 0.82);
    color: #0f172a;
}

.modhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.76rem;
    font-weight: 600;
}

.dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 8px;
    border-radius: 50%;
    box-shadow: 0 0 10px currentColor;
}

.velocity {
    margin-bottom: 8px;
    color: #64748b;
    font-family: "Consolas", "SFMono-Regular", monospace;
}

.kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
}

.kpi {
    padding: 7px 4px;
    border-radius: 7px;
    background: rgba(15, 23, 42, 0.06);
    text-align: center;
}

.kpi .n {
    font-size: 0.92rem;
    font-weight: 500;
    font-family: "Consolas", "SFMono-Regular", monospace;
}

.kpi .t {
    margin-top: 3px;
    color: #64748b;
}

.row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

button {
    flex: 1;
    appearance: none;
    cursor: pointer;
    padding: 11px 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: rgba(15, 23, 42, 0.05);
    color: var(--text);
    font-size: 0.70rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(255, 255, 255, 0.18);
}

button:active:not(:disabled) {
    transform: scale(0.985);
}

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

button.active-toggle {
    border-color: rgba(34, 197, 94, 0.55);
    color: #a7f3d0;
    background: rgba(34, 197, 94, 0.10);
}

#log {
    margin-top: 14px;
    height: 164px;
    overflow-y: auto;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    color: #475569;
    font-size: 0.65rem;
    line-height: 1.48;
    font-family: "Consolas", "SFMono-Regular", monospace;
}

#log::-webkit-scrollbar {
    width: 4px;
}

#log::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.14);
    border-radius: 999px;
}

.logline {
    margin-bottom: 4px;
}

.logline .time {
    color: #64748b;
    margin-right: 6px;
}

.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 0.52rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border: 1px solid transparent;
}

.badge.ok {
    color: #16a34a;
    background: rgba(34, 197, 94, 0.10);
    border-color: rgba(34, 197, 94, 0.26);
}

.badge.danger {
    color: #dc2626;
    background: rgba(244, 63, 94, 0.10);
    border-color: rgba(244, 63, 94, 0.24);
}

#transcriptOverlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.62);
    backdrop-filter: blur(12px);
}

#transcriptCard {
    width: min(440px, calc(100vw - 50px));
    padding: 22px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: var(--panel-strong);
    box-shadow: 0 30px 80px -40px rgba(0, 0, 0, 0.45);
}

#transcriptCard h2 {
    margin: 0 0 12px;
    font-size: 1rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#transcriptCard .content {
    margin-bottom: 18px;
    color: #cbd5e1;
    white-space: pre-wrap;
    line-height: 1.54;
    font-size: 0.84rem;
    font-family: "Consolas", "SFMono-Regular", monospace;
}

#transcriptCard .closeBtn {
    width: 100%;
}

@media (max-aspect-ratio: 4/3) {
    #dash {
        top: auto;
        left: calc(env(safe-area-inset-left) + 12px);
        right: calc(env(safe-area-inset-right) + 12px);
        bottom: calc(env(safe-area-inset-bottom) + 12px);
        width: auto;
        max-height: 44vh;
        padding: 16px;
    }

    .stagegrid,
    .grid,
    .meta {
        grid-template-columns: 1fr 1fr;
    }
}
