@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

:root {
    --bg: #c4bfaa;
    --text: #2a2a20;
    --text-secondary: #5a5a4a;
    --text-muted: #7a7a6a;
    --container-bg: #d4cfba;
    --container-border: #8a8570;
    --overlay-bg: rgba(196, 191, 170, 0.95);
    --pill-bg: #b8b3a0;
    --pill-active-bg: #e8e3d0;
    --pill-active-border: #6a6555;
    --console-bg: #d0cbb5;
    --console-border: #9a9580;
    --btn-bg: #5a8a3a;
    --btn-hover: #4a7a2a;
}

[data-theme="dark"] {
    --bg: #0e0e1a;
    --text: #c8c8d0;
    --text-secondary: #8888a0;
    --text-muted: #666678;
    --container-bg: #1a1a2e;
    --container-border: #3a3a55;
    --overlay-bg: rgba(14, 14, 26, 0.95);
    --pill-bg: #2a2a44;
    --pill-active-bg: #3a3a55;
    --pill-active-border: #5a5a77;
    --console-bg: #16162a;
    --console-border: #2a2a44;
    --btn-bg: #338833;
    --btn-hover: #44aa44;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Press Start 2P', monospace;
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Console shell — Game Boy style */
#console {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    max-width: 100%;
    background: var(--console-bg);
    border: 4px solid var(--console-border);
    border-radius: 12px;
    overflow: hidden;
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* Top section: header + screen */
.console-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 10px 10px;
    flex: 1;
    width: 100%;
    min-height: 0; /* important for flex children with overflow */
}

header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    margin-bottom: 6px;
    flex-shrink: 0;
}

header h1 {
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: 0.05em;
    color: var(--text);
    text-align: center;
    text-shadow: 2px 2px 0 var(--container-border);
}

/* Theme Toggle */
.theme-toggle {
    position: absolute;
    right: 0;
    width: 32px;
    height: 32px;
    border: 2px solid var(--container-border);
    border-radius: 0;
    background: var(--pill-bg);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.theme-toggle:active {
    background: var(--pill-active-bg);
}

.theme-icon-dark {
    display: none;
}

[data-theme="dark"] .theme-icon-light {
    display: none;
}

[data-theme="dark"] .theme-icon-dark {
    display: inline;
}

/* Game Container — fills available top space */
#game-container {
    position: relative;
    background: var(--container-bg);
    border: 3px solid var(--container-border);
    border-radius: 0;
    overflow: hidden;

    /* key: always square, driven by width */
    width: 100%;
    max-width: 100%;
    aspect-ratio: 1 / 1;

    /* allow flex parent to size properly */
    flex: 1;
    min-height: 0;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Game HUD — score + buttons */
.game-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 5;
}

.game-hud.visible {
    opacity: 1;
}

#score-display {
    font-size: 0.55rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.hud-buttons {
    display: flex;
    gap: 6px;
    pointer-events: auto;
}

.hud-btn {
    width: 30px;
    height: 30px;
    border: 2px solid var(--container-border);
    border-radius: 0;
    background: var(--pill-bg);
    color: var(--text);
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    opacity: 0.7;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.hud-btn:hover {
    opacity: 1;
}

.hud-btn:active {
    background: var(--pill-active-bg);
}

/* Overlays */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-bg);
    transition: opacity 0.3s ease;
    z-index: 10;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    padding: 24px;
    width: 100%;
    max-width: 90%;
}

.overlay-content h2 {
    font-size: 1.2rem;
    font-weight: 400;
    margin-bottom: 28px;
    color: var(--text);
    text-shadow: 2px 2px 0 var(--container-border);
}

/* Food Selector */
.food-selector {
    margin-bottom: 20px;
}

.food-selector p {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.8;
}

.food-options {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.food-option {
    cursor: pointer;
}

.food-option input {
    display: none;
}

.food-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 28px;
    border: 3px solid var(--container-border);
    background: var(--pill-bg);
    transition: background 0.15s ease, border-color 0.15s ease;
}

.food-option input:checked + .food-card {
    background: var(--pill-active-bg);
    border-color: var(--btn-bg);
}

.food-preview {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.food-card span {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55rem;
    color: var(--text-secondary);
}

.food-option input:checked + .food-card span {
    color: var(--text);
}

/* Speed Selector */
.speed-selector {
    margin-bottom: 24px;
}

.speed-selector p {
    font-size: 0.55rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.speed-options {
    display: flex;
    gap: 0;
    border: 2px solid var(--container-border);
    border-radius: 0;
}

.speed-option {
    flex: 1;
    cursor: pointer;
}

.speed-option input {
    display: none;
}

.speed-option span {
    display: block;
    padding: 8px 12px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5rem;
    color: var(--text-secondary);
    background: var(--pill-bg);
    border-right: 2px solid var(--container-border);
    text-align: center;
    transition: background 0.15s ease;
}

.speed-option:last-child span {
    border-right: none;
}

.speed-option input:checked + span {
    background: var(--pill-active-bg);
    color: var(--text);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 12px 24px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6rem;
    color: #fff;
    background: var(--btn-bg);
    border: 3px solid var(--container-border);
    border-radius: 0;
    cursor: pointer;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.4);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease;
}

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

.btn:active {
    transform: translate(1px, 1px);
}

/* Instructions */
.instructions {
    margin-top: 20px;
}

.instructions p {
    font-size: 0.45rem;
    color: var(--text-muted);
    line-height: 2;
}

/* Final Score */
.final-score {
    font-size: 0.7rem;
    color: var(--text);
    margin-bottom: 24px;
}

@media (max-width: 400px) {
    header h1 {
        font-size: 0.8rem;
    }
}
