* { box-sizing: border-box; }
body {
    margin: 0;
    background: #0a0a0c;
    color: white;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
}

canvas {
    background: #111;
    border: 2px solid #333;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    max-width: 98vw;
    max-height: 92vh;
    width: auto;
    height: auto;
    display: block;
    margin: 0 auto;
}

.hud {
    position: absolute; top: 12px; left: 20px;
    display: flex; gap: 20px; align-items: center;
    background: rgba(10,10,12,0.95); padding: 8px 24px;
    border-radius: 8px; border: 1px solid #444;
    border-bottom: 4px solid #fbbf24;
    transition: border-bottom-color 0.1s;
    z-index: 10;
}
.stat { font-size: 0.8rem; font-weight: bold; text-transform: uppercase; }
.stat span { font-size: 1.2rem; margin-left: 6px; }
.warning { color: #fff !important; font-weight: 900; background: #ef4444; padding: 0 4px; border-radius: 4px; }

#timer-panel {
    position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center;
    pointer-events: none; z-index: 15;
    background: rgba(10,10,12,0.85); padding: 10px 30px; border-radius: 8px; border: 1px solid #333;
}
#match-clock {
    font-size: 2.8rem; font-weight: 900; letter-spacing: 3px;
    color: #fff; text-shadow: 0 0 20px rgba(251,191,36,0.5);
    line-height: 1;
}
#match-clock.auto-phase  { color: #a78bfa; text-shadow: 0 0 20px rgba(167,139,250,0.6); }
#match-clock.delay-phase { color: #ef4444; text-shadow: 0 0 20px rgba(239,68,68,0.6); }
#match-clock.endgame-phase { color: #f97316; text-shadow: 0 0 20px rgba(249,115,22,0.7); }
#match-clock.stopped { color: #555; text-shadow: none; }
#phase-label {
    font-size: 0.7rem; font-weight: 900; letter-spacing: 4px;
    color: #888; margin-top: 4px; text-transform: uppercase;
}
#phase-timer {
    font-size: 1.4rem; font-weight: 900; letter-spacing: 2px;
    margin-top: 2px; transition: color 0.2s, text-shadow 0.2s;
}

.controls-wrapper {
    position: absolute; top: 12px; right: 20px; z-index: 20;
    display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
    max-height: 95vh; overflow-y: auto; padding-right: 5px;
}
.controls-wrapper::-webkit-scrollbar { width: 6px; }
.controls-wrapper::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

#toggle-controls-btn {
    background: #333; color: white; border: 1px solid #555;
    width: auto; padding: 6px 12px; font-size: 0.7rem; margin-bottom: 4px;
}
#toggle-controls-btn:hover { background: #444; }

.controls {
    display: flex; flex-direction: column; gap: 5px; width: 190px;
    transition: opacity 0.2s, transform 0.2s; transform-origin: top right;
}
.controls.collapsed {
    opacity: 0; pointer-events: none; transform: scale(0.95); height: 0; overflow: hidden;
}

button { padding: 6px 10px; border-radius: 6px; border: 2px solid #fff; cursor: pointer; font-weight: 900; background: #fbbf24; color: #000; transition: transform 0.1s; font-size: 0.7rem; }
button:active { transform: scale(0.95); }
.red-team { background: #ef4444; color: white; border-color: #ef4444; }
.blue-team { background: #3b82f6; color: white; border-color: #3b82f6; }
.purple-team { background: #8b5cf6; color: white; border-color: #8b5cf6; }
#p2-toggle.disabled { background: #4b5563; border-color: #4b5563; color: #ccc;}
#reset-btn { background: #333; color: #fff; border-color: #555; margin-top: 5px;}
#start-btn { background: #22c55e; color: #000; border-color: #22c55e; margin-bottom: 5px;}
#start-btn.running { background: #f97316; color: #000; border-color: #f97316; }

.btn-unstick { background: #991b1b !important; border-color: #fca5a5 !important; }
.btn-unstick.blue-team { background: #1e3a8a !important; border-color: #93c5fd !important; }
.btn-unstick.disabled { opacity: 0.3; cursor: not-allowed; transform: none !important; }

#shift-flash {
    position: absolute; inset: 0; pointer-events: none; z-index: 50;
    opacity: 0; background: rgba(255,255,255,0.08);
    transition: opacity 0.15s;
}
#shift-flash.flash { opacity: 1; }

#auto-winner {
    position: absolute; top: 120px; left: 50%; transform: translateX(-50%);
    font-size: 0.7rem; font-weight: 900; letter-spacing: 2px; color: #a78bfa;
    opacity: 0; transition: opacity 0.5s; pointer-events: none; z-index: 20;
}
#auto-winner.visible { opacity: 1; }

#controls-modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 100;
    display: flex; justify-content: center; align-items: center;
    opacity: 1; transition: opacity 0.2s;
}
#controls-modal.hidden { opacity: 0; pointer-events: none; }
.modal-content {
    background: #111; border: 2px solid #444; border-radius: 8px;
    padding: 25px 40px; text-align: center; box-shadow: 0 0 40px rgba(0,0,0,1);
    max-width: 400px; width: 90%;
}
.modal-content h2 { color: #fbbf24; margin-top: 0; font-weight: 900; letter-spacing: 2px; margin-bottom: 20px;}
.control-section { text-align: left; margin-bottom: 15px; background: rgba(255,255,255,0.05); padding: 12px 16px; border-radius: 6px; border-left: 3px solid #666;}
.control-section h3 { margin: 0 0 8px 0; color: #a78bfa; font-size: 0.95rem; letter-spacing: 1px; text-transform: uppercase; }
.control-section p { margin: 6px 0; font-size: 0.9rem; color: #ccc; }
.control-section b { color: #fff; background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px; font-family: monospace; }
.control-section.highlight { border-left-color: #ef4444; background: rgba(239, 68, 68, 0.08); }
.control-section.highlight h3 { color: #ef4444; }
#close-controls-btn { margin-top: 15px; padding: 10px 30px; font-size: 0.9rem; width: 100%; background: #444; border-color: #666; color: white;}
#close-controls-btn:hover { background: #555; }