:root {
    --bg-dark: #0a0a0a;
    --panel-dark: #141414;
    --neon-green: #39ff14;
    --neon-red: #ff073a;
    --neon-blue: #00ffff;
    --text-light: #e0e0e0;
    --grid-bg: rgba(0, 0, 0, 0.8);
    --grid-border: #222;
    --font-main: 'Courier New', Courier, monospace;
    /* Shared width for reel frame + control bar — use directly, never inside calc(). */
    --panel-width: min(calc(100vw - 40px), calc(100vh - 200px), 1008px);
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    font-family: var(--font-main);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto; /* let the UI scroll if it's taller than the viewport so controls are never cut off */
    background-image: radial-gradient(circle at center, #1a1a1a 0%, #000 100%);
}

#app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 1200px;
    padding: 10px 20px 20px;
}

header {
    text-align: center;
}

header h1 {
    font-size: clamp(1.3rem, 3.6vh, 2.6rem);
    color: var(--neon-red);
    text-shadow: 0 0 10px rgba(255, 7, 58, 0.5), 0 0 20px rgba(255, 7, 58, 0.3);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0 0 4px;
}

#free-spin-label {
    margin: 8px auto;
    padding: 10px 15px;
    border: 2px solid #ff0055;
    border-radius: 8px;
    background: rgba(50, 0, 0, 0.9);
    color: #ffb3d9;
    font-weight: bold;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(255, 0, 85, 0.6);
    max-width: 320px;
    text-align: center;
}

#free-spin-label.hidden {
    display: none;
}

#escalator {
    font-size: 1.5rem;
    color: var(--neon-green);
    text-shadow: 0 0 8px rgba(57, 255, 20, 0.5);
    transition: transform 0.2s, color 0.2s;
}

#escalator.active {
    transform: scale(1.2);
    color: #fff;
    text-shadow: 0 0 15px var(--neon-green);
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

#slot-machine {
    position: relative;
    background: linear-gradient(180deg, rgba(10,10,10,0.96), rgba(25,25,25,0.96));
    border: 4px solid rgba(255,255,255,0.08);
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8), inset 0 0 24px rgba(255,255,255,0.05);
    width: var(--panel-width);
    max-width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
}

#grid-container {
    display: grid;
    gap: 4px;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: repeat(7, minmax(0, 1fr));
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.cell {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.symbol {
    width: 90%;
    height: 90%;
    object-fit: contain;
    position: absolute;
    transition: top 0.5s cubic-bezier(0.25, 1, 0.5, 1), transform 0.2s;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
}

.symbol.winning {
    animation: dropOff 1.5s cubic-bezier(0.5, 0, 1, 0.5) forwards;
    z-index: 10;
    filter: drop-shadow(0 0 15px #bf00ff);
}

@keyframes dropOff {
    0% { transform: translateY(0) scale(1); filter: drop-shadow(0 0 15px #bf00ff); z-index: 20; }
    40% { transform: translateY(-10px) scale(1.1); filter: drop-shadow(0 0 35px #bf00ff); z-index: 20; }
    100% { transform: translateY(150vh) scale(1); opacity: 0; filter: drop-shadow(0 0 5px #bf00ff); z-index: 20; }
}

.symbol.wild { filter: drop-shadow(0 0 8px #ff00ff); }
.symbol.scatter { filter: drop-shadow(0 0 8px var(--neon-blue)); }

/* Big Win Overlay */
#big-win-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.5s;
}

#big-win-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#confetti-canvas {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
}

#big-win-text {
    font-size: 5rem;
    font-weight: bold;
    color: gold;
    text-shadow: 0 0 20px #ffaa00, 2px 2px 0 #000;
    animation: pulse 1s infinite alternate;
    z-index: 101;
}

#big-win-amount {
    font-size: 3rem;
    color: #fff;
    text-shadow: 0 0 10px var(--neon-green);
    margin-top: 20px;
    z-index: 101;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

/* Controls Overhaul */
#controls {
    background: linear-gradient(135deg, rgba(12,12,12,0.94), rgba(28,28,28,0.98));
    padding: 18px 26px;
    border: 2px solid rgba(255,255,255,0.08);
    border-radius: 18px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    width: var(--panel-width);
    max-width: 100%;
    box-sizing: border-box;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45), inset 0 0 25px rgba(255,255,255,0.05);
    flex-shrink: 0;
}

button {
    background: #1d1d1d;
    color: var(--text-light);
    border: 1px solid rgba(255,255,255,0.12);
    padding: 10px 14px;
    font-family: var(--font-main);
    font-size: 1.05rem;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

button:hover {
    background: rgba(255,255,255,0.05);
    border-color: var(--neon-blue);
    box-shadow: 0 0 14px rgba(0, 255, 255, 0.22);
}

button:active {
    transform: scale(0.95);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #444;
    box-shadow: none;
}

.hidden {
    display: none !important;
}

#spin-btn {
    background: linear-gradient(135deg, #5f0000 0%, #a50000 100%);
    border: 2px solid var(--neon-red);
    font-size: 1.5rem;
    padding: 14px 40px;
    font-weight: 700;
    color: #fff;
    border-radius: 12px;
    text-shadow: 0 0 10px var(--neon-red);
    box-shadow: 0 0 22px rgba(255, 7, 58, 0.35);
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 1px;
    min-width: 150px;
}

#spin-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #730000 0%, #b30000 100%);
    box-shadow: 0 0 25px rgba(255, 7, 58, 0.7);
    transform: scale(1.03);
}

#spin-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.control-group {
    display: flex;
    gap: 10px;
    width: 100%;
}

.spin-controls {
    flex-direction: column;
}

.auto-spin-wrapper {
    display: flex;
    align-items: center;
    background: #000;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}

#auto-spin-count {
    width: 60px;
    height: 36px;
    background: #111;
    color: #fff;
    border: 1px solid #444;
    text-align: center;
    font-family: var(--font-main);
    font-size: 1.1rem;
    border-radius: 4px;
}

#auto-spin-btn {
    height: 36px;
    padding: 0 15px;
    font-size: 1rem;
}

/* Horizontal Stats Panel */
.stats-panel-horizontal {
    display: flex;
    flex-direction: row;
    gap: 20px;
    background: #000000;
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid #222;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
    min-width: 0;
    flex: 1 1 200px;
}

.stat-horizontal {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-label {
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.neon-cyan-text {
    color: var(--neon-blue);
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.4);
}

.neon-green-text {
    color: var(--neon-green);
    text-shadow: 0 0 8px rgba(57, 255, 20, 0.4);
}

.neon-pink-text {
    color: #ff007f;
    text-shadow: 0 0 8px rgba(255, 0, 127, 0.4);
}

/* Horizontal Bet Controls */
.bet-controls-horizontal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.bet-selector {
    display: flex;
    align-items: center;
    background: #000;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 2px 4px;
}

.bet-adjust-btn {
    background: #1a1a1a;
    color: #fff;
    border: 1px solid #444;
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50% !important;
    padding: 0;
    line-height: 1;
    transition: all 0.15s;
}

.bet-adjust-btn:hover:not(:disabled) {
    background: #2a2a2a;
    border-color: var(--neon-blue);
    color: var(--neon-blue);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
}

.bet-adjust-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: #222;
}

.bet-value {
    font-size: 1.4rem;
    font-weight: bold;
    color: #ffffff;
    min-width: 60px;
    text-align: center;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

.spin-controls-horizontal {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    flex: 1 1 200px;
    min-width: 0;
    justify-content: center;
}

.utility-controls-horizontal {
    display: flex;
    flex-direction: row;
    gap: 10px;
    flex: 0 1 auto;
    min-width: 0;
    justify-content: flex-end;
}

.utility-controls-horizontal button {
    font-size: 0.95rem;
    padding: 10px 16px;
}

#controls > .stats-panel-horizontal,
#controls > .bet-controls-horizontal,
#controls > .spin-controls-horizontal,
#controls > .utility-controls-horizontal {
    flex-shrink: 0;
}

@media (max-width: 900px) {
    #controls {
        justify-content: center;
    }

    #controls > .stats-panel-horizontal,
    #controls > .bet-controls-horizontal,
    #controls > .spin-controls-horizontal,
    #controls > .utility-controls-horizontal {
        flex: 1 1 100%;
        min-width: auto;
    }

    .spin-controls-horizontal,
    .utility-controls-horizontal {
        justify-content: center;
    }
}

body.dungeon-mode #controls {
    background: rgba(20, 0, 0, 0.85);
    border-color: #8b0000;
    box-shadow: 0 0 30px rgba(139, 0, 0, 0.5);
}

body.dungeon-mode .stats-panel-horizontal,
body.dungeon-mode .bet-selector,
body.dungeon-mode .auto-spin-wrapper {
    background: #100000;
    border-color: #500;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--panel-dark);
    border: 2px solid var(--grid-border);
    padding: 30px;
    border-radius: 10px;
    width: 80%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 10px; right: 20px;
    font-size: 2rem;
    cursor: pointer;
    color: var(--neon-red);
}

.rules-text {
    margin: 20px 0;
    color: #aaa;
    line-height: 1.5;
}

#paytable-symbols {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.paytable-item {
    background: #111;
    padding: 10px;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid #333;
}

.paytable-item img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    margin-bottom: 10px;
}

.paytable-item h4 {
    margin-bottom: 5px;
    font-size: 0.9rem;
    text-align: center;
}

.paytable-item .pays {
    font-size: 0.8rem;
    color: #888;
    text-align: center;
}

.symbol {
    cursor: pointer;
}

.small-modal {
    max-width: 400px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.small-modal img {
    width: 200px;
    height: 200px;
    object-fit: contain;
    margin-bottom: 20px;
    filter: drop-shadow(0 0 20px var(--neon-blue));
    animation: pulse 2s infinite alternate;
}

.small-modal h2 {
    color: var(--neon-blue);
    margin-bottom: 15px;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.small-modal .pays {
    font-size: 1.2rem;
    line-height: 1.6;
    color: var(--text-light);
}

/* Dungeon Mode */
body.dungeon-mode {
    background-image: linear-gradient(rgba(20, 0, 0, 0.9), rgba(0, 0, 0, 0.95)), url('Symbol_Artwork/dungeon_bg.png');
    background-size: cover;
    background-position: center;
    background-blend-mode: overlay;
    background-color: #300;
}

body.dungeon-mode #app-container {
    background: rgba(0, 0, 0, 0.1);
}

body.dungeon-mode #slot-machine {
    background: rgba(15, 0, 0, 0.75);
    border-color: #8b0000;
}

body.dungeon-mode #grid-container {
    box-shadow: inset 0 0 40px rgba(255, 0, 0, 0.25);
}

body.dungeon-mode .status-panel {
    background: rgba(20, 0, 0, 0.75);
    border-color: rgba(255, 0, 0, 0.4);
}

body.dungeon-mode header h1 {
    color: #ff0000;
    text-shadow: 0 0 20px #ff0000, 0 0 40px #800000;
}

body.dungeon-mode #slot-machine {
    border-color: #8b0000;
    box-shadow: 0 0 50px rgba(139, 0, 0, 0.8), inset 0 0 30px rgba(255,0,0,0.2);
}

/* Mini Game */
.mini-game-content {
    text-align: center;
    background: rgba(10, 10, 10, 0.95);
    border: 3px solid var(--neon-red);
}

#lotion-options {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 30px 0;
}

.lotion-item {
    width: 80px;
    height: 120px;
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
    filter: drop-shadow(0 0 5px rgba(255,255,255,0.2));
}

.lotion-item:hover {
    transform: scale(1.1);
    filter: drop-shadow(0 0 15px var(--neon-green));
}

.lotion-item.selected {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
}

.basket-container {
    position: relative;
    display: inline-block;
    margin-top: 20px;
}

#basket-img {
    width: 150px;
    height: 150px;
    object-fit: contain;
}

#basket-count {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    font-weight: bold;
    color: var(--neon-green);
    text-shadow: 0 0 10px #000;
}

/* Horizontal Buff Panel */
.buff-panel-horizontal {
    display: flex;
    flex-direction: row;
    align-items: center;
    background: rgba(10, 0, 15, 0.85);
    border: 1px solid #bf00ff;
    padding: 10px 20px;
    border-radius: 8px;
    width: var(--panel-width);
    max-width: 100%;
    box-sizing: border-box;
    gap: 15px;
    box-shadow: 0 0 15px rgba(191, 0, 255, 0.2);
    animation: neon-pulse-purple 2s infinite alternate;
    flex-shrink: 0;
}

.buff-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: #bf00ff;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(191, 0, 255, 0.5);
    white-space: nowrap;
}

#buff-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    list-style: none;
    padding: 0;
    margin: 0;
}

#buff-list li {
    background: rgba(191, 0, 255, 0.15);
    border: 1px solid #bf00ff;
    color: #ffb3ff;
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 20px;
    text-shadow: 0 0 4px rgba(191, 0, 255, 0.5);
    box-shadow: 0 0 5px rgba(191, 0, 255, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@keyframes neon-pulse-purple {
    from {
        box-shadow: 0 0 10px rgba(191, 0, 255, 0.2), inset 0 0 5px rgba(191, 0, 255, 0.1);
        border-color: rgba(191, 0, 255, 0.6);
    }
    to {
        box-shadow: 0 0 20px rgba(191, 0, 255, 0.4), inset 0 0 10px rgba(191, 0, 255, 0.2);
        border-color: rgba(191, 0, 255, 1);
    }
}
