/* Mobile and focus stability layer for the Router and Midnight Signal adventure. */
html {
  overflow-x: hidden;
  scroll-behavior: auto;
}

body.router-page {
  overflow-x: hidden;
}

.router-page .history {
  -webkit-overflow-scrolling: touch;
  overflow-anchor: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  touch-action: pan-y;
}

.router-page .composer {
  overflow-anchor: none;
}

.router-page #command {
  scroll-margin: 0;
}

@media (pointer: coarse) {
  .router-page #command {
    font-size: 16px !important;
  }

  .router-page .send,
  .router-page .coco-walk-choice,
  .router-page .command-autocomplete-option {
    touch-action: manipulation;
  }
}

@media (max-width: 760px) {
  body.router-page {
    min-height: 100svh;
    overflow-y: auto !important;
    overscroll-behavior-y: auto;
  }

  .router-page .app {
    width: 100%;
    min-height: 100svh;
    height: auto;
  }

  .router-page .hero {
    width: calc(100% - 20px);
    min-height: auto;
    height: auto;
    grid-template-rows: auto auto auto;
    gap: 14px;
    padding: 22px 0 max(18px, env(safe-area-inset-bottom));
  }

  .router-page .hero-title h1 {
    font-size: clamp(44px, 14vw, 62px);
  }

  .router-page .terminal {
    min-height: min(640px, calc(100svh - 150px));
    max-height: none;
  }

  .router-page .history {
    min-height: 320px;
    max-height: min(58svh, 620px);
    overflow-x: hidden;
    overflow-y: auto;
    padding: 16px 12px 14px;
  }

  .router-page .line {
    grid-template-columns: 16px minmax(0, 1fr);
    column-gap: 7px;
    font-size: 11px;
    line-height: 1.62;
  }

  .router-page .composer {
    padding: 11px 12px max(11px, env(safe-area-inset-bottom));
  }

  .router-page .composer-meta {
    margin-bottom: 6px;
  }

  .router-page .composer-grid {
    grid-template-columns: 16px minmax(0, 1fr) auto;
    gap: 7px;
    align-items: end;
  }

  .router-page .input-prefix {
    grid-row: 1;
    padding-top: 7px;
  }

  .router-page #command {
    min-height: 48px;
    max-height: 104px;
    padding: 6px 0;
    font-size: 16px !important;
    line-height: 1.42;
  }

  .router-page .send {
    grid-column: 3;
    min-width: 64px;
    min-height: 40px;
    margin: 0;
    padding: 8px 10px;
  }

  body.coco-walk-active .hero-head,
  body.coco-walk-active .hero-foot {
    display: none;
  }

  body.coco-walk-active .hero {
    display: block;
    width: calc(100% - 12px);
    padding: 8px 0 max(12px, env(safe-area-inset-bottom));
  }

  body.coco-walk-active .terminal.is-coco-walk {
    display: grid;
    grid-template-rows: 36px auto auto;
    min-height: calc(100svh - 74px);
    overflow: visible;
    border-radius: 12px;
  }

  body.coco-walk-active .terminal.is-coco-walk .term-top {
    position: sticky;
    top: 62px;
    z-index: 12;
    background: rgba(2, 10, 12, 0.96);
    backdrop-filter: blur(16px);
  }

  body.coco-walk-active .terminal.is-coco-walk .history {
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 12px 8px 18px;
    overscroll-behavior: auto;
  }

  body.coco-walk-active .terminal.is-coco-walk .composer {
    position: sticky;
    bottom: 0;
    z-index: 14;
    border-top-color: rgba(113, 221, 201, 0.28);
    background: rgba(2, 10, 12, 0.97);
    backdrop-filter: blur(18px) saturate(120%);
    box-shadow: 0 -18px 42px rgba(0, 0, 0, 0.34);
  }

  body.coco-walk-active .terminal.is-coco-walk .composer-meta {
    display: none;
  }

  body.coco-walk-active .terminal.is-coco-walk #command {
    min-height: 44px;
    max-height: 88px;
  }

  body.coco-walk-active .coco-walk-card,
  body.coco-walk-active .coco-walk-compact {
    width: 100%;
    border-radius: 10px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.24);
  }

  body.coco-walk-active .coco-walk-card-head {
    gap: 8px;
    padding-top: 13px;
    padding-bottom: 12px;
  }

  body.coco-walk-active .coco-walk-card h2 {
    font-size: clamp(20px, 6.4vw, 27px);
    line-height: 1.08;
  }

  body.coco-walk-active .coco-walk-narrative p,
  body.coco-walk-active .coco-walk-compact p {
    font-size: 12px;
    line-height: 1.58;
  }

  body.coco-walk-active .coco-walk-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.coco-walk-active .coco-walk-choice {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: 3px 8px;
    min-height: 64px;
    padding: 10px 11px;
  }

  body.coco-walk-active .coco-walk-choice code {
    grid-column: 1;
    grid-row: 1;
    white-space: normal;
  }

  body.coco-walk-active .coco-walk-choice-copy {
    grid-column: 1;
    grid-row: 2;
    gap: 3px;
  }

  body.coco-walk-active .coco-walk-choice-copy strong,
  body.coco-walk-active .coco-walk-choice-copy small {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  body.coco-walk-active .coco-walk-choice-copy strong {
    font-size: 11px;
  }

  body.coco-walk-active .coco-walk-choice-copy small {
    font-size: 9.5px;
    line-height: 1.4;
  }

  body.coco-walk-active .coco-walk-choice-arrow {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
  }
}

@media (max-width: 390px) {
  .router-page .hero {
    width: calc(100% - 12px);
  }

  .router-page .history {
    padding-left: 8px;
    padding-right: 8px;
  }

  .router-page .composer {
    padding-left: 8px;
    padding-right: 8px;
  }

  .router-page .send {
    min-width: 56px;
    padding-inline: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .router-page .history {
    scroll-behavior: auto;
  }
}
