:root {
    --bg-dark: #121826;
    --panel-bg: #1e293b;
    --panel-border: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --purple-team: #9333ea;
    --purple-light: #d8b4fe;
    --purple-endzone: rgba(147, 51, 234, 0.15);
    
    --green-team: #16a34a;
    --green-light: #86efac;
    --green-endzone: rgba(22, 163, 74, 0.15);
    
    --board-bg: #0f172a;
    --cell-bg: #1e293b;
    --cell-border: #334155;
    
    --highlight-move: rgba(56, 189, 248, 0.4);
    --highlight-move-border: #38bdf8;
    
    --highlight-tackle: rgba(239, 68, 68, 0.4);
    --highlight-tackle-border: #ef4444;
    
    --highlight-pass: rgba(250, 204, 21, 0.4);
    --highlight-pass-border: #facc15;
    
    --acorn-glow: 0 0 10px #fbbf24;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
}

#app-container {
    display: flex;
    flex-direction: row;
    width: 100vw;
    height: 100vh;
}

@supports (height: 100dvh) {
    body, #app-container { height: 100dvh; }
}

/* --- BOARD AREA --- */
#board-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
}

.copyright-footer {
    position: fixed;
    left: 8px;
    bottom: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
    pointer-events: none;
    z-index: 500;
}

.board-score-label {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: clamp(2rem, 5vw, 4rem);
    font-weight: 800;
    opacity: 0.15;
    pointer-events: none;
    z-index: 1;
    writing-mode: vertical-rl;
    text-align: center;
    letter-spacing: 10px;
}
#green-score-label {
    left: 40px;
    color: var(--green-team);
    transform: translateY(-50%) rotate(180deg);
}
#purple-score-label {
    right: 40px;
    color: var(--purple-team);
}

#grid-container {
    display: grid;
    grid-template-columns: repeat(13, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 4px;
    background-color: var(--board-bg);
    padding: 8px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    aspect-ratio: 13 / 9;
    max-height: 90vh;
    width: 100%;
    max-width: 1200px;
    z-index: 2;
}

.cell {
    background-color: var(--cell-bg);
    border: 1px solid var(--cell-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: default;
    transition: all 0.2s ease;
    user-select: none;
    overflow: hidden;
}

.cell.endzone-purple {
    background-color: var(--purple-endzone);
}

.cell.endzone-green {
    background-color: var(--green-endzone);
}

.cell.occupied-purple {
    border-color: var(--purple-light);
    box-shadow: inset 0 0 0 3px rgba(216, 180, 254, 0.8),
                0 0 6px rgba(216, 180, 254, 0.25);
}

.cell.occupied-green {
    border-color: var(--green-light);
    box-shadow: inset 0 0 0 3px rgba(134, 239, 172, 0.8),
                0 0 6px rgba(134, 239, 172, 0.25);
}

.cell.highlight-move {
    background-color: var(--highlight-move);
    border-color: var(--highlight-move-border);
    cursor: pointer;
}

.cell.highlight-tackle {
    background-color: var(--highlight-tackle);
    border-color: var(--highlight-tackle-border);
    cursor: pointer;
}

.cell.highlight-pass {
    background-color: var(--highlight-pass);
    border-color: var(--highlight-pass-border);
    cursor: pointer;
}

.animal {
    position: relative;
    z-index: 10;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.emoji-inner {
    font-size: clamp(1.5rem, 4vw, 3rem);
    display: inline-block;
    transition: transform 0.2s;
}

.animal.team-purple .emoji-inner {
    transform: scaleX(-1);
}

.animal.team-purple {
    text-shadow: 0 0 10px var(--purple-light);
}

.animal.team-green {
    text-shadow: 0 0 10px var(--green-light);
}

.animal.selected {
    transform: scale(1.2);
    animation: bounce 1s infinite alternate;
}

@keyframes bounce {
    0% { transform: translateY(0) scale(1.2); }
    100% { transform: translateY(-5px) scale(1.2); }
}

.acorn {
    font-size: clamp(1.1rem, 2.4vw, 2rem);
    position: absolute;
    z-index: 5;
    filter: drop-shadow(var(--acorn-glow));
}

.animal.carrying-acorn::before {
    content: '🏈';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 0.65em;
    filter: drop-shadow(var(--acorn-glow));
    z-index: 15;
    background: rgba(0,0,0,0.4);
    border-radius: 50%;
    width: 1.35em;
    height: 1.35em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-badge {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.4em;
    background: #ef4444;
    color: white;
    padding: 2px 4px;
    border-radius: 6px;
    font-weight: bold;
    z-index: 20;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}


/* --- SIDE PANELS --- */
#controls-panel {
    width: 380px;
    min-width: 380px;
    background-color: var(--panel-bg);
    border-left: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: -5px 0 15px rgba(0,0,0,0.3);
    z-index: 100;
}

#log-panel {
    width: 320px;
    min-width: 320px;
    background-color: var(--panel-bg);
    border-right: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-shadow: 5px 0 15px rgba(0,0,0,0.3);
    z-index: 100;
}

header {
    padding: 20px;
    border-bottom: 1px solid var(--panel-border);
    text-align: center;
}

header h1 {
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 10px;
    color: #fcd34d;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    letter-spacing: 2px;
}

#game-status {
    background: rgba(0,0,0,0.2);
    padding: 10px;
    border-radius: 8px;
}

#current-player {
    font-size: 1.2rem;
    margin-bottom: 5px;
}
#current-player.turn-purple { color: var(--purple-light); }
#current-player.turn-green { color: var(--green-light); }

#actions-remaining {
    font-weight: bold;
    color: var(--text-muted);
}
#actions-count { color: white; font-size: 1.2em; }

.guidance-message {
    margin-top: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    color: #f8fafc;
    font-size: 0.9rem;
    font-style: italic;
    border-left: 3px solid #38bdf8;
}


#selection-panel {
    padding: 15px;
    border-bottom: 1px solid var(--panel-border);
}

#selected-info {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    background: rgba(0,0,0,0.2);
    padding: 10px;
    border-radius: 8px;
}

#selected-emoji {
    font-size: 3rem;
    width: 60px;
    text-align: center;
}

#selected-stats {
    flex: 1;
}

#selected-name {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

#selected-trait {
    font-size: 0.85rem;
    color: #fbbf24;
    margin-bottom: 8px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.stats-grid span span { color: white; font-weight: bold; }

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

.action-btn {
    background: #334155;
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.action-btn:hover:not(:disabled) {
    background: #475569;
    transform: translateY(-2px);
}

.action-btn:active:not(:disabled) {
    transform: translateY(0);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-btn.active-mode {
    background: #38bdf8;
    color: #0f172a;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

#btn-special { background: #8b5cf6; }
#btn-special:hover:not(:disabled) { background: #a78bfa; }


#dice-display {
    padding: 15px;
    text-align: center;
    border-bottom: 1px solid var(--panel-border);
    background: rgba(0,0,0,0.1);
}

.dice {
    --pip: radial-gradient(circle, #111827 50%, transparent 55%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background-color: #ffffff;
    border: 2px solid #111827;
    border-radius: 8px;
    position: relative;
    margin: 0 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.35);
    background-repeat: no-repeat;
    vertical-align: middle;
}

.dice.die-1 { background-image: var(--pip); background-size: 12px 12px; background-position: center; }
.dice.die-2 { background-image: var(--pip), var(--pip); background-size: 10px 10px; background-position: 20% 20%, 80% 80%; }
.dice.die-3 { background-image: var(--pip), var(--pip), var(--pip); background-size: 10px 10px; background-position: 20% 20%, center, 80% 80%; }
.dice.die-4 { background-image: var(--pip), var(--pip), var(--pip), var(--pip); background-size: 10px 10px; background-position: 20% 20%, 80% 20%, 20% 80%, 80% 80%; }
.dice.die-5 { background-image: var(--pip), var(--pip), var(--pip), var(--pip), var(--pip); background-size: 10px 10px; background-position: 20% 20%, 80% 20%, center, 20% 80%, 80% 80%; }
.dice.die-6 { background-image: var(--pip), var(--pip), var(--pip), var(--pip), var(--pip), var(--pip); background-size: 10px 10px; background-position: 20% 20%, 80% 20%, 20% 50%, 80% 50%, 20% 80%, 80% 80%; }

.dice.die-waiting::before {
    content: "?";
    color: #111827;
    font-weight: 800;
    font-size: 1.5rem;
    background: none;
    width: auto;
    height: auto;
}

#dice-result {
    margin-top: 10px;
    font-weight: bold;
    font-size: 1.1rem;
    color: #fcd34d;
}

#suspense-panel {
    padding: 15px;
    text-align: center;
    border-bottom: 1px solid var(--panel-border);
    background: rgba(0,0,0,0.3);
    border-left: 3px solid #f59e0b;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

#suspense-title {
    color: #f59e0b;
    font-size: 1.1rem;
    margin-bottom: 5px;
}

#suspense-desc {
    font-size: 0.9rem;
    color: #cbd5e1;
    margin-bottom: 15px;
    line-height: 1.3;
}

#suspense-dice-area {
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

#suspense-panel .dice {
    width: 48px;
    height: 48px;
}

#btn-roll-dice {
    background: #f59e0b;
    color: #0f172a;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.2s;
    width: 100%;
}
#btn-roll-dice:hover { transform: scale(1.05); }

#benches {
    padding: 10px 15px;
    display: flex;
    gap: 10px;
    border-bottom: 1px solid var(--panel-border);
}

.bench {
    flex: 1;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 6px;
}

.bench h4 {
    font-size: 0.75rem;
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.bench-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    min-height: 20px;
}
.bench-slots .animal {
    font-size: 1.2rem;
}


#match-log-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 15px;
    overflow: hidden;
    min-height: 250px;
}

#match-log-container h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#match-log {
    flex: 1;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 12px;
    background: rgba(0,0,0,0.4);
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.1);
    color: #e2e8f0;
}

.log-entry { 
    margin-bottom: 12px; 
    border-left: 3px solid #475569; 
    padding-left: 10px; 
    padding-bottom: 4px;
}
.log-entry:last-child {
    font-weight: 600;
    color: #ffffff;
    background: rgba(255,255,255,0.05);
    border-radius: 0 4px 4px 0;
}
.log-entry.purple { border-color: var(--purple-team); }
.log-entry.green { border-color: var(--green-team); }
.log-entry.system { border-color: #fcd34d; color: #fcd34d; }
.log-entry.error { border-color: #ef4444; color: #fca5a5; }

.panel-footer {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #0f172a;
}

.control-btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    background: #10b981;
    color: white;
    transition: background 0.2s;
}

.control-btn:hover { background: #059669; }

.control-btn.secondary {
    background: transparent;
    border: 1px solid #475569;
    color: var(--text-muted);
    padding: 10px;
    font-size: 0.9rem;
}
.control-btn.secondary:hover { background: rgba(255,255,255,0.05); }


.hidden { display: none !important; }

/* Overlay */
#victory-overlay, #start-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#start-overlay {
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(4px);
}

#victory-overlay {
    background: rgba(0,0,0,0.35);
    backdrop-filter: none;
}

#victory-text {
    font-size: 4rem;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(255,255,255,0.5);
}

#start-text {
    font-size: 3rem;
    margin-bottom: 10px;
    color: #fcd34d;
    text-shadow: 0 0 20px rgba(0,0,0,0.5);
}

#start-desc {
    font-size: 1.5rem;
    margin-bottom: 25px;
    color: white;
}

#restart-btn-overlay, #btn-start-match {
    padding: 15px 30px;
    font-size: 1.5rem;
    background: #fcd34d;
    color: #0f172a;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s;
}

#btn-start-match {
    background: #10b981;
    color: white;
}

#restart-btn-overlay:hover, #btn-start-match:hover { transform: scale(1.05); }
#btn-start-match:hover { background: #059669; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* Responsive */
@media (max-width: 1500px) {
    #board-area { padding: 10px; }
    #grid-container { gap: 3px; padding: 6px; }
    #controls-panel { width: 330px; min-width: 330px; }
    #log-panel { width: 280px; min-width: 280px; }
    header { padding: 12px; }
    header h1 { font-size: 1.8rem; margin-bottom: 5px; }
    #selection-panel { padding: 10px; }
    #selected-info { margin-bottom: 10px; padding: 8px; }
    #dice-display { padding: 10px; }
    #suspense-panel { padding: 10px; }
    #benches { padding: 8px 10px; }
    #match-log-container { padding: 10px; min-height: 180px; }
    .panel-footer { padding: 10px; }
    .action-btn { padding: 8px; font-size: 0.95rem; }
    .board-score-label { font-size: clamp(1.5rem, 4vw, 3rem); }
    #btn-roll-dice { padding: 8px 15px; }
}

@media (orientation: landscape) and (max-width: 1600px) {
    #app-container {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 280px;
        grid-template-rows: minmax(0, 68vh) minmax(150px, 32vh);
        grid-template-areas:
            "board log"
            "controls log";
        height: 100vh;
        overflow: hidden;
    }
    @supports (height: 100dvh) {
        #app-container { height: 100dvh; }
    }
    
    #board-area {
        grid-area: board;
        padding: 5px;
        height: 100%;
        min-height: 0;
        overflow: hidden;
        align-items: center;
        justify-content: center;
    }
    
    #log-panel {
        grid-area: log;
        width: auto;
        min-width: 0;
        height: 100vh;
        max-height: 100vh;
        box-shadow: none;
        border-right: none;
        border-left: 1px solid var(--panel-border);
        display: grid;
        grid-template-rows: minmax(0, 52dvh) auto auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }
    @supports (height: 100dvh) {
        #log-panel { height: 100dvh; max-height: 100dvh; }
    }
    
    #controls-panel {
        grid-area: controls;
        width: 100%;
        min-width: 0;
        height: 100%;
        max-height: none;
        overflow-y: auto;
        overflow-x: hidden;
        box-shadow: 0 -5px 15px rgba(0,0,0,0.3);
        border-left: none;
        border-top: 1px solid var(--panel-border);
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-start;
        padding: 6px 8px;
        gap: 8px;
    }

    header { flex: 1; min-width: 200px; padding: 0; border: none; }
    header h1 { font-size: 1.4rem; margin-bottom: 2px; }
    #current-player { font-size: 1rem; margin-bottom: 2px; }
    .guidance-message { margin-top: 5px; padding: 6px; font-size: 0.85rem; }
    
    #selection-panel { flex: 2; min-width: 300px; padding: 0; border: none; display: flex; gap: 15px; align-items: center; }
    #selected-info { margin-bottom: 0; padding: 8px; gap: 10px; flex: 1; }
    #selected-emoji { font-size: 2rem; width: 40px; }
    #selected-name { font-size: 1rem; }
    .stats-grid { font-size: 0.8rem; gap: 3px; }
    
    #action-buttons { flex: 1; gap: 6px; }
    .action-btn { padding: 8px; font-size: 0.95rem; }
    
    #dice-display { flex: 1; min-width: 120px; padding: 8px; border: none; background: rgba(0,0,0,0.2); border-radius: 8px; }
    .dice { font-size: 1.5rem; }
    #dice-result { margin-top: 5px; font-size: 1rem; }
    
    #suspense-panel { flex: 1.5; min-width: 200px; padding: 8px; border-bottom: none; border-left: 3px solid #f59e0b; min-height: 110px; }
    #suspense-title { font-size: 1rem; margin-bottom: 3px; }
    #suspense-desc { font-size: 0.85rem; margin-bottom: 8px; }
    #btn-roll-dice { padding: 8px 15px; font-size: 1rem; }
    
    .panel-footer {
        display: flex;
        flex-direction: column;
        flex: none;
        min-height: 72px;
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 4px 6px 6px;
        background: transparent;
        border-top: 1px solid var(--panel-border);
        gap: 5px;
        overflow: visible;
    }
    .control-btn { display: block; padding: 7px 8px; font-size: 0.85rem; width: 100%; line-height: 1.1; }
    .control-btn.secondary { padding: 6px 8px; font-size: 0.78rem; }
    
    #benches { display: flex; flex-direction: row; gap: 4px; padding: 3px 6px; flex: none; min-height: 56px; max-height: none; overflow: hidden; }
    .bench { flex: 1; min-width: 0; padding: 3px; }
    .bench h4 { font-size: 0.6rem; margin-bottom: 1px; }
    .bench-slots { min-height: 38px; max-height: none; overflow: visible; gap: 4px; align-items: center; }
    .bench-slots .animal { width: 36px; height: 36px; flex: 0 0 36px; font-size: 1rem; overflow: visible; }
    .bench-slots .animal .emoji-inner { font-size: 1.55rem; }
    .bench-slots .animal::before { transform: scale(0.85); }
    #match-log-container { padding: 6px; flex: 1 1 auto; max-height: 52dvh; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
    #match-log-container h3 { margin-bottom: 4px; font-size: 0.75rem; }
    #match-log { padding: 6px; font-size: 0.78rem; line-height: 1.3; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
    .log-entry { margin-bottom: 5px; padding-left: 7px; padding-bottom: 2px; }
    
    #grid-container { 
        gap: 3px; padding: 6px; 
        height: min(100%, calc((100vw - 280px) * 9 / 13)); 
        width: auto; 
        max-width: 100%; 
        max-height: 100%;
        aspect-ratio: 13 / 9;
    }
    .board-score-label { font-size: clamp(1.2rem, 3vw, 2.5rem); opacity: 0.1; }
    #green-score-label { left: 10px; }
    #purple-score-label { right: 10px; }
    .emoji-inner { font-size: clamp(1.3rem, 3vw, 2.5rem); }
}

@media (max-width: 900px) {
    #app-container {
        flex-direction: column;
        display: flex;
        overflow-y: auto;
        height: auto;
    }
    
    #board-area {
        flex: none;
        height: auto;
        padding: 10px;
        order: 1;
    }
    
    #controls-panel {
        width: 100%;
        min-width: 100%;
        height: auto;
        border-left: none;
        border-top: 1px solid var(--panel-border);
        order: 2;
    }

    #log-panel {
        width: 100%;
        min-width: 100%;
        height: auto;
        border-right: none;
        border-top: 1px solid var(--panel-border);
        order: 3;
    }
    
    #match-log-container {
        min-height: 200px;
    }
}
