/* RandoMatic 3000 - Vintage 50s/60s Diner Style & Dark Mode */

:root {
    /* Default Light Mode (Diner / Atomic Age Palette) */
    --bg-primary: #FDFBF7; /* Creamy off-white */
    --bg-secondary: #E0E0E0; /* Chrome/Metal base */
    --bg-tertiary: #FFFFFF; /* Pure white */
    
    --accent-primary: #EF476F; /* Diner Pink/Red */
    --accent-secondary: #06D6A0; /* Seafoam/Mint */
    --accent-tertiary: #FFD166; /* Golden Yellow */
    --accent-dark: #118AB2; /* Deep Blue */
    
    --text-primary: #2B2D42; /* Soft Black */
    --text-secondary: #5D5F71; /* Muted Gray */
    --text-light: #FDFBF7; /* Off-white text */
    
    --border-color: #8D99AE;
    --chrome-gradient: linear-gradient(135deg, #f5f5f5 0%, #dcdcdc 50%, #f5f5f5 100%);
    
    --shadow-soft: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-hard: 4px 4px 0px rgba(0,0,0,0.2);
    --shadow-inset: inset 2px 2px 5px rgba(0,0,0,0.1);

    /* Engine specific fix */
    --die-bg: #FFFFFF;
    --die-dot: #2B2D42;
    --die-shadow: #ccc;
    --card-bg: #FFFFFF;
    --viz-text: #2B2D42;
}

[data-theme="dark"] {
    /* Dark Mode (Neon / Cyber Diner) */
    --bg-primary: #121212; /* Deep Dark */
    --bg-secondary: #1E1E1E; /* Dark Gray */
    --bg-tertiary: #2D2D2D; /* Lighter Dark */
    
    --accent-primary: #FF5C8D; /* Bright Pink */
    --accent-secondary: #00FF9D; /* Neon Green */
    --accent-tertiary: #FFD166; /* Golden Yellow (keeps warmth) */
    --accent-dark: #4CC9F0; /* Bright Cyan */
    
    --text-primary: #E0E0E0; /* Off-white */
    --text-secondary: #A0A0A0; /* Light Gray */
    --text-light: #121212; /* Dark text for light buttons */
    
    --border-color: #404040;
    --chrome-gradient: linear-gradient(135deg, #2D2D2D 0%, #1E1E1E 50%, #2D2D2D 100%);
    
    --shadow-soft: 0 4px 6px rgba(0,0,0,0.5);
    --shadow-hard: 4px 4px 0px rgba(0,0,0,0.5);
    --shadow-inset: inset 2px 2px 5px rgba(0,0,0,0.5);

    /* Engine specific fix */
    --die-bg: #E0E0E0;
    --die-dot: #121212;
    --die-shadow: #000;
    --card-bg: #E0E0E0;
    --viz-text: #FFFFFF;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', system-ui, sans-serif;
    background-color: var(--bg-primary);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(239, 71, 111, 0.05) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(6, 214, 160, 0.05) 0%, transparent 20%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Header */
.header {
    background: var(--chrome-gradient);
    padding: 10px;
    text-align: center;
    border-bottom: 4px solid var(--accent-primary);
    box-shadow: var(--shadow-soft);
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header-content {
    position: relative;
    width: 100%;
    max-width: 1600px;
}

.header h1 {
    font-family: 'Righteous', cursive;
    font-size: 2rem;
    color: var(--accent-primary);
    text-shadow: 2px 2px 0px var(--accent-tertiary);
    letter-spacing: 2px;
    margin-bottom: 2px;
    text-transform: uppercase;
}

.header .tagline {
    font-family: 'Roboto', sans-serif;
    font-weight: 700;
    color: var(--accent-dark);
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Theme Toggle */
.theme-toggle-wrapper {
    position: absolute;
    top: 5px;
    right: 20px;
}

.theme-toggle {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
    box-shadow: var(--shadow-soft);
}

.theme-toggle:hover {
    transform: scale(1.1);
    border-color: var(--accent-secondary);
    color: var(--accent-secondary);
}

/* Main Layout */
.main-container {
    display: grid;
    grid-template-columns: 320px 1fr 350px;
    gap: 20px;
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
    align-items: start;
}

/* Mobile / Tablet Responsive */
@media (max-width: 1100px) {
    .main-container {
        grid-template-columns: 1fr; /* Stack vertically */
        max-width: 800px;
        padding: 15px;
        gap: 20px;
    }
    
    .theme-toggle-wrapper {
        position: relative;
        top: auto;
        right: auto;
        margin-top: 15px;
    }
    
    .viz-panel {
        order: -1;
    }
}

/* Panels - Jukebox Card Style */
.panel {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 16px;
    box-shadow: var(--shadow-hard);
    position: relative;
    overflow: hidden;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Decorative top bar for panels */
.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    background: repeating-linear-gradient(
        45deg,
        var(--accent-secondary),
        var(--accent-secondary) 10px,
        var(--bg-tertiary) 10px,
        var(--bg-tertiary) 20px
    );
}

.panel h3 {
    font-family: 'Righteous', cursive;
    color: var(--accent-dark);
    font-size: 1.2rem;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 2px dashed var(--border-color);
    text-transform: uppercase;
}

/* Buttons - Physical Clicky Feel */
.btn {
    font-family: 'Righteous', cursive;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--text-primary);
    padding: 10px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.1s;
    box-shadow: 3px 3px 0px var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover:not(:disabled) {
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0px var(--text-primary);
    background: var(--bg-tertiary);
}

.btn:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0px var(--text-primary);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: translate(2px, 2px);
}

.btn.active {
    background: var(--accent-tertiary);
    box-shadow: inset 2px 2px 4px rgba(0,0,0,0.1);
    transform: translate(1px, 1px);
    color: var(--text-light);
    border-color: var(--text-primary);
}
/* Ensure text contrast for active buttons in dark mode */
[data-theme="dark"] .btn.active {
    color: #121212;
}


.btn-run {
    background: var(--accent-secondary);
    color: #fff;
    border-color: #04966f;
    box-shadow: 3px 3px 0px #04966f;
    width: 100%;
    font-size: 1.2rem;
    padding: 15px;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.btn-run:hover:not(:disabled) {
    background: #05e0a7;
}

.btn-stop {
    background: var(--accent-primary);
    color: white;
    border-color: #b00e34;
    box-shadow: 3px 3px 0px #b00e34;
}

/* Engine Selector */
#engine-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.btn-engine {
    flex: 1 1 calc(50% - 10px);
    min-width: 100px;
    font-size: 0.9rem;
}

/* Mode Selector */
#mode-selector {
    background: var(--bg-secondary);
    padding: 5px;
    border-radius: 14px;
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.btn-mode {
    flex: 1;
    border: none;
    box-shadow: none;
    background: transparent;
    color: var(--text-secondary);
}

.btn-mode.active {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Options Panel */
.options-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.option-count {
    background: var(--accent-tertiary);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.8rem;
    color: #2B2D42; /* Always dark text on yellow */
    border: 2px solid var(--text-primary);
}

.options-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 15px;
    padding-right: 5px;
}

.option-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    background: var(--bg-tertiary);
    padding: 8px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 2px 2px 0px var(--border-color);
}

.option-number {
    width: 28px;
    height: 28px;
    background: var(--accent-dark);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: bold;
    flex-shrink: 0;
}

.option-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: 'Roboto', sans-serif;
    font-size: 1rem;
    color: var(--text-primary);
    padding: 4px;
    min-width: 0; /* Fix flexbox overflow */
}

.option-input:focus {
    outline: none;
    background: var(--bg-secondary);
    border-radius: 4px;
}

.btn-remove {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff0f0;
    border-color: #ffcccc;
    color: var(--accent-primary);
    box-shadow: 2px 2px 0px #ffcccc;
}
[data-theme="dark"] .btn-remove {
    background: #2a1a1a;
    border-color: #503030;
    box-shadow: 2px 2px 0px #503030;
}

.btn-add {
    width: 100%;
    border-style: dashed;
    background: rgba(6, 214, 160, 0.1);
    color: var(--accent-secondary);
    border-color: var(--accent-secondary);
    box-shadow: none;
}

.btn-add:hover {
    background: rgba(6, 214, 160, 0.2);
}

/* Trials Panel */
.trial-presets {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.btn-preset {
    flex: 1;
    font-size: 0.9rem;
}

.trial-custom {
    width: 80px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px;
    border-radius: 10px;
    text-align: center;
    font-family: 'Roboto', sans-serif;
    font-weight: bold;
}

.trial-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.trial-controls .btn {
    flex: 1;
}

.progress-bar {
    height: 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
}

.progress-fill {
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        var(--accent-secondary),
        var(--accent-secondary) 10px,
        #04b486 10px,
        #04b486 20px
    );
    width: 0;
    transition: width 0.1s;
}

/* Visualization Area */
.viz-panel {
    display: flex;
    flex-direction: column;
}

#visualization {
    flex: 1;
    min-height: 350px; /* Reduced for better desktop fit */
    background: #1a1a1a; /* TV Screen black */
    border-radius: 20px; /* TV shape */
    border: 8px solid #dcdcdc; /* TV Bezel */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    box-shadow: 
        inset 0 0 40px rgba(0,0,0,0.5),
        0 10px 20px rgba(0,0,0,0.2);
}

[data-theme="dark"] #visualization {
    border-color: #404040;
}

/* CRT Scanline Effect Overlay */
#visualization::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    z-index: 5;
}

/* Results Panel */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.btn-clear {
    font-size: 0.8rem;
    padding: 6px 12px;
    background: var(--bg-secondary);
}

.result-row {
    margin-bottom: 15px;
}

.result-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-weight: bold;
    font-size: 0.95rem;
}

.medal {
    font-size: 1.2rem;
}

.result-bar-container {
    position: relative;
    height: 30px;
    background: var(--bg-secondary);
    border-radius: 15px; /* Pill shape */
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.result-bar {
    height: 100%;
    background: var(--accent-secondary);
    transition: width 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    position: relative;
}

/* Striped candy cane effect for top bar */
.result-row:first-child .result-bar {
    background: repeating-linear-gradient(
        45deg,
        var(--accent-primary),
        var(--accent-primary) 10px,
        #d63056 10px,
        #d63056 20px
    );
}

.result-count {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    color: #2B2D42; /* Always dark text for readability on bars */
    font-weight: bold;
    z-index: 2;
}

.results-summary {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 12px;
    border-left: 5px solid var(--accent-dark);
    margin-top: 20px;
}

/* Position Table */
.position-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 5px;
    font-size: 0.9rem;
}

.position-table th {
    text-transform: uppercase;
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 10px;
    letter-spacing: 1px;
}

.position-table td {
    background: var(--bg-tertiary);
    padding: 10px;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.position-table td:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
    border-left: 1px solid var(--border-color);
    font-weight: bold;
    color: var(--accent-dark);
}

.position-table td:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    border-right: 1px solid var(--border-color);
}

.suggested-order {
    margin-top: 15px;
    padding: 15px;
    background: var(--accent-tertiary); /* Yellow note */
    color: #2B2D42; /* Always dark text on yellow */
    border-radius: 2px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
    transform: rotate(-1deg);
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
}

/* --- Engine Specific Visuals --- */

/* Canvas Containers */
.viz-wheel, .viz-crypto, .viz-dice, .viz-cards, .viz-lottery, .viz-coins {
    width: 100%;
    height: 100%;
}

/* Crypto */
.viz-crypto {
    background: #000;
}

/* Wheel */
.viz-wheel {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle, #333 0%, #111 100%);
}

/* Dice */
.viz-dice {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(rgba(42, 157, 143, 0.2) 1px, transparent 1px);
    background-size: 20px 20px;
    background-color: var(--bg-secondary);
}

.dice-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

.die {
    width: 90px;
    height: 90px;
    background: var(--die-bg);
    border-radius: 16px;
    box-shadow: 0 8px 0px var(--die-shadow), 0 8px 20px rgba(0,0,0,0.3);
    border: 2px solid var(--border-color);
}

.die-cell.dot {
    background: var(--die-dot); /* Specific contrasting color */
    box-shadow: inset 1px 1px 2px rgba(0,0,0,0.5);
}

.dice-result {
    font-family: 'Righteous', cursive;
    font-size: 2rem;
    color: var(--accent-primary);
    text-shadow: 2px 2px 0px var(--bg-primary);
}

/* Cards */
.viz-cards {
    background-color: #35654d; /* Felt Green */
    background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.05) 0px, rgba(255,255,255,0.05) 2px, transparent 2px, transparent 10px);
}

.card-front {
    border: 4px solid var(--card-bg);
    background: var(--card-bg);
}

.card-back {
    background: repeating-linear-gradient(
        45deg,
        #e63946,
        #e63946 10px,
        #f1faee 10px,
        #f1faee 20px
    );
    border: 2px solid white;
}

/* Ensure suits are visible */
.card-suit {
    /* Color is set inline by JS, but we ensure background is white/light */
}

.card-label {
    color: #2B2D42 !important; /* Force dark text for card labels */
}

/* Lottery */
.lottery-machine {
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.1), transparent),
                linear-gradient(135deg, #457b9d, #1d3557);
    border-radius: 50%;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.5);
}

.lottery-ball {
    border: 2px solid rgba(255,255,255,0.3);
    font-family: 'Arial', sans-serif;
    color: white; /* Ensure ball numbers are white */
}

.ball-label {
    background: white;
    color: #2B2D42;
    padding: 2px 8px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    font-weight: bold;
}

/* Coins */
.viz-coins {
    background: var(--bg-secondary);
}

.coin-front {
    background: linear-gradient(135deg, #ffd700, #f1c40f);
    border: 4px solid #d4af37;
    color: #8b6914;
}

.coin-back {
    background: linear-gradient(135deg, #bdc3c7, #ecf0f1);
    border: 4px solid #95a5a6;
    color: #7f8c8d;
}

.coins-result .binary {
    font-family: 'Courier New', monospace;
    color: var(--viz-text);
}

.coins-result .winner {
    font-family: 'Righteous', cursive;
    color: var(--accent-secondary);
    font-size: 1.8rem;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.5);
}

/* Result Overlay text in Viz */
.order-result {
    color: var(--accent-secondary);
    background: rgba(0,0,0,0.9);
    border: 1px solid var(--accent-secondary);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
    border: 2px solid var(--bg-primary);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-secondary);
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 16px 20px;
    margin-top: 20px;
    background: var(--chrome-gradient);
    border-top: 3px solid var(--border-color);
    font-family: 'Roboto', sans-serif;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.site-footer p {
    margin: 0;
}

.site-footer a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 700;
    transition: color 0.2s ease, text-shadow 0.2s ease;
}

.site-footer a:hover {
    color: var(--accent-secondary);
    text-shadow: 0 0 8px var(--accent-secondary);
}

[data-theme="dark"] .site-footer {
    box-shadow: 0 -2px 10px rgba(0, 255, 157, 0.1);
}

@media (max-width: 768px) {
    .site-footer {
        padding: 12px 16px;
        font-size: 0.85rem;
    }
}
