/* Mobile layout: normal document flow keeps every control reachable. */
@media (max-width: 700px) {
    body { overflow-x: hidden; overflow-y: auto; }
    .app { display: block; height: auto; min-height: 100dvh; overflow: visible; }
    .sidebar {
        width: 100%; height: auto; min-height: 0; padding: 8px 12px;
        flex-direction: row; align-items: center; justify-content: space-between;
        gap: 8px; border-right: 0; border-bottom: 1px solid var(--border);
    }
    .sidebar .logo { padding: 0; margin: 0; gap: 6px; flex-shrink: 0; }
    .sidebar .logo-icon { width: 30px; height: 30px; flex-basis: 30px; }
    .sidebar .logo-icon img { width: 100%; height: 100%; object-fit: contain; }
    .sidebar .menu { display: flex; flex-direction: row; gap: 4px; margin: 0; }
    .sidebar .menu-item { width: 40px; height: 40px; min-height: 40px; padding: 0; margin: 0; }
    .sidebar .sidebar-footer { display: none; }
    .sidebar .theme-toggle { width: 40px; height: 40px; flex-basis: 40px; }
    .conteudo { height: auto; overflow: visible; padding: 12px 12px max(20px, env(safe-area-inset-bottom)); }
    .topbar { height: auto; min-height: 0; margin-bottom: 12px; display: block; }
    .topbar > div:first-child { display: block; margin-bottom: 10px; }
    .topbar h1 { font-size: 21px; margin: 0; }
    .topbar-direita {
        display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 8px; height: auto; overflow: visible; padding: 0;
    }
    .topbar-direita > * { min-width: 0; max-width: 100%; margin: 0; }
    .timer-settings-btn { grid-column: 1; grid-row: 1; position: static; width: 100%; min-height: 42px; background: var(--card, rgba(127,150,170,.08)); font-size: 13px; }
    .timer-settings-btn-label { display: inline; }
    .mode-card { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); padding: 4px; width: 100%; }
    .mode-card .mode-btn { min-height: 40px; padding: 8px 4px; font-size: 12px; }
    .event-card { grid-column: 1; grid-row: 2; padding: 6px 8px; }
    .event-select-wrap { width: 100%; gap: 4px; }
    .event-select-wrap > span { display: inline; font-size: 9px; }
    .event-select-wrap select { min-width: 0; max-width: 100%; width: 100%; height: 36px; font-size: 13px; }
    .session-card { grid-column: 1 / -1; grid-row: 3; padding: 6px 8px; gap: 6px; }
    .session-select-wrap { min-width: 0; flex: 1; }
    .session-select-wrap > span { display: inline; font-size: 9px; }
    .session-select-wrap select { min-width: 0; width: 100%; max-width: none; height: 36px; font-size: 13px; }
    .session-actions { gap: 4px; flex-shrink: 0; }
    .session-actions button { width: 36px; height: 36px; font-size: 15px; }
    .party-top-btn { min-height: 42px; width: 100%; font-size: 12px; }
    #partyBtn { grid-column: 2; grid-row: 2; }
    .cross-analyze-button { grid-column: 2; grid-row: 1; }
    .relogio { display: none; }
    .cube-page, body[data-timer-mode="manual"] .cube-page {
        display: flex; flex-direction: column; height: auto; min-height: 0; gap: 12px;
    }
    .scramble-bar, body[data-timer-mode="manual"] .scramble-bar {
        order: 0; min-height: 68px; padding: 8px 0; gap: 6px;
        grid-template-columns: 36px minmax(0, 1fr) 36px;
    }
    .scramble-button { width: 36px; height: 40px; }
    .scramble-text, body[data-timer-mode="manual"] .scramble-text { font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
    .main-timer-card, body[data-timer-mode="manual"] .main-timer-card {
        order: 2; display: grid; grid-template-columns: 1fr; min-height: 0; padding: 12px; gap: 12px;
    }
    body:not(.solve-focus-active) .timer-zone { min-height: 155px; padding: 14px 4px; }
    body:not(.solve-focus-active) .timer-display { font-size: clamp(62px, 20vw, 100px); }
    body:not(.solve-focus-active) .timer-display.resolving-text { font-size: clamp(32px, 11vw, 54px); }
    .inspection-hint { font-size: 11px; line-height: 1.5; }
    .cube-preview, body[data-timer-mode="manual"] .cube-preview { border-left: 0; border-top: 1px solid var(--border); padding: 8px 0 0; min-height: 0; }
    .cube-preview twisty-player, body[data-timer-mode="manual"] .cube-preview twisty-player { width: 100%; height: 100%; min-height: 180px; }
    .cube-help { font-size: 10px; }
    body[data-timer-mode="manual"] .cube-preview { border-top: 0; padding: 0; }
    body[data-timer-mode="manual"] #manualPanel { order: 1; display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 12px; }
    body[data-timer-mode="manual"] #manualPanel.hidden { display: none; }
    body[data-timer-mode="manual"] #manualPanel > div:first-child b { font-size: 13px; }
    body[data-timer-mode="manual"] .manual-entry { width: 100%; gap: 8px; }
    body[data-timer-mode="manual"] .manual-entry input { height: 44px; font-size: 16px; }
    body[data-timer-mode="manual"] .manual-entry button { height: 44px; font-size: 12px; padding: 8px 14px; }
    #stackmatPanel { order: 1; padding: 12px; flex-wrap: wrap; gap: 12px; }
    .stackmat-actions button { min-height: 44px; }
    .stats-grid { order: 3; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
    .stat { padding: 10px 8px; }
    .stat span { font-size: 11px; }
    .stat strong { font-size: 21px; }
    .stat small { font-size: 10px; }
    .history-card { order: 4; min-height: 220px; height: auto; max-height: 400px; padding: 10px; }
    .timer-setting-copy b { font-size: 13px; }
    .timer-setting-copy small { font-size: 11px; line-height: 1.45; }
    .timer-setting-row { padding: 12px 10px; min-height: 72px; }
    .settings-action-btn { min-height: 40px; font-size: 11px; }
    .timer-settings-close { min-width: 40px; min-height: 40px; }
}

/* Keep a definite rendering area for the WebGL player, including Safari. */
@media (max-width: 700px) {
    .main-timer-card,
    body[data-timer-mode="manual"] .main-timer-card {
        flex: 0 0 auto;
        grid-template-rows: auto;
    }
    .cube-preview,
    body[data-timer-mode="manual"] .cube-preview {
        display: flex;
        position: relative;
        width: 100%;
        height: 200px;
        min-height: 200px;
        flex: 0 0 200px;
        overflow: visible;
    }
    .cube-preview twisty-player,
    body[data-timer-mode="manual"] .cube-preview twisty-player {
        width: 100%;
        height: 200px;
        min-height: 200px;
        flex: 1 1 auto;
    }
    body:not([data-timer-mode="manual"]) .main-timer-card {
        grid-template-columns: minmax(0, 1fr) minmax(120px, 42%);
        align-items: center;
        gap: 6px;
        padding: 8px;
    }
    body:not([data-timer-mode="manual"]):not(.solve-focus-active) .timer-display {
        font-size: clamp(42px, 13vw, 78px);
    }
    body:not([data-timer-mode="manual"]):not(.solve-focus-active) .timer-display.resolving-text {
        font-size: clamp(22px, 6vw, 36px);
        white-space: normal;
    }
    body:not([data-timer-mode="manual"]) .cube-preview {
        border-top: 0;
        padding: 0;
    }
    .cube-help { max-width: 100%; font-size: 9px; text-align: center; }
}

@media (max-width: 700px) { .timer-mode-setting .mode-card { grid-column: auto; grid-row: auto; order: 0; } }
