:root {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --accent-color: #ffffff;
    --dim-text: rgba(255, 255, 255, 0.5);
    --btn-bg: rgba(255, 255, 255, 0.1);
    --btn-hover: rgba(255, 255, 255, 0.2);
    --blue: #3b82f6;
    --red: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#status-bar {
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 10;
}

#listening-indicator {
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    color: var(--dim-text);
    display: none;
    align-items: center;
}

#listening-indicator::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #ff4444;
    border-radius: 50%;
    margin-right: 8px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.5);
        opacity: 0.5;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#status-left,
#status-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#install-btn {
    background: #44aa44;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.2s ease;
}

#install-btn:hover {
    background: #55bb55;
    transform: scale(1.05);
}

/* The flash is a separate overlay: animating the body background itself
   fades it to "transparent", which the browser paints as white. */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    background: rgba(255, 255, 255, 0.4);
}

body.flash-home::after {
    background: rgba(59, 130, 246, 0.6);
}

body.flash-away::after {
    background: rgba(239, 68, 68, 0.6);
}

@keyframes flash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

body.flash-active::after {
    animation: flash 1s ease-out;
}

#central-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: auto;
}

#end-match-btn {
    background: #ff4444 !important;
    color: white !important;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

#end-match-btn:hover {
    background: #ff6666;
    transform: scale(1.05);
}

#fullscreen-btn {
    background: none;
    border: 1px solid var(--dim-text);
    color: var(--dim-text);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#fullscreen-btn:hover {
    border-color: var(--text-color);
    color: var(--text-color);
}

#undo-btn,
#reset-btn {
    background: none;
    border: 1px solid var(--dim-text);
    color: var(--dim-text);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.2s ease;
}

#undo-btn:hover:not(:disabled),
#reset-btn:hover {
    border-color: var(--text-color);
    color: var(--text-color);
}

#scoreboard {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    padding: 1rem;
    width: 100%;
}

.score-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    position: relative;
    padding: 1rem;
    min-height: 300px;
}

.label {
    font-size: clamp(0.8rem, 2vmin, 1.5rem);
    font-weight: 300;
    letter-spacing: 0.5em;
    color: var(--dim-text);
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.team-blue .label,
.team-blue .score-display {
    color: var(--blue);
}

.team-red .label,
.team-red .score-display {
    color: var(--red);
}

.score-display {
    font-size: clamp(8rem, 30vmin, 50vh);
    font-weight: 900;
    line-height: 0.8;
    cursor: default;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 1;
    margin: 0.2rem 0;
}

.score-display.bump {
    transform: scale(1.1);
}

.divider {
    width: 1px;
    height: 40%;
    background-color: rgba(255, 255, 255, 0.05);
}

.controls {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
}

.manual-btn {
    background: var(--btn-bg);
    border: none;
    color: var(--text-color);
    width: clamp(40px, 8vmin, 60px);
    height: clamp(40px, 8vmin, 60px);
    border-radius: 50%;
    font-size: clamp(1rem, 4vmin, 2rem);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.manual-btn:hover {
    background: var(--btn-hover);
    transform: scale(1.1);
}

.manual-btn:active {
    transform: scale(0.95);
}

#winner-banner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    justify-content: center;
    align-items: center;
    z-index: 50;
    pointer-events: none;
    background-color: rgba(0, 0, 0, 0.6);
    font-size: clamp(2.5rem, 10vmin, 6rem);
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    text-align: center;
    animation: winner-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#winner-banner[hidden] {
    display: none;
}

#winner-banner.winner-blue {
    color: var(--blue);
}

#winner-banner.winner-red {
    color: var(--red);
}

@keyframes winner-pop {
    0% {
        transform: scale(0.7);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 100;
    display: flex;
    text-align: center;
    overflow-y: auto;
    padding: max(1.5rem, env(safe-area-inset-top)) 1rem max(1.5rem, env(safe-area-inset-bottom));
}

/* margin:auto centres when it fits and scrolls (not clips) when it doesn't */
.overlay-content {
    margin: auto;
    max-width: 100%;
}

.overlay-content h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.overlay-content p {
    color: var(--dim-text);
    margin-bottom: 3rem;
}

#start-btn {
    background: var(--text-color);
    color: var(--bg-color);
    border: none;
    padding: 1.5rem 4rem;
    font-size: 1.2rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

#start-btn:hover {
    transform: scale(1.05);
}

.pwa-guide {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.9rem;
    margin: 1rem 0;
    color: var(--text-color);
}

.secure-note {
    font-size: 0.7rem;
    opacity: 0.5;
    max-width: 300px;
    margin: 1rem auto;
}

.hint {
    margin-top: 1rem;
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--dim-text);
}

/* Mobile Portrait Adjustment */
@media (max-width: 768px) and (orientation: portrait) {
    #scoreboard {
        flex-direction: column;
        justify-content: center;
        padding: 1rem;
    }

    .divider {
        width: 30%;
        height: 1px;
        margin: 1rem 0;
    }

    .score-display {
        font-size: 30vh;
    }

    .label {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }

    .controls {
        margin-top: 0.5rem;
        gap: 1rem;
    }

    .score-column {
        height: auto;
        flex: initial;
    }
}
#undo-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

#refresh-btn {
    background: none;
    border: 1px solid var(--dim-text);
    color: var(--dim-text);
    padding: 0.6rem 1.2rem;
    margin-top: 1rem;
    border-radius: 4px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
}

#new-match-btn {
    pointer-events: auto;
    background: #fff;
    color: #111;
    border: none;
    border-radius: 8px;
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
}

.overlay-content .version {
    font-size: 0.8rem;
    opacity: 0.6;
    margin: 0 0 1.5rem;
}

.winner-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

#home-btn {
    pointer-events: auto;
    background: none;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 8px;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
}

#refresh-btn { margin-top: 1.25rem; }

/* Phones: compact header, smaller overlay, stacked winner buttons */
@media (max-width: 600px), (max-height: 500px) {
    #status-bar {
        padding: max(0.5rem, env(safe-area-inset-top)) 0.75rem 0.5rem;
        gap: 0.5rem;
    }

    #status-left,
    #status-right {
        gap: 0.4rem;
    }

    #status-right {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    #install-btn,
    #end-match-btn,
    #undo-btn,
    #reset-btn {
        padding: 0.45rem 0.7rem;
        font-size: 0.65rem;
        letter-spacing: 0.05em;
    }

    #fullscreen-btn {
        width: 30px;
        height: 30px;
    }

    .overlay-content h1 {
        font-size: clamp(1.8rem, 9vw, 3rem);
        letter-spacing: 0.1em;
        margin-bottom: 0.5rem;
    }

    .overlay-content p {
        margin-bottom: 1.5rem;
    }

    #start-btn {
        padding: 1.1rem 3rem;
    }

    .hint {
        letter-spacing: 0.1em;
        line-height: 1.5;
    }

    #winner-banner {
        gap: 1.25rem;
        padding: 1rem;
    }

    .winner-actions {
        flex-direction: column;
        width: min(100%, 320px);
    }

    #new-match-btn,
    #home-btn {
        width: 100%;
        padding: 1rem;
    }
}

#refresh-btn {
    display: block;
    margin-left: auto;
    margin-right: auto;
}
