:root {
    /* Layout */
    --munch-bg-page: #f5f5f5;
    --munch-bg-enemies: #fff5f5;
    --munch-bg-players: #f5f5ff;
    --munch-border-soft: #e0e0e0;

    /* Typography / text */
    --munch-text-main: #333333;

    /* Primary buttons (add entity) */
    --munch-btn-primary-bg: #16a34a;
    --munch-btn-primary-bg-hover: #22c55e;

    /* Danger buttons */
    --munch-btn-danger-bg: #d32f2f;
    --munch-btn-danger-bg-hover: #b71c1c;

    /* Reset / neutral button */
    --munch-btn-reset-bg: #757575;
    --munch-btn-reset-bg-hover: #616161;

    /* Cards / level buttons */
    --munch-card-bg: #ffffff;
    --munch-card-border: #e0e0e0;
    --munch-level-btn-bg: #f0f0f0;
    --munch-level-btn-border: #d0d0d0;
    --munch-level-btn-border-hover: #b0b0b0;

    /* Levels / tallies */
    --munch-level-inc: #2e7d32;
    --munch-level-dec: #c62828;
    --munch-tally-players-bg: #e8f5e9;
    --munch-tally-enemies-bg: #ffebee;
    --munch-tally-neutral-border: #757575;
    --munch-tally-neutral-bg: #f5f5f5;
}

@media (prefers-color-scheme: dark) {
    :root {
        --munch-bg-page: #050608;
        --munch-bg-enemies: #161925;
        --munch-bg-players: #111827;
        --munch-border-soft: #303549;

        --munch-text-main: #e5e7eb;

        --munch-btn-primary-bg: #16a34a;
        --munch-btn-primary-bg-hover: #22c55e;

        --munch-btn-danger-bg: #f97373;
        --munch-btn-danger-bg-hover: #fb5f5f;

        --munch-btn-reset-bg: #9ca3af;
        --munch-btn-reset-bg-hover: #d1d5db;

        --munch-card-bg: #020617;
        --munch-card-border: #4b5563;
        --munch-level-btn-bg: #374151;
        --munch-level-btn-border: #4b5563;
        --munch-level-btn-border-hover: #9ca3af;

        --munch-level-inc: #4ade80;
        --munch-level-dec: #fb7185;
        --munch-tally-players-bg: #064e3b;
        --munch-tally-enemies-bg: #7f1d1d;
        --munch-tally-neutral-border: #9ca3af;
        --munch-tally-neutral-bg: #111827;
    }

    body {
        color: var(--munch-text-main);
    }

    .tally-badge {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.8);
    }

    .reset-btn {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    }
}

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

body {
    font-family: "Helvetica", "Arial", sans-serif;
    background-color: var(--munch-bg-page);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.app {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.game-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.side {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 20px 20px;
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 0;
}

.enemies-side {
    background: var(--munch-bg-enemies);
    border-right: 2px solid var(--munch-border-soft);
}

.players-side {
    background: var(--munch-bg-players);
}

.side-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    column-gap: 12px;
    margin: 0 0 20px 0;
    padding: 24px 0 15px 0;
    border-bottom: 2px solid var(--munch-border-soft);
}

.enemies-side .side-header {
    background: var(--munch-bg-enemies);
}

.players-side .side-header {
    background: var(--munch-bg-players);
}

.side-header h2 {
    font-size: 1.8rem;
    font-weight: 300;
}

.side-title {
    justify-self: start;
}

.side-score {
    justify-self: center;
    font-size: 1.1rem;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.enemies-side .side-score {
    color: var(--munch-level-dec);
}

.players-side .side-score {
    color: var(--munch-level-inc);
}

.add-btn {
    background: var(--munch-btn-primary-bg);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    justify-self: end;
}

.add-btn:hover {
    background: var(--munch-btn-primary-bg-hover);
}

.add-btn:active {
    transform: scale(0.98);
    will-change: transform;
}

.entities-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.entity-card {
    background: var(--munch-card-bg);
    border: 2px solid var(--munch-card-border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.entity-card:only-child {
    grid-column: 1 / -1;
}

.entity-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
}

.entity-name {
    font-size: 1.2rem;
    font-weight: 500;
    justify-self: start;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entity-name[contenteditable="true"] {
    cursor: text;
    outline: none;
    border-radius: 4px;
    padding: 2px 4px;
    margin: -2px -4px;
}

.entity-name[contenteditable="true"]:focus {
    background: rgba(0, 0, 0, 0.05);
}

.remove-btn {
    justify-self: end;
    background: var(--munch-btn-danger-bg);
    color: white;
    border: none;
    border-radius: 4px;
    width: 32px;
    height: 32px;
    font-size: 1.3rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.remove-btn:hover {
    background: var(--munch-btn-danger-bg-hover);
}

button {
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

button:focus-visible {
    outline: 3px solid #4A90E2;
    outline-offset: 2px;
}

.entity-controls {
    display: flex;
}

.level-display {
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    min-width: 40px;
    justify-self: center;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.button-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    flex: 1;
}

.level-btn {
    background: var(--munch-level-btn-bg);
    border: 2px solid var(--munch-level-btn-border);
    border-radius: 6px;
    padding: 15px 10px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.level-btn:hover {
    background: #e0e0e0;
    border-color: var(--munch-level-btn-border-hover);
}

.level-btn:active {
    transform: scale(0.95);
    will-change: transform;
}

.level-btn.increment {
    color: var(--munch-level-inc);
}

.level-btn.decrement {
    color: var(--munch-level-dec);
}

.tally-container {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tally-badge {
    background: #ffffff;
    border: 3px solid var(--munch-card-border);
    border-radius: 24px;
    padding: 12px 24px;
    font-size: 1.2rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

.reset-btn {
    background: var(--munch-btn-reset-bg);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.4rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.reset-btn:hover {
    background: var(--munch-btn-reset-bg-hover);
}

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

.tally-badge.players-winning {
    border-color: var(--munch-level-inc);
    color: var(--munch-level-inc);
    background: var(--munch-tally-players-bg);
}

.tally-badge.enemies-winning {
    border-color: var(--munch-level-dec);
    color: var(--munch-level-dec);
    background: var(--munch-tally-enemies-bg);
}

.tally-badge.tied {
    border-color: var(--munch-tally-neutral-border);
    color: var(--munch-tally-neutral-border);
    background: var(--munch-tally-neutral-bg);
}

@media (max-width: 900px) {
    .game-container {
        flex-direction: column;
    }

    .game-container::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 0;
        right: 0;
        height: 60px;
        transform: translateY(-50%);
        background: linear-gradient(
            to bottom,
            var(--munch-bg-enemies) 0%,
            var(--munch-bg-enemies) 49%,
            var(--munch-border-soft) 49%,
            var(--munch-border-soft) 51%,
            var(--munch-bg-players) 51%,
            var(--munch-bg-players) 100%
        );
        z-index: 5;
        pointer-events: none;
    }

    .enemies-side {
        border-right: none;
        border-bottom: 2px solid var(--munch-border-soft);
        order: 1;
        transform: rotate(180deg);
    }

    .players-side {
        order: 2;
    }

    .side {
        flex: 0 0 50vh;
        height: 50vh;
        padding: 0 12px 12px;
        overflow-y: auto;
    }

    .entities-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 2px;
    }

    .entity-card {
        padding: 10px;
        gap: 10px;
    }

    .side-header {
        margin: 0 0 12px 0;
        padding: 18px 0 12px 0;
    }

    .enemies-side .side-header {
        padding-top: 30px;
    }

    .side-header h2 {
        font-size: 1.3rem;
    }

    .entity-name {
        font-size: 1rem;
    }

    .level-display {
        font-size: 1.3rem;
        min-width: 35px;
    }

    .button-group {
        width: 100%;
        gap: 6px;
    }

    .level-btn {
        padding: 12px 8px;
        font-size: 1rem;
    }

    .tally-container {
        top: 50%;
        transform: translate(-50%, -50%);
    }

    .tally-badge {
        font-size: 1rem;
        padding: 10px 20px;
    }

    .reset-btn {
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
    }
}

@media (max-width: 1024px) and (min-width: 901px) {
    .side-header h2 {
        font-size: 1.5rem;
    }

    .add-btn {
        width: 40px;
        height: 40px;
        font-size: 1.3rem;
    }
}
