@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Roboto+Mono:wght@500;700&display=swap');

:root {
    --bg-dark: #1e1e2e;
    --bg-panel: #26263a;
    --primary: #6c5ce7;
    --accent: #00cec9;
    --danger: #ff7675;
    --success: #55efc4;
    --warning: #fdcb6e;
    --text-main: #dfe6e9;
}

body {
    background-color: #13131a;
    background-image: radial-gradient(circle at 50% 50%, #1e1e2e 0%, #13131a 100%);
    color: var(--text-main);
    font-family: 'Press Start 2P', cursive;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* --- LAYOUT --- */
#game-wrapper {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: 100vh;
    max-height: 900px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    border-left: 1px solid #333;
    border-right: 1px solid #333;
}

#canvas-container {
    flex: 6; 
    position: relative;
    background: #202028;
    border-bottom: 4px solid var(--primary);
    overflow: hidden;
    background-image: linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    transition: flex 0.3s;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#controls {
    flex: 4; 
    background: var(--bg-panel);
    display: flex; 
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
}

/* --- HUD --- */
.hud-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; 
    padding: 15px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.hud-left, .hud-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end; 
}
.hud-left { align-items: flex-start; }

.stat-badge {
    background: rgba(0,0,0,0.6);
    padding: 8px 12px;
    border-radius: 4px;
    border-left: 3px solid;
    font-size: 10px;
    text-transform: uppercase;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    pointer-events: auto; 
    display: flex; align-items: center; gap: 6px;
}

.hp-badge { border-color: var(--danger); }
.lvl-badge { border-color: var(--success); }
.diamond-badge { border-color: var(--accent); color: var(--accent); }
.diff-badge { border-color: var(--warning); }
.time-badge { border-color: #a29bfe; font-family: 'Roboto Mono', monospace; letter-spacing: 1px; }

.speed-btn, .pause-btn {
    cursor: pointer;
    border-color: #fff;
    color: #fff;
    transition: all 0.1s;
    min-width: 20px;
    text-align: center;
    justify-content: center;
}
.speed-btn:hover, .pause-btn:hover { background: rgba(255, 255, 255, 0.2); transform: scale(1.05); }
.speed-btn:active, .pause-btn:active { transform: scale(0.95); }

.icon-diamond {
    width: 12px; height: 12px;
    fill: var(--accent);
}

.xp-bar-container {
    width: 100%;
    max-width: 200px;
    height: 8px;
    background: #000;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 4px;
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--warning), #f39c12);
    width: 0%;
    transition: width 0.3s ease-out;
}

/* --- INPUTS --- */
#question {
    font-family: 'Roboto Mono', monospace;
    font-weight: 700;
    font-size: 42px; 
    margin-bottom: 30px;
    color: var(--text-main);
    text-shadow: 0 0 10px rgba(255,255,255,0.2);
    letter-spacing: 2px;
}

input[type="number"] {
    font-family: 'Press Start 2P', cursive;
    font-size: 28px;
    padding: 20px;
    width: 240px;
    text-align: center;
    border: 3px solid #444;
    border-radius: 8px;
    background: #1a1a24;
    color: var(--accent);
    outline: none;
    transition: all 0.2s;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

input[type="number"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 15px rgba(0, 206, 201, 0.3);
    transform: scale(1.02);
}

.shake { animation: shake 0.4s; border-color: var(--danger) !important; color: var(--danger) !important; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* --- OVERLAYS --- */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(19, 19, 26, 0.98);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    backdrop-filter: blur(5px);
}

h1 {
    color: var(--warning);
    text-shadow: 4px 4px var(--danger);
    font-size: 40px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.btn {
    background: var(--bg-panel);
    border: 2px solid #555;
    color: white;
    padding: 12px 20px; 
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    margin: 8px;
    cursor: pointer;
    transition: all 0.1s;
    text-transform: uppercase;
    border-radius: 4px;
    width: 240px;
    position: relative;
    overflow: hidden;
}
.btn:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 4px 0 rgba(255,255,255,0.2);
    border-color: white;
}
.btn:active { transform: translateY(2px); box-shadow: none; }

.btn-green { border-color: var(--success); color: var(--success); }
.btn-green:hover { background: rgba(85, 239, 196, 0.1); }

.btn-red { border-color: var(--danger); color: var(--danger); }
.btn-red:hover { background: rgba(255, 118, 117, 0.1); }

.btn-blue { border-color: var(--primary); color: var(--primary); }
.btn-blue:hover { background: rgba(108, 92, 231, 0.1); }

.btn-purple { border-color: #a29bfe; color: #a29bfe; }
.btn-purple:hover { background: rgba(162, 155, 254, 0.1); }

.btn-dark { border-color: #636e72; color: #b2bec3; background: #2d3436; }
.btn-dark:hover { background: #333; color: white; border-color: white; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; background: #333; color: #888; border-color: #555; }

.lock-icon { margin-left: 10px; font-size: 8px; color: #aaa; }

/* SHOP UI */
.shop-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
    max-width: 600px;
}
.shop-item {
    background: #2d2d3d;
    border: 1px solid #444;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    border-radius: 6px;
}
.shop-cost { color: var(--accent); margin-top: 5px; font-weight: bold; }

/* STATS PANEL */
.stats-panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #444;
    margin-bottom: 20px;
    width: 100%;
    max-width: 500px;
}
.stat-row { font-size: 10px; color: #a2a2a2; text-align: left; }
.stat-val { color: white; float: right; }

/* TOOLTIPS */
.tooltip-trigger { position: relative; display: inline-flex; align-items: center; cursor: help; gap: 5px; }
.info-icon { 
    background: #636e72; color: white; border-radius: 50%; 
    width: 14px; height: 14px; font-size: 9px; line-height: 14px; text-align: center;
    font-family: 'Roboto Mono', monospace; font-weight: bold;
}
.tooltip-content {
    visibility: hidden; position: absolute; bottom: 120%; left: 50%; transform: translateX(-50%);
    width: 180px; background: #2d3436; color: #dfe6e9; text-align: center;
    padding: 10px; border-radius: 4px; font-size: 9px; border: 1px solid #7f8c8d;
    z-index: 1000; opacity: 0; transition: opacity 0.2s; pointer-events: none;
    line-height: 1.5; box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    font-family: sans-serif;
}
.tooltip-trigger:hover .tooltip-content { visibility: visible; opacity: 1; }

/* UPGRADE CARDS */
.card-container {
    display: flex;
    gap: 15px;
    margin-top: 10px;
    flex-wrap: wrap;
    justify-content: center;
}
.card {
    background: #dfe6e9;
    color: #2d3436;
    border: 4px solid #b2bec3;
    padding: 12px;
    width: 140px;
    min-height: 180px;
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.card:hover { transform: translateY(-10px) scale(1.02); z-index: 10; }

.card h3 { font-size: 10px; margin-bottom: 10px; line-height: 1.4; color: #000; }
.card p { font-size: 9px; line-height: 1.4; color: #636e72; }

.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 5px; }

.card .stat-diff { 
    font-size: 9px; 
    color: #2d3436; 
    font-weight: bold; 
    margin-top: auto; 
    padding-top: 8px; 
    border-top: 1px solid rgba(0,0,0,0.1); 
    background: rgba(0,0,0,0.05);
    margin: 10px -12px -12px -12px;
    padding: 8px;
    text-align: center;
}

.rarity-tag { font-size: 8px; text-transform: uppercase; font-weight: 900; letter-spacing: 1px; }

.card.common { border-color: #b2bec3; }
.card.common .rarity-tag { color: #636e72; }

.card.rare { border-color: #0984e3; background: #e3f2fd; }
.card.rare .rarity-tag { color: #0984e3; }

.card.epic { border-color: #8e44ad; background: #f3e5f5; }
.card.epic .rarity-tag { color: #8e44ad; }

.card.legendary { 
    border-color: #f1c40f; 
    background: #fff8e1;
    box-shadow: 0 0 20px rgba(241, 196, 15, 0.4); 
    animation: pulse-gold 2s infinite; 
}
.card.legendary .rarity-tag { color: #f39c12; }

@keyframes pulse-gold { 
    0% { box-shadow: 0 0 15px rgba(241, 196, 15, 0.4); } 
    50% { box-shadow: 0 0 30px rgba(241, 196, 15, 0.8); } 
    100% { box-shadow: 0 0 15px rgba(241, 196, 15, 0.4); } 
}

/* LUCK BREAKDOWN PANEL */
.luck-breakdown {
    font-size: 9px; color: #a2a2a2; margin-top: 10px;
    display: flex; gap: 15px; justify-content: center;
    background: rgba(0,0,0,0.2); padding: 5px; border-radius: 4px;
}
.luck-val { font-weight: bold; }