:root {
    color-scheme: dark;
    --page: #000;
    --ink: #f7faf8;
    --muted: #aab4ae;
    --line: rgba(255, 255, 255, 0.9);
    --grass-a: #287c42;
    --grass-b: #23804a;
    --grass-c: #1d6d3d;
    --blue: #1769e0;
    --blue-deep: #0a3f91;
    --red: #db3030;
    --red-deep: #8f1616;
    --panel: #111513;
    --border: #313b35;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.48);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

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

body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #121715;
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    min-height: 40px;
    padding: 0 14px;
}

button:hover,
button:focus-visible {
    border-color: #8fa09a;
    outline: none;
}

button.primary {
    background: #e9f1ec;
    border-color: #e9f1ec;
    color: #0a0d0c;
}

.app-shell {
    min-height: 100vh;
    padding: 18px;
}

.toolbar {
    align-items: center;
    display: flex;
    gap: 18px;
    justify-content: space-between;
    margin: 0 auto 18px;
    max-width: 1480px;
}

.brand {
    align-items: center;
    display: flex;
    gap: 12px;
    min-width: 0;
}

.mark {
    background:
        radial-gradient(circle at center, #fff 0 14%, transparent 15%),
        conic-gradient(from 18deg, #17231f 0 10%, #fff 10% 20%, #17231f 20% 30%, #fff 30% 40%, #17231f 40% 50%, #fff 50% 60%, #17231f 60% 70%, #fff 70% 80%, #17231f 80% 90%, #fff 90% 100%);
    border: 2px solid #f7faf8;
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 auto;
    height: 42px;
    width: 42px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 1.25rem;
    line-height: 1.15;
}

.brand p {
    color: var(--muted);
    font-size: 0.92rem;
    margin-top: 2px;
}

.actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.player-count {
    display: flex;
    gap: 4px;
}

.player-count button {
    min-height: 34px;
    padding: 0 10px;
}

.player-count button.is-active {
    background: #fff4a8;
    border-color: #fff4a8;
    color: #0a0d0c;
}

.board-layout {
    align-items: start;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(120px, 150px) minmax(320px, 1fr) minmax(120px, 150px);
    margin: 0 auto;
    max-width: 1480px;
}

.field-wrap {
    min-width: 0;
    position: relative;
}

.field {
    aspect-ratio: 16 / 10;
    background:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 7.5%, transparent 7.5% 15%),
        linear-gradient(135deg, var(--grass-a), var(--grass-b) 45%, var(--grass-c));
    border: 4px solid rgba(255, 255, 255, 0.86);
    box-shadow: var(--shadow);
    min-height: 480px;
    overflow: hidden;
    position: relative;
    touch-action: none;
    width: 100%;
}

.pitch-lines {
    inset: 0;
    pointer-events: none;
    position: absolute;
    z-index: 1;
}

.vision-overlay {
    height: 100%;
    inset: 0;
    pointer-events: none;
    position: absolute;
    width: 100%;
    z-index: 2;
}

.draw-overlay {
    height: 100%;
    inset: 0;
    pointer-events: none;
    position: absolute;
    width: 100%;
    z-index: 3;
}

.pitch-lines span {
    pointer-events: none;
    position: absolute;
}

.pitch-lines::before {
    border: 3px solid var(--line);
    content: "";
    inset: 20px;
    position: absolute;
}

.center-line {
    background: var(--line);
    bottom: 20px;
    left: 50%;
    top: 20px;
    transform: translateX(-50%);
    width: 3px;
}

.center-circle {
    border: 3px solid var(--line);
    border-radius: 50%;
    height: min(28%, 180px);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(18%, 180px);
}

.center-dot,
.penalty-dot {
    background: var(--line);
    border-radius: 50%;
    height: 10px;
    transform: translate(-50%, -50%);
    width: 10px;
}

.center-dot {
    left: 50%;
    top: 50%;
}

.box {
    border: 3px solid var(--line);
    bottom: 24%;
    top: 24%;
    width: 17%;
}

.box-left,
.goal-box.goal-left {
    border-left: 0;
    left: 20px;
}

.box-right,
.goal-box.goal-right {
    border-right: 0;
    right: 20px;
}

.goal-box {
    border: 3px solid var(--line);
    bottom: 35%;
    top: 35%;
    width: 7%;
}

.penalty-left {
    left: calc(20px + 11%);
    top: 50%;
}

.penalty-right {
    right: calc(20px + 11%);
    top: 50%;
}

.goal {
    background:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.5) 0 2px, transparent 2px 12px),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.5) 0 2px, transparent 2px 12px);
    border: 3px solid var(--line);
    bottom: 41%;
    top: 41%;
    width: 18px;
}

.goal-left-net {
    border-right: 0;
    left: 2px;
}

.goal-right-net {
    border-left: 0;
    right: 2px;
}

.penalty-arc {
    --arc-size: clamp(86px, 10vw, 142px);
    border: 3px solid var(--line);
    height: var(--arc-size);
    top: 50%;
    transform: translateY(-50%);
    width: calc(var(--arc-size) / 2);
}

.arc-left {
    border-left: 0;
    border-radius: 0 var(--arc-size) var(--arc-size) 0;
    left: calc(20px + 17% - 1px);
}

.arc-right {
    border-radius: var(--arc-size) 0 0 var(--arc-size);
    border-right: 0;
    right: calc(20px + 17% - 1px);
}

.corner {
    border: 3px solid var(--line);
    border-radius: 50%;
    height: 44px;
    width: 44px;
}

.corner-top-left {
    border-left-color: transparent;
    border-top-color: transparent;
    left: 20px;
    top: 20px;
}

.corner-top-right {
    border-right-color: transparent;
    border-top-color: transparent;
    right: 20px;
    top: 20px;
}

.corner-bottom-left {
    border-bottom-color: transparent;
    border-left-color: transparent;
    bottom: 20px;
    left: 20px;
}

.corner-bottom-right {
    border-bottom-color: transparent;
    border-right-color: transparent;
    bottom: 20px;
    right: 20px;
}

.player,
.ball {
    align-items: center;
    border: 2px solid rgba(255, 255, 255, 0.88);
    border-radius: 50%;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
    cursor: grab;
    display: flex;
    justify-content: center;
    left: 0;
    line-height: 1;
    min-height: 0;
    padding: 0;
    position: absolute;
    top: 0;
    transform: translate(-50%, -50%);
    user-select: none;
    z-index: 4;
}

.player {
    color: #fff;
    font-size: clamp(0.72rem, 1.2vw, 1rem);
    font-weight: 900;
    height: clamp(38px, 4.5vw, 58px);
    width: clamp(38px, 4.5vw, 58px);
}

.ball {
    background:
        radial-gradient(circle at 35% 30%, #fff 0 18%, #efefef 19% 45%, #151515 46% 51%, #f8f8f8 52%);
    height: clamp(18px, 2vw, 28px);
    width: clamp(18px, 2vw, 28px);
    z-index: 5;
}

.player:active,
.player.dragging,
.ball:active,
.ball.dragging {
    cursor: grabbing;
    z-index: 6;
}

.player.is-viewer {
    box-shadow:
        0 0 0 4px rgba(255, 245, 120, 0.55),
        0 0 24px rgba(255, 245, 120, 0.85);
}

.player.blue {
    background: radial-gradient(circle at 35% 28%, #6aa3ff, var(--blue) 48%, var(--blue-deep));
}

.player.red {
    background: radial-gradient(circle at 35% 28%, #ff8a8a, var(--red) 48%, var(--red-deep));
}

.field-tool,
.fullscreen-toggle {
    align-items: center;
    background: rgba(0, 0, 0, 0.42);
    border-color: rgba(255, 255, 255, 0.48);
    border-radius: 4px;
    display: flex;
    height: 18px;
    justify-content: center;
    min-height: 0;
    padding: 0;
    position: absolute;
    right: 6px;
    top: 6px;
    width: 18px;
    z-index: 10;
}

.field-tool {
    left: 6px;
    right: auto;
    top: 6px;
}

.draw-toggle {
    left: 30px;
}

.vision-toggle span {
    background: #fff;
    border-radius: 50%;
    display: block;
    height: 7px;
    position: relative;
    width: 7px;
}

.vision-toggle span::before {
    border: 1px solid #fff;
    border-radius: 50%;
    content: "";
    height: 13px;
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 13px;
}

.vision-toggle.is-active {
    background: rgba(255, 230, 98, 0.3);
    border-color: rgba(255, 245, 130, 0.9);
}

.draw-toggle span {
    background: #fff;
    border-radius: 2px;
    display: block;
    height: 2px;
    transform: rotate(-35deg);
    width: 12px;
}

.draw-toggle span::after {
    border-left: 4px solid #fff;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    content: "";
    position: absolute;
    right: -4px;
    top: -2px;
}

.draw-toggle.is-active {
    background: rgba(255, 230, 98, 0.3);
    border-color: rgba(255, 245, 130, 0.9);
}

.movement-vector {
    fill: none;
    stroke: #fff4a8;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 4;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.55));
}

.drawing-preview {
    opacity: 0.72;
    stroke-dasharray: 8 7;
}

.reset-drawings {
    background: rgba(0, 0, 0, 0.72);
    border-color: rgba(255, 255, 255, 0.48);
    bottom: 12px;
    color: #fff;
    min-height: 32px;
    padding: 0 10px;
    position: fixed;
    left: 12px;
    z-index: 1100;
}

.fullscreen-toggle span,
.fullscreen-toggle span::before {
    border: 1px solid #fff;
    display: block;
    height: 9px;
    width: 9px;
}

.fullscreen-toggle span {
    position: relative;
}

.fullscreen-toggle span::before {
    content: "";
    left: 3px;
    position: absolute;
    top: 3px;
}

.fullscreen-toggle.is-fullscreen span::before {
    left: -3px;
    top: -3px;
}

.field-wrap:fullscreen,
.field-wrap:-webkit-full-screen,
.field-wrap.fullscreen-fallback {
    align-items: center;
    background: #000;
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 10px;
    position: fixed;
    z-index: 1000;
}

.field-wrap:fullscreen .field,
.field-wrap:-webkit-full-screen .field,
.field-wrap.fullscreen-fallback .field {
    height: min(calc(100dvh - 20px), calc((100dvw - 20px) / 1.6));
    min-height: 0;
    width: min(calc(100dvw - 20px), calc((100dvh - 20px) * 1.6));
}

body.fullscreen-fallback-active {
    overflow: hidden;
}

.formation-panel {
    min-width: 0;
}

.formation-group {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--ink);
}

.formation-group summary {
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 800;
    list-style: none;
    padding: 11px 12px;
    user-select: none;
}

.formation-group summary::-webkit-details-marker {
    display: none;
}

.formation-group summary::after {
    content: "+";
    float: right;
    font-weight: 900;
}

.formation-group[open] summary::after {
    content: "-";
}

.formation-buttons {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr;
}

.formation-menu {
    display: grid;
    gap: 8px;
    padding: 0 12px 12px;
}

.formation-menu h3 {
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0;
    margin: 2px 0 -2px;
}

.formation-reset {
    width: 100%;
}

.formation-blue summary {
    color: #8fb8ff;
}

.formation-red summary {
    color: #ff9b9b;
}

@media (max-width: 920px) {
    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .actions {
        justify-content: flex-start;
    }

    .field {
        min-height: auto;
    }

    .board-layout {
        grid-template-columns: 1fr;
    }

    .formation-panel-blue {
        order: 2;
    }

    .field-wrap {
        order: 1;
    }

    .formation-panel-red {
        order: 3;
    }

    .formation-buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .app-shell {
        padding: 12px;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .player-count {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .field {
        aspect-ratio: 10 / 14;
    }

    .formation-buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
