/* ============================================
   红绿灯辅助 — Mobile-first accessible design v2
   ============================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg:     #0a0a0a;
    --surface: rgba(255,255,255,0.06);
    --border:  rgba(255,255,255,0.1);
    --text:    #f0f0f0;
    --dim:     #aaa;
    --red:     #ef4444;
    --green:   #22c55e;
    --amber:   #f59e0b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", sans-serif;
    background: #000;
    color: var(--text);
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
}

.skip-link {
    position: fixed; top: -100px; left: 16px;
    padding: 8px 16px; background: #fff; color: #000;
    z-index: 9999; border-radius: 6px;
}
.skip-link:focus { top: 16px; }

/* ---- App shell ---- */
.app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ---- Start overlay ---- */
.start-overlay {
    position: absolute; inset: 0;
    z-index: 100;
    background: #060606;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: opacity 0.5s, visibility 0.5s;
}
.start-overlay.hidden {
    opacity: 0; visibility: hidden; pointer-events: none;
}

/* Animated background dots */
.start-bg {
    position: absolute; inset: 0;
    background:
        radial-gradient(2px 2px at 20% 30%, rgba(34,197,94,0.3), transparent),
        radial-gradient(2px 2px at 70% 20%, rgba(34,197,94,0.2), transparent),
        radial-gradient(1px 1px at 40% 70%, rgba(34,197,94,0.25), transparent),
        radial-gradient(2px 2px at 80% 60%, rgba(34,197,94,0.15), transparent),
        radial-gradient(1px 1px at 10% 80%, rgba(34,197,94,0.2), transparent),
        radial-gradient(2px 2px at 60% 90%, rgba(34,197,94,0.15), transparent),
        radial-gradient(1px 1px at 90% 40%, rgba(34,197,94,0.2), transparent),
        radial-gradient(2px 2px at 30% 55%, rgba(34,197,94,0.15), transparent);
    animation: bg-float 8s ease-in-out infinite;
}
@keyframes bg-float {
    0%, 100% { opacity: 0.6; transform: translateY(0); }
    50%      { opacity: 1;   transform: translateY(-4px); }
}

.start-content {
    position: relative; z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 32px;
}

/* Traffic light icon */
.start-icon { margin-bottom: 8px; }

.traffic-light {
    width: 40px;
    background: #1a1a1a;
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border: 1.5px solid rgba(255,255,255,0.12);
    box-shadow: 0 0 30px rgba(34,197,94,0.15);
}

.tl-light {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #222;
    transition: background 0.6s, box-shadow 0.6s;
}
.tl-light.red    { background: #3a1010; }
.tl-light.yellow { background: #2a2005; }
.tl-light.green.active {
    background: var(--green);
    box-shadow: 0 0 16px var(--green), 0 0 32px rgba(34,197,94,0.4);
    animation: glow-pulse 2s ease-in-out infinite;
}
@keyframes glow-pulse {
    0%, 100% { box-shadow: 0 0 16px var(--green), 0 0 32px rgba(34,197,94,0.4); }
    50%      { box-shadow: 0 0 24px var(--green), 0 0 48px rgba(34,197,94,0.6); }
}

/* Title */
.start-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.04em;
}
.start-subtitle {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.4);
    letter-spacing: 0.08em;
}

/* Button with ring animation */
.start-btn {
    position: relative;
    margin-top: 12px;
    padding: 18px 56px;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    background: var(--green);
    border: none;
    border-radius: 100px;
    cursor: pointer;
    overflow: visible;
    transition: transform 0.15s, background 0.2s;
}
.start-btn:active { transform: scale(0.95); background: #15803d; }

.btn-ring {
    position: absolute; inset: -6px;
    border-radius: 100px;
    border: 2px solid rgba(34,197,94,0.3);
    animation: ring-expand 2s ease-out infinite;
    pointer-events: none;
}
.btn-ring:nth-child(2) { animation-delay: 0s; }
@keyframes ring-expand {
    0%   { inset: -6px; opacity: 0.6; }
    100% { inset: -20px; opacity: 0; }
}

.btn-text { position: relative; z-index: 1; }

.start-hint {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.3);
}

/* Reference badges */
.start-refs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 20px;
    max-width: 300px;
}
.ref-badge {
    font-size: 0.62rem;
    color: rgba(255,255,255,0.25);
    padding: 4px 10px;
    border-radius: 100px;
    border: 1px solid rgba(255,255,255,0.06);
    white-space: nowrap;
}

/* ---- Video stage ---- */
.video-stage {
    position: relative;
    flex: 1;
    background: #000;
    min-height: 0;
}

.video-stage video {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
}

.video-stage canvas {
    display: none;
}

/* ---- Detection box ---- */
.roi-box {
    position: absolute;
    border: 2.5px solid var(--green);
    border-radius: 6px;
    pointer-events: none;
    z-index: 20;
    display: none;
    box-shadow: 0 0 12px rgba(34,197,94,0.5);
}
.roi-box.red {
    border-color: var(--red);
    box-shadow: 0 0 12px rgba(239,68,68,0.5);
}

/* ---- Top-left status badge ---- */
.status-overlay {
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 12px));
    left: 12px; right: 12px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 30;
    pointer-events: none;
}

.light-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: rgba(0,0,0,0.85);
    border-radius: 100px;
    border: 1px solid rgba(255,255,255,0.2);
}

.light-dot {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #555;
    flex-shrink: 0;
    transition: background 0.3s, box-shadow 0.3s;
}
.light-dot.red   { background: var(--red);  box-shadow: 0 0 12px var(--red); }
.light-dot.green { background: var(--green); box-shadow: 0 0 12px var(--green); }

.light-label {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

/* ---- Top-right countdown ---- */
.countdown-ring {
    width: 66px; height: 66px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-shrink: 0;
    transition: border-color 0.3s;
}
.countdown-ring.active { border-color: var(--green); }
.countdown-ring.urgent {
    border-color: var(--red);
    animation: ring-pulse 0.6s ease-in-out infinite;
}
@keyframes ring-pulse {
    0%, 100% { border-color: var(--red); }
    50%      { border-color: rgba(239,68,68,0.2); }
}

.countdown-value {
    font-size: 1.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #fff;
    line-height: 1;
}

/* ---- Bottom guidance ---- */
.guidance-bar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 14px 16px;
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
    text-align: center;
    font-size: 0.875rem;
    color: var(--dim);
    background: linear-gradient(to top, rgba(0,0,0,0.85), transparent);
    z-index: 30;
    pointer-events: none;
    transition: color 0.3s;
}
.guidance-bar.active { color: var(--amber); font-weight: 600; }

/* ---- Bottom control bar ---- */
.control-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    background: var(--bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.conn-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #555;
    flex-shrink: 0;
    transition: background 0.3s;
}
.conn-dot.connected    { background: var(--green); }
.conn-dot.disconnected { background: var(--red); }
.conn-dot.connecting   { background: var(--amber); animation: pulse-dot 0.8s ease-in-out infinite; }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.25; }
}

.conn-label, .fps-label {
    font-size: 0.7rem;
    color: var(--dim);
}

.spacer { flex: 1; }

.ctrl-btn {
    width: 46px; height: 46px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--dim);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}
.ctrl-btn:active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    transform: scale(0.94);
}
