.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.toolbar #zero {
    min-width: 140px;
    font-size: 17px;
}

.toolbar .leave {
    margin-left: auto;
}

.zero-info {
    font-size: 14px;
}

.zero-badge {
    display: inline-block;
    margin-left: 4px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    vertical-align: 1px;
}

.caption {
    font-size: 13px;
    margin: 8px 0 0;
}

#level,
#compass {
    display: block;
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
}

.level-ring {
    fill: none;
    stroke: var(--grid);
    stroke-width: 1;
}

.level-ring.outer {
    fill: var(--surface-2);
    stroke: var(--axis);
}

.level-axis {
    stroke: var(--axis);
    stroke-width: 1;
}

.level-label {
    font-size: 9px;
    fill: var(--text-muted);
}

.level-dot {
    fill: var(--series-1);
    stroke: var(--surface-1);
    stroke-width: 2;
    transition: cx 0.1s linear, cy 0.1s linear;
}

.level-dot[data-state="good"] {
    fill: var(--good);
}

.compass-ring {
    fill: var(--surface-2);
    stroke: var(--axis);
}

.compass-ticks line {
    stroke: var(--text-muted);
}

.compass-cardinal {
    font-size: 15px;
    font-weight: 650;
    fill: var(--text-secondary);
    text-anchor: middle;
}

.compass-cardinal.north {
    fill: var(--critical);
}

.compass-zero {
    stroke: var(--text-secondary);
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
}

.needle {
    fill: var(--series-1);
}

.needle-hub {
    fill: var(--text-primary);
}

#compass-needle.relative .needle {
    fill: var(--text-muted);
}

.scene {
    height: 260px;
    perspective: 900px;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.world {
    position: relative;
    width: 0;
    height: 0;
    transform-style: preserve-3d;
    transform: rotateX(55deg);
}

.ground {
    position: absolute;
    left: -110px;
    top: -110px;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    border: 1px dashed var(--axis);
    background: radial-gradient(circle, var(--surface-2) 0%, transparent 70%);
    transform: translateZ(-90px);
}

.ground-n {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 700;
    color: var(--critical);
}

.phone {
    position: absolute;
    left: -35px;
    top: -70px;
    width: 70px;
    height: 140px;
    transform-style: preserve-3d;
}

.phone-face {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    backface-visibility: hidden;
    display: grid;
    place-items: center;
    font-size: 11px;
}

.phone-face.front {
    background: #222;
    border: 3px solid #555;
    color: #9a9a9a;
    transform: translateZ(4px);
}

.phone-face.back {
    background: var(--series-1);
    border: 3px solid #555;
    transform: rotateY(180deg) translateZ(4px);
    place-items: start end;
    padding: 10px;
}

.lens {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #111;
    box-shadow: 0 0 0 3px #ddd;
}

#map {
    height: 260px;
    border-radius: 10px;
    background: var(--surface-2);
}

.legend {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

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

.key {
    display: inline-block;
    width: 16px;
    height: 2px;
    border-radius: 2px;
    background: var(--key);
}

.chart-box {
    position: relative;
    height: 240px;
}

#chart {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: pan-y;
}

.tooltip {
    position: absolute;
    top: 8px;
    pointer-events: none;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    white-space: nowrap;
}

.tooltip .row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip strong {
    font-variant-numeric: tabular-nums;
    min-width: 4.5ch;
    text-align: right;
}

.tooltip .when {
    color: var(--text-muted);
    margin-bottom: 4px;
}

details {
    margin-top: 12px;
}

#history-table th {
    width: auto;
}

.raw-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.raw-grid caption {
    text-align: left;
    font-weight: 600;
    padding-bottom: 6px;
}

.stat .value[data-state]::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 10px;
    vertical-align: middle;
    background: var(--text-muted);
}

.stat .value[data-state="good"]::before {
    background: var(--good);
}

.stat .value[data-state="warning"]::before {
    background: var(--warning);
}

.stat .value[data-state="critical"]::before {
    background: var(--critical);
}

@media (max-width: 640px) {
    .toolbar {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 8px;
    }

    .toolbar .btn {
        white-space: nowrap;
    }

    .toolbar #zero {
        min-height: 52px;
        min-width: 0;
        order: 1;
    }

    .toolbar .leave {
        margin-left: 0;
        order: 2;
    }

    .zero-info {
        order: 3;
        font-size: 13px;
    }

    .toolbar #clear-zero {
        order: 4;
    }

    .zero-info:empty {
        display: none;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stats .card {
        padding: 12px;
    }

    .stat .value {
        font-size: 28px;
    }

    .stat .value[data-state]::before {
        width: 10px;
        height: 10px;
        margin-right: 6px;
    }

    .grid {
        gap: 8px;
    }

    .scene,
    #map {
        height: 220px;
    }

    .chart-box {
        height: 200px;
    }

    #level,
    #compass {
        max-width: 240px;
    }

    .raw-grid {
        gap: 8px;
    }

    table.kv {
        font-size: 13px;
    }
}
