/* ==========================================================================
   RangeTyper - Main Stylesheet
   Layout: Grid (macro) + Flexbox (component) per STANDARDS.md
   Design: Tablet-first, arcade aesthetic with CRT/neon vibes
   ========================================================================== */

/* -- Custom Properties: Central theme config for arcade look -- */
:root {
    --bg-primary: #0a0a12;
    --bg-secondary: #12121f;
    --bg-tertiary: #1a1a2e;
    --text-primary: #e0e0ff;
    --text-secondary: #8888aa;
    --text-dim: #555577;
    --accent-cyan: #00f0ff;
    --accent-magenta: #ff00aa;
    --accent-yellow: #ffee00;
    --accent-green: #00ff88;
    --accent-red: #ff2244;
    --accent-orange: #ff8800;
    --accent-purple: #aa44ff;
    --glow-cyan: 0 0 10px #00f0ff, 0 0 30px #00f0ff44;
    --glow-magenta: 0 0 10px #ff00aa, 0 0 30px #ff00aa44;
    --glow-yellow: 0 0 10px #ffee00, 0 0 30px #ffee0044;
    --font-main: 'Courier New', 'Consolas', monospace;
    --font-display: 'Courier New', 'Consolas', monospace;
    --lane-width: 60px;
    --hit-zone-y: 85%;
    --transition-fast: 0.15s ease;
    --transition-med: 0.3s ease;
    --border-arcade: 2px solid #333355;
}

/* -- Reset & Base -- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    height: 100%;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    /* WHY: CRT scanline overlay for arcade feel */
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.15) 2px,
            rgba(0, 0, 0, 0.15) 4px
        );
}

/* -- App Shell: Grid macro-layout -- */
/* WHY: Grid defines 3 vertical regions - header, main content, footer */
.app-shell {
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "title"
        "main"
        "footer";
    height: 100vh;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* -- Region: Title Bar -- */
.region-title {
    grid-area: title;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem;
    border-bottom: var(--border-arcade);
    background: var(--bg-secondary);
}

.logo {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: 0.15em;
    color: var(--accent-cyan);
    text-shadow: var(--glow-cyan);
    text-transform: uppercase;
}

.logo-accent {
    color: var(--accent-magenta);
    text-shadow: var(--glow-magenta);
}

.status-bar {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* -- Region: Main Content -- */
.region-main {
    grid-area: main;
    position: relative;
    overflow: hidden;
}

/* -- Region: Footer -- */
.region-footer {
    grid-area: footer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 1rem;
    border-top: var(--border-arcade);
    background: var(--bg-secondary);
    font-size: 0.65rem;
    color: var(--text-dim);
}

/* ==========================================================================
   SCENE SYSTEM
   WHY: Only one scene visible at a time, transitions between them
   ========================================================================== */

/* WHY: Scenes use display:none/flex for reliable hiding.
   Opacity transition still runs via the .scene-enter class for fade-in */
.scene {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    padding: 1rem;
    transition: opacity var(--transition-med);
}

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

/* ==========================================================================
   MENU SYSTEM
   WHY: Keyboard-navigable arcade menus with visual focus indicators
   ========================================================================== */

.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    width: 100%;
    max-width: 600px;
}

.ascii-title {
    font-size: 0.55rem;
    line-height: 1.1;
    color: var(--accent-cyan);
    text-shadow: var(--glow-cyan);
    text-align: center;
    white-space: pre;
    user-select: none;
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
    max-width: 350px;
}

.menu-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    font-family: var(--font-display);
    font-size: 1.1rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 2px;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
    text-align: center;
}

.menu-item:hover,
.menu-item.focused {
    color: var(--accent-cyan);
    background: rgba(0, 240, 255, 0.05);
    border-color: var(--accent-cyan);
    text-shadow: var(--glow-cyan);
}

.menu-item.focused::before {
    content: '\25B6';
    color: var(--accent-cyan);
    animation: menu-pulse 0.8s ease-in-out infinite alternate;
}

.menu-item.disabled {
    color: var(--text-dim);
    cursor: default;
}

.menu-item.disabled.focused {
    color: var(--text-dim);
    border-color: #333355;
    text-shadow: none;
    background: transparent;
}

@keyframes menu-pulse {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

.menu-footer {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.key-hint {
    font-size: 0.7rem;
    color: var(--text-dim);
    letter-spacing: 0.05em;
}

.key-hint kbd {
    color: var(--accent-yellow);
}

/* -- Scene Headings -- */
.scene-heading {
    font-family: var(--font-display);
    font-size: 2rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent-cyan);
    text-shadow: var(--glow-cyan);
    text-align: center;
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   DIFFICULTY SELECT
   ========================================================================== */

.difficulty-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    gap: 1.5rem;
}

/* WHY: Beat analysis info shows kick/snare counts so the player
   understands what each difficulty level maps to */
.beat-analysis-info {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--bg-tertiary);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.02);
}

.beat-info-title {
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    text-transform: uppercase;
    text-align: center;
    margin-bottom: 0.25rem;
}

/* WHY: Detected tempo badge sits inline in the analysis title */
.beat-info-bpm {
    color: var(--accent-cyan);
    font-weight: bold;
    margin-left: 0.4rem;
}

.beat-info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.5rem;
    border-radius: 2px;
}

.beat-info-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.beat-info-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.beat-info-dot.kick { background: var(--accent-magenta); box-shadow: 0 0 6px var(--accent-magenta); }
.beat-info-dot.snare { background: var(--accent-cyan); box-shadow: 0 0 6px var(--accent-cyan); }

.beat-info-count {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
}

.diff-description {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-align: center;
    margin-top: -0.5rem;
    min-height: 1.2rem;
}

/* ==========================================================================
   SONG SELECT / UPLOAD
   ========================================================================== */

.song-select-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    gap: 1.5rem;
}

.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 2rem;
    border: 2px dashed var(--text-dim);
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.upload-zone:focus,
.upload-zone.focused,
.upload-zone.dragover {
    border-color: var(--accent-cyan);
    background: rgba(0, 240, 255, 0.05);
    box-shadow: var(--glow-cyan);
}

.upload-icon {
    font-size: 3rem;
    color: var(--accent-magenta);
    text-shadow: var(--glow-magenta);
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.upload-sub {
    font-size: 0.75rem !important;
    color: var(--text-dim) !important;
}

.song-library {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
}

.song-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: 2px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.song-item.focused {
    color: var(--accent-cyan);
    border-color: var(--accent-cyan);
    background: rgba(0, 240, 255, 0.05);
    text-shadow: var(--glow-cyan);
}

.song-item-title { flex: 1; }

.song-item-duration {
    color: var(--text-dim);
    font-size: 0.75rem;
}

.analysis-status {
    width: 100%;
    text-align: center;
}

.analysis-status.hidden { display: none; }

.analysis-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.analysis-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta));
    transition: width 0.3s ease;
}

.analysis-text {
    font-size: 0.8rem;
    color: var(--accent-yellow);
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ==========================================================================
   GAME AREA
   ========================================================================== */

.game-container {
    position: relative;
    width: 100%;
    height: 100%;
}

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

/* -- HUD Overlay -- */
.game-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem 1.5rem;
    z-index: 10;
    pointer-events: none;
}

.game-hud > div {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hud-label {
    font-size: 0.6rem;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    text-transform: uppercase;
}

.hud-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-shadow: 0 0 8px rgba(255,255,255,0.3);
}

.hud-combo-number {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--accent-yellow);
    text-shadow: var(--glow-yellow);
    transition: transform 0.1s ease;
}

.hud-combo-number.bump {
    transform: scale(1.3);
}

/* -- Judgment Display -- */
.judgment-display {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    pointer-events: none;
    opacity: 0;
    z-index: 20;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.judgment-display.show {
    opacity: 1;
}

.judgment-display.perfect {
    color: var(--accent-cyan);
    text-shadow: var(--glow-cyan);
}

.judgment-display.great {
    color: var(--accent-green);
    text-shadow: 0 0 10px #00ff88, 0 0 30px #00ff8844;
}

.judgment-display.good {
    color: var(--accent-yellow);
    text-shadow: var(--glow-yellow);
}

.judgment-display.miss {
    color: var(--accent-red);
    text-shadow: 0 0 10px #ff2244, 0 0 30px #ff224444;
}

/* ==========================================================================
   RESULTS SCREEN
   ========================================================================== */

.results-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 500px;
}

.results-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    width: 100%;
}

.result-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem;
    border: 1px solid var(--bg-tertiary);
    border-radius: 4px;
}

.result-stat-label {
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    text-transform: uppercase;
}

.result-stat-value {
    font-size: 1.8rem;
    font-weight: 700;
}

.results-grade {
    font-family: var(--font-display);
    font-size: 6rem;
    font-weight: 900;
    text-align: center;
}

.grade-s { color: var(--accent-cyan); text-shadow: var(--glow-cyan); }
.grade-a { color: var(--accent-green); text-shadow: 0 0 15px #00ff88; }
.grade-b { color: var(--accent-yellow); text-shadow: var(--glow-yellow); }
.grade-c { color: var(--accent-orange); text-shadow: 0 0 15px #ff8800; }
.grade-f { color: var(--accent-red); text-shadow: 0 0 15px #ff2244; }

/* ==========================================================================
   HI-SCORES
   ========================================================================== */

.hiscores-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    gap: 1rem;
}

.hiscores-table {
    width: 100%;
}

.hiscore-row {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #222244;
    font-size: 0.85rem;
    transition: background var(--transition-fast);
}

.hiscore-row.highlight {
    background: rgba(0, 240, 255, 0.08);
    border-color: var(--accent-cyan);
}

.hiscore-rank {
    width: 2.5rem;
    font-weight: 700;
    color: var(--text-dim);
}

.hiscore-rank.gold { color: #ffd700; text-shadow: 0 0 8px #ffd70066; }
.hiscore-rank.silver { color: #c0c0c0; text-shadow: 0 0 8px #c0c0c066; }
.hiscore-rank.bronze { color: #cd7f32; text-shadow: 0 0 8px #cd7f3266; }

.hiscore-name {
    flex: 1;
    color: var(--text-primary);
    letter-spacing: 0.1em;
}

.hiscore-score {
    width: 6rem;
    text-align: right;
    font-weight: 700;
    color: var(--accent-yellow);
}

.hiscore-song {
    width: 8rem;
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   SETTINGS
   ========================================================================== */

.settings-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    gap: 1rem;
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border: 1px solid transparent;
    border-radius: 2px;
    transition: all var(--transition-fast);
}

.setting-item.focused {
    border-color: var(--accent-cyan);
    background: rgba(0, 240, 255, 0.05);
}

.setting-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
}

.setting-value {
    font-size: 0.85rem;
    color: var(--accent-yellow);
    min-width: 4rem;
    text-align: right;
}

/* ==========================================================================
   UTILITIES & ANIMATIONS
   ========================================================================== */

/* WHY: Screen shake effect triggered on misses or big combos */
.shake {
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

/* WHY: Flash overlay for big hits */
.screen-flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    opacity: 0;
    animation: flash 0.2s ease-out;
}

@keyframes flash {
    from { opacity: 0.3; }
    to { opacity: 0; }
}

/* -- Scrollbar Styling -- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ==========================================================================
   NAME ENTRY (Arcade-style 3-letter initials input)
   ========================================================================== */

.name-entry {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.name-entry-prompt {
    font-size: 1.2rem;
    color: var(--accent-yellow);
    text-shadow: var(--glow-yellow);
    letter-spacing: 0.15em;
    animation: blink 1s step-end infinite;
}

.name-entry-chars {
    display: flex;
    gap: 1rem;
}

.name-char {
    width: 3rem;
    height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 900;
    border-bottom: 3px solid var(--text-dim);
    color: var(--text-primary);
}

.name-char.active {
    border-bottom-color: var(--accent-cyan);
    color: var(--accent-cyan);
    text-shadow: var(--glow-cyan);
}

/* ==========================================================================
   RESPONSIVE: Tablet-first breakpoints
   WHY: Per STANDARDS.md, tablet-first with mobile as priority
   ========================================================================== */

/* Mobile portrait */
@media (max-width: 600px) {
    .app-shell {
        grid-template-rows: auto 1fr auto;
    }

    .logo { font-size: 1.1rem; }

    .ascii-title { font-size: 0.35rem; }

    .menu-item { font-size: 0.9rem; padding: 0.6rem 1rem; }

    .hud-value { font-size: 1.1rem; }
    .hud-combo-number { font-size: 1.8rem; }

    .game-hud { padding: 0.5rem 0.75rem; }

    .scene-heading { font-size: 1.4rem; }

    .results-grade { font-size: 4rem; }

    .hiscore-song { display: none; }
}

/* Desktop */
@media (min-width: 1024px) {
    .ascii-title { font-size: 0.7rem; }

    .menu-item { font-size: 1.2rem; }

    .hud-combo-number { font-size: 3rem; }
}

/* ==========================================================================
   AURORA THEME OVERRIDES + STUDIO
   ========================================================================== */
:root {
    --bg-primary: #050a12;
    --bg-secondary: #0a121c;
    --bg-tertiary: #122331;
    --text-primary: #effffb;
    --text-secondary: #9bbcb8;
    --text-dim: #597477;
    --accent-cyan: #66f6d1;
    --accent-magenta: #ff72bd;
    --accent-yellow: #ffd166;
    --accent-green: #72f2a4;
    --accent-purple: #b89cff;
    --glow-cyan: 0 0 12px #66f6d1, 0 0 34px #66f6d144;
    --glow-magenta: 0 0 12px #ff72bd, 0 0 34px #ff72bd44;
    --border-arcade: 1px solid rgba(141, 255, 225, .16);
}
body {
    position: relative;
    background-color: var(--bg-primary);
    background-image:
        linear-gradient(118deg, transparent 0 17%, rgba(53, 255, 176, .08) 30%, transparent 43%),
        linear-gradient(72deg, transparent 8%, rgba(78, 170, 255, .08) 28%, rgba(255, 84, 190, .05) 44%, transparent 62%);
}
body::before {
    content: '';
    position: fixed;
    inset: -25% -10% 20%;
    pointer-events: none;
    background: linear-gradient(105deg, transparent 12%, rgba(43, 255, 165, .16) 26%, rgba(68, 214, 255, .1) 39%, transparent 52%, rgba(255, 80, 191, .1) 68%, transparent 82%);
    filter: blur(42px);
    transform: skewY(-6deg);
    animation: aurora-drift 14s ease-in-out infinite alternate;
}
@keyframes aurora-drift { from { transform: translateX(-4%) skewY(-6deg); opacity: .65; } to { transform: translateX(5%) skewY(1deg); opacity: 1; } }
.app-shell { max-width: 1440px; position: relative; background: rgba(3, 10, 16, .38); border-inline: 1px solid rgba(141,255,225,.08); }
.region-title, .region-footer { background: rgba(5, 14, 22, .78); backdrop-filter: blur(18px); }
.logo { letter-spacing: .08em; }
.scene-heading { letter-spacing: .12em; }
.menu-item { border-radius: 6px; letter-spacing: .06em; }
.menu-item:hover, .menu-item.focused, .setting-item.focused, .song-item.focused { background: rgba(102,246,209,.08); }
.upload-zone { background: rgba(8, 22, 30, .46); border-color: rgba(102,246,209,.32); border-radius: 6px; }
.beat-analysis-info, .result-stat { background: rgba(8,22,30,.58); border-color: rgba(102,246,209,.14); backdrop-filter: blur(12px); }

.scene-studio { align-items: stretch; padding: 0; }
.studio-shell { width: 100%; height: 100%; min-height: 0; display: grid; grid-template-rows: auto 1fr; background: rgba(3,10,16,.82); }
.studio-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .65rem 1rem; border-bottom: 1px solid rgba(102,246,209,.18); background: rgba(8,19,27,.9); }
.studio-kicker { display: block; color: var(--accent-green); font-size: .62rem; font-weight: 700; letter-spacing: .12em; }
.studio-title { width: min(320px,35vw); border: 0; border-bottom: 1px solid transparent; background: transparent; color: var(--text-primary); font: 700 1.15rem var(--font-main); padding: .25rem 0; outline: none; }
.studio-title:focus { border-color: var(--accent-green); }
.studio-transport { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
button, input, select { font-family: inherit; }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid rgba(102,246,209,.2); border-radius: 6px; color: var(--text-primary); background: #10212b; cursor: pointer; font-weight: 700; }
.icon-button:hover { border-color: var(--accent-green); color: var(--accent-green); }
.transport-play { color: #05110e; background: var(--accent-green); }
.studio-number { display: flex; align-items: center; gap: .35rem; color: var(--text-dim); font-size: .62rem; font-weight: 700; }
.studio-number input { width: 58px; height: 36px; border: 1px solid rgba(102,246,209,.2); border-radius: 5px; background: #08151e; color: var(--text-primary); padding: .4rem; }
.studio-command, .sample-upload { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: .5rem .8rem; border: 1px solid var(--accent-green); border-radius: 5px; background: rgba(102,246,209,.08); color: var(--accent-green); font-size: .68rem; font-weight: 700; cursor: pointer; }
.studio-body { min-height: 0; display: grid; grid-template-columns: 240px minmax(0,1fr); }
.track-panel { min-height: 0; display: flex; flex-direction: column; border-right: 1px solid rgba(102,246,209,.14); background: rgba(8,18,26,.9); }
.track-panel-head { height: 47px; padding: .4rem .7rem; display: flex; align-items: center; justify-content: space-between; font-size: .68rem; color: var(--text-dim); }
.track-list { overflow-y: auto; flex: 1; }
.studio-track { border-top: 1px solid rgba(255,255,255,.05); border-left: 3px solid transparent; padding: .5rem; }
.studio-track.selected { border-left-color: var(--track-color); background: rgba(255,255,255,.035); }
.track-select { width: 100%; display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: .45rem; border: 0; background: transparent; color: var(--text-primary); text-align: left; cursor: pointer; }
.track-select i { width: 8px; height: 8px; border-radius: 50%; background: var(--track-color); box-shadow: 0 0 8px var(--track-color); }
.track-select small { color: var(--text-dim); font-size: .55rem; }
.track-controls { display: grid; grid-template-columns: 28px 1fr 55px 25px; gap: .25rem; margin-top: .5rem; }
.track-controls button, .track-controls select { height: 26px; border: 1px solid rgba(255,255,255,.1); border-radius: 4px; background: #0b1922; color: var(--text-secondary); font-size: .6rem; }
.track-mute.active { color: #08120f !important; background: var(--accent-yellow) !important; }
.track-controls input { min-width: 0; accent-color: var(--track-color); }
.sample-upload { margin: .65rem; border-color: rgba(105,183,255,.5); color: #8ec9ff; }
.roll-area { min-width: 0; min-height: 0; display: grid; grid-template-rows: 32px minmax(0,1fr) 30px; overflow: hidden; }
.roll-ruler { margin-left: 72px; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: center; color: var(--text-dim); font-size: .58rem; background: #08131b; }
.roll-ruler span { padding-left: .4rem; border-left: 1px solid rgba(102,246,209,.18); }
.piano-roll-wrap { position: relative; min-height: 0; display: grid; grid-template-columns: 72px minmax(720px,1fr); overflow: auto; background: #060e15; }
.piano-keyboard { position: sticky; left: 0; z-index: 3; display: grid; grid-template-rows: repeat(13, minmax(30px,1fr)); background: #0b1821; }
.piano-keyboard div { display: flex; align-items: center; justify-content: flex-end; padding-right: .45rem; border-bottom: 1px solid #172b35; color: var(--text-secondary); font-size: .6rem; }
.piano-keyboard .black { background: #03080c; color: #789095; }
.piano-grid { display: grid; grid-template-columns: repeat(var(--steps), minmax(22px,1fr)); grid-template-rows: repeat(13,minmax(30px,1fr)); }
.roll-cell { min-width: 0; border: 0; border-right: 1px solid rgba(114,155,164,.1); border-bottom: 1px solid rgba(114,155,164,.1); background: rgba(255,255,255,.012); cursor: crosshair; }
.roll-cell.beat { border-left: 1px solid rgba(102,246,209,.25); }
.roll-cell:hover { background: rgba(102,246,209,.13); }
.roll-cell.active { margin: 4px 2px; border: 1px solid var(--track-color); border-radius: 3px; background: var(--track-color); box-shadow: 0 0 11px color-mix(in srgb,var(--track-color) 60%,transparent); }
.studio-playhead { position: absolute; z-index: 5; top: 0; bottom: 0; left: 72px; width: 2px; background: var(--accent-yellow); pointer-events: none; box-shadow: 0 0 8px var(--accent-yellow); }
.studio-legend { display: flex; justify-content: space-between; align-items: center; padding: 0 .7rem; color: var(--text-dim); font-size: .58rem; border-top: 1px solid rgba(102,246,209,.12); }
@media (max-width: 780px) {
    .studio-header { align-items: flex-start; }
    .studio-body { grid-template-columns: 170px minmax(0,1fr); }
    .track-controls { grid-template-columns: 28px 1fr 25px; }
    .track-controls input { display: none; }
    .studio-number { display: none; }
    .studio-command { font-size: .58rem; }
    .studio-legend span:last-child { display: none; }
}
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } }
/* STUDIO INTERACTION UPGRADE */
#studio-loop.active {
    color: #06120e;
    background: var(--accent-green);
    border-color: var(--accent-green);
    box-shadow: 0 0 14px rgba(114,242,164,.4);
}
.track-heading {
    display: grid;
    grid-template-columns: 26px 18px minmax(0,1fr);
    align-items: center;
    gap: .3rem;
}
.track-visibility {
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 4px;
    color: var(--track-color);
    background: transparent;
    cursor: pointer;
    font-size: .9rem;
}
.track-hidden .track-visibility { color: var(--text-dim); }
.track-hidden .track-select { opacity: .48; }
.track-color {
    position: relative;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--track-color);
    box-shadow: 0 0 8px var(--track-color);
    cursor: pointer;
    overflow: hidden;
}
.track-color input {
    position: absolute;
    width: 30px;
    height: 30px;
    inset: -8px;
    opacity: 0;
    cursor: pointer;
}
.track-select {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    align-items: center;
    gap: .4rem;
}
.track-select span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.track-controls { grid-template-columns: 28px minmax(72px,1fr) 55px 25px; }
.piano-roll-wrap { cursor: default; }
.piano-roll-wrap.panning { cursor: grabbing; user-select: none; }
.piano-grid {
    position: relative;
    width: max-content;
    margin-right: 52px;
    grid-template-columns: repeat(var(--steps), var(--cell-width, 28px));
}
.roll-ruler {
    width: max-content;
    grid-template-columns: repeat(var(--bars), var(--bar-width));
    grid-auto-flow: row;
}
.roll-cell {
    position: relative;
    overflow: hidden;
}
.roll-layer {
    position: relative;
    display: inline-block;
    width: 4px;
    height: calc(100% - 10px);
    margin: 5px 1px;
    border-radius: 2px;
    opacity: .38;
    box-shadow: 0 0 6px currentColor;
    pointer-events: none;
}
.roll-cell.active .roll-layer { opacity: .55; }
.studio-extend {
    position: absolute;
    z-index: 6;
    top: 50%;
    width: 36px;
    height: 52px;
    transform: translateY(-50%);
    border: 1px solid var(--accent-green);
    border-radius: 5px;
    color: var(--accent-green);
    background: rgba(8,25,29,.94);
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: 0 0 18px rgba(102,246,209,.14);
}
.studio-extend:hover {
    color: #06120e;
    background: var(--accent-green);
}
@media (max-width: 780px) {
    .track-heading { grid-template-columns: 24px 16px minmax(0,1fr); }
    .track-controls { grid-template-columns: 28px minmax(64px,1fr) 25px; }
}
/* STUDIO PROJECT LIBRARY + GAME EXPORT */
.studio-project-heading {
    display: grid;
    grid-template-columns: minmax(180px,320px) minmax(120px,190px);
    align-items: end;
    column-gap: .65rem;
}
.studio-project-heading .studio-kicker { grid-column: 1 / -1; }
.studio-project-select {
    height: 31px;
    min-width: 0;
    border: 1px solid rgba(102,246,209,.2);
    border-radius: 5px;
    background: #08151e;
    color: var(--text-secondary);
    padding: .35rem .5rem;
    font-size: .65rem;
}
.studio-export-loop {
    display: flex;
    align-items: center;
    gap: .45rem;
    min-height: 36px;
    padding: .25rem .5rem;
    border: 1px solid rgba(255,209,102,.24);
    border-radius: 5px;
    background: rgba(255,209,102,.05);
}
.studio-export-loop.hidden { display: none; }
.studio-export-loop label {
    display: flex;
    align-items: center;
    gap: .35rem;
    color: var(--text-dim);
    font-size: .56rem;
    font-weight: 700;
}
.studio-export-loop input {
    width: 42px;
    height: 26px;
    border: 1px solid rgba(255,209,102,.25);
    border-radius: 4px;
    background: #08151e;
    color: var(--accent-yellow);
    padding: .25rem;
}
#studio-save-duration {
    color: var(--accent-yellow);
    font-size: .68rem;
    font-weight: 700;
    white-space: nowrap;
}
@media (max-width: 1050px) {
    .studio-project-heading { grid-template-columns: minmax(150px,240px); }
    .studio-project-heading .studio-kicker { grid-column: 1; }
    .studio-project-select { height: 27px; }
    .studio-export-loop label { font-size: 0; }
    .studio-export-loop label::before { content: 'LOOPS'; font-size: .55rem; }
}