/* 
    BeatCraft - KO II / Riddim Hardware Theme 
*/

:root {
    /* Design Tokens */
    --color-shell-light: #d9d8d7; /* KO II Gray */
    --color-shell-dark: #c4c3c2;
    --color-screen: #111317;
    --color-pad-dark: #262626;
    --color-pad-light: #f4f4f4;
    --color-text-main: #222;
    --color-text-screen: #e2feff; /* Glowing cyan/white */
    
    /* Accents */
    --color-accent-orange: #f25822;
    --color-accent-green: #0aa36a;
    --color-accent-red: #e53935;

    /* Shadows */
    --shadow-strong: 2px 2px 0px rgba(0,0,0,0.25), inset 1px 1px 1px rgba(255,255,255,0.5);
    --shadow-soft: 0 4px 10px rgba(0,0,0,0.15);
    --shadow-inset: inset 2px 2px 4px rgba(0,0,0,0.2);
    --shadow-pressed: inset 2px 2px 5px rgba(0,0,0,0.4);

    /* Dimensions */
    --radius-shell: 18px;
    --radius-pad: 6px; /* Slightly round for buttons */
    --radius-screen: 6px;
    
    --pad-size: 42px; /* Larger for better visibility */
    --pad-gap: 6px;   /* Horizontal gap between pads */
    --pad-gap-vertical: 10px; /* Vertical gap between pads (can be larger to compensate for box-shadow) */
}

body {
    background-color: #333; /* Table surface */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    color: var(--color-text-main);
    user-select: none;
    padding: 20px; /* Prevent edge touching on small screens */
}

/* The Device Container */
.device {
    background-color: var(--color-shell-light);
    width: 950px; /* Optimized for the grid width */
    max-width: 98vw;
    border-radius: var(--radius-shell);
    box-shadow: 
        0 20px 50px rgba(0,0,0,0.4), /* Lift off table */
        inset 0 1px 0 rgba(255,255,255,0.8); /* Top highlight */
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 25px;
    position: relative;
}

/* Device Top Strip (Header) */
.device-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0 10px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding-bottom: 15px;
}

.device-brand {
    font-weight: 800;
    letter-spacing: 2px;
    font-size: 1.2rem;
    color: var(--color-text-main);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.device-brand span {
    font-size: 0.6rem;
    font-weight: 400;
    opacity: 0.6;
}

.speaker-grill {
    width: 100px;
    height: 40px;
    background-image: radial-gradient(circle, #aaa 1px, transparent 1px);
    background-size: 4px 4px;
    border-radius: 20px;
    box-shadow: inset 1px 1px 3px rgba(0,0,0,0.1);
}

/* Device Screen */
.device-screen {
    background-color: var(--color-screen);
    border-radius: var(--radius-screen);
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
    position: relative;
    overflow: hidden;
}

#visualizer-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1; /* Behind text but above background */
    opacity: 0.8;
}

/* Glass reflection effect on screen */
.device-screen::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 40%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.05), transparent);
    pointer-events: none;
}

.screen-content {
    color: var(--color-text-screen);
    font-family: 'Courier New', Courier, monospace; /* Mono for digital look */
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 2;
}

/* Customer Info - Left side of screen */
.customer-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 180px;
}

.customer-name {
    font-size: 1rem;
    font-weight: bold;
    color: var(--color-text-screen);
    text-shadow: 0 0 8px rgba(226, 254, 255, 0.4);
}

.beat-request {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 4px;
    letter-spacing: 0.5px;
}

/* Center of screen - Dancer + Step feedback */
.screen-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px; /* Space between dancer and feedback */
    transition: justify-content 0.3s ease; /* Smooth transition when victory appears */
}

/* ASCII Art Customer Dancer */
.customer-dancer {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    line-height: 1.1;
    white-space: pre; /* Preserve ASCII art spacing */
    color: var(--color-text-screen);
    text-shadow: 0 0 10px rgba(226, 254, 255, 0.4);
    min-width: 60px; /* Prevent layout shift */
    text-align: center;
    transition: color 0.1s ease, text-shadow 0.1s ease;
    /* Default: dancer appears first in DOM order, centered with feedback */
}

/* When victory message is showing, align items to left so dancer is clearly on left */
.screen-center.showing-victory {
    justify-content: flex-start; /* Align to left: dancer on left, victory message on right */
    padding-left: 20px; /* Add some padding so it doesn't touch the edge */
}

/* Dancer turns green on correct notes */
.customer-dancer.dance-correct {
    color: #4ade80;
    text-shadow: 0 0 15px rgba(74, 222, 128, 0.8);
}

/* Dancer turns red on incorrect notes */
.customer-dancer.dance-incorrect {
    color: #f87171;
    text-shadow: 0 0 15px rgba(248, 113, 113, 0.8);
}

/* Step feedback - moved to right of dancer */
.step-feedback {
    font-size: 1.6rem;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s ease;
    text-shadow: 0 0 15px rgba(226, 254, 255, 0.5);
    min-width: 70px; /* Prevent layout shift when feedback appears */
    /* Default: feedback comes second (right side) */
    /* When victory shows, it appears to the right of dancer due to parent's flex-start alignment */
}

.step-feedback.visible {
    opacity: 1;
}

.step-feedback.positive {
    color: #4ade80; /* Green for correct */
    text-shadow: 0 0 15px rgba(74, 222, 128, 0.6);
}

.step-feedback.negative {
    color: #f87171; /* Red for incorrect */
    text-shadow: 0 0 15px rgba(248, 113, 113, 0.6);
}

/* Patience display - Right side of screen */
.patience-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 140px;
    justify-content: flex-end;
}

.patience-label {
    font-size: 0.65rem;
    opacity: 0.6;
    letter-spacing: 1px;
}

.patience-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #f87171; /* Heart red */
    text-shadow: 0 0 10px rgba(248, 113, 113, 0.4);
}

.patience-heart {
    font-size: 1.2rem;
}

.screen-label {
    font-size: 0.7rem;
    opacity: 0.7;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

/* Controls Row */
.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px;
    background-color: rgba(0,0,0,0.03); /* Subtle differentiation */
    padding: 15px 20px;
    border-radius: 10px;
    border: 1px solid rgba(0,0,0,0.05);
}

.knobs-container {
    display: flex;
    gap: 40px;
}

.knob-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.knob {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: conic-gradient(#eee, #ccc, #eee);
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.2),
        inset 0 1px 3px rgba(255,255,255,0.8);
    position: relative;
    border: 1px solid #bbb;
    cursor: grab;
    user-select: none;
    transition: cursor 0.1s;
    transform-origin: center center;
}

.knob:active {
    cursor: grabbing;
}

/* Knob Indicator Line - positioned at top, will rotate with parent */
.knob::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 50%;
    width: 4px;
    height: 20px;
    background-color: var(--color-accent-orange);
    transform: translateX(-50%);
    border-radius: 2px;
    transform-origin: bottom center;
}

.knob-value {
    font-size: inherit;
    font-weight: bold;
    color: var(--color-text-main);
    font-family: inherit; /* Match BPM input */
    text-align: center;
    min-height: 1em;
    width: 50px; /* Match BPM input width */
    background: transparent;
    border: none;
}

/* Style the BPM input specifically */
#bpm-input {
    padding: 0; /* Remove default input padding */
}

.transport-container {
    display: flex;
    gap: 15px;
}

/* Buttons (Play/Stop) */
.btn-hardware {
    background-color: var(--color-pad-light);
    border: none;
    padding: 12px 20px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 1px;
    color: var(--color-text-main);
    box-shadow: 
        0 4px 0 #bbb,
        0 6px 5px rgba(0,0,0,0.2);
    transition: all 0.1s;
    cursor: pointer;
    text-transform: uppercase;
}

.btn-large {
    padding: 15px 30px;
    font-size: 1rem;
}

.btn-hardware:active {
    transform: translateY(4px);
    box-shadow: 
        0 0 0 #bbb,
        inset 0 2px 5px rgba(0,0,0,0.2);
}

.btn-hardware.btn-orange {
    background-color: var(--color-accent-orange);
    color: white;
    box-shadow: 
        0 4px 0 #c43e10,
        0 6px 5px rgba(0,0,0,0.2);
}

.btn-hardware.btn-orange:active {
    box-shadow: 0 0 0 #c43e10, inset 0 2px 5px rgba(0,0,0,0.2);
}

/* Center Column: The Sequencer Grid */
.sequencer-area {
    background-color: #222; /* Darker background for contrast */
    padding: 25px;
    border-radius: 10px;
    box-shadow: inset 2px 2px 10px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center; /* Center the grid */
}

.lane {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    justify-content: center; /* Center content */
    margin-bottom: var(--pad-gap-vertical); /* Vertical spacing between lanes (accounts for box-shadow) */
}

/* Renamed from lane-label to lane-header and updated styles */
.lane-header {
    width: 140px; /* Increased width for button */
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.track-selector {
    position: relative;
    width: 100%;
}

.track-select-btn {
    width: 100%;
    background: #333;
    color: #ddd;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: all 0.1s;
    box-shadow: 0 2px 0 #111;
}

.track-select-btn:hover {
    background: #444;
    color: white;
    border-color: #777;
}

.track-select-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 #111;
}

/* Context Menu for Sample Selection */
#sample-menu {
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    padding: 5px 0;
    min-width: 180px;
    max-height: 250px;
    overflow-y: auto;
    font-size: 0.85rem;
    color: #333;
    z-index: 2000 !important; /* Ensure it's on top */
}

.menu-header {
    padding: 8px 15px;
    font-weight: bold;
    color: #888;
    border-bottom: 1px solid #eee;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: #f9f9f9;
}

.menu-item {
    padding: 10px 15px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid #f5f5f5;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:hover {
    background: #f0f0f0;
}


.steps-container {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    column-gap: var(--pad-gap); /* Horizontal spacing between columns */
    /* Note: row-gap doesn't work here since each container is a single row.
       Vertical spacing between lanes is controlled by margin-bottom on .lane */
    align-items: start; /* Align items to top to prevent stretching */
}

/* The Step Buttons (Pads) */
.step-btn {
    width: var(--pad-size);
    height: var(--pad-size); /* Fixed height matching width */
    background-color: #444; /* Slightly lighter than background */
    border-radius: var(--radius-pad);
    box-shadow: 0 2px 0 #111;
    cursor: pointer;
    position: relative;
    transition: transform 0.05s, box-shadow 0.05s;
    box-sizing: border-box; /* Ensure consistent sizing */
    /* Ensure buttons don't stretch and maintain consistent height */
    min-height: var(--pad-size);
    max-height: var(--pad-size);
}

/* Lighter styling for specific step positions (1st, 5th, 9th, 12th steps) */
/* Note: Steps are 0-indexed in code, so 1st=0, 5th=4, 9th=8, 12th=11 */
.step-btn[data-step="0"],
.step-btn[data-step="4"],
.step-btn[data-step="8"],
.step-btn[data-step="12"] {
    background-color: #555; /* Lighter than default #444 */
}

/* Ensure lighter steps stay lighter when active */
.step-btn[data-step="0"].active,
.step-btn[data-step="4"].active,
.step-btn[data-step="8"].active,
.step-btn[data-step="12"].active {
    background-color: #f8f8f8; /* Slightly lighter than default active color */
}

.step-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

/* LED on the pad */
.step-btn::after {
    content: '';
    position: absolute;
    top: 5px; right: 5px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background-color: white;
    opacity: 0.1;
    box-shadow: 0 0 2px rgba(255,255,255,0.5);
    transition: opacity 0.1s;
}

/* Active Step (Programmed) */
.step-btn.active {
    background-color: var(--color-pad-light);
    box-shadow: 0 2px 0 #999;
}

.step-btn.active::after {
    background-color: var(--color-accent-green);
    opacity: 1;
    box-shadow: 0 0 8px var(--color-accent-green);
}

/* Playing Playhead */
.step-btn.playing {
    filter: brightness(1.3);
    border: 1px solid rgba(255,255,255,0.5);
}

.step-btn.active.playing {
    background-color: white; 
}

/* Step Correct - Green highlight when step matches target pattern */
.step-btn.step-correct {
    background-color: var(--color-accent-green) !important;
    box-shadow: 0 0 12px var(--color-accent-green), 0 2px 0 #067a4e !important;
}

.step-btn.step-correct::after {
    background-color: #4ade80 !important;
    opacity: 1 !important;
    box-shadow: 0 0 10px #4ade80 !important;
}

/* Step Incorrect - Red highlight when step doesn't match target */
.step-btn.step-incorrect {
    background-color: var(--color-accent-red) !important;
    box-shadow: 0 0 12px var(--color-accent-red), 0 2px 0 #b91c1c !important;
}

.step-btn.step-incorrect::after {
    background-color: #fca5a5 !important;
    opacity: 1 !important;
    box-shadow: 0 0 10px #fca5a5 !important;
}

/* Note: Old step-score-display removed - now using step-correct/step-incorrect classes */

/* Bottom Panel (Store) */
.bottom-panel {
    border-top: 2px solid rgba(0,0,0,0.1);
    padding-top: 15px;
}

.store-panel {
    background: #eee;
    border-radius: 8px;
    padding: 20px;
    height: 450px; /* Fixed height - keeps device size consistent when switching tabs */
    overflow-y: auto; /* Allow scrolling if content exceeds height */
    border: 1px solid #ccc;
    font-size: 0.9rem;
}

/* Store container grid layout - columns are set dynamically via JavaScript */
#store-container {
    display: grid;
    gap: 10px;
}

/* Store section headers - always span all columns to stay on the left */
#store-container h3 {
    grid-column: 1 / -1; /* Span from first column to last column */
    margin-top: 0;
    margin-bottom: 0;
}

/* Store messages (like "No samples unlocked yet") also span all columns */
#store-container > div:not(.store-row) {
    grid-column: 1 / -1; /* Span all columns for non-row elements */
}

/* Store Header - Title and Money Display */
.store-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.store-panel h2 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--color-text-main);
}

/* Money Display */
.money-display {
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--color-accent-green);
    background: #222;
    padding: 6px 16px;
    border-radius: 6px;
    font-family: 'Courier New', Courier, monospace;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

/* Store Tab Navigation */
.store-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--color-accent-orange);
    padding-bottom: 0;
}

/* Individual Tab Button */
.store-tab {
    background: #ddd;
    border: 1px solid #ccc;
    border-bottom: none; /* Remove bottom border so it connects to content */
    border-radius: 6px 6px 0 0; /* Rounded top corners only */
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.15s ease;
    position: relative;
    bottom: -2px; /* Overlap the border slightly */
}

/* Tab hover state */
.store-tab:hover {
    background: #e8e8e8;
    color: #444;
}

/* Active tab - stands out and connects to content */
.store-tab.active {
    background: white;
    color: var(--color-accent-orange);
    border-color: var(--color-accent-orange);
    border-bottom: 2px solid white; /* Hide the bottom border by overlapping */
}

/* Dynamic Store Elements */
.store-row {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    background: white;
    border: 1px solid #ddd;
    margin-bottom: 10px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: transform 0.1s;
}

.store-row:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.store-info {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.store-name {
    font-weight: bold;
    font-size: 1rem;
    color: var(--color-text-main);
}
.store-sub {
    font-size: 0.85em;
    color: #666;
    margin-top: 2px;
}

.store-btn-buy {
    background: var(--color-accent-green);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 3px 0 #067a4e;
    margin-left: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Upgrade button - lighter shade of green for unlocked samples */
.store-btn-upgrade {
    background: #2db87f; /* Lighter green than accent-green (#0aa36a) */
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 3px 0 #1a8a5f; /* Lighter shadow to match */
    margin-left: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.store-btn-buy:active {
    transform: translateY(3px);
    box-shadow: none;
}
.store-btn-buy:disabled,
.store-btn-upgrade:disabled {
    background: #ccc;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.7;
}

.store-btn-upgrade:active {
    transform: translateY(3px);
    box-shadow: none;
}
