/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --home:    #e8e8e8;   /* white team */
    --away:    #666666;   /* black team */
    --bg:      #0a0a0a;
    --surface: #141414;
    --border:  #2a2a2a;
    --text:    #ffffff;
    --muted:   #888;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100dvh;   /* dynamic viewport — accounts for iOS Safari toolbar */
    height: 100vh;    /* fallback */
}

button { cursor: pointer; font-family: inherit; }

/* ── Header ──────────────────────────────────────────────────────────────── */
#header {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 52px;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#brand {
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 3px;
    color: var(--home);
}
#versionLabel {
    position: fixed;
    top: 6px;
    right: 10px;
    font-size: 10px;
    color: var(--muted);
    z-index: 10;
    pointer-events: none;
}

.dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.dot-active   { background: #2ecc71; box-shadow: 0 0 6px #2ecc71; }
.dot-inactive { background: var(--muted); }

.badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 2px 6px;
    border-radius: 4px;
}
.badge-online  { background: #1a3a1a; color: #2ecc71; }
.badge-offline { background: #2a1a1a; color: #e74c3c; }

.header-spacer { flex: 1; }

.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    padding: 4px;
    color: var(--text);
    opacity: 0.7;
    border-radius: 6px;
}
.icon-btn:active { opacity: 1; background: var(--border); }

/* ── Scoreboard ──────────────────────────────────────────────────────────── */
#scoreboard {
    display: flex;
    align-items: center;
    flex: 1;
    min-height: 0;
    padding: 8px 0;
}

.team-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.team-name {
    font-size: clamp(13px, 3.5vw, 18px);
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--muted);
}

#homeSide .team-name { color: var(--home); }
#awaySide .team-name { color: var(--away); }

.score {
    font-size: clamp(72px, 22vw, 130px);
    font-weight: 900;
    line-height: 1;
}

#scoreDivider {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    flex-shrink: 0;
}

#clockDisplay {
    font-size: clamp(22px, 6vw, 36px);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    letter-spacing: 2px;
    transition: color 0.3s;
}
#clockDisplay.clock-red { color: #e74c3c; }

.half-display {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--muted);
    text-transform: uppercase;
    min-height: 16px;
}

.clock-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 20px;
    width: 44px; height: 44px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.clock-toggle:active { background: var(--border); }

/* ── Game status banner ──────────────────────────────────────────────────── */
#gameStatus {
    text-align: center;
    padding: 8px;
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 3px;
    background: #1a1a00;
    color: #ffd700;
    flex-shrink: 0;
}

/* ── Score buttons ───────────────────────────────────────────────────────── */
#scoreButtons {
    display: flex;
    flex-shrink: 0;
}

.score-btn {
    flex: 1;
    height: clamp(90px, 22vw, 130px);
    border: none;
    font-size: clamp(16px, 4vw, 22px);
    font-weight: 800;
    letter-spacing: 2px;
    color: #fff;
    transition: filter 0.08s;
}
.score-btn:active { filter: brightness(0.75); }
.score-btn:disabled { filter: brightness(0.35); cursor: default; }

.home-btn { background: #d8d8d8; color: #0a0a0a; }
.away-btn { background: #2a2a2a; color: #ffffff; border: 1px solid #555; }

/* ── Controls ────────────────────────────────────────────────────────────── */
#controls {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.ctrl-btn {
    flex: 1;
    height: 40px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: #ccc;
    border-radius: 8px;
    font-size: clamp(11px, 2.5vw, 13px);
    font-weight: 600;
}
.ctrl-btn:active  { background: var(--border); }
.ctrl-btn:disabled { opacity: 0.4; cursor: default; }

/* ── Overlays ────────────────────────────────────────────────────────────── */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
}

/* Voice overlay */
#voiceOverlay {
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

#voicePulse {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--home);
    animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { transform: scale(1);   opacity: 0.8; }
    50%       { transform: scale(1.2); opacity: 1;   }
}

#voiceStatus {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--muted);
}

#voiceTranscript {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    padding: 0 32px;
    min-height: 32px;
    color: var(--text);
}

.overlay-cancel {
    background: var(--surface);
    border: 1px solid var(--border);
    color: #ccc;
    padding: 10px 28px;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 12px;
}
.overlay-cancel:active { background: var(--border); }

/* Setup overlay */
#setupOverlay {
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
}

.dialog {
    background: #1c1c1c;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 28px 24px;
    width: 320px;
    max-width: 92vw;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.dialog h2 {
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 2px;
    text-align: center;
    color: var(--home);
}

.dialog label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--muted);
    text-transform: uppercase;
}

.dialog input, .dialog select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    width: 100%;
}
.dialog input:focus, .dialog select:focus {
    outline: none;
    border-color: var(--home);
}
.dialog select option { background: #1c1c1c; }

.dialog-btns {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}
.dialog-btns .ctrl-btn { font-size: 14px; }
.dialog-btns .score-btn {
    height: 44px;
    font-size: 14px;
    border-radius: 8px;
    flex: 2;
}

/* ── Log panel ───────────────────────────────────────────────────────────── */
.panel {
    position: fixed;
    inset: 0;
    background: #0f0f0f;
    z-index: 150;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 1px;
    flex-shrink: 0;
}

#logList {
    overflow-y: auto;
    flex: 1;
    padding: 8px 0;
}

.log-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #1a1a1a;
    font-size: 15px;
}

.log-score {
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    min-width: 52px;
    color: var(--text);
}

.log-team { font-weight: 700; }
.log-team.home-team { color: var(--home); }
.log-team.away-team { color: var(--away); }

.log-time {
    margin-left: auto;
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.log-empty {
    text-align: center;
    color: var(--muted);
    padding: 40px 16px;
    font-size: 15px;
}

/* ── Update banner ───────────────────────────────────────────────────────── */
#updateBanner {
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: #1a1a2e;
    border-top: 1px solid #3a3a5c;
    font-size: 14px;
    font-weight: 600;
    color: #aab;
}
#updateBanner.hidden { display: none; }
#updateReloadBtn {
    background: var(--home);
    border: none;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: 16px;
    white-space: nowrap;
}
#updateReloadBtn:active { filter: brightness(0.8); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(10px);
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 300;
    max-width: 90vw;
    text-overflow: ellipsis;
    overflow: hidden;
}
#toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
