@import url('https://fonts.googleapis.com/css2?family=Inter:wght@500;700;800;900&display=swap');

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: Inter, Arial, sans-serif;
    color: #f6fbff;
    background:
        radial-gradient(circle at 18% 18%, rgba(255, 221, 87, 0.18), transparent 25%),
        radial-gradient(circle at 88% 14%, rgba(0, 184, 148, 0.18), transparent 26%),
        linear-gradient(135deg, #07151d 0%, #102428 42%, #161820 100%);
    min-height: 100vh;
    overflow-x: hidden;
    touch-action: manipulation;
}

button {
    font: inherit;
}

.back-link {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 30;
    color: #f8fbff;
    text-decoration: none;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: rgba(4, 13, 18, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 10px 12px;
    border-radius: 6px;
    backdrop-filter: blur(14px);
}

.game-shell {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 64px 18px 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 18px;
}

.stadium-panel {
    position: relative;
    min-height: calc(100vh - 88px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    overflow: hidden;
    background: #0a1518;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

#scene {
    display: block;
    width: 100%;
    height: calc(100vh - 88px);
    min-height: 560px;
    background: #102018;
    touch-action: none;
}

.scoreboard {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    display: grid;
    grid-template-columns: 150px 116px 150px;
    align-items: stretch;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.score-team,
.clock-box {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(3, 13, 18, 0.8);
    backdrop-filter: blur(16px);
}

.score-team span,
.clock-box span {
    color: rgba(255, 255, 255, 0.72);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.score-team strong,
.clock-box strong {
    color: #ffffff;
    font-size: 28px;
    line-height: 1;
}

.score-team--stars {
    border-top: 4px solid #32d583;
}

.score-team--rivals {
    border-top: 4px solid #ff4d6d;
}

.clock-box {
    flex-direction: column;
    gap: 2px;
    border-left: 1px solid rgba(255, 255, 255, 0.12);
    border-right: 1px solid rgba(255, 255, 255, 0.12);
}

.clock-box strong {
    font-size: 24px;
    color: #ffe66d;
}

.hud-panel {
    min-height: calc(100vh - 88px);
    padding: 20px;
    border-radius: 8px;
    background: rgba(4, 16, 20, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.eyebrow {
    margin: 0 0 8px;
    color: #7ee4a8;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hud-panel h1,
.overlay-card h1,
.overlay-card h2 {
    margin: 0;
    font-size: clamp(28px, 4vw, 46px);
    line-height: 1.02;
    letter-spacing: 0;
}

.hud-panel h1 {
    font-size: 29px;
}

.summary,
.lede,
.controls-note p {
    color: rgba(246, 251, 255, 0.78);
    line-height: 1.55;
    font-size: 14px;
}

.team-card {
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    padding: 14px;
    background: rgba(255, 255, 255, 0.06);
}

.team-card h2,
.match-stats span {
    margin: 0 0 12px;
    color: rgba(255, 255, 255, 0.62);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

.team-card--stars {
    border-top: 4px solid #32d583;
}

.team-card--rivals {
    border-top: 4px solid #ff4d6d;
}

.roster {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.player-pill {
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.22);
    color: #fff;
    font-size: 12px;
    font-weight: 900;
}

.player-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 0 14px currentColor;
    flex: 0 0 auto;
}

.match-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.match-stats div {
    min-height: 76px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.match-stats span {
    display: block;
    margin-bottom: 8px;
}

.match-stats strong {
    font-size: 15px;
    line-height: 1.25;
}

.controls-note {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 12px;
}

.overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, rgba(2, 12, 16, 0.9), rgba(7, 31, 29, 0.76));
    backdrop-filter: blur(8px);
}

.overlay.hidden {
    display: none;
}

.overlay-card {
    width: min(560px, 100%);
    padding: 28px;
    border-radius: 8px;
    background: rgba(7, 18, 24, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 24px 90px rgba(0, 0, 0, 0.45);
}

.mode-row,
.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 18px 0;
}

.mode-choice,
.primary-btn,
.button-row button {
    min-height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    padding: 0 16px;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    font-weight: 900;
}

.mode-choice.active,
.primary-btn {
    background: #32d583;
    color: #052014;
    border-color: #32d583;
}

.control-grid {
    display: grid;
    gap: 8px;
    margin: 18px 0;
}

.control-grid div {
    padding: 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.76);
    font-size: 13px;
}

.control-grid span {
    display: inline-flex;
    min-width: 42px;
    color: #ffe66d;
    font-weight: 900;
}

#toast {
    position: absolute;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(16px);
    z-index: 14;
    opacity: 0;
    pointer-events: none;
    color: #061416;
    background: #ffe66d;
    border-radius: 6px;
    padding: 11px 14px;
    font-size: 13px;
    font-weight: 900;
    transition: opacity 160ms ease, transform 160ms ease;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.3);
}

#toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.football-controls-fallback {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    pointer-events: none;
    justify-content: space-between;
    box-sizing: border-box;
}

.football-controls-fallback .touch-team {
    display: contents;
}

.football-controls-fallback .touch-label {
    position: fixed;
    color: #f8fbff;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: rgba(4, 13, 18, 0.74);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 5px;
    padding: 4px 7px;
}

.football-controls-fallback .dpad {
    display: grid;
    pointer-events: auto;
}

.football-controls-fallback .dpad-btn,
.football-controls-fallback .action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    cursor: pointer;
}

.football-controls-fallback .dpad-center.empty {
    pointer-events: none;
    opacity: 0;
}

.football-controls-fallback .dpad-up {
    grid-column: 2;
    grid-row: 1;
}

.football-controls-fallback .dpad-left {
    grid-column: 1;
    grid-row: 2;
}

.football-controls-fallback .dpad-right {
    grid-column: 3;
    grid-row: 2;
}

.football-controls-fallback .dpad-down {
    grid-column: 2;
    grid-row: 3;
}

.football-controls-fallback .action-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: flex-end;
    pointer-events: auto;
}

@media (max-width: 1050px) {
    .game-shell {
        grid-template-columns: 1fr;
    }

    .hud-panel,
    .stadium-panel {
        min-height: auto;
    }

    #scene {
        height: 68vh;
        min-height: 480px;
    }
}

@media (max-width: 680px) {
    .game-shell {
        padding: 52px 8px 16px;
        gap: 10px;
    }

    .back-link {
        top: 10px;
        left: 10px;
        font-size: 10px;
    }

    .scoreboard {
        top: 8px;
        width: calc(100% - 12px);
        grid-template-columns: minmax(0, 1fr) 78px minmax(0, 1fr);
        border-radius: 6px;
    }

    .score-team,
    .clock-box {
        min-height: 46px;
        gap: 5px;
        padding: 0 5px;
    }

    .score-team span,
    .clock-box span {
        font-size: 8px;
        letter-spacing: 0.04em;
    }

    .score-team strong,
    .clock-box strong {
        font-size: 19px;
    }

    #scene {
        height: 58vh;
        min-height: 340px;
        max-height: 500px;
    }

    .hud-panel {
        padding: 12px;
        gap: 10px;
    }

    .hud-panel h1 {
        font-size: 22px;
    }

    .summary,
    .lede,
    .controls-note p {
        font-size: 12px;
        line-height: 1.45;
    }

    .team-card {
        padding: 10px;
    }

    .roster,
    .match-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
    }

    .player-pill {
        min-height: 36px;
        padding: 7px;
        font-size: 10px;
    }

    .match-stats div {
        min-height: 62px;
        padding: 9px;
    }

    .match-stats span,
    .team-card h2 {
        font-size: 9px;
        margin-bottom: 7px;
    }

    .match-stats strong {
        font-size: 12px;
    }

    .overlay {
        padding: 10px;
        align-items: flex-start;
        padding-top: 74px;
    }

    .overlay-card {
        padding: 16px;
        max-height: calc(100vh - 94px);
        overflow-y: auto;
    }

    .overlay-card h1 {
        font-size: 31px;
    }

    .overlay-card h2 {
        font-size: 25px;
    }

    .mode-row,
    .button-row {
        margin: 12px 0;
        gap: 8px;
    }

    .mode-choice,
    .primary-btn,
    .button-row button {
        min-height: 42px;
        padding: 0 12px;
    }

    .control-grid {
        margin: 12px 0;
    }

    .control-grid div {
        font-size: 11px;
        padding: 8px;
    }

    #toast {
        bottom: 132px;
        width: calc(100% - 32px);
        text-align: center;
        font-size: 12px;
    }

    body.football-touch #game-container {
        padding-bottom: 112px !important;
    }

    body.football-touch #scene {
        height: calc(100vh - 72px);
        min-height: 560px;
        max-height: none;
    }

    body.football-touch .stadium-panel {
        min-height: 560px;
    }

    body.football-touch .hud-panel {
        margin-bottom: 118px;
    }

    body.football-touch .mobile-controls {
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
        align-items: flex-end;
        background: linear-gradient(180deg, transparent, rgba(4, 13, 18, 0.72));
    }

    body.football-touch:not(.football-playing) .mobile-controls {
        display: none !important;
    }

    body.football-touch .touch-team--p1 .touch-label {
        left: 10px;
        bottom: 106px;
        color: #7ee4a8;
    }

    body.football-touch .touch-team--p2 .touch-label {
        right: 10px;
        top: 116px;
        color: #ff9aac;
        display: none;
    }

    body.football-touch .touch-team--p1 .dpad {
        grid-template-columns: 44px 44px 44px;
        grid-template-rows: 44px 44px 44px;
        gap: 3px;
    }

    body.football-touch .touch-team--p2 .dpad {
        position: fixed;
        top: 142px;
        right: 10px;
        grid-template-columns: 38px 38px 38px;
        grid-template-rows: 38px 38px 38px;
        gap: 3px;
        display: none;
        pointer-events: auto;
    }

    body.football-touch .dpad-btn {
        width: 44px;
        height: 44px;
        font-size: 15px;
        background: rgba(50, 213, 131, 0.28);
        border-color: rgba(50, 213, 131, 0.58);
        color: #7ee4a8;
    }

    body.football-touch .touch-team--p2 .dpad-btn {
        width: 38px;
        height: 38px;
        font-size: 13px;
        color: #ff9aac;
        background: rgba(255, 77, 109, 0.24);
        border-color: rgba(255, 77, 109, 0.58);
    }

    body.football-touch .touch-team--p1 .action-buttons {
        max-width: 144px;
        gap: 7px;
    }

    body.football-touch .touch-team--p2 .action-buttons {
        position: fixed;
        top: 150px;
        left: 10px;
        max-width: 120px;
        gap: 6px;
        display: none;
        pointer-events: auto;
    }

    body.football-touch .action-btn {
        width: 54px;
        height: 54px;
        font-size: 8px;
        background: rgba(255, 230, 109, 0.24);
        border-color: rgba(255, 230, 109, 0.62);
        color: #ffe66d;
    }

    body.football-touch .action-btn.primary {
        width: 64px;
        height: 64px;
        color: #ff7b92;
        background: rgba(255, 77, 109, 0.25);
        border-color: rgba(255, 77, 109, 0.66);
    }

    body.football-touch.football-two-player .touch-team--p2 .dpad,
    body.football-touch.football-two-player .touch-team--p2 .action-buttons,
    body.football-touch.football-two-player .touch-team--p2 .touch-label {
        display: block;
    }

    body.football-touch.football-two-player .touch-team--p2 .dpad {
        display: grid;
    }

    body.football-touch.football-two-player .touch-team--p2 .action-buttons {
        display: flex;
    }

    body.football-touch.football-two-player #scene {
        filter: saturate(1.05);
    }
}

@media (max-width: 420px) {
    .roster,
    .match-stats {
        grid-template-columns: 1fr;
    }

    .score-team {
        flex-direction: column;
        gap: 1px;
    }

    .score-team--rivals {
        flex-direction: column-reverse;
    }

    #scene {
        height: 56vh;
        min-height: 320px;
    }
}
