:root {
    --bg-color: #0d0d0d;
    --surface-color: #1a1a1a;
    --primary-color: #00ff9d;
    /* Neon Green */
    --secondary-color: #ff0055;
    /* Neon Red */
    --text-color: #ffffff;
    --text-dim: #888888;

    --judge-perfect: #00e5ff;
    --judge-good: #00ff9d;
    --judge-ok: #ffaa00;
    --judge-miss: #ff0055;

    --font-main: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    height: 100vh;
    height: 100dvh;
    /* Mobile viewport fix */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#app {
    width: 100%;
    width: 100%;
    max-width: 1200px;
    height: 100%;
    position: relative;
    padding: 0;
    /* Remove default padding here, control in screen */
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
    /* Add safe padding */
    box-sizing: border-box;
}

.screen.active {
    display: flex;
    z-index: 10;
}

/* Typography */
h1.logo {
    font-size: 3rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-color), var(--judge-perfect));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-dim);
    margin-bottom: 2rem;
}

/* Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 300px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.9rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

input[type="number"] {
    background: var(--surface-color);
    border: 1px solid #333;
    color: white;
    padding: 10px;
    border-radius: 8px;
    font-size: 1.2rem;
    text-align: center;
}

.btn {
    border: none;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    width: 100%;
}

.btn:active {
    transform: scale(0.98);
}

.btn.primary {
    background: var(--primary-color);
    color: var(--bg-color);
}

.btn.secondary {
    background: transparent;
    border: 2px solid #333;
    color: var(--text-dim);
}

select.btn.secondary {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 30px !important;
}

option {
    background: var(--surface-color);
    color: var(--text-color);
}

.instruction {
    margin-top: 2rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    text-align: center;
}

/* Play Screen */
.top-bar {
    /* Changed from absolute to flow to prevent overlap */
    position: relative;
    top: auto;
    display: flex;
    gap: 1rem;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
    margin-bottom: 20px;
    /* Space below */
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-box .label {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.stat-box .value {
    font-size: 1.5rem;
    font-weight: 700;
}

.visualizer-container {
    width: 100%;
    height: 200px;
    background: var(--surface-color);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    margin: 2rem 0;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#visualizer,
#overlay-layer {
    position: absolute;
    top: 0;
    left: 0;
}

#overlay-layer {
    pointer-events: none;
    z-index: 2;
    /* On top of visualizer */
}

#target-line {
    display: none;
}

.feedback-area {
    height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.judge {
    font-size: 3rem;
    font-weight: 900;
    text-transform: uppercase;
    animation: pop 0.1s ease-out;
}

.offset {
    font-size: 1rem;
    margin-top: 0.5rem;
    font-family: monospace;
}

/* Judgement Colors */
.judge.perfect {
    color: var(--judge-perfect);
    text-shadow: 0 0 10px var(--judge-perfect);
}

.judge.great {
    color: #00ffea;
    text-shadow: 0 0 5px #00ffea;
}

/* Cyan-ish */
.judge.good {
    color: var(--judge-good);
}

.judge.bad {
    color: #b700ff;
}

/* Purple */
.judge.ok {
    color: var(--judge-ok);
}

.judge.miss {
    color: var(--judge-miss);
}

/* Result Screen */
.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 2rem 0;
    width: 100%;
}

.result-item {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
}

@keyframes pop {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Pattern Grid Styles */
.pattern-group {
    width: 100%;
    margin-bottom: 20px;
}

.pattern-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* 4 columns -> 4x4 */
    gap: 8px;
    margin-top: 10px;
    max-width: 300px;
    /* Constrain width */
    margin-left: auto;
    margin-right: auto;
}

.checkbox-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.checkbox-wrapper:hover {
    background: rgba(255, 255, 255, 0.1);
}

.checkbox-wrapper input {
    margin-bottom: 4px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary-color);
}


.checkbox-wrapper span {
    font-size: 0.75rem;
    color: #aaa;
}

/* Mobile Adjustments */
/* Mobile Adjustments */
@media (max-width: 600px) {
    body {
        /* Ensure scrolling if content is too tall */
        overflow-y: auto;
        justify-content: flex-start;
        /* Align top if overflows */
    }

    .screen {
        /* Allow scroll */
        position: relative;
        height: auto;
        min-height: 100dvh;
        padding: 50px 20px;
        /* More top/bottom padding for "Allowance" */
        justify-content: flex-start;
    }

    h1.logo {
        font-size: 1.8rem;
        margin-top: 10px;
    }

    .subtitle {
        margin-bottom: 1rem;
        font-size: 0.8rem;
    }

    .top-bar {
        gap: 0.5rem;
        justify-content: space-around;
        z-index: 50;
        /* High z-index */
        position: relative;
        margin-bottom: 20px;
        margin-top: 0;
        flex-wrap: wrap;
    }

    .stat-box .value {
        font-size: 1rem;
    }

    .stat-box .label {
        font-size: 0.6rem;
    }

    /* Compact Controls */
    .controls {
        gap: 1rem;
    }

    /* Make sliders larger for touch */
    input[type="range"] {
        height: 25px;
        /* Even taller hit area */
        position: relative;
        z-index: 21;
        touch-action: none;
    }

    /* Wrap pattern grid more aggressively */
    .pattern-group {
        width: 100%;
        margin-bottom: 10px;
    }

    .pattern-grid {
        gap: 4px;
        max-width: 100%;
    }

    .visualizer-container {
        height: 120px;
        /* Even smaller to save space */
        margin: 1rem 0;
    }

    .feedback-area {
        height: 60px;
        /* Reduced from 100px */
    }

    .judge {
        font-size: 2rem;
    }

    .btn {
        padding: 12px 20px;
        font-size: 0.9rem;
    }
}