:root {
    color-scheme: light;

    --bg: #ffffff;
    --surface: #ffffff;
    --surface-raised: #fff7f0;
    --line: #f1e4d8;
    --text: #1f1611;
    --muted: #7a6a5f;
    --accent: #f97316;
    --accent-hover: #ea6a0c;
    --accent-ink: #1f1611;
    --accent-soft: #fff1e6;

    --hazard: #e5383b;
    --caution: #f5b301;
    --clear: #22a559;
    /* Darker shades for text on white, where the base colors lack contrast. */
    --hazard-ink: #c1121f;
    --caution-ink: #9a6b00;
    --clear-ink: #157a3f;

    --radius-lg: 28px;
    --radius-md: 20px;
    --shadow: 0 18px 40px rgba(120, 60, 10, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--text);
    background:
        radial-gradient(120% 50% at 50% -10%, rgba(249, 115, 22, 0.1), transparent 60%),
        var(--bg);
    font-family: "Manrope", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.site-shell {
    width: min(100%, 560px);
    margin: 0 auto;
    padding: calc(14px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}

.app {
    display: grid;
    gap: 14px;
}

/* Header ---------------------------------------------------------------- */

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

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

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex: none;
}

.brand-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.brand-subtitle {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.status-pill {
    --pill-color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: none;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 700;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pill-color);
}

.status-pill[data-state="live"] { --pill-color: var(--clear); }
.status-pill[data-state="starting"] { --pill-color: var(--caution); }
.status-pill[data-state="error"] { --pill-color: var(--hazard); }

.status-pill[data-state="live"] .status-dot {
    box-shadow: 0 0 0 0 rgba(34, 165, 89, 0.5);
    animation: pulse 1.8s ease-out infinite;
}

@keyframes pulse {
    to { box-shadow: 0 0 0 8px rgba(34, 165, 89, 0); }
}

/* Camera ---------------------------------------------------------------- */

.camera-stage {
    position: relative;
    overflow: hidden;
    aspect-ratio: 3 / 4;
    max-height: 62vh;
    max-height: 62dvh;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: #1f1611;
    box-shadow: var(--shadow);
}

.camera-feed,
.overlay-canvas,
.camera-placeholder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.camera-feed {
    object-fit: contain;
}

.overlay-canvas {
    pointer-events: none;
}

.zone-labels {
    position: absolute;
    top: 12px;
    left: var(--frame-left, 0px);
    width: var(--frame-width, 100%);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease;
}

.zone-labels span {
    justify-self: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(5, 10, 11, 0.55);
    backdrop-filter: blur(6px);
    color: rgba(238, 245, 243, 0.85);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.camera-stage.is-live .zone-labels {
    opacity: 1;
}

.camera-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 24px;
    text-align: center;
    background:
        radial-gradient(circle at 50% 42%, rgba(249, 115, 22, 0.12), transparent 55%),
        var(--surface-raised);
}

.camera-placeholder[hidden] {
    display: none;
}

.placeholder-icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 76px;
    height: 76px;
    margin-bottom: 10px;
    border: 1px solid rgba(249, 115, 22, 0.35);
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
}

.placeholder-icon svg {
    width: 34px;
    height: 34px;
}

.placeholder-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 800;
}

.placeholder-text {
    margin: 0;
    max-width: 30ch;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.5;
}

/* Side panel ------------------------------------------------------------ */

.side-panel {
    display: grid;
    gap: 14px;
}

.alert-card {
    --level-color: #e3d3c5;
    display: grid;
    gap: 6px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-left: 6px solid var(--level-color);
    border-radius: var(--radius-md);
    background:
        linear-gradient(90deg, color-mix(in srgb, var(--level-color) 14%, transparent), transparent 70%),
        var(--surface);
    transition: border-color 200ms ease, background 200ms ease;
}

.alert-card[data-level="clear"] { --level-color: var(--clear); --level-ink: var(--clear-ink); }
.alert-card[data-level="caution"] { --level-color: var(--caution); --level-ink: var(--caution-ink); }
.alert-card[data-level="hazard"] { --level-color: var(--hazard); --level-ink: var(--hazard-ink); }

.alert-level {
    color: var(--level-ink, var(--muted));
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.alert-text {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 800;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.direction-meter {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.direction-cell {
    --cell-color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 6px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
    transition: background 200ms ease, color 200ms ease, border-color 200ms ease;
}

.direction-cell svg {
    width: 18px;
    height: 18px;
}

.direction-cell[data-level="caution"] { --cell-color: var(--caution); }
.direction-cell[data-level="hazard"] { --cell-color: var(--hazard); }

.direction-cell[data-level="caution"],
.direction-cell[data-level="hazard"] {
    border-color: var(--cell-color);
    background: color-mix(in srgb, var(--cell-color) 18%, var(--surface));
    color: var(--text);
}

.control-dock {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.control-button {
    appearance: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 76px;
    padding: 10px 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-raised);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    transition: transform 150ms ease, background 150ms ease, color 150ms ease, opacity 150ms ease;
}

.control-button svg {
    width: 26px;
    height: 26px;
}

.control-label {
    font-size: 0.85rem;
    font-weight: 700;
}

.control-button:hover:not(:disabled) {
    background: var(--accent-soft);
}

.control-button:active:not(:disabled) {
    transform: scale(0.97);
}

.control-button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.control-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.control-button-primary {
    border-color: transparent;
    background: var(--accent);
    color: var(--accent-ink);
}

.control-button-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.control-button-primary.is-active {
    border-color: rgba(229, 56, 59, 0.45);
    background: #fdecec;
    color: var(--hazard-ink);
}

.control-button-primary.is-active:hover:not(:disabled) {
    background: #fbdcdc;
}

.control-button.is-muted {
    color: var(--muted);
}

.control-button.is-muted [data-audio-wave] {
    display: none;
}

.about-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
}

.about-card summary {
    padding: 14px 18px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
}

.about-card summary:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-md);
}

.about-card p {
    margin: 0;
    padding: 0 18px 16px;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.65;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* Desktop: camera on the left, controls on the right --------------------- */

@media (min-width: 900px) {
    .site-shell {
        width: min(100% - 48px, 1180px);
        padding-top: 28px;
    }

    .app {
        grid-template-columns: minmax(0, 1fr) 360px;
        grid-template-areas:
            "header header"
            "stage  panel";
        gap: 20px 24px;
        align-items: start;
    }

    .app-header { grid-area: header; }
    .camera-stage { grid-area: stage; aspect-ratio: 4 / 3; max-height: none; }
    .side-panel { grid-area: panel; }
}
