/* NEXA V10: iPhone / Mobile Safari layout and touch-quality hardening.
 * Viewport widths tested from 320–440 CSS px; safe-area insets follow the device.
 * No changes to quotations, margin accounting, futures execution or i18n keys.
 */
@supports (-webkit-touch-callout: none) {
  html { -webkit-text-size-adjust: 100%; }
}
@media (max-width: 640px) {
  :root {
    --nexa-safe-top: env(safe-area-inset-top, 0px);
    --nexa-safe-right: env(safe-area-inset-right, 0px);
    --nexa-safe-bottom: env(safe-area-inset-bottom, 0px);
    --nexa-safe-left: env(safe-area-inset-left, 0px);
    --header: calc(56px + var(--nexa-safe-top));
  }
  html, body { width:100%; max-width:100%; }
  html { scroll-padding-top: calc(var(--header) + 16px); }
  html:has(.has-route-bar) { scroll-padding-top:calc(var(--header) + var(--route-bar-height) + 16px); }
  body { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(77px + var(--nexa-safe-bottom)); }
  /* The header sits clear of the Dynamic Island / notch; the back bar follows it. */
  .site-header {
    height: var(--header);
    min-height: var(--header);
    padding-top: var(--nexa-safe-top);
    padding-left: max(12px, var(--nexa-safe-left));
    padding-right: max(12px, var(--nexa-safe-right));
    gap: 8px;
    isolation: isolate;
  }
  .site-header .brand { flex: 0 1 auto; min-width:0; font-size:clamp(19px,5vw,22px); }
  .brand-divider, .brand small { display:none; }
  .header-actions { min-width:0; flex-shrink:0; gap:4px; }
  .header-actions .language-btn { min-width:44px; min-height:44px; padding:10px 3px; font-size:12px; }
  .header-actions .contest-account-btn { min-width:44px; min-height:44px; }
  .header-actions .icon-button { min-width:44px; min-height:44px; }
  .route-back-shell { top: var(--header); }
  .route-back-inner { width: auto; margin-left:max(12px,var(--nexa-safe-left)); margin-right:max(12px,var(--nexa-safe-right)); }
  .route-back-shell :is(.back-button, .terminal-toolbar button) { min-height:44px; }
  .route-back-shell .back-bar { gap:7px; }
  .route-back-shell .back-bar > :not(.back-button) { min-width:0; }
  /* Bottom home-indicator clearance and equal touch regions. */
  .mobile-nav {
    height: calc(66px + var(--nexa-safe-bottom));
    padding: 5px max(5px,var(--nexa-safe-right)) var(--nexa-safe-bottom) max(5px,var(--nexa-safe-left));
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }
  .mobile-nav button { min-width:0; min-height:55px; touch-action:manipulation; }
  :is(button, a, input[type="range"], select) { touch-action: manipulation; }
  /* iOS Safari auto-zooms any focused input with a font under 16px. */
  input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
  select, textarea,
  .directory-search input, .directory-sector select,
  .arena-tools .search-field input,
  .trade-form-panel input, .modal-search input,
  dialog input, dialog select { font-size: 16px !important; }
  input, textarea, select { max-width:100%; }
  .directory-controls .directory-search, .directory-page .directory-search { height:auto; min-height:46px; }
  .directory-controls .directory-sector, .directory-page .directory-sector { min-height:46px; }
  .directory-sector select { height:44px; }
  .market-groups, .hub-tabs, .arena-tools > .filters, .directory-source-switch {
    overflow-x:auto; overflow-y:hidden;
    -webkit-overflow-scrolling:touch;
    overscroll-behavior-x:contain;
    scrollbar-width:none;
    scroll-padding-left:12px;
    scroll-padding-right:12px;
  }
  .market-groups::-webkit-scrollbar,.hub-tabs::-webkit-scrollbar,
  .arena-tools > .filters::-webkit-scrollbar,.directory-source-switch::-webkit-scrollbar{display:none}
  .market-groups button, .arena-tools .filter, .hub-tabs button,
  .directory-source-switch button { min-height:44px; flex: 0 0 auto; }
  .market-groups,.arena-tools > .filters,.hub-tabs { -webkit-mask-image:linear-gradient(to right,#000 0%,#000 97%,transparent 100%); mask-image:linear-gradient(to right,#000 0%,#000 97%,transparent 100%); }
  /* Keep the content behind the iOS keyboard scrollable in short visual viewports. */
  dialog {
    width: min(520px,calc(100% - 24px));
    max-width:calc(100% - 24px);
    max-height:calc(100vh - 24px);
    max-height:calc(100dvh - 24px - var(--nexa-safe-top) - var(--nexa-safe-bottom));
    overscroll-behavior-y:contain;
    -webkit-overflow-scrolling:touch;
  }
  dialog .modal-body { padding-bottom:max(18px, var(--nexa-safe-bottom)); }
  dialog .modal-actions > * { min-width:0; min-height:44px; overflow-wrap:anywhere; }
  /* Hide/show navigation is the application's own route state, not a breakpoint hack. */
  .market-overview, .home-directory, .reading-page, .terminal-page, .arena-main { min-width:0; }
  .reading-section table { display:block; max-width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
  .reading-section td, .reading-section th { min-width:0; }
  /* Reduce a disproportionate trading progress block on smaller iPhone screens. */
  .terminal-page .contest-progress-card { margin:8px 0 12px; padding:13px 12px; }
  .terminal-page .contest-progress-summary { gap:7px; }
  .terminal-page .contest-progress-summary > div { flex:1 1 185px; gap:7px; }
  .terminal-page .contest-progress-summary > div > .icon { width:19px; height:19px; }
  .terminal-page .contest-progress-summary > div > div > strong { font-size:14px; line-height:1.25; }
  .terminal-page .contest-progress-summary > div > div > span { font-size:11px; line-height:1.3; }
  .terminal-page .contest-progress-summary > .text-btn { font-size:12px; }
  .terminal-page .contest-progress-numbers { margin:10px 0 9px; }
  .terminal-page .contest-progress-numbers span, .terminal-page .contest-progress-numbers dt { min-height:0; font-size:11px; line-height:1.3; margin-bottom:5px; }
  .terminal-page .contest-progress-numbers strong, .terminal-page .contest-progress-numbers dd { font-size:clamp(14px,4.2vw,20px); line-height:1.27; overflow-wrap:anywhere; letter-spacing:-.45px; }
  .terminal-page .contest-progress-numbers small { font-size:10px; }
  .terminal-page .contest-progress-foot, .terminal-page .contest-progress-foot p { font-size:11px; line-height:1.4; }
  .terminal-page .contest-progress-foot { margin-top:5px; }
  /* Tighten the first prize stage on iPhone SE while keeping the prize legible. */
  .arena-hero-inner { padding-top:21px; padding-bottom:20px; }
  .arena-prize-display { margin-top:17px; margin-bottom:17px; }
  .arena-goal-track { padding:13px; gap:10px 7px; }
  .arena-goal-start>span,.arena-goal-target>span { min-height:0; font-size:12px; }
  .arena-goal-start strong,.arena-goal-target strong { font-size:clamp(19px,5.4vw,24px); }
  .arena-goal-return { padding-top:9px; }
  .arena-goal-return strong { font-size:24px; }
  .arena-hero-actions { margin-top:16px; gap:8px 15px; }
  .arena-hero-actions > p { font-size:12px; line-height:1.5; }
  .arena-rail-inner { min-height:65px; padding-top:8px; padding-bottom:8px; }
  .arena-rail-prize > span,.arena-rail-goal > span { font-size:11px; }
  .arena-rail-prize strong { font-size:clamp(17px,5vw,23px); }
  .arena-rail-goal strong { font-size:18px; }
  .arena-rail-inner > .text-btn { min-height:44px; font-size:12px; }
}
@media (max-width: 375px) {
  .site-header { gap:4px; }
  .header-actions { gap:2px; }
  .language-btn { letter-spacing:-.4px; }
  .arena-prize-number { font-size:clamp(40px,11.8vw,47px); }
  .arena-prize-number small { font-size:12px; margin-left:5px; }
  .arena-rail-inner { gap:5px; }
  .arena-rail-goal { max-width:72px; }
  .arena-rail-goal > span { font-size:10px; }
  .arena-rail-goal strong { font-size:16px; }
  .arena-rail-inner > .text-btn { font-size:11px; }
  .terminal-page .contest-progress-numbers > * { padding-right:5px; }
  .terminal-page .contest-progress-numbers > * + * { padding-left:6px; }
  .terminal-page .contest-progress-numbers strong { font-size:14px; }
  .modal-actions { gap:8px; }
  .modal-actions .btn { padding-inline:8px; }
}
/* Landscape Safari makes the usable height much shorter; do not let sticky prizes and nav stack. */
@media (orientation:landscape) and (max-height: 540px) and (pointer:coarse) {
  :root { --header:calc(45px + env(safe-area-inset-top,0px)); --route-bar-height:39px; }
  .site-header { height:var(--header); min-height:var(--header); padding-top:env(safe-area-inset-top,0px); }
  .route-back-shell .back-bar { height:var(--route-bar-height); min-height:39px; }
  .route-back-shell :is(.back-button,.terminal-toolbar button) { min-height:39px; }
  .mobile-nav { height:calc(51px + env(safe-area-inset-bottom,0px)); }
  .mobile-nav button { min-height:40px; font-size:10px; }
  .mobile-nav .icon { height:18px; width:18px; }
  body { padding-bottom:calc(56px + env(safe-area-inset-bottom,0px)); }
  dialog { max-height:calc(100dvh - 16px); }
  .arena-prize-rail { position:relative; top:auto !important; }
}
@media (prefers-reduced-motion:reduce) {
  html { scroll-behavior:auto; }
  *,*::before,*::after { scroll-behavior:auto !important; }
}
