:root {
    --stage-w: 512;
    --stage-h: 384;
    --gold: #ffd54a;
    /* sprite sheet 156x81, frame 75x77, escala original 0.43 */
    --btn-scale: 0.43;
    --btn-frame-w: 75;
    --btn-frame-h: 77;
    --btn-w: 32;
    --btn-h: 33;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: #051018;
    color: #fff;
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* ===== AUTH ===== */
.auth-panel {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at top, #1a3a5c, #0a1628);
}

.auth-box {
    width: 100%;
    max-width: 400px;
    background: rgba(10, 30, 50, 0.95);
    border: 2px solid rgba(77, 184, 232, 0.35);
    border-radius: 18px;
    padding: 28px 24px;
    text-align: center;
}

.auth-logo { width: 180px; max-width: 100%; margin-bottom: 10px; }
.auth-box h1 { margin: 0 0 6px; color: var(--gold); font-size: 1.5rem; }
.auth-box p { color: #a8cce0; margin-bottom: 16px; font-size: 0.9rem; }

.auth-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.auth-tab {
    flex: 1; padding: 10px; border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(0,0,0,0.25); color: #a8cce0;
    cursor: pointer; font-weight: 700;
}
.auth-tab.active {
    border-color: #4db8e8;
    color: #fff;
    background: rgba(77,184,232,0.2);
}

.auth-form input {
    display: block; width: 100%; margin: 8px 0;
    padding: 12px 14px; border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(0,0,0,0.35); color: #fff;
}
.auth-form input:focus { outline: none; border-color: #4db8e8; }
.btn-primary {
    width: 100%; margin-top: 8px; padding: 12px;
    border: none; border-radius: 10px; cursor: pointer;
    background: linear-gradient(180deg, #6dd5ff, #2196d6);
    color: #0a2540; font-weight: 800;
}
.msg { color: #ffb347; min-height: 20px; margin-top: 10px; font-size: 0.85rem; }

/* ===== GAME STAGE (512x384) ===== */
.game-panel {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    background: #051018;
}

.game-stage {
    position: relative;
    width: min(100vw - 16px, calc((100vh - 16px) * var(--stage-w) / var(--stage-h)));
    aspect-ratio: var(--stage-w) / var(--stage-h);
    background: url('../assets/drawable/background.png') center / 100% 100% no-repeat;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.55);
    border-radius: 8px;
    user-select: none;
    container-type: size;
    container-name: stage;
}

.btn-exit {
    position: absolute;
    top: calc(4 / var(--stage-h) * 100%);
    right: calc(6 / var(--stage-w) * 100%);
    z-index: 40;
    width: 26px; height: 26px; line-height: 24px; text-align: center;
    background: rgba(0,0,0,0.45); color: #fff; text-decoration: none;
    border-radius: 50%; font-size: 13px; border: 1px solid rgba(255,255,255,0.2);
}

.hud-values { position: absolute; inset: 0; z-index: 12; pointer-events: none; }

.hud-val {
    position: absolute;
    font-family: 'Arial Black', Arial, sans-serif;
    font-weight: 900;
    font-size: clamp(11px, 2.6vw, 20px);
    font-size: calc(15 / var(--stage-w) * 100cqw);
    color: var(--gold);
    text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 0 2px 2px rgba(0,0,0,0.5);
    line-height: 1.2;
    white-space: nowrap;
}

.hud-valor-rs {
    top: calc(10 / var(--stage-h) * 100%);
    left: calc(132 / var(--stage-w) * 100%);
    transform: translateX(-100%);
    text-align: right;
}
.hud-creditos {
    top: calc(24 / var(--stage-h) * 100%);
    left: calc(128 / var(--stage-w) * 100%);
    transform: translateX(-100%);
    text-align: right;
}
.hud-pago {
    top: calc(37 / var(--stage-h) * 100%);
    left: calc(124 / var(--stage-w) * 100%);
    transform: translateX(-100%);
    text-align: right;
}
.hud-acumulado {
    top: calc(20 / var(--stage-h) * 100%);
    left: 50%;
    transform: translateX(-42%);
    font-size: calc(20 / var(--stage-w) * 100cqw);
    color: #ffe566;
    text-shadow: 2px 2px 0 #1a5080, 0 0 8px rgba(100,200,255,0.6);
}
.hud-aposta-total {
    top: calc(6 / var(--stage-h) * 100%);
    right: calc(14 / var(--stage-w) * 100%);
    text-align: right;
    min-width: 14%;
    pointer-events: auto;
    cursor: pointer;
}
.hud-aposta-linha {
    top: calc(24 / var(--stage-h) * 100%);
    right: calc(14 / var(--stage-w) * 100%);
    text-align: right;
    min-width: 14%;
    pointer-events: auto;
    cursor: pointer;
}

/* Rolos */
.slot-machine {
    position: absolute;
    left: calc(33 / var(--stage-w) * 100%);
    top: calc(83 / var(--stage-h) * 100%);
    width: calc(447 / var(--stage-w) * 100%);
    height: calc(212 / var(--stage-h) * 100%);
    z-index: 6;
}

.reel-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
    z-index: 4;
}

.paylines-draw {
    position: absolute;
    left: calc(42 / 447 * 100%);
    top: calc(18 / 212 * 100%);
    width: calc(363 / 447 * 100%);
    height: calc(168 / 212 * 100%);
    z-index: 9;
    pointer-events: none;
    overflow: visible;
}

.paylines-draw polyline {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.95;
    filter: drop-shadow(0 0 3px rgba(255,255,255,0.8));
}

.reels-viewport {
    position: absolute;
    left: calc(42 / 447 * 100%);
    top: calc(18 / 212 * 100%);
    width: calc(363 / 447 * 100%);
    height: calc(168 / 212 * 100%);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    z-index: 8;
    overflow: hidden;
}

.reel {
    position: relative;
    height: 100%;
    overflow: hidden;
    background: transparent;
}

.reel-strip {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    will-change: transform;
}

.reel-strip.spin-mode {
    display: flex;
    flex-direction: column;
    grid-template-rows: unset;
    height: auto;
    bottom: auto;
    top: 0;
    min-height: 100%;
}

.reel-strip.spin-mode .symbol {
    flex: 0 0 auto;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.symbol {
    width: 100%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.sym-img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background-repeat: no-repeat;
    background-position: center center;
    image-rendering: auto;
    flex-shrink: 0;
    overflow: hidden;
}

.symbol.win .sym-img {
    filter: drop-shadow(0 0 6px gold);
    animation: pulse-win 0.6s ease-in-out infinite alternate;
}

@keyframes pulse-win {
    from { filter: drop-shadow(0 0 4px gold); }
    to { filter: drop-shadow(0 0 10px #ffea00); }
}

.reel.spinning .sym-img {
    animation: symbol-blur 0.08s steps(2) infinite;
}

@keyframes symbol-blur {
    50% { opacity: 0.85; }
}

/* Linhas de pagamento */
.paylines-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: calc(54 / var(--stage-w) * 100%);
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

.paylines-layer.paylines-right {
    left: auto;
    right: 0;
    width: calc(54 / var(--stage-w) * 100%);
}

.line-badge {
    position: absolute;
    width: calc(24 / var(--stage-w) * 100%);
    height: calc(24 / var(--stage-h) * 100%);
    transform: translate(-50%, -50%);
    background-repeat: no-repeat;
    background-size: 300% 100%;
    background-position: 0 0;
    cursor: pointer;
    pointer-events: auto;
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.2s;
    border: none;
    padding: 0;
    background-color: transparent;
}

.paylines-right .line-badge { transform: translate(50%, -50%); }

.line-badge.active {
    opacity: 1;
    background-position: 100% 0;
    transform: translate(-50%, -50%) scale(1.12);
    filter: drop-shadow(0 0 4px rgba(255,255,255,0.8));
}

.paylines-right .line-badge.active {
    transform: translate(50%, -50%) scale(1.12);
}

/* Controles — posicoes do sceneGame.lua (escala 0.43) */
.controls-layer {
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
}

.btn-sprite {
    position: absolute;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.12s;
    width: calc(var(--btn-w) / var(--stage-w) * 100cqw);
    height: calc(var(--btn-h) / var(--stage-h) * 100cqh);
    min-width: 30px;
    min-height: 30px;
}

.btn-icon {
    display: block;
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-size: 200% 100%;
    background-position: 0 0;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.35));
}

.btn-icon-spin {
    width: 100%;
    height: 100%;
}

.btn-sprite:active .btn-icon { background-position: 100% 0; }
.btn-sprite:active { transform: scale(0.92); }
.btn-sprite:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sprite.spinning .btn-icon-spin { animation: spin-btn-pulse 0.4s ease-in-out infinite alternate; }

@keyframes spin-btn-pulse {
    from { filter: drop-shadow(0 0 4px rgba(100,200,255,0.6)); }
    to { filter: drop-shadow(0 0 10px rgba(100,200,255,1)); }
}

/* Posicoes do sceneGame.lua (escala 0.43) — referencia imagem original */
.btn-menu {
    left: calc(14 / var(--stage-w) * 100%);
    top: calc(302 / var(--stage-h) * 100%);
}

.btn-spin {
    left: calc(458 / var(--stage-w) * 100%);
    top: calc(296 / var(--stage-h) * 100%);
    width: calc(48 / var(--stage-w) * 100cqw);
    height: calc(50 / var(--stage-h) * 100cqh);
    min-width: 36px;
    min-height: 36px;
    z-index: 25;
}

.controls-extra {
    position: absolute;
    left: calc(52 / var(--stage-w) * 100%);
    top: calc(302 / var(--stage-h) * 100%);
    display: flex;
    gap: calc(4 / var(--stage-w) * 100%);
    z-index: 21;
    pointer-events: auto;
}

.controls-extra.hidden { display: none !important; }

.btn-aux { position: relative; left: auto; top: auto; }

.msg-banner {
    position: absolute;
    left: calc(388 / var(--stage-w) * 100%);
    top: calc(322 / var(--stage-h) * 100%);
    transform: translateX(-50%);
    width: calc(188 / var(--stage-w) * 100%);
    height: calc(36 / var(--stage-h) * 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 19;
}

.msg-banner img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.partial-win {
    position: absolute;
    right: calc(8 / var(--stage-w) * 100%);
    font-family: 'Arial Black', Arial, sans-serif;
    font-size: calc(13 / var(--stage-w) * 100cqw);
    color: #ff9800;
    text-shadow: 1px 1px 0 #000;
    display: none;
}

.partial-win.visible { display: block; }

.resultado {
    position: absolute;
    left: 50%;
    top: calc(248 / var(--stage-h) * 100%);
    transform: translateX(-50%);
    padding: 3px 10px;
    background: rgba(0,0,0,0.5);
    border-radius: 999px;
    color: var(--gold);
    font-weight: 800;
    font-size: calc(12 / var(--stage-w) * 100cqw);
    z-index: 22;
    white-space: nowrap;
    text-shadow: 1px 1px 0 #000;
}

.paytable {
    position: absolute;
    bottom: 2px;
    right: 6px;
    font-size: 9px;
    color: #a8cce0;
    z-index: 18;
    max-width: 48%;
    pointer-events: auto;
}
.paytable summary { cursor: pointer; color: #7ec8ff; }
.paytable table { width: 100%; border-collapse: collapse; font-size: 9px; background: rgba(0,0,0,0.75); }
.paytable th, .paytable td { border: 1px solid rgba(255,255,255,0.1); padding: 2px; text-align: center; }

@media (max-width: 480px) {
    .game-panel { padding: 0; }
    .game-stage { width: 100vw; border-radius: 0; }
}
