/* Theme variables */
[data-theme="dark"] {
    --bg-primary: #0a1628;
    --bg-container: rgba(10, 22, 40, 0.9);
    --text-primary: #e8e8e8;
    --text-secondary: #8899aa;
    --accent: #00e676;
    --accent-glow: rgba(0, 230, 118, 0.3);
    --input-bg: rgba(255, 255, 255, 0.08);
    --input-border: rgba(255, 255, 255, 0.15);
    --pitch-green: #2e7d32;
    --pitch-line: rgba(255, 255, 255, 0.7);
    --player-bg: rgba(0, 0, 0, 0.7);
    --player-border: #00e676;
}

[data-theme="light"] {
    --bg-primary: #e8eef5;
    --bg-container: rgba(255, 255, 255, 0.9);
    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --accent: #1b5e20;
    --accent-glow: rgba(27, 94, 32, 0.3);
    --input-bg: rgba(0, 0, 0, 0.04);
    --input-border: rgba(0, 0, 0, 0.15);
    --pitch-green: #388e3c;
    --pitch-line: rgba(255, 255, 255, 0.8);
    --player-bg: rgba(255, 255, 255, 0.85);
    --player-border: #1b5e20;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    transition: background-color 0.3s, color 0.3s;
}

#theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: var(--bg-container);
    font-size: 1.3rem;
    cursor: pointer;
    z-index: 100;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 0 15px var(--accent-glow);
}

.app-container {
    max-width: 700px;
    width: 100%;
    padding: 30px;
    background: var(--bg-container);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    margin-top: 20px;
    transition: background 0.3s;
}

h1 {
    text-align: center;
    font-size: 2rem;
    color: var(--accent);
    margin-bottom: 25px;
}

h2 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    text-align: center;
}

/* Input Section */
.input-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.formation-select {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.formation-select label {
    font-weight: bold;
    font-size: 1rem;
}

.formation-select select {
    padding: 10px 20px;
    font-size: 1.1rem;
    border-radius: 8px;
    border: 2px solid var(--accent);
    background: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: bold;
}

#input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.player-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-input-row .position-label {
    min-width: 36px;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--accent);
    text-align: center;
    background: var(--input-bg);
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid var(--accent);
}

.player-input-row input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.3s;
}

.player-input-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}

#build-btn, #reset-btn {
    width: 100%;
    padding: 14px;
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 15px var(--accent-glow);
}

#build-btn:hover, #reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px var(--accent-glow);
}

#reset-btn {
    margin-top: 20px;
    background: transparent;
    border: 2px solid var(--accent);
    color: var(--accent);
}

/* Pitch Section */
.pitch-section {
    margin-top: 10px;
}

.pitch {
    position: relative;
    width: 100%;
    aspect-ratio: 68 / 100;
    background: var(--pitch-green);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.4);
    margin-top: 15px;
    /* Grass stripes */
    background-image: repeating-linear-gradient(
        to bottom,
        rgba(255,255,255,0.03) 0px,
        rgba(255,255,255,0.03) 40px,
        transparent 40px,
        transparent 80px
    );
}

.pitch-lines {
    position: absolute;
    inset: 0;
    border: 3px solid var(--pitch-line);
    border-radius: 12px;
}

.center-line {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--pitch-line);
}

.center-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 22%;
    aspect-ratio: 1;
    border: 2px solid var(--pitch-line);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.penalty-area {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 55%;
    height: 16%;
    border: 2px solid var(--pitch-line);
}

.top-penalty { top: 0; border-top: none; }
.bottom-penalty { bottom: 0; border-bottom: none; }

.goal-area {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 28%;
    height: 6%;
    border: 2px solid var(--pitch-line);
}

.top-goal { top: 0; border-top: none; }
.bottom-goal { bottom: 0; border-bottom: none; }

/* Players on pitch */
#players-on-pitch {
    position: absolute;
    inset: 0;
}

.player-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    text-align: center;
    transition: all 0.5s ease;
    animation: popIn 0.4s ease backwards;
}

.player-marker .marker-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--player-bg);
    border: 2px solid var(--player-border);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 4px;
    font-size: 0.7rem;
    font-weight: bold;
    color: var(--accent);
    box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

.player-marker .marker-circle.gk {
    background: #ff9800;
    border-color: #e65100;
    color: #fff;
}

.player-marker .player-name {
    font-size: 0.65rem;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Responsive */
@media (max-width: 500px) {
    .app-container { padding: 15px; }
    h1 { font-size: 1.5rem; }
    #input-grid { grid-template-columns: 1fr; }
    .player-marker .marker-circle { width: 32px; height: 32px; font-size: 0.6rem; }
    .player-marker .player-name { font-size: 0.55rem; max-width: 60px; }
}
