:root {
    --bg: #120a1a;
    --ink: #e9dfc8;
    --gold: #e0a63a;
    --gold-glow: rgba(224, 166, 58, 0.4);
    --green: #4ade80;
    --red: #f87171;
    --crimson: #5a2236;
    --card-bg: #221430;
    --border: #4a3463;
    color-scheme: dark;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    scroll-padding-top: env(safe-area-inset-top, 0px);
    height: 100%;
}

body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 500 16px 'Pixelify Sans', monospace, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    overflow: hidden;
}

canvas {
    display: none;
    width: min(100%, 960px);
    max-height: 70vh;
    aspect-ratio: 16/9;
    image-rendering: pixelated;
    background: #000;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.help {
    display: none;
    font-size: 13px;
    opacity: .75;
    text-align: center;
    padding: 0 12px;
    margin: 0;
}

body.play {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

body.play *::selection,
.pad *::selection {
    background: transparent;
    color: inherit;
}

body.play .help {
    display: block;
}

#ui {
    width: min(100%, 560px);
    max-height: 94vh;
    overflow-y: auto;
    padding: 14px;
    box-sizing: border-box;
    text-align: center;
}

h1 {
    color: var(--gold);
    letter-spacing: 2px;
    margin: 4px 0 8px 0;
    font-size: 32px;
    text-shadow: 0 2px 8px rgba(224, 166, 58, 0.25);
}

h2 {
    margin: 4px 0;
}

.card {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 4px;
    padding: 10px;
    margin: 6px 0;
    text-align: left;
}

small {
    display: block;
    opacity: .7;
    font-size: 13px;
}

button {
    font: inherit;
    color: var(--ink);
    background: var(--crimson);
    border: 2px solid #8a3a52;
    padding: 8px 14px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}

button:hover:not(:disabled) {
    background: #732a44;
    border-color: var(--gold);
}

button:disabled {
    opacity: .45;
    cursor: default;
    background: #2b1b3a;
    border-color: #4a3463;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin: 8px 0;
}

.tabs .on {
    background: #8a3a52;
    border-color: var(--gold);
}

.sw {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    flex: none;
    border: 2px solid var(--ink);
}

.coins {
    color: var(--gold);
    font-size: 20px;
    font-weight: 700;
}

.msg {
    color: var(--gold);
    margin: 6px 0;
}

.ghost {
    background: none;
    border-color: transparent;
    margin-top: 6px;
    opacity: 0.85;
}

.ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: #6b4a8a;
    opacity: 1;
}

/* Indicadores de Status de Banco de Dados */
.db-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 12px;
    margin: 2px 0 10px 0;
}

.db-badge.online {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid #22c55e;
    color: #4ade80;
}

.db-badge.local {
    background: rgba(234, 179, 8, 0.15);
    border: 1px solid #eab308;
    color: #fde047;
}

.db-badge.error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid #ef4444;
    color: #f87171;
}

.ad-card {
    background: #2b1f14;
    border-color: #8c6020;
}

/* ==========================================================================
   TELA DE AUTENTICAÇÃO (LOGIN / CADASTRO)
   ========================================================================== */
.auth-box {
    background: #1b1026;
    border: 2px solid #5d3d7d;
    border-radius: 8px;
    padding: 18px;
    margin: 8px auto;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    text-align: left;
}

.auth-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 2px solid #361f4c;
    padding-bottom: 8px;
}

.auth-nav button {
    flex: 1;
    padding: 8px;
    font-size: 14px;
    background: #251438;
    border: 1px solid #4a3463;
    border-radius: 4px;
}

.auth-nav button.active {
    background: #5a2236;
    border-color: var(--gold);
    color: var(--gold);
    font-weight: 700;
}

.auth-field {
    margin-bottom: 12px;
}

.auth-field label {
    display: block;
    font-size: 13px;
    color: #cfc3a8;
    margin-bottom: 4px;
}

.auth-field input {
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    font-size: 14px;
    padding: 10px 12px;
    background: #100819;
    color: var(--ink);
    border: 2px solid #4a3463;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.15s ease;
}

.auth-field input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 6px var(--gold-glow);
}

.auth-alert {
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 12px;
    line-height: 1.3;
}

.auth-alert.error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid #ef4444;
    color: #fca5a5;
}

.auth-alert.success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid #22c55e;
    color: #86efac;
}

.btn-primary-block {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    font-weight: 700;
    margin-top: 6px;
    background: #6e1f32;
    border-color: var(--gold);
}

.btn-primary-block:hover:not(:disabled) {
    background: #8a243c;
}

.auth-footer {
    text-align: center;
    margin-top: 14px;
    border-top: 1px solid #361f4c;
    padding-top: 10px;
}

.pad {
    display: none;
    gap: 8px;
    width: min(100%, 960px);
    justify-content: space-between;
    padding: 0 10px;
    box-sizing: border-box;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.pad div {
    display: flex;
    gap: 8px;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.pad button {
    font: 700 20px 'Pixelify Sans', monospace;
    width: 60px;
    height: 54px;
    background: #2b1b3a;
    border: 2px solid #6b4a8a;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    user-drag: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease;
}

.pad button:active,
.pad button.active {
    background: #5a2236;
    border-color: var(--gold);
    box-shadow: 0 0 8px var(--gold-glow);
    transform: scale(0.96);
}

@media (pointer:coarse) {
    body.play .pad {
        display: flex;
    }

    .help {
        display: none !important;
    }
}
/* ==========================================================================
   MODAL DE ANÚNCIOS RECOMPENSADOS (REWARDED ADS)
   ========================================================================== */
.ad-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(5, 2, 10, 0.92);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

.ad-modal-box {
    width: min(92vw, 460px);
    background: #1e122b;
    border: 2px solid var(--gold);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8), 0 0 16px rgba(224, 166, 58, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ad-modal-header {
    background: #140a1f;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #361f4c;
}

.ad-badge-tag {
    font-size: 11px;
    background: #5a2236;
    color: var(--gold);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--gold);
    font-weight: 700;
}

.ad-timer {
    font-size: 13px;
    color: #cfc3a8;
}

.ad-close-btn {
    background: #3a1a24;
    border: 1px solid #6b2a3a;
    color: #cfc3a8;
    padding: 4px 10px;
    font-size: 13px;
    border-radius: 4px;
    cursor: pointer;
}

.ad-close-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ad-progress-bar-bg {
    width: 100%;
    height: 6px;
    background: #140a1f;
}

.ad-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #e0a63a, #4ade80);
    width: 0%;
    transition: width 0.1s linear;
}

.ad-content-area {
    padding: 24px 16px;
    text-align: center;
    background: radial-gradient(circle at center, #2e1844 0%, #170d22 100%);
    min-height: 160px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.ad-sponsor-logo {
    font-size: 46px;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}

.ad-sponsor-title {
    color: var(--gold);
    font-size: 20px;
    font-weight: 700;
    margin: 0;
}

.ad-sponsor-desc {
    color: #e9dfc8;
    font-size: 14px;
    opacity: 0.85;
    max-width: 340px;
    margin: 0;
}

.ad-modal-footer {
    padding: 10px 14px;
    background: #140a1f;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #361f4c;
}

/* Submenu de Modos: História vs Sobrevivência */
.mode-nav {
    display: flex;
    gap: 8px;
    margin: 4px 0 14px 0;
    width: 100%;
}

.mode-nav button {
    flex: 1;
    padding: 9px 12px;
    font-size: 14px;
    background: #1c1028;
    border: 2px solid var(--border);
    border-radius: 6px;
    color: var(--ink);
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    transition: all 0.2s ease;
}

.mode-nav button:hover {
    border-color: var(--gold);
    background: #28173a;
}

.mode-nav button.active {
    background: #46162a;
    border-color: #f87171;
    color: #fff;
    box-shadow: 0 0 10px rgba(248, 113, 113, 0.4);
}

.survival-card {
    border-left: 4px solid #f87171 !important;
    background: linear-gradient(135deg, rgba(34, 20, 48, 0.95), rgba(70, 20, 35, 0.5)) !important;
    align-items: flex-start;
    padding: 14px;
}

.surv-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 12px;
    color: var(--gold);
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed rgba(224, 166, 58, 0.3);
}

.btn-survival {
    background: #8b1d2f !important;
    border: 2px solid #f87171 !important;
    color: #fff !important;
    font-weight: 700;
    padding: 8px 16px;
    align-self: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-survival:hover {
    background: #b91c1c !important;
    box-shadow: 0 0 14px rgba(248, 113, 113, 0.6) !important;
    transform: scale(1.03);
}