:root {
    --bg-color: #FFF8E1;
    --accent-red: #FF5252;
    --accent-wood: #5D4037;
    --text-dark: #3E2723;
}

body {
    margin: 0;
    background-color: var(--bg-color);
    background-image: radial-gradient(#EFEBE9 2px, transparent 2px);
    background-size: 20px 20px;
    font-family: 'Zen Maru Gothic', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
    user-select: none;
    color: var(--text-dark);
    touch-action: none; /* Prevents zooming/scrolling on mobile */
}

h1 {
    font-family: 'Mochiy Pop P One', sans-serif;
    font-size: 2.5rem;
    color: var(--accent-red);
    margin: 20px;
    text-shadow: 2px 2px 0px var(--text-dark);
    letter-spacing: 1px;
}

.subtitle {
    font-size: 1rem;
    margin-bottom: 30px;
    color: var(--accent-wood);
    font-weight: 700;
}

/* --- HUD --- */
#hud-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 10px;
    width: 100%;
    max-width: 600px;
    z-index: 2;
}

.stat-pill {
    background: #fff;
    border: 3px solid var(--accent-wood);
    border-radius: 50px;
    padding: 0px 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 4px 4px 0px rgba(0,0,0,0.1);
    min-width: 80px;
}

.stat-label {
    font-size: 10px;
    color: #888;
    font-weight: 900;
    text-transform: uppercase;
}

.stat-value {
    font-family: 'Mochiy Pop P One', sans-serif;
    font-size: 24px;
    color: var(--accent-wood);
    line-height: 1.2;
}

/* --- Game Box --- */
#game-container {
    position: relative;
    width: 95%; /* Responsive width */
    max-width: 600px;
    aspect-ratio: 600 / 400; 
    background: #fff;
    border: 6px solid var(--accent-wood);
    border-radius: 12px;
    box-shadow: 0px 10px 0px rgba(0,0,0,0.15);
    cursor: crosshair;
    overflow: hidden;
    touch-action: none;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* --- Floating Text --- */
.floating-text {
    position: absolute;
    font-family: 'Mochiy Pop P One', sans-serif;
    font-size: 24px;
    -webkit-text-stroke: 1px white; 
    animation: floatUp 0.8s ease-out forwards;
    pointer-events: none;
    z-index: 6;
    white-space: nowrap;
}

@keyframes floatUp {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-30px) scale(1); opacity: 0; }
}

/* --- Messages --- */
#message {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    text-align: center;
    font-family: 'Mochiy Pop P One', sans-serif;
    font-size: 24px;
    color: var(--accent-red);
    display: none;
    background: rgba(255, 255, 255, 0.98);
    padding: 20px;
    border: 4px solid var(--text-dark);
    border-radius: 16px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    z-index: 10;
    /* Make it clickable for restart */
    cursor: pointer;
}

/* --- Controls (Desktop) --- */
#controls {
    margin-top: 15px;
    display: flex;
    gap: 20px;
    opacity: 0.7;
}
.control-key { 
    display: inline-block; 
    background: #333; color: #fff; 
    padding: 2px 6px; border-radius: 4px; 
    font-weight: bold; font-family: monospace; font-size: 12px;
}

/* --- QUEUE SYSTEM --- */
#queue-display {
    position: absolute;
    top: 10px; 
    left: 50%;
    transform: translateX(-50%);
    width: 205px;
    height: 50px;
    background: rgba(255, 255, 255, 0.8); 
    border-radius: 8px;
    overflow: hidden; 
    z-index: 5;
    border: 4px solid var(--accent-wood);
}

#queue-track {
    display: flex;
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    transition: transform 0.1s ease-out; 
}

.queue-item {
    width: 50px; 
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Mochiy Pop P One', sans-serif;
    font-size: 24px;
    color: var(--accent-wood);
    border-right: 2px dashed rgba(0,0,0,0.1);
}

#queue-target-box {
    position: absolute;
    left: 0;
    top: 0;
    width: 46px;
    height: 43px; 
    border: 4px solid var(--accent-red);
    box-shadow: 0 0 10px rgba(255, 82, 82, 0.5);
    border-radius: 4px;
    pointer-events: none;
}

/* --- MOBILE CONTROLS (Unified) --- */
#mobile-controls {
    display: none; /* HIDDEN BY DEFAULT on Desktop */
    width: 95%;
    max-width: 600px;
    margin-top: 10px;
    gap: 10px;
    justify-content: center;
    z-index: 10;
}

#hammer-btn {
    flex: 2; /* Hammer button is larger */
    background-color: var(--accent-red);
    color: white;
    font-family: 'Mochiy Pop P One', sans-serif;
    font-size: 20px;
    border: 3px solid var(--text-dark);
    border-radius: 12px;
    padding: 20px 0;
    box-shadow: 0px 4px 0px var(--text-dark);
    cursor: pointer;
    text-transform: uppercase;
    touch-action: manipulation;
}

.hand-btn {
    flex: 1;
    background-color: #FFB74D; /* Orange */
    color: var(--text-dark);
    font-family: 'Zen Maru Gothic', sans-serif;
    font-weight: 900;
    font-size: 14px;
    border: 3px solid var(--text-dark);
    border-radius: 12px;
    box-shadow: 0px 4px 0px var(--text-dark);
    cursor: pointer;
}

#hammer-btn:active, .hand-btn:active {
    box-shadow: 0px 0px 0px var(--text-dark);
    transform: translateY(4px);
}

footer {
    margin-top: auto;
    padding: 10px;
    font-size: 10px;
    color: #999;
}

/* --- MOBILE & TOUCH OPTIMIZATIONS --- */

/* 1. Detect Touch Devices (No Hover) -> Switch to Mobile UI */
@media (hover: none) {
    #mobile-controls { display: flex; }
    #controls { display: none; } /* Hide keyboard instructions */
    
    /* HIDE THE TYPING PROMPT (QUEUE) ON MOBILE */
    #queue-display { display: none !important; }

    /* Scale down floating text on mobile & prevent wrapping */
    .floating-text { 
        font-size: 14px; 
        -webkit-text-stroke: 0px; 
        text-shadow: 1px 1px 0 #fff; 
        white-space: nowrap; /* Prevents "Combo Bonus" from breaking lines */
    }
    h1 { font-size: 1.8rem; }
    .subtitle { font-size: 0.8rem; }
}

/* 2. Landscape Mode Optimizations */
@media (max-height: 500px) and (orientation: landscape) {
    h1, .subtitle, footer { display: none; } /* Hide decoration to save space */
    #hud-container { margin-bottom: 5px; gap: 10px; }
    .stat-pill { padding: 0 10px; min-width: 60px; }
    .stat-value { font-size: 18px; }
    
    /* Make game container as big as possible */
    #game-container { 
        height: 80vh; 
        width: auto; /* Width auto to maintain aspect ratio */
        border-width: 4px;
    }
    #mobile-controls {
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
        width: 120px;
        height: 120px;
        margin: 0;
        flex-direction: column; /* Stack buttons in landscape */
    }
    #hammer-btn { transform: scale(0.9); font-size: 16px; line-height: 1.2; }
}