/* =========================================================================
   Atomic Ionic Reactions — HUD
   Tudo local e offline: nenhuma fonte, folha ou script externo.
   ========================================================================= */

:root {
    color-scheme: dark;

    /* superficies */
    --bg: #05060a;
    --surface: rgba(17, 20, 30, 0.72);
    --surface-strong: rgba(13, 16, 24, 0.92);
    --surface-raise: rgba(255, 255, 255, 0.06);
    --surface-raise-hi: rgba(255, 255, 255, 0.12);
    --border: rgba(255, 255, 255, 0.10);
    --border-hi: rgba(255, 255, 255, 0.20);

    /* texto */
    --text: #e9edf6;
    --text-dim: #99a3ba;
    --text-faint: #8b95ad;

    /* destaque */
    --accent: #22d3ee;
    --accent-soft: rgba(34, 211, 238, 0.16);
    --accent-ink: #04222a;
    --violet: #a78bfa;

    /* forma */
    --radius: 14px;
    --radius-sm: 10px;
    --radius-pill: 999px;
    --shadow: 0 10px 34px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
    --blur: blur(18px) saturate(150%);

    /* espacamento */
    --gap: 12px;
    --pad: 12px;
    --tap: 40px;

    /* areas seguras (iOS notch etc.) */
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
        "Noto Sans", sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

/* `hidden` tem que vencer qualquer display do componente (ex.: .help-overlay). */
[hidden] { display: none !important; }

html, body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* canvas ocupa a tela toda, inclusive sob o notch (viewport-fit=cover) */
#canvas {
    position: fixed;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    z-index: 1;
    touch-action: none;
    background: var(--bg);
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ------------------------------- camada HUD ------------------------------ */

.hud {
    position: fixed;
    inset: 0;
    z-index: 2;
    padding: var(--sat) var(--sar) var(--sab) var(--sal);
    pointer-events: none;
}

.hud[data-hidden="true"] > :not(.hud-restore) { display: none; }

.panel,
.topbar,
.help-card,
.hud-restore {
    pointer-events: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
}

.panel-title,
.ctrl-group-label,
.shells-label {
    margin: 0 0 8px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
}

/* --------------------------------- botoes -------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: var(--tap);
    min-width: var(--tap);
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--surface-raise);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease,
        transform 0.1s ease;
}

.btn-icon { padding: 0; }
.btn-ghost { background: transparent; }
.btn-wide { width: 100%; margin-top: 4px; }

.btn:hover { background: var(--surface-raise-hi); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
    padding: 0 14px;
}
.btn-primary:hover { background: #4fe0f4; }

:where(.btn, .switch, .minimap-wrap, .range):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.icon {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* --------------------------------- topbar -------------------------------- */

.topbar {
    position: absolute;
    top: var(--gap);
    left: var(--gap);
    right: var(--gap);
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: 6px 10px;
    border-radius: var(--radius);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    padding-left: 4px;
    color: var(--text);
}

.brand-mark { width: 22px; height: 22px; color: var(--violet); }

.brand-name {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.brand-name-dim { color: var(--text-dim); font-weight: 500; }

.transport { display: flex; gap: 6px; margin-left: auto; }
.topbar-end { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.icon-play { display: none; }
#btn-play[aria-pressed="false"] .icon-play { display: block; }
#btn-play[aria-pressed="false"] .icon-pause { display: none; }

.fps {
    display: flex;
    align-items: baseline;
    gap: 3px;
    margin: 0 4px 0 0;
    padding: 0 8px;
    height: 28px;
    border-radius: var(--radius-pill);
    background: var(--surface-raise);
    color: var(--text-dim);
    font-size: 11px;
}

.fps-value {
    min-width: 3ch;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
}

.fps-unit { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; }

#btn-settings[aria-pressed="true"],
#btn-help[aria-expanded="true"] {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(34, 211, 238, 0.35);
}

/* ------------------------------ estatisticas ----------------------------- */

.stats {
    position: absolute;
    top: calc(var(--gap) + 64px);
    left: var(--gap);
    width: 200px;
    padding: var(--pad);
}

.stat-grid { display: grid; gap: 2px; margin: 0; }

.stat {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 0;
}

.stat + .stat { border-top: 1px solid rgba(255, 255, 255, 0.05); }

.stat dt { color: var(--text-dim); font-size: 12px; }

.stat dd {
    margin: 0;
    min-width: 4ch;
    text-align: right;
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    transition: color 0.35s ease;
}

.stat dd.is-bump { color: var(--accent); transition: none; }

/* --------------------------- navegacao / minimapa ------------------------ */

.nav {
    position: absolute;
    right: var(--gap);
    bottom: var(--gap);
    width: 216px;
    padding: 8px;
}

.minimap-wrap {
    position: relative;
    display: block;
    width: 100%;
    height: 132px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.45);
    overflow: hidden;
    cursor: crosshair;
    touch-action: none;
}

.minimap { display: block; width: 100%; height: 100%; }

.navrow {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
}

.zoom-readout {
    flex: 1;
    min-width: 52px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
}

/* -------------------------- inspector / ajustes -------------------------- */

.sheet {
    display: flex;
    flex-direction: column;
    padding: var(--pad);
}

.sheet-body {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-raise-hi) transparent;
}

.sheet-body::-webkit-scrollbar { width: 6px; }
.sheet-body::-webkit-scrollbar-thumb {
    border-radius: var(--radius-pill);
    background: var(--surface-raise-hi);
}

/* pega de arraste: so aparece no modo bottom sheet */
.sheet-grip { display: none; }

.sheet-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.sheet-titles { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.sheet-title { font-size: 14px; font-weight: 700; }
.sheet-sub { font-size: 11px; color: var(--text-dim); }

.atom-badge {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: 11px;
    border: 1px solid var(--border-hi);
    background: var(--surface-raise);
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.inspector {
    position: absolute;
    left: var(--gap);
    bottom: var(--gap);
    width: 252px;
    max-height: calc(100% - var(--gap) * 2 - 64px);
}

.kv { display: grid; gap: 0; margin: 0; }

.kv-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 0;
}

.kv-row + .kv-row { border-top: 1px solid rgba(255, 255, 255, 0.05); }
.kv-row dt { color: var(--text-dim); font-size: 12px; }

.kv-row dd {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.shells-label { margin: 12px 0 6px; }

.shells {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0;
}

.shell-chip {
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--surface-raise);
    border: 1px solid var(--border);
    font-size: 11px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
}

.settings {
    position: absolute;
    right: var(--gap);
    top: calc(var(--gap) + 64px);
    width: 264px;
    max-height: calc(100% - var(--gap) * 2 - 64px - 190px);
}

.ctrl { margin-bottom: 14px; }

.ctrl-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-dim);
}

.ctrl-value {
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    min-width: 5ch;
    text-align: right;
}

.ctrl-hint { margin: 6px 0 0; font-size: 11px; color: var(--text-faint); }

/* ------------------------- tamanho do mundo (worldScale) ------------------ */

/* Mundo maior que a tela: a dica e o atalho de reenquadrar ganham destaque. */
.ctrl-world .btn-wide { margin-top: 8px; }
.ctrl-world.is-large .ctrl-hint { color: var(--accent); }

.btn.is-attention {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(34, 211, 238, 0.45);
    animation: fit-attention 1.5s ease-out 3;
}

.btn.is-attention:hover { background: rgba(34, 211, 238, 0.26); }

@keyframes fit-attention {
    0% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.5); }
    70%, 100% { box-shadow: 0 0 0 8px rgba(34, 211, 238, 0); }
}

.range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 22px;
    margin: 0;
    background: transparent;
    cursor: pointer;
}

.range::-webkit-slider-runnable-track {
    height: 5px;
    border-radius: var(--radius-pill);
    background: var(--surface-raise-hi);
}

.range::-moz-range-track {
    height: 5px;
    border-radius: var(--radius-pill);
    background: var(--surface-raise-hi);
}

.range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    margin-top: -5.5px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.16);
}

.range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.16);
}

.toggles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 12px;
}

.switch {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.switch-track {
    position: relative;
    flex: none;
    width: 28px;
    height: 16px;
    border-radius: var(--radius-pill);
    background: var(--surface-raise-hi);
    transition: background 0.15s ease;
}

.switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: transform 0.15s ease, background 0.15s ease;
}

.switch[aria-pressed="true"] { color: var(--text); border-color: rgba(34, 211, 238, 0.3); }
.switch[aria-pressed="true"] .switch-track { background: var(--accent-soft); }
.switch[aria-pressed="true"] .switch-thumb { transform: translateX(12px); background: var(--accent); }
.switch:hover { background: var(--surface-raise); }
.switch-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------- ajuda --------------------------------- */

.help-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(3, 5, 10, 0.62);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    pointer-events: auto;
    z-index: 5;
}

.help-card {
    width: min(460px, 100%);
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    background: var(--surface-strong);
}

.shortcuts { display: grid; gap: 2px; margin: 0; }

.shortcut {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
}

.shortcut + .shortcut { border-top: 1px solid rgba(255, 255, 255, 0.05); }
.shortcut dt { display: flex; gap: 4px; width: 108px; flex: none; }
.shortcut dd { margin: 0; color: var(--text-dim); font-size: 13px; }

kbd {
    display: inline-block;
    min-width: 26px;
    padding: 3px 7px;
    border: 1px solid var(--border-hi);
    border-bottom-width: 2px;
    border-radius: 7px;
    background: var(--surface-raise);
    color: var(--text);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}

.hud-restore {
    position: absolute;
    top: var(--gap);
    right: var(--gap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
}

/* ================================= MOBILE ================================= */

@media (max-width: 767px), (max-height: 479px) {
    :root { --gap: 8px; --pad: 10px; --tap: 44px; }

    .topbar { padding: 5px 8px; gap: 8px; }
    .brand { display: none; }
    .btn-text { display: none; }
    .transport { margin-left: 0; }
    .btn-primary { padding: 0; }
    .fps { height: 26px; padding: 0 7px; }

    /* estatisticas viram barra inferior compacta e rolavel na horizontal */
    .stats {
        top: auto;
        left: var(--gap);
        right: var(--gap);
        bottom: var(--gap);
        width: auto;
        padding: 6px 10px;
    }

    .panel-title { display: none; }

    .stat-grid {
        display: flex;
        gap: 0;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
    }

    .stat-grid::-webkit-scrollbar { display: none; }

    .stat {
        flex: 1 0 auto;
        flex-direction: column-reverse;
        align-items: center;
        justify-content: center;
        gap: 0;
        min-width: 62px;
        padding: 2px 6px;
    }

    .stat + .stat {
        border-top: 0;
        border-left: 1px solid rgba(255, 255, 255, 0.06);
    }

    .stat dt { font-size: 10px; letter-spacing: 0.04em; }
    .stat dd { font-size: 16px; text-align: center; min-width: 0; }

    /* minimapa flutuante acima da barra inferior */
    .nav {
        width: 176px;
        right: var(--gap);
        bottom: calc(var(--gap) + 62px);
        padding: 6px;
    }

    .minimap-wrap { height: 86px; }
    .navrow { flex-wrap: wrap; justify-content: center; gap: 4px; margin-top: 6px; }
    .navrow .btn { min-width: 44px; min-height: 44px; }
    .zoom-readout { flex: 1 1 46px; min-width: 46px; }

    /* inspector e ajustes viram bottom sheets */
    .sheet {
        position: absolute;
        left: var(--gap);
        right: var(--gap);
        bottom: var(--gap);
        top: auto;
        width: auto;
        max-height: 34dvh;
        padding-top: 6px;
        z-index: 4;
        border-radius: 18px;
        background: var(--surface-strong);
        touch-action: none;
        transition: transform 0.18s ease;
    }

    .settings { max-height: 34dvh; }

    .sheet-grip {
        display: block;
        flex: none;
        width: 40px;
        height: 4px;
        margin: 2px auto 8px;
        border-radius: var(--radius-pill);
        background: var(--surface-raise-hi);
    }

    .sheet-head { cursor: grab; }
    .ctrl { margin-bottom: 12px; }
    .toggles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .shortcut dt { width: 96px; }
}

/* paisagem curta: compacta ainda mais e joga os paineis para a lateral */
@media (max-height: 479px) and (orientation: landscape) {
    :root { --gap: 6px; }

    .topbar { padding: 4px 6px; }
    .brand { display: none; }
    .fps { height: 24px; }

    .stats { padding: 3px 8px; }
    .stat { min-width: 56px; padding: 0 6px; }
    .stat dd { font-size: 14px; }

    .nav { width: 168px; bottom: calc(var(--gap) + 58px); padding: 5px; }
    .minimap-wrap { height: 62px; }
    .navrow { margin-top: 5px; }

    .sheet {
        left: auto;
        right: var(--gap);
        top: calc(var(--gap) + 56px);
        bottom: var(--gap);
        width: min(300px, 34vw);
        max-height: none;
        padding-top: var(--pad);
    }

    .settings { max-height: none; }
    .sheet-grip { display: none; }
    .sheet-head { cursor: default; }

    .help-card { padding: 12px; }
    .shortcut { padding: 3px 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
