:root {
    --bg-color: #1a1a2e;
    --grid-bg: #16213e;
    --wall-color: #0f3460;
    --floor-color: #1a1a2e;
    --target-color: #e94560;
    --box-color: #fca311;
    --box-on-target: #4cc9f0;
    --player-color: #ffffff;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --font-main: 'Outfit', sans-serif;
    --cell-size: min(10vw, 50px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.screen.active {
    display: flex;
    z-index: 10;
}

/* Start Screen */
#start-screen {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    text-align: center;
    padding: 2rem;
}

h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.highlight {
    color: var(--accent);
}

.input-group {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

input {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    padding: 1rem;
    border-radius: 12px;
    color: white;
    font-size: 1.2rem;
    text-align: center;
    font-family: var(--font-main);
    outline: none;
    transition: border-color 0.3s;
    width: 250px;
}

input:focus {
    border-color: var(--accent);
}

button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    font-family: var(--font-main);
    transition: transform 0.1s, opacity 0.2s;
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

button:active {
    transform: scale(0.95);
}

/* HUD - Compact Top Right */
#game-ui {
    /* Remove padding that pushed it down, let it be full screen relative */
    padding-top: 0;
    justify-content: center;
    /* Center the board */
}

.header {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: 10px;
    width: auto;
    max-width: 35%;
    /* User requested ~30% */
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border-radius: 10px;
    /* margin-bottom removed as it is absolute */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    z-index: 20;
    pointer-events: none;
    /* Let clicks pass through if needed, though buttons need events */
}

.header .info-block {
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
}

.header .label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-right: 8px;
}

.header .value {
    font-size: 0.9rem;
    font-weight: 700;
}

.header #restart-btn {
    pointer-events: auto;
    font-size: 1.2rem;
    padding: 0;
    align-self: flex-end;
    margin-top: 5px;
}

/* Adjust Game Board Layout to not be covered by header if possible, 
   but user asked for header "inside/overlay". 
   We center the board. */


/* Game Board */
#game-container {
    display: grid;
    gap: 1px;
    background: var(--grid-bg);
    padding: 10px;
    border-radius: 10px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    position: relative;
    touch-action: none;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: transform 0.15s ease, background-color 0.2s;
    font-size: calc(var(--cell-size) * 0.6);
}

.wall {
    background-color: var(--wall-color);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.floor {
    background-color: var(--floor-color);
}

.target {
    background-color: var(--floor-color);
}

.target::after {
    content: '';
    width: 30%;
    height: 30%;
    background: var(--target-color);
    border-radius: 50%;
    opacity: 0.5;
    box-shadow: 0 0 10px var(--target-color);
}

/* Entities */
.entity {
    position: absolute;
    width: var(--cell-size);
    height: var(--cell-size);
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.player {
    z-index: 10;
}

.player-inner {
    width: 70%;
    height: 70%;
    background: var(--player-color);
    border-radius: 50%;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.6);
}

.box {
    z-index: 5;
}

.box-inner {
    width: 85%;
    height: 85%;
    background: var(--box-color);
    border-radius: 6px;
    border: 2px solid rgba(0, 0, 0, 0.2);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s;
}

.box.on-target .box-inner {
    background: var(--box-on-target);
    box-shadow: 0 0 15px var(--box-on-target);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity 0.3s;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: #1a1a2e;
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    animation: slideUp 0.3s forwards;
}

@keyframes slideUp {
    to {
        transform: translateY(0);
    }
}

.stats {
    display: flex;
    justify-content: space-around;
    margin: 2rem 0;
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 12px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.stat strong {
    font-size: 1.5rem;
    color: var(--accent);
}

.controls-hint {
    margin-top: 1rem;
    /* Adjust margin */
    margin-bottom: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    opacity: 0.6;
}

/* D-Pad Controls */
#controls-area {
    margin-top: auto;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    width: 100%;
}

.d-pad {
    display: grid;
    grid-template-columns: 60px 60px 60px;
    grid-template-rows: 60px 60px;
    gap: 5px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.d-btn {
    width: 60px;
    height: 60px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
    transition: transform 0.1s, background-color 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.d-btn:active {
    transform: translateY(4px);
    box-shadow: none;
    background: var(--accent);
}

.d-btn.up {
    grid-column: 2;
    grid-row: 1;
}

.d-btn.left {
    grid-column: 1;
    grid-row: 2;
}

.d-btn.down {
    grid-column: 2;
    grid-row: 2;
}

.d-btn.right {
    grid-column: 3;
    grid-row: 2;
}

/* Desktop override to hide if preferred, but user asked for it */
@media (min-width: 768px) {
    /* Optional: Make it smaller on desktop or keep as is for touch laptops */
}