* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    background: #0a0a15;
    font-family: 'Segoe UI', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Anchor to top instead of vertically centering — otherwise the canvas
       jumps up/down when bet-section hides on battle start, or when the
       switch-bet panel inserts at VIP 5. */
    justify-content: flex-start;
    padding: 16px 0;
    min-height: 100vh;
    color: #eee;
}
h1 {
    margin-bottom: 6px;
    font-size: clamp(18px, 5vw, 26px);
    text-shadow: 0 0 15px rgba(255,200,50,0.4);
    color: #f0d060;
    letter-spacing: 2px;
}
#history-bar {
    display: flex;
    gap: 3px;
    margin: 5px 0;
    align-items: center;
}
#history-bar::before {
    content: 'HISTORY';
    font-size: 9px;
    color: #555;
    margin-right: 4px;
    letter-spacing: 1px;
}
.history-dot {
    width: 18px; height: 18px;
    border-radius: 3px;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px;
}
.history-dot.rock { background: #3a1515; color: #f66; }
.history-dot.paper { background: #152535; color: #6af; }
.history-dot.scissors { background: #153520; color: #6d6; }
#arena-container {
    position: relative;
    width: min(650px, 95vw);
    aspect-ratio: 650 / 500;
    overflow: visible;
    margin: 10px 15px;
}
#coin-fly-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; overflow: visible;
}
.flying-coin-el {
    position: absolute; pointer-events: none;
    font-size: 16px;
    filter: drop-shadow(0 0 4px rgba(240,208,96,0.8));
    transition: none;
}
#arena {
    display: block;
    width: 100%;
    height: 100%;
    background: #111;
    border: 2px solid #333;
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    touch-action: none;
}
/* Settings — fixed to viewport top-right, outside the arena */
#settings-btn {
    position: fixed; top: 12px; right: 12px; z-index: 50;
    width: 32px; height: 32px; border-radius: 50%;
    background: rgba(30,30,40,0.8); border: 1px solid #555;
    color: #aaa; font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, color 0.2s, transform 0.3s;
}
#settings-btn:hover { background: rgba(50,50,70,0.9); color: #fff; transform: rotate(45deg); }
#settings-panel {
    position: fixed; top: 50px; right: 12px; z-index: 50;
    background: rgba(15,15,25,0.95); border: 1px solid #444;
    border-radius: 8px; padding: 12px 16px; min-width: 200px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.settings-title { font-size: 13px; font-weight: bold; color: #f0d060; margin-bottom: 10px; letter-spacing: 1px; }
.settings-row { display: flex; flex-direction: column; gap: 6px; }
.settings-row > span { font-size: 12px; color: #aaa; }
.speed-controls { display: flex; gap: 4px; }
.speed-btn {
    padding: 4px 10px; font-size: 11px; font-weight: bold;
    background: rgba(255,255,255,0.08); color: #888;
    border: 1px solid #444; border-radius: 4px; cursor: pointer;
    transition: all 0.15s;
}
.speed-btn:hover { background: rgba(255,255,255,0.15); color: #ccc; }
.speed-btn.active { background: rgba(243,156,18,0.25); color: #f39c12; border-color: #f39c12; }
/* VIP Bar */
#vip-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(650px, 95vw);
    margin: 4px 0;
    padding: 6px 10px;
    background: linear-gradient(90deg, rgba(50,40,20,0.6), rgba(30,25,10,0.4));
    border-radius: 6px;
    border: 1px solid rgba(218,165,32,0.3);
}
#vip-label {
    font-size: 13px;
    font-weight: bold;
    color: #f0d060;
    white-space: nowrap;
    min-width: 42px;
}
#vip-progress-area {
    flex: 1;
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
}
#vip-win-label {
    position: absolute;
    font-size: 9px;
    font-weight: bold;
    color: rgba(240,208,96,0.7);
    white-space: nowrap;
    transform: translateX(-50%);
    transition: left 0.3s ease;
    pointer-events: none;
    height: 13px;
    line-height: 13px;
    z-index: 10;
    text-shadow: 0 0 4px rgba(240,208,96,0.6), 0 1px 3px rgba(0,0,0,0.8);
}
#vip-win-area {
    position: absolute;
    top: -14px;
    left: 0; right: 0;
    height: 13px;
}
#vip-progress-wrap {
    width: 100%;
    height: 10px;
    background: rgba(255,255,255,0.08);
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}
#vip-fill-peak {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #6b1a1a, #8b2020);
    border-radius: 5px;
    transition: width 0.5s ease;
}
#vip-fill-current {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #c8860a, #f0d060);
    border-radius: 5px;
    transition: width 0.3s ease;
    z-index: 1;
}
#vip-fill-potential {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, rgba(240,208,96,0.25), rgba(255,230,120,0.3));
    border-radius: 5px;
    transition: width 0.3s ease, left 0.3s ease;
    z-index: 2;
}
#vip-peak-marker {
    position: absolute;
    top: -2px; bottom: -2px;
    width: 2px;
    background: #8b2020;
    z-index: 4;
    transition: left 0.5s ease;
    border-radius: 1px;
    pointer-events: none;
}
#vip-below-labels {
    position: absolute;
    bottom: -14px;
    left: 0; right: 0;
    height: 13px;
    pointer-events: none;
}
#vip-cur-label {
    position: absolute;
    font-size: 9px;
    font-weight: bold;
    color: #f0d060;
    white-space: nowrap;
    transform: translateX(-50%);
    transition: left 0.3s ease;
    z-index: 2;
    text-shadow: 0 0 4px rgba(240,208,96,0.5), 0 1px 3px rgba(0,0,0,0.8);
}
#vip-peak-label {
    position: absolute;
    font-size: 9px;
    font-weight: bold;
    color: #8b2020;
    white-space: nowrap;
    transform: translateX(-50%);
    z-index: 1;
    text-shadow: 0 0 4px rgba(139,32,32,0.5), 0 1px 3px rgba(0,0,0,0.8);
    transition: left 0.5s ease;
}
#vip-next {
    display: flex;
    flex-direction: column;
    align-items: center;
    white-space: nowrap;
    min-width: 48px;
}
#vip-next-level {
    font-size: 11px;
    font-weight: bold;
    color: #f0d060;
}
#vip-next-amount {
    font-size: 12px;
    font-weight: bold;
    color: #888;
}
#vip-bar.vip1 { border-color: rgba(218,165,32,0.3); }
#vip-bar.vip2 { border-color: rgba(80,200,255,0.3); }
#vip-bar.vip2 #vip-label { color: #5cf; }
#vip-bar.vip2 #vip-progress-fill { background: linear-gradient(90deg, #2980b9, #5cf); }
#vip-bar.vip3 { border-color: rgba(255,200,50,0.3); }
#vip-bar.vip3 #vip-label { color: #f0d060; }
#vip-bar.vip3 #vip-progress-fill { background: linear-gradient(90deg, #f39c12, #f0d060); }
#vip-bar.vip4 { border-color: rgba(255,100,50,0.3); }
#vip-bar.vip4 #vip-label { color: #ff6040; }
#vip-bar.vip4 #vip-progress-fill { background: linear-gradient(90deg, #e74c3c, #ff6040); }
#vip-bar.vip5 { border-color: rgba(255,50,50,0.4); background: linear-gradient(90deg, rgba(60,20,20,0.6), rgba(40,10,10,0.4)); }
#vip-bar.vip5 #vip-label { color: #ff4444; text-shadow: 0 0 8px rgba(255,50,50,0.6); }
#vip-bar.vip5 #vip-progress-fill { background: linear-gradient(90deg, #c0392b, #ff4444); }
/* VIP Actions */
#vip-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
#vip-actions:empty { display: none; }
.vip-action-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    opacity: 0.85;
}
.vip-action-btn:hover { transform: translateY(-1px); opacity: 1; }
.vip-action-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }
.vip-action-btn.double-btn { background: #2a1a40; color: #c9a0ff; border-color: #9b59b6; }
.vip-action-btn.allin-btn { background: #3a1515; color: #ff6666; border-color: #c0392b; }
/* Controls */
#controls {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 0 10px;
    width: 100%;
    max-width: 650px;
}
#balance { font-size: clamp(18px, 4.5vw, 22px); font-weight: bold; color: #f39c12; transition: transform 0.15s ease-out; }
#odds-display { display: none; }
#bet-status { font-size: clamp(14px, 4vw, 18px); font-weight: bold; min-height: 22px; color: #f39c12; }
#bet-section { display: flex; gap: clamp(6px, 2vw, 12px); justify-content: center; width: 100%; max-width: 480px; }
.bet-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    min-width: 0;
}
.bet-label {
    font-size: 11px;
    font-weight: bold;
    color: #f0d060;
    min-height: 18px;
    margin-bottom: 4px;
    text-align: center;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
}
.bet-label.visible { opacity: 1; }
.bet-btn {
    width: 100%;
    padding: clamp(6px, 1.5vw, 8px) 0;
    font-size: clamp(10px, 2.5vw, 12px);
    font-weight: bold;
    border: 3px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s, border-color 0.2s;
    opacity: 0.7;
    text-align: center;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bet-btn:hover { transform: translateY(-2px); opacity: 1; }
.bet-btn:active { transform: translateY(0); opacity: 1; }
.bet-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.bet-btn.selected { opacity: 1; border-color: #f39c12; box-shadow: 0 0 12px rgba(243,156,18,0.4); }
.bet-rock { background: #8b2020; color: #fcc; }
.bet-paper { background: #1a4a7a; color: #cef; }
.bet-scissors { background: #1a4a25; color: #afa; }
#start-btn {
    padding: clamp(10px, 2.5vw, 12px) clamp(30px, 8vw, 40px);
    font-size: clamp(16px, 4vw, 18px);
    font-weight: bold; border: none; border-radius: 8px;
    background: linear-gradient(135deg, #f5a623, #e8751a);
    color: white; cursor: pointer;
    box-shadow: 0 4px 15px rgba(243, 156, 18, 0.3);
}
#start-btn:hover { transform: translateY(-2px); }
#start-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
#message { font-size: clamp(13px, 3.5vw, 16px); min-height: 20px; font-weight: bold; text-align: center; }
.win-msg { color: #2ecc71; }
.lose-msg { color: #e74c3c; }
.neutral-msg { color: #f39c12; }
#round-info { font-size: clamp(10px, 2.5vw, 12px); color: #888; text-align: center; }
#streak-display { font-size: clamp(12px, 3vw, 14px); color: #f80; font-weight: bold; min-height: 18px; }
#streak-display.hot { animation: pulse 0.5s infinite alternate; }
@keyframes pulse { from { opacity: 0.7; } to { opacity: 1; transform: scale(1.05); } }
@keyframes glow-pulse { 0%,100% { box-shadow: 0 0 8px rgba(243,156,18,0.3); } 50% { box-shadow: 0 0 18px rgba(243,156,18,0.7); } }
.bet-btn.glow { opacity: 1; animation: glow-pulse 1.5s infinite; }
.bet-rock.glow { animation: glow-rock 1.5s infinite; }
.bet-paper.glow { animation: glow-paper 1.5s infinite; }
.bet-scissors.glow { animation: glow-scissors 1.5s infinite; }
@keyframes glow-rock { 0%,100% { box-shadow: 0 0 8px rgba(255,80,80,0.3); } 50% { box-shadow: 0 0 18px rgba(255,80,80,0.7); } }
@keyframes glow-paper { 0%,100% { box-shadow: 0 0 8px rgba(80,160,255,0.3); } 50% { box-shadow: 0 0 18px rgba(80,160,255,0.7); } }
@keyframes glow-scissors { 0%,100% { box-shadow: 0 0 8px rgba(80,200,80,0.3); } 50% { box-shadow: 0 0 18px rgba(80,200,80,0.7); } }
#start-btn.glow { animation: glow-fight 1.2s infinite; }
@keyframes glow-fight { 0%,100% { box-shadow: 0 4px 15px rgba(243,156,18,0.3); } 50% { box-shadow: 0 4px 25px rgba(243,156,18,0.8), 0 0 40px rgba(243,156,18,0.4); } }

@media (max-width: 480px) {
    body { justify-content: flex-start; padding-top: 8px; }
    #arena-container { margin: 10px 8px; }
    #controls { gap: 10px; }
}
@media (max-width: 768px) {
    .bet-btn {
        padding: 0;
        font-size: 13px;
        height: 42px;
    }
    #start-btn {
        padding: 14px 44px;
        font-size: 18px;
        min-height: 48px;
    }
    .history-dot {
        width: 24px; height: 24px;
        font-size: 12px;
    }
    #bet-section { gap: 10px; }
}
@keyframes vipFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes vipSlideIn { from { opacity: 0; transform: scale(0.8) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* Cheat — Set Balance */
.cheat-row { margin-top: 6px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,0.08); }
.cheat-controls { display: flex; gap: 4px; }
.cheat-controls input {
    flex: 1; min-width: 0;
    padding: 4px 8px; font-size: 11px;
    background: rgba(255,255,255,0.08); color: #ccc;
    border: 1px solid #444; border-radius: 4px;
}
.cheat-controls input:focus { outline: none; border-color: #f39c12; }
.cheat-controls button {
    padding: 4px 12px; font-size: 11px; font-weight: bold;
    background: rgba(243,156,18,0.2); color: #f39c12;
    border: 1px solid #f39c12; border-radius: 4px;
    cursor: pointer; transition: background 0.15s;
}
.cheat-controls button:hover { background: rgba(243,156,18,0.4); }

/* Switch-bet focus mode: dim everything except canvas and switch panel */
body > *,
#controls > * { transition: opacity 0.3s ease; }
body.switch-active > *:not(#arena-container):not(#controls) {
    opacity: 0.15; pointer-events: none;
}
body.switch-active #controls > *:not(#switch-panel) {
    opacity: 0.15; pointer-events: none;
}

/* Map Shape selector */
.shape-controls { display: flex; gap: 4px; flex-wrap: wrap; }
.shape-btn {
    padding: 4px 10px; font-size: 11px; font-weight: bold;
    background: rgba(255,255,255,0.08); color: #888;
    border: 1px solid #444; border-radius: 4px; cursor: pointer;
    transition: all 0.15s;
}
.shape-btn:hover { background: rgba(255,255,255,0.15); color: #ccc; }
.shape-btn.active { background: rgba(243,156,18,0.25); color: #f39c12; border-color: #f39c12; }

/* Hide canvas border/shadow when arena shape isn't a rectangle */
body.shape-circle #arena,
body.shape-octagon #arena {
    border: none;
    box-shadow: none;
    background: transparent;
}

/* Audio controls */
.audio-controls { display: flex; gap: 6px; align-items: center; }
.audio-controls input[type=range] {
    flex: 1; min-width: 60px; height: 4px;
    accent-color: #f39c12; cursor: pointer;
}
.audio-mute-btn, .audio-music-btn {
    padding: 3px 8px; font-size: 11px; font-weight: bold;
    background: rgba(255,255,255,0.08); color: #ccc;
    border: 1px solid #444; border-radius: 4px; cursor: pointer;
    transition: all 0.15s;
}
.audio-mute-btn:hover, .audio-music-btn:hover { background: rgba(255,255,255,0.15); }
.audio-music-btn.active { background: rgba(243,156,18,0.25); color: #f39c12; border-color: #f39c12; }
