﻿@import url('vendor/oxanium/oxanium.css');

/* =========================================================================
   TEMA  (claro por padrão; body.dark-mode sobrescreve)
   Sistema de cores:
     verde  = ação principal / dificuldade FÁCIL
     âmbar  = destaque / dificuldade MÉDIO / placar
     coral  = dificuldade DIFÍCIL
   ========================================================================= */
:root {
    /* superfícies */
    --bg: #f3f5fb;
    --surface: #ffffff;
    --surface-2: #eaecf4;
    --text: #1a1c24;
    --text-dim: #6b6f80;
    --border: #e2e5ef;

    /* marca / ações */
    --accent: #3596C7;
    --accent-press: #2a7bb8;
    --accent-soft: #edf6e6;

    /* dificuldade */
    --easy: #5F9126;
    --easy-press: #4c7720;
    --medium: #e0971a;
    --medium-press: #c47f10;
    --hard: #e05656;
    --hard-press: #c63f3f;

    /* status */
    --gold: #f1b211;
    --correct: #2ecc71;
    --wrong: #e74c3c;

    --key-text: #ffffff;
    --disabled: #d8dbe6;
    --disabled-text: #9aa0b0;
}

body.dark-mode {
    --bg: #0b0c11;
    --surface: #15161e;
    --surface-2: #1f2129;
    --text: #f3f4fa;
    --text-dim: #969aab;
    --border: #282b37;

    --accent: #3596C7;
    --accent-press: #2a7bb8;
    --accent-soft: #1b2a13;

    --easy: #6aa12c;
    --easy-press: #588a25;
    --medium: #e3a52b;
    --medium-press: #c98a18;
    --hard: #ea6a6a;
    --hard-press: #d34f4f;

    --gold: #f1b211;
    --correct: #34d27f;
    --wrong: #ff5b4a;

    --disabled: #23252f;
    --disabled-text: #555a68;


}

/* ===== Barras do sistema (notch, barra de status, barra de gestos) =====
   Com viewport-fit=cover o app desenha embaixo das barras, e o Capacitor
   preenche esses env(). No navegador — e em WebView antiga, que nao entende
   env() — tudo cai pra 0px e o layout fica igual ao de sempre.
   Pra conferir o encaixe sem celular, sobrescreva os valores no devtools. */
:root {
    --safe-top: 0px;
    --safe-bottom: 0px;
    --safe-left: 0px;
    --safe-right: 0px;
}

@supports (padding: env(safe-area-inset-top)) {
    :root {
        --safe-top: env(safe-area-inset-top, 0px);
        --safe-bottom: env(safe-area-inset-bottom, 0px);
        --safe-left: env(safe-area-inset-left, 0px);
        --safe-right: env(safe-area-inset-right, 0px);
    }
}

/* ===== Reset / base ===== */
* {
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);

}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Oxanium", sans-serif;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background .25s, color .25s;
    overflow-x: hidden;
}

/* ===== Topbar ===== */
#topbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    height: calc(52px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    border-top: 1px solid var(--border);
    z-index: 60;
}

.topbar-right {
    display: flex;
    width: 100%;
}

.icon-btn {
    flex: 1;
    height: 100%;
    background: var(--surface);
    color: var(--text);
    border: none;
    border-left: 1px solid var(--border);
    cursor: pointer;
    font-size: 19px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
}

.icon-btn:first-child {
    border-left: none;
}

.icon-btn:hover {
    background: var(--surface-2);
}

#leaderboard-button {
    color: var(--gold);
}

/* ===== Modal de configurações ===== */
.config-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 8px;
}

.config-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 14px 16px;
}

.config-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
}

.config-label i {
    color: var(--accent);
    width: 20px;
    text-align: center;
    flex: none;
}

/* explicação curta embaixo do nome da opção (ex: modo celular) */
.config-hint {
    display: block;
    margin-top: 3px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--text-dim);
}

.theme-btn {
    width: 46px;
    height: 46px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, transform .12s;
}

.theme-btn:hover {
    transform: scale(1.06);
}

.config-credit {
    color: var(--accent);
    text-decoration: none;
    font-size: 16px;
}

.config-select {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    outline: none;
}

/* ===== Acordeão "como funciona a pontuação" =====
   Conteúdo gerado pelo buildHelp() a partir das constantes do jogo. */
.help-row {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
}

.help-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 16px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    color: var(--text);
}

.help-chevron {
    color: var(--text-dim);
    transition: transform .3s;
}

#help-block.open .help-chevron {
    transform: rotate(180deg);
}

.help-body {
    max-height: 0;
    overflow: hidden;
    padding: 0 16px;
    transition: max-height .35s ease;
}

/* folgado o bastante pra caber o conteúdo mesmo quebrando linha num celular
   estreito: max-height animável não aceita 'auto', então sobra dar margem */
#help-block.open .help-body {
    max-height: 2000px;
    padding-bottom: 16px;
}

.help-formula {
    margin: 0;
    padding: 11px;
    background: var(--surface-2);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    line-height: 1.4;
}

.help-sec {
    margin: 18px 0 2px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-dim);
}

/* ----- linhas de operação e de bônus -----
   As duas listas compartilham a mesma grade: marcador de largura fixa, rótulo
   elástico e valor à direita. Sem o marcador fixo, o texto das operações
   começava num lugar e o dos bônus em outro. */
.help-line {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

/* a última linha de cada lista não desenha borda, senão ela encosta no
   título da seção seguinte e vira uma risca solta */
.help-list .help-line:last-child {
    border-bottom: none;
}

.help-line > i,
.help-dot {
    flex: none;
    width: 18px;
    text-align: center;
}

.help-line > i {
    color: var(--accent);
    font-size: 13px;
}

/* bolinha de dificuldade, mesma linguagem da tela de operações */
.help-dot {
    width: 10px;
    height: 10px;
    margin: 0 4px;
}

.d-easy { background: var(--easy); }
.d-medium { background: var(--medium); }
.d-hard { background: var(--hard); }

.help-label {
    flex: 1;
    min-width: 0;
    font-weight: 700;
    line-height: 1.25;
}

.help-label small {
    display: block;
    margin-top: 3px;
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
}

.help-line > b {
    flex: none;
    color: var(--gold);
    white-space: nowrap;
}

.help-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.help-chip {
    padding: 5px 10px;
    background: var(--surface-2);
    font-size: 13px;
    white-space: nowrap;
}

.help-chip b {
    color: var(--gold);
}

.help-txt {
    margin: 8px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-dim);
}

.config-version {
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    margin: 18px 0 0;
}

/* ===== Telas (largura base mobile; cada tela expande no PC) ===== */
.screen {
    width: 100%;
  
    margin: 0 auto;
    padding:
        calc(32px + var(--safe-top))
        calc(16px + var(--safe-right))
        calc(84px + var(--safe-bottom))
        calc(16px + var(--safe-left));
    min-height: 100vh;
}

/* =========================================================================
   TELA 1: OPERAÇÕES
   ========================================================================= */
.logo-img {
    display: block;
    width: 100%;
    height: auto;
    margin: 4px auto 8px;
    margin-bottom: 20px;
}

.logo-dark {
    display: none;
}

.logo-light {
    display: block;
}

body.dark-mode .logo-dark {
    display: block;
}

body.dark-mode .logo-light {
    display: none;
}



.screen-sub {
    text-align: center;
    color: var(--text-dim);
    font-size: 15px;
    margin: 0 0 24px;
}

.cat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    font-weight: 700;
    margin: 0 0 10px 2px;
}

.op-sections {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* cada dificuldade vira um card */
.op-section {}

.op-section .cat-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    margin: 0 0 12px;
}

/* bolinha colorida = sinaliza o nível num olhar */
.op-section .cat-label::before {
    content: '';
    width: 10px;
    height: 10px;
    flex: none;
}

.lvl-easy .cat-label::before {
    background: var(--easy);
}

.lvl-medium .cat-label::before {
    background: var(--medium);
}

.lvl-hard .cat-label::before {
    background: var(--hard);
}

.op-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.op-btn {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 56px;
    padding: 10px 14px;
    border: none;
    background: var(--easy);
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.15;
    text-align: left;
    cursor: pointer;
    transition: transform .12s ease, background .15s;
}

/* ícone num "chip" translúcido — dá hierarquia e fica fácil de escanear */
.op-btn i {
    flex: none;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, .22);
    font-size: 15px;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}


.op-btn span {
    flex: 1;
}

.op-btn.wide {
    grid-column: 1 / -1;
}

.op-btn:hover {
        clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);

}

.op-btn:active {
    transform: translateY(0) scale(.98);
}

.op-btn:focus-visible {
    outline: 3px solid var(--text);
    outline-offset: 2px;
}

/* cores por dificuldade */
.lvl-easy .op-btn {
    background: var(--easy);
}

.lvl-easy .op-btn:hover {
    background: var(--easy-press);
}

.lvl-medium .op-btn {
    background: var(--medium);
}

.lvl-medium .op-btn:hover {
    background: var(--medium-press);
}


.lvl-hard .op-btn {
    background: var(--hard);
}

.lvl-hard .op-btn:hover {
    background: var(--hard-press);
}

/* =========================================================================
   TELA 2: TEMPO
   ========================================================================= */
.time-title {
    text-align: center;
    font-size: 24px;
    font-weight: 800;
    margin: 8px 0 26px;
    color: var(--text);
}

.time-title>span:first-child {
    color: var(--text);
}

#time-op-name {
    color: var(--accent);
}

#time-op-name.lvl-easy {
    color: var(--easy);
}

#time-op-name.lvl-medium {
    color: var(--medium);
}

#time-op-name.lvl-hard {
    color: var(--hard);
}

.time-layout {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.time-grid {
    display: grid;
    grid-template-columns: 1fr 1fr ;
    gap: 10px;
}

/* são 6 tempos fixos (3 linhas cheias) mais o Infinito: ele fecha o grid
   ocupando a linha inteira, em vez de sobrar meia linha vazia do lado */
.time-btn.wide {
    grid-column: 1 / -1;
}

.time-btn {
    padding: 18px 6px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: transform .1s, background .15s;
}

.time-btn i {
    opacity: .8;
}

.time-btn:hover {
    background: var(--accent-press);
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);

    
}

.time-btn.selected {
    transform: translateY(0) scale(.98);
    background: var(--correct);
    clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 0 100%);
}

.time-btn.selected:hover {
    background: var(--correct);
}

/* botão do modo infinito: dourado, se destaca dos tempos fixos */
.time-btn-infinite {
    background: #ffc93c;
    color: #1a1c24;
}
.time-btn-infinite i {
    opacity: 1;
}
.time-btn-infinite:hover {
    background: linear-gradient(135deg, #ffc93c, var(--gold));
}
.time-btn-infinite.selected,
.time-btn-infinite.selected:hover {
    background: var(--correct);
    color: #fff;
}

/* tempos travados pelo bônus Relâmpago (só o Infinito segue clicável) */
.time-btn:disabled,
.time-btn:disabled:hover {
    background: var(--disabled);
    color: var(--disabled-text);
    cursor: not-allowed;
    clip-path: none;
}

/* aviso de por que o tempo ficou preso no Infinito */
.time-note {
    margin: 12px 0 0;
    padding: 10px 12px;
    border: 1px solid var(--gold);
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.35;
}

.time-note b {
    color: var(--text);
}

/* barra "Voltar + Jogar" no rodapé da tela de tempo */
.time-actions {
    display: flex;
    gap: 10px;
    margin-top: 22px;
    align-items: stretch;
}

.time-actions .ghost-btn {
    margin: 0;
    flex: 0 0 auto;
}

.play-btn {
    flex: 1;
    padding: 14px;
    border: none;
    background: var(--correct);
    color: #fff;
    font-family: inherit;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: filter .15s;
}

.play-btn:hover:not(:disabled) {
    filter: brightness(1.08);
}

.play-btn:disabled {
    background: var(--disabled);
    color: var(--disabled-text);
    cursor: default;
}

.time-start {
    width: 100%;
    margin-top: 14px;
    padding: 14px;
    border: none;

    background: var(--correct);
    color: #fff;
    font-family: inherit;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
}

.time-start:active {
    filter: brightness(.92);
}

/* bônus = ajustes (cartão neutro, não botão de ação) */
.bonus-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.bonus-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);

    padding: 12px 14px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    line-height: 1.2;
    transition: border-color .2s, background .2s;
}

/* são 7 bônus num grid de 2 colunas: o último sozinho esticaria só metade da
   linha e deixaria um buraco, então ele ocupa as duas */
.bonus-row.wide {
    grid-column: 1 / -1;
}

.bonus-row:has(.switch:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* bônus que não muda nada na operação escolhida (ver OP_BONUS no script.js) */
.bonus-row.bonus-na {
    background: var(--disabled);
    border-color: transparent;
    color: var(--disabled-text);
    cursor: not-allowed;
}

.bonus-row.bonus-na .bonus-info i {
    color: var(--disabled-text);
}

.bonus-row.bonus-na .switch {
    background: var(--disabled);
    border-color: var(--border);
    cursor: not-allowed;
}

.bonus-row.bonus-na .switch::after {
    background: var(--disabled-text);
}

.bonus-info {
    display: flex;
    align-items: center;
    gap: 9px;
}

.bonus-info i {
    color: var(--accent);
    width: 18px;
    text-align: center;
    flex: none;
}

.switch {
    appearance: none;
    -webkit-appearance: none;
    width: 44px;
    height: 24px;

    background: var(--surface-2);
    border: 1px solid var(--border);
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .2s, border-color .2s;
}

.switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;

    background: #fff;
    transition: left .2s;
}

.switch:checked {
    background: var(--correct);
    border-color: var(--correct);
}

.switch:checked::after {
    left: 22px;
}

.ghost-btn {
    display: block;
    margin: 22px auto 0;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 12px 28px;

    cursor: pointer;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
}

.ghost-btn:hover {
    background: var(--surface);
    color: var(--text);
}

/* =========================================================================
   TELA 3: JOGO
   ========================================================================= */
#screen-game {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    /* altura travada: o rascunho cresce/encolhe sem empurrar o resto */
    overflow: hidden;
    padding-bottom: 64px;
}

#hud {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.hud-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 72px;
    background: var(--surface);
    border: 1px solid var(--border);

    padding: 7px 14px;
    font-size: 18px;
    font-weight: 700;
}

.hud-item i {
    font-size: 15px;
}

.hud-correct {
    color: var(--correct);
}

.hud-wrong {
    color: var(--wrong);
}

/* sequência: o fogo só "acende" quando existe sequência de verdade */
.hud-streak {
    color: var(--gold);
    transition: color .2s, opacity .2s;
}

.hud-streak.cold {
    color: var(--text-dim);
    opacity: .55;
}

/* relógio do HUD: âncora pro "+Ns" flutuante e badge de infinito */
#hud-clock {
    position: relative;
}
/* o FontAwesome entra depois deste arquivo e também define display nos
   ícones, então o seletor precisa do #hud pra ter mais peso — senão o
   infinito ficava visível em TODA partida, não só no modo infinito */
#hud .hud-inf-badge {
    display: none;
    color: var(--gold);
}
body.infinite-mode #hud .hud-inf-badge {
    display: inline-block;
}

/* "+Ns" que sobe e some quando se ganha tempo no modo infinito */
.time-bonus-float {
    position: absolute;
    top: -6px;
    right: 6px;
    color: var(--correct);
    font-size: 15px;
    font-weight: 800;
    pointer-events: none;
    animation: timeBonusFloat .85s ease-out forwards;
}
@keyframes timeBonusFloat {
    0%   { opacity: 0; transform: translateY(4px) scale(.8); }
    20%  { opacity: 1; transform: translateY(-6px) scale(1); }
    100% { opacity: 0; transform: translateY(-26px) scale(1); }
}

#time-bar-wrap {
    width: 100%;
    height: 10px;
    background: var(--surface-2);

    overflow: hidden;
    margin-bottom: 18px;
}

#time-bar {
    height: 100%;
    width: 100%;
    background: var(--accent);

    transition: width .2s linear, background .25s;
}

#problem-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

/* ----- Bônus Relâmpago: barra do tempo desta conta ----- */
#flash-bar-wrap {
    display: none;
    width: 100%;
    height: 6px;
    background: var(--surface-2);
    overflow: hidden;
    margin: -8px 0 14px;
}

body.flash-mode #flash-bar-wrap {
    display: block;
}

#flash-bar {
    height: 100%;
    width: 100%;
    background: var(--gold);
    transition: width .1s linear, background .2s;
}

/* ----- Bônus Piscar: a conta some, mas o espaço dela fica -----
   borrar em vez de esconder mantém a largura do campo de resposta parada
   (o texto é nowrap e o input é flex: 1, sumir faria tudo pular) */
#problem-text.blinked {
    filter: blur(12px);
    opacity: .3;
    user-select: none;
}

#problem-text {
    font-size: clamp(24px, 7vw, 34px);
    font-weight: 800;
    white-space: nowrap;
    transition: filter .25s, opacity .25s;
}

#answer-input {
    flex: 1;
    min-width: 0;
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    padding: 12px;
    border: 2px solid var(--border);

    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    outline: none;
    transition: border-color .2s, background .2s;
}

#answer-input:focus {
    border-color: var(--accent);
}

#problem-row.correct #answer-input {
    border-color: var(--correct);
    background: var(--accent-soft);
}

#problem-row.wrong #answer-input {
    border-color: var(--wrong);
    animation: shake .3s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0)
    }

    25% {
        transform: translateX(-7px)
    }

    75% {
        transform: translateX(7px)
    }
}

#backspace-btn {
    width: 54px;
    height: 54px;
    flex: none;
    border: none;

    background: var(--surface-2);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
}

#backspace-btn:active {
    background: var(--border);
}

#game-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

#finish-btn {
    flex: 1;
    padding: 13px;
    border: none;

    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

#finish-btn:hover {
    background: var(--accent-press);
}

#toggle-keypad {
    width: 56px;
    border: none;

    background: var(--accent);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

#toggle-keypad.off {
    background: var(--surface-2);
    color: var(--text-dim);
}

#scratch-wrap {
    position: relative;
    /* base 0 + min-height 0: a altura vem só do espaço livre do flex,
       não do tamanho do canvas (senão não encolhia ao mostrar o teclado) */
    flex: 1 1 0;
    min-height: 0;
    background: var(--surface);
    border: 1px solid var(--border);

    overflow: hidden;
    margin-bottom: 12px;
}

#scratch-pad {
    /* fora do fluxo: nunca influencia a altura do wrap */
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}

#clear-scratch {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border: none;

    background: var(--accent);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
}

#clear-scratch:active {
    background: var(--accent-press);
}

#keypad {
    /* flutua por cima do rodapé do canvas: o rascunho não muda de tamanho */
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 10px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 2;
}

body.keypad-hidden #keypad {
    display: none;
}

/* teclado neutro tipo calculadora — menos "parede verde", mais legível */
.key {
    padding: 18px 0;
    border: 1px solid var(--border);

    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 24px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .05s, background .15s;
}

.key:active {
    transform: scale(.95);
    background: var(--surface-2);
}

/* operadores em destaque (sinal e vírgula) */
.key-sign,
.key-dot {
    color: var(--accent);
}

.key.disabled {
    background: var(--disabled);
    color: var(--disabled-text);
    border-color: transparent;
    pointer-events: none;
}

/* =========================================================================
   TELA 4: RESUMO
   ========================================================================= */
.summary-title {
    text-align: center;
    font-size: 24px;
    font-weight: 800;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    margin: 8px 0 20px;
}

.summary-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.summary-col-left,
.summary-col-right {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 6 colunas internas pra caber linha de 1, de 3 e de 2 no mesmo grid, sem
   sobrar buraco: destaque (6) / acertos-erros-tempo (2 cada) / precisão-
   sequência (3 cada) */
.summary-stats {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
}

.sc-hero { grid-column: span 6; }
.sc-third { grid-column: span 2; }
.sc-half { grid-column: span 3; }

.sc-hero {
    border-color: var(--gold);
    padding: 18px 8px;
}

.sc-hero .ss-val {
    font-size: 44px;
}

.ic-points {
    color: var(--gold);
}

.points-c {
    color: var(--gold);
}

.ic-streak {
    color: var(--gold);
}

/* a conta aberta: "29 × 2,01" — sem isso o jogador não tem como perceber
   que ligar um bônus multiplicou a pontuação dele */
.ss-formula {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-dim);
    cursor: help;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);

    padding: 14px 8px;
}

.sc-icon {
    font-size: 17px;
    color: var(--text-dim);
}

.ic-correct {
    color: var(--correct);
}

.ic-wrong {
    color: var(--wrong);
}

.ss-label {
    font-size: 13px;
    color: var(--text-dim);
}

.ss-val {
    font-size: 30px;
    font-weight: 800;
    line-height: 1;
}

.correct-c {
    color: var(--correct);
}

.wrong-c {
    color: var(--wrong);
}

#save-area {
    background: var(--surface);
    border: 1px solid var(--border);

    padding: 16px;
    text-align: center;
}

#player-name-input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    text-align: center;
    border: 2px solid var(--border);

    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    outline: none;
    margin-bottom: 10px;
}

#player-name-input:focus {
    border-color: var(--accent);
}

#save-score-btn {
    width: 100%;
    padding: 13px;
    border: none;

    background: var(--gold);
    color: #2a2200;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

#save-score-btn:active {
    filter: brightness(.95);
}

#save-score-btn:disabled {
    background: var(--disabled);
    color: var(--disabled-text);
    cursor: default;
}

#save-status {
    font-size: 14px;
    color: var(--text-dim);
    margin: 8px 0 0;
    min-height: 18px;
}

/* motivo de o botão estar travado (acertos abaixo do mínimo) */
#save-status.warn {
    color: var(--gold);
}

#player-name-input:disabled {
    background: var(--disabled);
    color: var(--disabled-text);
    cursor: default;
}

.history-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    font-weight: 700;
    margin: 0 0 4px 2px;
}

#history-list {
    max-height: 42vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 2px;
}

.hist-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 12px;

    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 16px;
}

.hist-item .h-q {
    font-weight: 700;
}

.hist-item .h-a {
    color: var(--text-dim);
}

.hist-item.ok {
    border-left: 4px solid var(--correct);
}

.hist-item.no {
    border-left: 4px solid var(--wrong);
}

.hist-item.no .h-q b {
    color: var(--wrong);
    text-decoration: line-through;
}

.summary-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.summary-buttons button {
    padding: 14px;
    border: none;

    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
}

.summary-buttons button:hover {
    filter: brightness(1.05);
}

.summary-buttons button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.summary-buttons button.secondary:hover {
    background: var(--surface);
    filter: none;
}

/* =========================================================================
   POPUP DO PLACAR
   ========================================================================= */
.popup {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding:
        calc(14px + var(--safe-top))
        calc(14px + var(--safe-right))
        calc(14px + var(--safe-bottom))
        calc(14px + var(--safe-left));
}

.popup-content {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);

    padding: 22px;
    width: 100%;
    max-width: 1080px;
    animation: pop .22s ease;

    /* sem teto de altura, conteúdo alto (ex: o acordeão da pontuação aberto)
       transborda — e como o .popup centraliza, o topo fica inalcançável em vez
       de só sobrar pra baixo. O 28px desconta o padding do .popup. */
    max-height: calc(100dvh - 28px);
    overflow-y: auto;
}

/* o placar é a exceção: altura travada e quem rola é a lista lá dentro, então
   aqui a rolagem fica desligada pra não existirem duas barras */
#leaderboard-popup .popup-content {
    height: calc(100dvh - 40px);
    max-height: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* cabeçalho e filtros ficam fixos; só a lista estica e rola */
#leaderboard-popup .leaderboard-head,
#leaderboard-popup .lb-filter-row {
    flex: none;
}

#leaderboard-popup #leaderboard-list {
    flex: 1 1 auto;
    max-height: none;
    min-height: 0;
}

@keyframes pop {
    from {
        transform: scale(.92);
        opacity: 0
    }

    to {
        transform: scale(1);
        opacity: 1
    }
}

.leaderboard-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.leaderboard-head h2 {
    margin: 0;
    font-size: 22px;
    color: var(--gold);
}

.close-x {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 24px;
    cursor: pointer;
}

.lb-filter-row {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.lb-filter-row input,
.lb-filter-row select {
    flex: 1;
    min-width: 120px;
    padding: 10px;
    border: 1px solid var(--border);

    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    outline: none;
}

.lb-filter-row input:focus,
.lb-filter-row select:focus {
    border-color: var(--accent);
}

.lb-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    margin-left: 8px;

    background: var(--surface-2);
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 700;
    vertical-align: middle;
}

#leaderboard-list {
    max-height: 56vh;
    overflow-y: auto;
    overflow-x: auto;
}

.leaderboard-table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
}

.lb-correct b {
    color: var(--correct);
}

/* só na célula: no cabeçalho a classe existe pra dar largura, e o ícone lá
   deve ficar da cor dos outros títulos */
td.lb-wrong {
    color: var(--wrong);
}

/* pontos = a métrica que ordena o placar, então é o número que salta */
.lb-points b {
    color: var(--gold);
    font-size: 15px;
}

.lb-bonus {
    white-space: nowrap;
}

.lb-bonus-i {
    color: var(--accent);
    margin: 0 2px;
    font-size: 12px;
}

.lb-dash {
    color: var(--text-dim);
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 9px 6px;
    text-align: center;
    font-size: 14px;
}

.leaderboard-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg);
    border-bottom: 2px solid var(--border);
    color: var(--text-dim);
}

.lb-name {
    text-align: left !important;
    font-weight: 700;
}

/* zebrado por classe, não por nth-child: as linhas de seção do pódio contam
   como irmãs e deixariam a alternância irregular */
.lb-row.lb-alt {
    background: var(--surface);
}

/* título de faixa do pódio ("Rápido · 15–30s") e da classificação geral */
.leaderboard-table .lb-section td {
    padding: 16px 8px 7px;
    text-align: left;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.lb-pos {
    font-weight: 900;
    width: 34px;
}

/* medalhas do pódio (ícone FontAwesome no lugar dos emojis de medalha) */
.lb-medal {
    font-size: 17px;
}
.lb-medal-1 { color: var(--gold); }
.lb-medal-2 { color: #b8c0cc; }
.lb-medal-3 { color: #cd7f32; }

.lb-row.highlight-new {
    animation: flash 1.4s ease;
    font-weight: 700;
}

@keyframes flash {

    0%,
    100% {
        background: transparent
    }

    30% {
        background: var(--accent-soft)
    }
}

.no-scores {
    padding: 30px;
    text-align: center;
    color: var(--text-dim);
}

/* ----- Placar em telas estreitas -----
   com min-width: 540px a tabela saía da tela e as últimas colunas (%, sequência
   e bônus) ficavam cortadas. Aqui ela encolhe pra caber sem rolagem lateral. */
@media (max-width: 620px) {
    .popup {
        padding: 8px;
    }

    #leaderboard-popup .popup-content {
        padding: 14px 10px;
        height: calc(100dvh - 28px);
    }

    .lb-filter-row {
        gap: 6px;
    }

    .lb-filter-row input,
    .lb-filter-row select {
        min-width: 0;
        padding: 8px 6px;
        font-size: 13px;
    }

    /* 4 filtros não cabem numa linha só: a busca fica em cima sozinha e os
       três selects dividem a linha de baixo */
    .lb-filter-row input {
        flex: 1 0 100%;
    }

    .leaderboard-table {
        min-width: 0;
        table-layout: fixed;
    }

    .leaderboard-table th,
    .leaderboard-table td {
        padding: 8px 1px;
        font-size: 11px;
    }

    /* Dez colunas não cabem num celular. Erros e maior sequência saem: a
       precisão já diz o mesmo que os erros, e as duas continuam no resumo da
       partida. Sobram oito — uma a menos do que antes de existirem pontos. */
    .lb-wrong,
    .lb-streak {
        display: none;
    }

    /* larguras fixas: apelido e operação ficam com o espaço que sobra, o resto
       são números curtos. Só essas duas colunas podem quebrar palavra. */
    .lb-name,
    .lb-op {
        overflow-wrap: anywhere;
        hyphens: auto;
    }

    .lb-pos    { width: 20px; }
    .lb-points { width: 34px; }
    .lb-op     { width: 24%; }
    .lb-time   { width: 30px; }
    .lb-correct { width: 26px; }
    .lb-acc    { width: 32px; }
    .lb-bonus  { width: 38px; }

    .lb-points b {
        font-size: 12px;
    }

    .lb-medal {
        font-size: 13px;
    }

    .lb-bonus-i {
        margin: 0 1px;
        font-size: 10px;
    }
}

/* =========================================================================
   MENSAGENS DE CONEXÃO / ALERTAS / FOOTER
   ========================================================================= */
.connection-message {
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    padding: 0 12px;

    background: var(--surface);
    border: 1px solid var(--border);

    margin: 0;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity .4s, max-height .4s, margin .4s, padding .4s;
}

.connection-message.show {
    opacity: 1;
    max-height: 60px;
    margin-top: 16px;
    margin-bottom: 20px;
    padding: 10px 12px;
}

.offline-msg {
    border-left: 4px solid var(--wrong);
    color: var(--wrong);
}

.online-msg {
    border-left: 4px solid var(--correct);
    color: var(--correct);
}

#customAlertNoScore {
    position: fixed;
    top: calc(70px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--gold);
    color: #2a2200;
    padding: 14px 22px;

    font-weight: 700;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s, transform .3s;
}

#customAlertNoScore.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

footer {
    text-align: center;
    margin-top: 28px;
    color: var(--text-dim);
    font-size: 13px;
}

/* dica de teclado físico: só no PC (ver media query abaixo) */
.pc-hint {
    display: none;
}

/* =========================================================================
   RESPONSIVO
   ========================================================================= */

/* ----- Telefones pequenos ----- */
@media (max-width: 380px) {
    .op-btn {
        font-size: 13px;
        gap: 9px;
        padding: 10px 11px;
    }

    .op-btn i {
        width: 30px;
        height: 30px;
    }

    .summary-stats {
        gap: 8px;
    }

    .ss-val {
        font-size: 26px;
    }

}

/* ----- Telefones pequenos ----- */
@media (max-width: 450px) {

    /* com a sequência são 4 itens no HUD: sem apertar, eles estouram a largura
       de um celular de 360px */
    #hud {
        gap: 6px;
    }

    .hud-item {
        min-width: 0;
        padding: 7px 9px;
        font-size: 16px;
    }

    .bonus-row{
        flex-direction: column;
    }

    .bonus-row .switch{
        width: 100%;
    }

    /* como a largura agora é 100%, o "left: 22px" fixo deixa a bolinha no
       meio; usa calc no left (em vez de right) pra ir até o fim
       mantendo a transição deslizante */
    .bonus-row .switch:checked::after{
        left: calc(100% - 20px);
    }
}

/* ----- Tablet / Desktop: aproveita o espaço horizontal -----
   As telas deixam de ser uma coluna estreita e abrem em grade. */
@media (min-width: 760px) {

    /* Operações: 3 dificuldades lado a lado (Fácil | Médio | Difícil) */
    #screen-operations {
        max-width: 1080px;
    }

    .op-sections {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        align-items: start;
    }

    .op-section .op-grid {
        grid-template-columns: 1fr;
    }

    .op-section .op-btn.wide {
        grid-column: auto;
    }

    /* Tempo: presets à esquerda, bônus à direita */
    #screen-time {
        max-width: 1080px;
    }

    .time-layout {
        display: grid;
        grid-template-columns: 1.1fr .9fr;
        gap: 24px;
        align-items: start;
    }

    /* Resumo: estatísticas/ações à esquerda, histórico à direita */
    #screen-summary {
        max-width: 1080px;
    }
    
    .summary-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        align-items: start;
    }

    #history-list {
        max-height: 56vh;
    }
}

/* ----- No PC (mouse): sem teclado na tela e sem rascunho =====
   desenhar com mouse é ruim e o teclado físico já tem números, - e , */
/* ----- Layout de PC: sem teclado na tela e sem rascunho -----
   Vale sempre que o "modo celular" estiver desligado (body.desktop-mode), em
   qualquer largura — desenhar com mouse é ruim e o teclado físico já tem
   números, - e ,. Quem está no celular e prefere assim também pode desligar.
   A classe é posta pelo script inline do index.html, antes da primeira
   pintura, pra tela nenhuma piscar com o layout errado. */
body.desktop-mode #keypad,
body.desktop-mode #scratch-wrap,
body.desktop-mode #toggle-keypad,
body.desktop-mode #backspace-btn {
    display: none !important;
}

/* a tela não precisa ocupar 100% da altura sem o rascunho */
body.desktop-mode #screen-game {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    justify-content: flex-start;
    padding-top: 32px;
    max-width: 620px;
}

/* conta vira um cartão grande e centrado: foco total no problema */
body.desktop-mode #problem-row {
    gap: 18px;
    margin-top: 18px;
    padding: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
}

body.desktop-mode #problem-text {
    font-size: 42px;
}

body.desktop-mode #answer-input {
    width: 100%;
    font-size: 32px;
    padding: 16px;
}

body.desktop-mode .pc-hint {
    display: block;
    text-align: center;
    color: var(--text-dim);
    font-size: 15px;
    margin-top: 16px;
}

.pc-hint kbd {
    background: var(--surface-2);
    border: 1px solid var(--border);

    padding: 2px 8px;
    font-family: inherit;
    font-weight: 700;
    color: var(--text);
}

/* numa tela pequena o cartão grande não cabe: volta ao tamanho normal */
@media (max-width: 620px) {
    body.desktop-mode #problem-row {
        gap: 10px;
        margin-top: 10px;
        padding: 14px;
    }

    body.desktop-mode #problem-text {
        font-size: 28px;
    }

    body.desktop-mode #answer-input {
        font-size: 24px;
        padding: 10px;
    }

    body.desktop-mode .pc-hint {
        font-size: 13px;
    }
}

/* Modo celular numa tela grande (tablet, TV com touch): mantém o teclado e o
   rascunho, mas numa coluna estreita — o teclado esticado numa TV fica largo
   demais pra alcançar com o polegar. */
@media (min-width: 769px) {
    body.mobile-mode #screen-game {
        max-width: 560px;
    }
}
