/* Mobile & touch — equal priority to desktop (phones, tablets, landscape). */

:root {
  --touch-min: 44px;
  --pad-mobile: 16px;
}

html {
  overflow-x: clip;
}

body {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ---- Touch targets (coarse pointers + small screens) ---- */
@media (max-width: 768px), (pointer: coarse) {
  .btn,
  .btn-ghost-danger,
  .nav-toggle,
  .sim-actions .btn,
  .sim2-actions .btn {
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }

  .primary-nav a {
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
  }

  .nav-toggle {
    min-width: var(--touch-min);
  }

  /* Bigger hit area without turning the whole input into a grey bar: the
     input itself goes transparent, the visible 3px track moves into the
     track pseudo elements. */
  input[type='range'] {
    min-height: 32px;
    padding: 12px 0;
    touch-action: pan-y;
    background: transparent;
  }

  input[type='range']::-webkit-slider-runnable-track {
    height: 3px;
    background: var(--blue-grey-15);
    border-radius: 2px;
  }

  input[type='range']::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    margin-top: -10.5px; /* centre the 24px thumb on the 3px track */
  }

  input[type='range']::-moz-range-track {
    height: 3px;
    background: var(--blue-grey-15);
    border-radius: 2px;
  }

  input[type='range']::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  .sim-tabs a {
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    padding: 12px 16px;
  }
}

/* ---- Phone layouts ---- */
@media (max-width: 640px) {
  .container {
    padding-left: var(--pad-mobile);
    padding-right: var(--pad-mobile);
  }

  body {
    font-size: 16px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .section {
    padding: clamp(40px, 10vw, 64px) 0;
  }

  .hero {
    padding: clamp(40px, 10vw, 56px) 0;
  }

  .hero-cta,
  .cta-actions,
  .error-page .hero-cta,
  .sim-cta {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .hero-cta .btn,
  .cta-actions .btn,
  .error-page .hero-cta .btn {
    width: 100%;
  }

  .section-lead {
    font-size: 1.05rem;
    margin-bottom: 32px;
  }

  .figure,
  .figure.figure-wide,
  .figure.figure-inline {
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

  .hazard-figures {
    gap: 20px;
  }

  .hazard-figure img {
    height: auto;
    min-height: 160px;
  }

  .card {
    padding: 20px;
  }

  .check-list {
    grid-template-columns: 1fr;
  }

  .site-header .header-inner {
    height: 64px;
  }

  .primary-nav {
    top: 64px;
    max-height: calc(100dvh - 64px);
  }
}

/* Narrow phones (iPhone SE, small Android) */
@media (max-width: 390px) {
  h1 {
    font-size: clamp(1.75rem, 8vw, 2.2rem);
  }

  .sim-tabs a {
    font-size: 0.82rem;
    padding: 10px 12px;
  }

  .sim-stats .stat span {
    font-size: 0.92rem;
  }
}

/* ---- Simulator v1 mobile ---- */
@media (max-width: 768px) {
  .sim-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .sim-actions .btn,
  .sim-actions .btn-ghost-danger {
    width: 100%;
    flex: none;
    font-size: 0.88rem;
    padding: 12px 10px;
  }

  .sim-actions #btnClear {
    grid-column: 1 / -1;
  }

  .sim-view {
    min-height: 0;
    padding: 12px;
  }

  .sim-view-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .sim-view-head .hint {
    font-size: 0.72rem;
  }

  #sideView {
    min-height: 220px;
    aspect-ratio: 2 / 1;
  }

  .sim-controls {
    padding: 14px;
    gap: 12px;
  }

  .sim-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .sim-stage,
  .sim2-stage {
    padding: 12px;
  }
}

@media (max-width: 400px) {
  .sim-actions {
    grid-template-columns: 1fr;
  }
}

/* ---- Simulator v2 mobile ---- */
@media (max-width: 768px) {
  .sim2-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .sim2-actions .btn {
    width: 100%;
    min-width: 0;
    font-size: 0.92rem;
  }

  .sim2-readout {
    width: 100%;
  }

  .sim2-readout span {
    flex: 1 1 auto;
    min-width: 0;
    text-align: center;
  }

  .sim2-throw-details dd {
    font-size: 0.92rem;
    word-break: break-word;
  }
}

/* ---- Landscape phones & small tablets ---- */
@media (max-width: 896px) and (orientation: landscape) {
  .sim-hero,
  .hero {
    padding-top: 28px;
    padding-bottom: 28px;
  }

  .sim-hero h1,
  .hero h1 {
    font-size: clamp(1.5rem, 4vw, 2rem);
  }

  .sim2-stage-head {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sim-canvas-area {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .sim-stats {
    grid-column: 1 / -1;
  }

  @media (max-height: 500px) {
    .sim-canvas-area {
      grid-template-columns: 1fr;
    }
  }
}

/* Nav open: prevent background scroll (class set by app.js on <html> and
   <body>). The lock must live on <html> — with `overflow-x: clip` on the
   root, body overflow no longer propagates to the viewport. */
html.nav-open {
  overflow: hidden;
}
body.nav-open {
  overflow: hidden;
  touch-action: none;
}
