:root {
    --primary-color: #ff3333;
    --secondary-color: #666666;
    --accent-color: #ffd700;
    --bg-dark: rgba(0, 0, 0, 0.7);
    --glass-bg: rgba(255, 255, 255, 0.15);
    --font-main: 'DotGothic16', 'Noto Sans JP', sans-serif;
    --font-heading: 'Noto Sans JP', sans-serif;
}

body {
    margin: 0;
    padding: 0;
    background-color: #1a1a2e;
    color: white;
    font-family: var(--font-main);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    touch-action: manipulation;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    height: 100vh;
    max-height: 700px;
    background-color: #000;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
}

#game-container::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.04) 0,
        rgba(255, 255, 255, 0.04) 1px,
        transparent 1px,
        transparent 4px
    );
    opacity: 0.28;
    z-index: 8;
}

@media (max-width: 450px) {
    #game-container {
        max-height: 100vh;
        border: none;
    }
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* Typography & Titles */
#title {
    position: absolute;
    top: 15%;
    width: 100%;
    font-family: var(--font-heading);
    font-size: 64px;
    line-height: 0.9;
    color: var(--primary-color);
    text-shadow: 
        0 4px 0 #800,
        0 8px 15px rgba(255, 51, 51, 0.4);
    text-align: center;
    margin: 0;
    font-weight: 900;
    letter-spacing: 0;
}

#instruction {
    position: absolute;
    top: 45%;
    width: 100%;
    text-align: center;
    font-size: 16px;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.highlight {
    display: inline-block;
    margin-top: 10px;
    color: var(--accent-color);
    font-size: 20px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* HUD (In-game UI) */
#hud {
    position: absolute;
    top: 20px;
    left: 20px;
    display: none;
    flex-direction: column;
    gap: 5px;
    pointer-events: none;
}

.label {
    font-size: 10px;
    color: rgba(255,255,255,0.6);
    letter-spacing: 1px;
}

#score-display {
    font-size: 32px;
    color: #fff;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

#best-time-display {
    font-size: 16px;
    color: var(--accent-color);
}

/* Buttons */
button {
    pointer-events: auto;
    font-family: var(--font-main);
    padding: 15px 50px;
    font-size: 24px;
    background: linear-gradient(to bottom, #ff5555, #ff3333);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 
        0 6px 0 #900,
        0 10px 20px rgba(0,0,0,0.3);
    transition: all 0.1s;
}

button:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #900;
}

button.secondary {
    background: var(--secondary-color);
    box-shadow: 0 6px 0 #333;
}

#start-btn {
    position: absolute;
    top: 65%;
    left: 50%;
    transform: translateX(-50%);
}

#pause-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    padding: 0;
    border-radius: 15px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: none;
    border: 1px solid rgba(255,255,255,0.2);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 20;
}

#pause-btn span {
    font-size: 18px;
    margin-top: -2px;
}

/* Screens */
#pause-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    pointer-events: auto;
}

#pause-screen h2 {
    font-size: 48px;
    color: #fff;
    margin: 0 0 20px 0;
}

@keyframes flash {
    from { opacity: 0.5; }
    to { opacity: 1; }
}

.back-link {
    margin-top: 20px;
    color: rgba(255,255,255,0.4);
    text-decoration: none;
    font-size: 12px;
}

/* Popups */
#milestone-display, #in-game-new-record {
    position: absolute;
    top: 35%;
    left: 50%;
    width: 100%;
    text-align: center;
    pointer-events: none;
    display: none;
    transform: translateX(-50%);
    font-size: 40px;
    color: var(--accent-color);
    font-weight: 900;
    text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
    z-index: 10;
}

#in-game-new-record {
    color: var(--primary-color);
    font-size: 36px;
    text-shadow: 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff;
}

#run-flash {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    background:
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.35), transparent 28%),
        rgba(255, 40, 40, 0.18);
    z-index: 9;
}

#run-flash.show {
    animation: retryFlash 0.45s ease-out forwards;
}

@keyframes popUp {
    0% { transform: translate(-50%, 40px) scale(0.5); opacity: 0; }
    20% { transform: translate(-50%, 0) scale(1.1); opacity: 1; }
    80% { transform: translate(-50%, -10px) scale(1.0); opacity: 1; }
    100% { transform: translate(-50%, -30px) scale(1.0); opacity: 0; }
}

@keyframes retryFlash {
    0% { opacity: 0; transform: scale(0.96); }
    25% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.08); }
}
