/* ==========================================================================
   NECROPOLIS V2 - MOBILE & TACTICAL UX
   Mobile-first stylesheet. Optimized for Zebra TC22 (5", 720x1280, gloved
   touch), iPhone 12-15, and Android premium devices. Override layer on top
   of design-tokens-v2.css. No JS dependencies.
   ========================================================================== */


/* ==========================================================================
   1. ROOT TOKENS - MOBILE OVERRIDES
   ========================================================================== */
:root {
    /* Touch targets - TC22 with industrial gloves needs 48px minimum */
    --tap-min: 48px;
    --tap-comfort: 56px;
    --tap-gap: 8px;

    /* Mobile typography scale (anti-zoom iOS = 16px floor for inputs) */
    --fs-body-mobile: 16px;
    --fs-small-mobile: 14px;
    --fs-tiny-mobile: 12px;
    --fs-h1-mobile: 28px;
    --fs-h2-mobile: 22px;
    --fs-h3-mobile: 18px;
    --lh-tight: 1.3;
    --lh-base: 1.5;
    --lh-relaxed: 1.7;

    /* Safe areas - iOS notch / Dynamic Island / Android gesture bar */
    --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);

    /* Bottom nav geometry */
    --nav-h: 64px;
    --nav-total-h: calc(var(--nav-h) + var(--safe-bottom));

    /* Top bar geometry */
    --topbar-h: 56px;
    --topbar-h-compact: 44px;
    --topbar-total-h: calc(var(--topbar-h) + var(--safe-top));

    /* Mobile motion budget - reduced from desktop */
    --t-fast: 120ms;
    --t-base: 180ms;
    --t-slow: 280ms;
    --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Active state feedback (gloves need visible press) */
    --press-scale: 0.96;
    --press-bg-overlay: rgba(255, 255, 255, 0.08);

    /* Backdrop blur - fallback safe color */
    --bd-blur-fallback: rgba(10, 12, 18, 0.92);
}


/* ==========================================================================
   2. GLOBAL RESETS - MOBILE
   ========================================================================== */
*,
*::before,
*::after {
    /* Touch tap highlight removal - we render our own active state */
    -webkit-tap-highlight-color: transparent;
    /* Prevent unwanted text selection on UI chrome */
    -webkit-touch-callout: none;
}

html {
    /* Anti-overscroll bounce on iOS body level */
    overscroll-behavior-y: none;
    /* Avoid horizontal pan when an inner scroller is at edge */
    overscroll-behavior-x: contain;
    /* Stop iOS from inflating font on landscape rotation */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* GPU smoothing for body-level scroll */
    scroll-behavior: smooth;
}

body {
    font-size: var(--fs-body-mobile);
    line-height: var(--lh-base);
    letter-spacing: 0.01em;
    /* Padding accounts for fixed bottom nav so last content is reachable */
    padding-bottom: var(--nav-total-h);
    /* Lock horizontal scroll - mobile design must never scroll H */
    overflow-x: hidden;
    /* Smooth text on retina */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Allow body content selection (excluded by selectors below for chrome) */
    -webkit-user-select: text;
    user-select: text;
}

/* Re-enable selection for content blocks (excluded above on UI chrome) */
.selectable,
p, h1, h2, h3, h4, h5, h6, li, td, th,
input, textarea {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}


/* ==========================================================================
   3. TOUCH TARGETS - 48px MIN, 8px GAP (TC22 GLOVE-FRIENDLY)
   ========================================================================== */
/* Cible UNIQUEMENT les boutons sans classe explicite V1 (.btn) ou V2 (.btn-v2)
   pour ne PAS ecraser leurs styles. */
button:not(.btn):not(.btn-v2):not(.btn-icon):not(.icon-btn),
input[type="button"],
input[type="submit"],
input[type="reset"],
[role="button"]:not(.btn):not(.btn-v2),
.touch-target {
    min-height: var(--tap-min);
    min-width: var(--tap-min);
    padding: 12px 16px;
    touch-action: manipulation;
    transition:
        transform var(--t-fast) var(--ease-out),
        background-color var(--t-fast) var(--ease-out),
        box-shadow var(--t-fast) var(--ease-out);
}

/* will-change retire pour eviter promotion GPU permanente sur tous boutons.
   Les boutons V1 .btn gardent leur transition propre via app.css. */

button:not(.btn):not(.btn-v2):active,
[role="button"]:not(.btn):not(.btn-v2):active,
.touch-target:active {
    transform: scale(var(--press-scale));
    background-image: linear-gradient(var(--press-bg-overlay), var(--press-bg-overlay));
}

/* Icon-only buttons need explicit min-tap regardless of icon size */
.btn-icon,
.icon-btn,
button.icon {
    min-height: var(--tap-min);
    min-width: var(--tap-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Stack of small buttons - guarantee 8px gap so gloves don't mis-tap */
.btn-stack > * + *,
.btn-row > * + *,
.touch-list > * + * {
    margin-top: var(--tap-gap);
}
.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tap-gap);
}
.btn-row > * + * {
    margin-top: 0;
}

/* List rows - tappable rows need padding to reach 48px tall */
.list-row,
li.tap,
.menu-item {
    min-height: var(--tap-min);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background-color var(--t-fast) var(--ease-out);
}
.list-row:active,
li.tap:active,
.menu-item:active {
    background-color: var(--press-bg-overlay);
}


/* ==========================================================================
   4. TYPOGRAPHY - MOBILE FIRST
   ========================================================================== */
h1, .h1 {
    font-size: var(--fs-h1-mobile);
    line-height: var(--lh-tight);
    letter-spacing: -0.01em;
    font-weight: 700;
}
h2, .h2 {
    font-size: var(--fs-h2-mobile);
    line-height: var(--lh-tight);
    letter-spacing: -0.005em;
    font-weight: 700;
}
h3, .h3 {
    font-size: var(--fs-h3-mobile);
    line-height: var(--lh-tight);
    font-weight: 600;
}
p, li, td, dd {
    font-size: var(--fs-body-mobile);
    line-height: var(--lh-base);
}
small, .text-small {
    font-size: var(--fs-small-mobile);
    line-height: var(--lh-base);
}
.text-tiny,
.caption {
    font-size: var(--fs-tiny-mobile);
    line-height: var(--lh-base);
    letter-spacing: 0.02em;
}

/* Numeric / HUD text - tabular for stable rendering */
.num,
.hud,
.stat-value,
.timer {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}


/* ==========================================================================
   5. TOP BAR - STICKY, BACKDROP BLUR, COMPACT-ON-SCROLL
   ========================================================================== */
.topbar,
.app-topbar,
header.sticky {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--topbar-total-h);
    padding-top: var(--safe-top);
    padding-left: max(16px, var(--safe-left));
    padding-right: max(16px, var(--safe-right));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background-color: var(--bd-blur-fallback);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    transition:
        height var(--t-base) var(--ease-out),
        background-color var(--t-base) var(--ease-out);
}

/* Compact mode - JS toggles .is-compact when scroll > threshold */
.topbar.is-compact,
.app-topbar.is-compact {
    height: calc(var(--topbar-h-compact) + var(--safe-top));
}
.topbar.is-compact .topbar-nav,
.app-topbar.is-compact .topbar-nav {
    /* Hide secondary nav, keep resources visible */
    display: none;
}
.topbar.is-compact .topbar-resources,
.app-topbar.is-compact .topbar-resources {
    transform: scale(0.92);
    transform-origin: right center;
}

.topbar-resources {
    display: flex;
    align-items: center;
    gap: 12px;
    transition: transform var(--t-base) var(--ease-out);
}

/* Scrolled visual lift */
.topbar.is-scrolled,
.app-topbar.is-scrolled {
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 8px 24px rgba(0, 0, 0, 0.35);
}


/* ==========================================================================
   6. BOTTOM NAVIGATION - SAFE AREA, ACTIVE PULSE
   ========================================================================== */
.bottom-nav,
nav.app-bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 60;
    height: var(--nav-total-h);
    padding-bottom: var(--safe-bottom);
    padding-left: max(0px, var(--safe-left));
    padding-right: max(0px, var(--safe-right));
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    align-items: stretch;
    background-color: var(--bd-blur-fallback);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.bottom-nav .nav-item,
nav.app-bottom-nav a {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--nav-h);
    padding: 6px 4px;
    color: var(--color-text-muted, rgba(255, 255, 255, 0.55));
    text-decoration: none;
    font-size: var(--fs-tiny-mobile);
    letter-spacing: 0.02em;
    transition:
        color var(--t-base) var(--ease-out),
        background-color var(--t-fast) var(--ease-out);
    touch-action: manipulation;
}

.bottom-nav .nav-item .icon,
nav.app-bottom-nav a .icon,
.bottom-nav .nav-item svg,
nav.app-bottom-nav a svg {
    width: 24px;
    height: 24px;
    transition: transform var(--t-base) var(--ease-spring);
}

.bottom-nav .nav-item:active,
nav.app-bottom-nav a:active {
    background-color: var(--press-bg-overlay);
}

/* Active route - icon scale + colored bg pulse */
.bottom-nav .nav-item.is-active,
.bottom-nav .nav-item[aria-current="page"],
nav.app-bottom-nav a.is-active,
nav.app-bottom-nav a[aria-current="page"] {
    color: var(--color-accent, #00ff95);
}
.bottom-nav .nav-item.is-active .icon,
.bottom-nav .nav-item[aria-current="page"] .icon,
.bottom-nav .nav-item.is-active svg,
.bottom-nav .nav-item[aria-current="page"] svg,
nav.app-bottom-nav a.is-active .icon,
nav.app-bottom-nav a[aria-current="page"] .icon,
nav.app-bottom-nav a.is-active svg,
nav.app-bottom-nav a[aria-current="page"] svg {
    transform: scale(1.12);
}

/* Pulse pill behind active icon */
.bottom-nav .nav-item.is-active::before,
.bottom-nav .nav-item[aria-current="page"]::before,
nav.app-bottom-nav a.is-active::before,
nav.app-bottom-nav a[aria-current="page"]::before {
    content: "";
    position: absolute;
    top: 4px;
    left: 50%;
    width: 40px;
    height: 28px;
    border-radius: 14px;
    background: radial-gradient(
        ellipse at center,
        var(--color-accent-glow, rgba(0, 255, 149, 0.18)) 0%,
        transparent 70%
    );
    transform: translateX(-50%);
    animation: nav-pulse 2.4s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes nav-pulse {
    0%, 100% { opacity: 0.6; transform: translateX(-50%) scale(1); }
    50%      { opacity: 1.0; transform: translateX(-50%) scale(1.06); }
}


/* ==========================================================================
   7. SCROLLING - MOMENTUM, SNAP, PULL-TO-REFRESH HINT
   ========================================================================== */
.scroll-x,
.h-scroll,
.cards-rail {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 16px;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    display: flex;
    gap: 12px;
    padding: 8px 16px 16px;
}
.scroll-x::-webkit-scrollbar,
.h-scroll::-webkit-scrollbar,
.cards-rail::-webkit-scrollbar { display: none; }

.scroll-x > *,
.h-scroll > *,
.cards-rail > .card {
    scroll-snap-align: start;
    scroll-snap-stop: always;
    flex: 0 0 auto;
}

.scroll-y {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* Pull-to-refresh hint - visual only (logic in JS via overscroll events) */
.pull-refresh-host { position: relative; }
.pull-refresh-indicator {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -100%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-surface, rgba(20, 24, 32, 0.92));
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition:
        transform var(--t-base) var(--ease-out),
        opacity var(--t-base) var(--ease-out);
    pointer-events: none;
}
.pull-refresh-host.is-pulling .pull-refresh-indicator {
    opacity: 1;
    transform: translate(-50%, 12px);
}
.pull-refresh-host.is-refreshing .pull-refresh-indicator {
    opacity: 1;
    transform: translate(-50%, 16px);
    animation: ptr-spin 0.9s linear infinite;
}
@keyframes ptr-spin {
    from { transform: translate(-50%, 16px) rotate(0deg); }
    to   { transform: translate(-50%, 16px) rotate(360deg); }
}


/* ==========================================================================
   8. GESTURES - SWIPE TO REVEAL ACTIONS, LONG PRESS, PINCH
   ========================================================================== */
.swipe-card {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    background: var(--color-surface, rgba(20, 24, 32, 0.92));
    touch-action: pan-y;
}
.swipe-card-content {
    transition: transform var(--t-base) var(--ease-out);
    will-change: transform;
}
.swipe-card.is-swiping .swipe-card-content {
    transition: none;
}
.swipe-card.is-revealed-right .swipe-card-content {
    transform: translateX(-96px);
}
.swipe-card.is-revealed-left .swipe-card-content {
    transform: translateX(96px);
}
.swipe-actions {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
}
.swipe-actions.right { right: 0; }
.swipe-actions.left { left: 0; }
.swipe-actions button {
    min-width: 96px;
    border: 0;
    color: #fff;
    font-weight: 600;
}
.swipe-actions .danger { background: var(--color-danger, #ef4444); }
.swipe-actions .success { background: var(--color-success, #10b981); }

/* Long press feedback */
.long-press {
    position: relative;
    transition: transform var(--t-slow) var(--ease-out);
}
.long-press::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, var(--color-accent-glow, rgba(0, 255, 149, 0.2)) 0%, transparent 70%);
    opacity: 0;
    transition: opacity var(--t-slow) var(--ease-out);
    pointer-events: none;
    border-radius: inherit;
}
.long-press.is-pressing {
    transform: scale(1.02);
}
.long-press.is-pressing::after {
    opacity: 1;
}

/* Pinch-zoom container (canvas hosts) */
.pinch-host {
    touch-action: pinch-zoom;
    overflow: hidden;
    overscroll-behavior: contain;
}


/* ==========================================================================
   9. GAME CANVAS - MOBILE LAYOUT
   ========================================================================== */
.game-canvas-host,
#game-canvas-host {
    position: relative;
    width: 100%;
    /* Adapts to viewport minus chrome */
    height: calc(100dvh - var(--topbar-total-h) - var(--nav-total-h));
    /* Fallback for browsers without dvh */
    min-height: calc(100vh - var(--topbar-total-h) - var(--nav-total-h));
    overflow: hidden;
    contain: layout paint size;
    /* Critical: prevent body scroll when finger drags inside game */
    touch-action: none;
    overscroll-behavior: none;
    background: var(--color-bg-game, #0a0c12);
    isolation: isolate;
}

.game-canvas-host canvas,
#game-canvas-host canvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    image-rendering: -webkit-optimize-contrast;
    touch-action: none;
}

/* HUD overlay sits above canvas, ignores pointer except own widgets */
.game-hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    padding-top: max(8px, var(--safe-top));
    padding-bottom: max(8px, var(--safe-bottom));
    padding-left: max(8px, var(--safe-left));
    padding-right: max(8px, var(--safe-right));
}
.game-hud > * {
    pointer-events: auto;
}


/* ==========================================================================
   10. FORMS - INPUT MODE, FLOATING LABELS, PASSWORD TOGGLE
   ========================================================================== */
input,
textarea,
select {
    /* 16px floor stops iOS zoom-on-focus */
    font-size: var(--fs-body-mobile);
    line-height: var(--lh-base);
    min-height: var(--tap-min);
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--color-input-bg, rgba(255, 255, 255, 0.04));
    color: var(--color-text, #fff);
    width: 100%;
    transition:
        border-color var(--t-fast) var(--ease-out),
        background-color var(--t-fast) var(--ease-out),
        box-shadow var(--t-fast) var(--ease-out);
    /* Native autofill cleanup on iOS */
    -webkit-appearance: none;
    appearance: none;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--color-accent, #00ff95);
    box-shadow: 0 0 0 3px var(--color-accent-glow, rgba(0, 255, 149, 0.15));
}

/* Disable iOS native autofill yellow */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--color-text, #fff);
    -webkit-box-shadow: 0 0 0 30px var(--color-input-bg, #1a1d24) inset;
    transition: background-color 9999s ease-in-out 0s;
}

/* Floating label */
.field {
    position: relative;
}
.field input,
.field textarea {
    padding-top: 22px;
    padding-bottom: 8px;
}
.field label {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: var(--fs-body-mobile);
    color: var(--color-text-muted, rgba(255, 255, 255, 0.55));
    transition:
        transform var(--t-base) var(--ease-out),
        font-size var(--t-base) var(--ease-out),
        color var(--t-base) var(--ease-out);
    transform-origin: left center;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label,
.field textarea:focus + label,
.field textarea:not(:placeholder-shown) + label {
    transform: translateY(-22px) scale(0.78);
    color: var(--color-accent, #00ff95);
}

/* Password show/hide toggle */
.field-password {
    position: relative;
}
.field-password input {
    padding-right: 56px;
}
.field-password .toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: var(--tap-min);
    height: var(--tap-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: var(--color-text-muted, rgba(255, 255, 255, 0.55));
    cursor: pointer;
}
.field-password.is-visible .toggle .icon-eye-off,
.field-password:not(.is-visible) .toggle .icon-eye {
    display: none;
}


/* ==========================================================================
   11. MODAL MOBILE - FULL SCREEN, DRAG-TO-DISMISS
   IMPORTANT : selecteur namespace `.modal--mobile` ou `dialog.modal[open]`
   pour ne PAS ecraser le `.modal` V1 d'app.css (modal centre 32rem).
   ========================================================================== */
.modal--mobile,
dialog.modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    margin: 0;
    border: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background: var(--color-surface, #0e1116);
    color: var(--color-text, #fff);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform var(--t-slow) var(--ease-out);
}
.modal--mobile.is-open,
dialog.modal[open] {
    transform: translateY(0);
}
.modal-handle {
    /* Drag handle bar at top of sheet */
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.25);
    margin: 8px auto 0;
    cursor: grab;
}
.modal-handle:active {
    cursor: grabbing;
}
.modal-header {
    padding: 16px;
    padding-top: max(16px, var(--safe-top));
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    overscroll-behavior: contain;
}
.modal-footer {
    padding: 12px 16px;
    padding-bottom: max(12px, var(--safe-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    gap: var(--tap-gap);
}
/* IMPORTANT : .modal-backdrop V1 (app.css) est immediatement visible avec flex.
   Cette version mobile (toggle via .is-open) doit etre namespace.
   On utilise `.modal-backdrop--mobile` pour eviter conflit. */
.modal-backdrop--mobile {
    position: fixed;
    inset: 0;
    z-index: 79;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    transition: opacity var(--t-slow) var(--ease-out);
    pointer-events: none;
}
.modal-backdrop--mobile.is-open {
    opacity: 1;
    pointer-events: auto;
}

/* Bottom-sheet variant */
.modal--mobile.sheet {
    top: auto;
    height: auto;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
}


/* ==========================================================================
   12. TOAST - TOP SAFE ON MOBILE (avoid bottom-nav overlap)
   ========================================================================== */
.toast-host {
    position: fixed;
    top: calc(var(--safe-top) + 8px);
    left: 0;
    right: 0;
    z-index: 90;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    pointer-events: none;
}
/* Toast mobile : utilise selecteur descendant `.toast-host .toast` pour ne pas
   ecraser le `.toast` V1 (app.css) qui s'auto-affiche via @keyframes fade-in-up. */
.toast-host .toast {
    pointer-events: auto;
    width: 100%;
    max-width: 480px;
    padding: 12px 16px;
    border-radius: 2px; /* respect tactical V1 (vs 12px soft) */
    background: var(--color-surface-elevated, rgba(28, 32, 40, 0.96));
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--color-text, #fff);
    font-size: var(--fs-small-mobile);
    line-height: var(--lh-base);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    /* PAS de transform/opacity:0 par defaut : laisse l'animation V1 fade-in-up
       gerer l'apparition via classe `.toast` dans app.css (animation 0.3s ease) */
}
.toast-host .toast.is-visible {
    transform: translateY(0);
    opacity: 1;
}
.toast-host .toast.success { border-color: rgba(16, 185, 129, 0.5); }
.toast-host .toast.danger  { border-color: rgba(239, 68, 68, 0.5); }
.toast-host .toast.warning { border-color: rgba(245, 158, 11, 0.5); }


/* ==========================================================================
   13. OFFLINE INDICATOR
   ========================================================================== */
.offline-indicator {
    position: fixed;
    top: var(--safe-top);
    left: 0;
    right: 0;
    z-index: 95;
    padding: 4px 16px;
    background: var(--color-warning, #f59e0b);
    color: #000;
    font-size: var(--fs-tiny-mobile);
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transform: translateY(-100%);
    transition: transform var(--t-base) var(--ease-out);
}
body.is-offline .offline-indicator {
    transform: translateY(0);
}


/* ==========================================================================
   14. CARDS, GRID, CONTAINER (MOBILE FIRST)
   ========================================================================== */
.container {
    width: 100%;
    padding-left: max(16px, var(--safe-left));
    padding-right: max(16px, var(--safe-right));
    margin: 0 auto;
}

.card {
    border-radius: 12px;
    background: var(--color-surface, rgba(20, 24, 32, 0.92));
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 16px;
    /* Avoid layout-thrash on touch */
    contain: layout style;
}
.card.compact { padding: 12px; }

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


/* ==========================================================================
   15. DENSITY ADAPTIVE (DPR-AWARE)
   ========================================================================== */
/* Standard DPR (1) - desktop / older Android */
@media (-webkit-max-device-pixel-ratio: 1.5),
       (max-resolution: 144dpi) {
    :root {
        --hud-ring-size: 32px;
        --fs-body-mobile: 16px;
    }
}

/* Mid DPR (2) - TC22, iPhone non-Pro, midrange Android */
@media (-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 2.5),
       (min-resolution: 144dpi) and (max-resolution: 240dpi) {
    :root {
        --hud-ring-size: 32px;
        --fs-body-mobile: 16px;
    }
}

/* High DPR (3+) - iPhone Pro, Pixel Pro, Galaxy S Ultra */
@media (-webkit-min-device-pixel-ratio: 2.5),
       (min-resolution: 240dpi) {
    :root {
        --hud-ring-size: 32px;
        --fs-body-mobile: 14px;
        --fs-small-mobile: 13px;
    }
    /* Slightly tighter line-height when text scales down */
    body { line-height: 1.45; }
}


/* ==========================================================================
   16. LOW MEMORY / LOW POWER FALLBACKS
   ========================================================================== */

/* Reduced motion - disables all non-essential animation */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .bottom-nav .nav-item.is-active::before,
    nav.app-bottom-nav a.is-active::before {
        animation: none;
    }
    /* Replace pulse with static glow */
    .bottom-nav .nav-item.is-active::before {
        opacity: 0.7;
    }
}

/* Low data mode (Android Save-Data) */
@media (prefers-reduced-data: reduce) {
    .bg-image,
    [data-bg-decorative] { background-image: none !important; }
    video[autoplay] { display: none; }
}

/* Backdrop-filter fallback - solid color when filter unsupported */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .topbar,
    .app-topbar,
    .bottom-nav,
    nav.app-bottom-nav,
    .toast {
        background-color: var(--color-bg-solid, #0a0c12);
    }
}

/* Increased contrast preference */
@media (prefers-contrast: more) {
    :root {
        --press-bg-overlay: rgba(255, 255, 255, 0.18);
    }
    .card,
    .topbar,
    .bottom-nav {
        border-color: rgba(255, 255, 255, 0.2);
    }
    button,
    .btn,
    a.btn {
        outline: 1px solid currentColor;
    }
}

/* Low-memory hint via class (set by JS reading navigator.deviceMemory) */
body.low-memory .parallax,
body.low-memory [data-parallax] { transform: none !important; }
body.low-memory .particles,
body.low-memory canvas.particles { opacity: 0.5; }
body.low-memory .bg-blur,
body.low-memory [data-blur] {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background-color: var(--bd-blur-fallback);
}


/* ==========================================================================
   17. ACCESSIBILITY - FOCUS, SCREEN READER, VOICE OVER
   ========================================================================== */
:focus-visible {
    outline: 2px solid var(--color-accent, #00ff95);
    outline-offset: 3px;
    border-radius: 6px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip to main link - visible on focus only */
.skip-link {
    position: absolute;
    top: 0;
    left: 0;
    transform: translateY(-100%);
    padding: 8px 16px;
    background: var(--color-accent, #00ff95);
    color: #000;
    z-index: 1000;
    transition: transform var(--t-fast) var(--ease-out);
}
.skip-link:focus {
    transform: translateY(0);
}


/* ==========================================================================
   18. ORIENTATION - LANDSCAPE COMPACT (TC22 SCANNER USE)
   ========================================================================== */
@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --topbar-h: 44px;
        --nav-h: 52px;
    }
    .topbar,
    .app-topbar {
        padding-top: max(4px, var(--safe-top));
    }
    .bottom-nav .nav-item .label,
    nav.app-bottom-nav a .label {
        display: none;
    }
    .bottom-nav .nav-item .icon,
    nav.app-bottom-nav a .icon,
    .bottom-nav .nav-item svg,
    nav.app-bottom-nav a svg {
        width: 22px;
        height: 22px;
    }
}


/* ==========================================================================
   19. BREAKPOINT OVERRIDES - SM, MD, LG, XL
   Mobile-first: rules above are the baseline. These widen for larger screens.
   ========================================================================== */

/* SM 640px+ - small tablet portrait */
@media (min-width: 640px) {
    :root {
        --fs-h1-mobile: 32px;
        --fs-h2-mobile: 24px;
    }
    .container { max-width: 640px; padding-left: 24px; padding-right: 24px; }
    .grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}

/* MD 768px+ - tablet landscape, iPad portrait */
@media (min-width: 768px) {
    .container { max-width: 768px; }
    .grid { grid-template-columns: repeat(3, 1fr); gap: 20px; }

    /* Bottom nav transitions to side-rail style on md+ */
    .bottom-nav.responsive,
    nav.app-bottom-nav.responsive {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        height: 100dvh;
        width: 80px;
        padding-top: var(--safe-top);
        padding-bottom: var(--safe-bottom);
        grid-auto-flow: row;
        grid-auto-columns: auto;
        grid-auto-rows: auto;
        border-top: 0;
        border-right: 1px solid rgba(255, 255, 255, 0.06);
    }
    body.has-side-rail {
        padding-bottom: 0;
        padding-left: 80px;
    }
}

/* LG 1024px+ - desktop small / iPad Pro */
@media (min-width: 1024px) {
    .container { max-width: 1024px; }
    .grid { grid-template-columns: repeat(4, 1fr); gap: 24px; }
    .topbar,
    .app-topbar {
        height: var(--topbar-h);
        padding-top: 0;
    }
    /* Hover-capable devices get hover state */
    @media (hover: hover) and (pointer: fine) {
        .btn:hover,
        button:hover,
        a.btn:hover {
            background-color: var(--press-bg-overlay);
        }
        .list-row:hover,
        .menu-item:hover {
            background-color: var(--press-bg-overlay);
        }
    }
}

/* XL 1280px+ - desktop normal */
@media (min-width: 1280px) {
    .container { max-width: 1280px; }
}

/* 2XL 1536px+ - large desktop */
@media (min-width: 1536px) {
    .container { max-width: 1440px; }
}


/* ==========================================================================
   20. UTILITIES - VISIBILITY, SAFE AREAS, MOBILE-ONLY HELPERS
   ========================================================================== */
.mobile-only      { display: block; }
.mobile-only-flex { display: flex; }
.desktop-only     { display: none; }

@media (min-width: 1024px) {
    .mobile-only,
    .mobile-only-flex { display: none; }
    .desktop-only     { display: block; }
}

.safe-pad-top    { padding-top: var(--safe-top); }
.safe-pad-bottom { padding-bottom: var(--safe-bottom); }
.safe-pad-x      { padding-left: var(--safe-left); padding-right: var(--safe-right); }
.safe-margin-top { margin-top: var(--safe-top); }

.no-select {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
.no-drag {
    -webkit-user-drag: none;
    user-drag: none;
}
.no-scroll {
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
}

/* Snappy scroll-to top affordance */
.fab {
    position: fixed;
    right: max(16px, var(--safe-right));
    bottom: calc(var(--nav-total-h) + 16px);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-accent, #00ff95);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    transition: transform var(--t-base) var(--ease-spring);
    z-index: 70;
}
.fab:active { transform: scale(0.92); }


/* ==========================================================================
   END mobile-v2.css
   ========================================================================== */
