/* Phone and iPad portrait. Every rule lives in this query so wider layouts stay put. */

@media (max-width: 900px) {
  html {
    overflow-x: clip;
    max-width: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: 168px;
  }

  body {
    max-width: 100%;
    overflow-x: clip;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }

  img, svg, video, canvas, iframe {
    max-width: 100%;
  }

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

  .chrome {
    padding-top: env(safe-area-inset-top);
  }

  .topbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 0;
    padding: 8px 10px 10px;
  }

  .brand {
    flex: 1 1 140px;
    min-width: 0;
  }

  .brand img {
    width: 22px;
    height: 22px;
  }

  .brand b {
    font-size: 13px;
    letter-spacing: 0.04em;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .top-meta {
    flex: 0 0 auto;
    margin-left: auto;
    gap: 8px;
    font-size: 12px;
  }

  .live-pill {
    letter-spacing: 0.08em;
    min-height: 44px;
  }

  .cmd {
    order: 5;
    flex: 1 1 100%;
    min-width: 0;
    height: 48px;
    padding: 0;
  }

  .cmd-prompt {
    padding: 0 12px;
    font-size: 16px;
  }

  .cmd-go {
    height: 44px;
    min-width: 52px;
    margin-right: 2px;
    padding: 0 14px;
    font-size: 13px;
  }

  .alertsbtn,
  .gate-signout,
  .gate-signout-btn,
  .gate-login,
  .gate-join,
  .gate-cta {
    min-height: 44px;
    height: auto;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
  }

  .gate-login {
    text-decoration: none;
    border: 1px solid var(--line-strong);
  }

  .free-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.4;
  }

  .navrow {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .navrow::-webkit-scrollbar {
    display: none;
  }

  .navrow a {
    height: 44px;
    padding: 0 14px;
    font-size: 13px;
    letter-spacing: 0.08em;
  }

  .ticker {
    height: 44px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .ticker::-webkit-scrollbar {
    display: none;
  }

  .ticker-track {
    animation: none !important;
    height: 44px;
  }

  .ti {
    height: 44px;
    padding: 0 16px;
    font-size: 14px;
  }

  .ti .k {
    font-size: 12px;
    letter-spacing: 0.08em;
  }

  .ti .v {
    font-size: 14px;
  }

  .fnbar {
    display: none;
  }

  .stage {
    padding: 8px;
    padding-bottom: 16px;
  }

  .stage,
  .panel,
  .grid-main,
  .grid-lower,
  .grid-signals,
  .chart-grid,
  .chart-pair,
  .page-split,
  .desk-grid,
  .desk-stats,
  main {
    min-width: 0;
    max-width: 100%;
  }

  .grid-main,
  .grid-lower,
  .grid-lower.pair,
  .grid-signals,
  .page-split,
  .chart-pair,
  .chart-grid,
  .chart-grid.cols-3,
  .chart-grid.perp-grid,
  .desk-grid,
  .launch-grid,
  .yield-trio,
  .btctc-charts,
  .fomc-list,
  .metric-grid,
  .hero,
  .feat-grid,
  .proof,
  .regime-wrap {
    grid-template-columns: 1fr;
  }

  .stats,
  .stats.duo,
  .stats.trio,
  .desk-stats,
  .mini-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .stats.etf {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }

  .hero-body {
    grid-template-columns: 1fr;
  }

  .panel,
  tr[id] {
    scroll-margin-top: 180px;
  }

  .panel-hd {
    flex-wrap: wrap;
    row-gap: 4px;
    min-height: 44px;
    height: auto;
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
  }

  .panel-hd .hd-note {
    max-width: 100%;
    white-space: normal;
    text-align: right;
    line-height: 1.35;
  }

  .panel-hd .seg,
  .screen-bar,
  .launch-bar,
  .perp-bar {
    flex: 1 1 100%;
    max-width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .panel-hd .seg::-webkit-scrollbar,
  .screen-bar::-webkit-scrollbar,
  .launch-bar::-webkit-scrollbar,
  .perp-bar::-webkit-scrollbar {
    display: none;
  }

  .maxbtn,
  .minbtn,
  .shotbtn,
  .drawbtn,
  .media-btn {
    width: 44px;
    height: 44px;
  }

  .maxbtn svg,
  .minbtn svg,
  .shotbtn svg,
  .drawbtn svg,
  .media-btn svg {
    width: 16px;
    height: 16px;
  }

  .media-controls {
    height: auto;
    min-height: 44px;
    flex-wrap: wrap;
    opacity: 1;
    pointer-events: auto;
  }

  .media-live,
  .media-cc {
    min-height: 44px;
    padding: 0 12px;
    font-size: 12px;
  }

  .media-frame {
    aspect-ratio: 16 / 9;
    min-height: 180px;
  }

  .btn,
  .seg .btn,
  .chip,
  .star,
  .launch-x {
    min-height: 44px;
    height: 44px;
    padding: 0 12px;
    font-size: 12px;
  }

  .chip {
    height: 44px;
    font-size: 12px;
    letter-spacing: 0.06em;
  }

  .star,
  .launch-x {
    min-width: 44px;
  }

  .controls,
  .chart-panel .controls {
    flex-wrap: wrap;
    overflow: visible;
    max-width: 100%;
    gap: 8px;
  }

  .seg {
    flex: 1 1 auto;
    flex-wrap: wrap;
    max-width: 100%;
  }

  .seg.yield-ranges {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .seg.yield-ranges .btn {
    min-height: 36px;
    height: 36px;
    padding: 0 8px;
  }

  .chart-status {
    margin-left: 0;
    font-size: 11px;
  }

  .lwc-end {
    padding: 0 3px;
    font-size: 9px;
    line-height: 13px;
  }

  .lwc-host.is-compact .lwc-end {
    padding: 0 2px;
    font-size: 8px;
    line-height: 11px;
  }

  .chart-tools {
    gap: 4px;
  }

  .chart-tool button {
    height: 32px;
    padding: 0 8px;
    font-size: 11px;
  }

  .chart-box,
  .viz-canvas,
  .chart-host,
  .perp-chart,
  .stack-chart,
  .max-chart,
  .lwc-host,
  .spark {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    touch-action: pan-y !important;
  }

  .chart-box *,
  .lwc-host *,
  .chart-host *,
  .perp-chart *,
  .stack-chart *,
  .max-chart *,
  .viz-canvas * {
    touch-action: pan-y !important;
  }

  .chart-box {
    height: min(52vh, 320px);
    min-height: 220px;
  }

  .chart-box.short {
    height: 220px;
    min-height: 200px;
  }

  .chart-box.mid {
    height: min(48vh, 300px);
  }

  .viz-canvas,
  .chart-host,
  .lwc-fill {
    height: 220px;
  }

  .viz-canvas.mini,
  .lwc-mini,
  .spark,
  .spark.lwc-mini {
    height: 72px;
    min-height: 0;
    touch-action: pan-y !important;
  }

  .spark.lwc-mini {
    width: calc(100% - 28px);
    max-width: none;
  }

  td .lwc-mini {
    width: 112px;
    min-width: 112px;
    max-width: 112px;
    height: 48px;
  }

  .lwc-legend,
  .stack-read,
  .perp-asof {
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 12px;
    line-height: 1.35;
  }

  .lwc-legend {
    right: 8px;
    max-width: calc(100% - 16px);
  }

  .perp-asof {
    flex: 1 1 100%;
    margin-left: 0;
    text-align: left;
  }

  .perp-chart {
    height: 220px;
    min-height: 200px;
  }

  .stack-chart.stack-price {
    height: 240px;
  }

  .stack-chart.stack-sub {
    height: 128px;
  }

  .score-num {
    font-size: clamp(52px, 16vw, 72px);
  }

  .gauge-labels {
    font-size: 9px;
    letter-spacing: 0;
    padding-left: 6px;
    padding-right: 6px;
  }

  .gauge-labels span {
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .hero-note,
  .metric-read,
  .chart-foot,
  .panel-foot,
  .desk-note,
  .stat-note {
    font-size: 13px;
    line-height: 1.45;
  }

  .metric-val,
  .figure {
    font-size: 28px;
  }

  .desk-stat b {
    font-size: 18px;
  }

  .news-row {
    grid-template-columns: 96px minmax(0, 1fr);
    min-height: 44px;
  }

  .news-row img {
    width: 96px;
    height: 54px;
  }

  .news-title {
    font-size: 14px;
  }

  .news-meta {
    font-size: 12px;
  }

  .ladder-row {
    grid-template-columns: 12px minmax(0, 1fr) auto;
    min-height: 44px;
  }

  .ladder-mean {
    display: none;
  }

  .swatch {
    grid-row: 1 / span 2;
    align-self: center;
  }

  .ladder-row > span:nth-child(3) {
    grid-column: 2;
    grid-row: 1;
  }

  .ladder-px {
    grid-column: 2;
    grid-row: 2;
    font-size: 16px;
  }

  .ladder-vs {
    grid-column: 3;
    grid-row: 1 / span 2;
    align-self: center;
  }

  .mini-level {
    grid-template-columns: minmax(0, 1.2fr) auto auto;
    min-height: 44px;
    align-items: center;
  }

  .mini-level > * {
    min-width: 0;
  }

  .alert-head,
  .alert-row,
  .watch-row {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.8fr) auto;
    min-height: 44px;
  }

  .alert-line,
  .alert-head span:nth-child(3) {
    display: none;
  }

  .wire-row {
    grid-template-columns: 1fr;
    gap: 4px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .wire-title {
    font-size: 15px;
    line-height: 1.35;
  }

  .wire-when {
    grid-column: auto;
    font-size: 12px;
  }

  .table-wrap,
  .eco-scroll,
  .cal-strip,
  .mp-stack,
  .mined-strip,
  .hbars {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .eco-scroll {
    max-height: none;
    overflow-y: visible;
  }

  .table-wrap table,
  .eco-scroll table {
    width: max-content;
    min-width: 100%;
  }

  .table-wrap th,
  .table-wrap td,
  .eco-scroll th,
  .eco-scroll td {
    font-size: 13px;
    padding: 10px 12px;
  }

  #watch .table-wrap table { width: 100%; }
  #watch th,
  #watch td {
    font-size: 12px;
    padding: 8px 6px;
  }

  .eco-table td.ev {
    max-width: 180px;
    white-space: normal;
  }

  .hbar,
  #regime-bars .hbar,
  #gdpnow-bars .hbar,
  .fomc-meet .hbar,
  .perp-bars .hbar {
    grid-template-columns: minmax(0, 38%) minmax(0, 1fr) auto;
    min-height: 32px;
  }

  .hbar-k,
  .fomc-meet .hbar-k,
  #regime-bars .hbar-k,
  .perp-bars .hbar-k,
  .perp-bars .hbar-n {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .regime-card {
    grid-template-columns: 84px minmax(0, 1fr);
    min-height: 44px;
  }

  .regime-mini {
    width: 84px;
    height: 84px;
  }

  .regime-name {
    font-size: 22px;
  }

  .regime-plot {
    min-height: 220px;
  }

  .cal-card {
    min-width: 200px;
  }

  .heat-grid,
  .mp-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .tool-inputs,
  .tool-row {
    flex-direction: column;
    align-items: stretch;
  }

  .tool-inputs label,
  .tool-field {
    width: 100%;
  }

  .tool-inputs input,
  .tool-inputs select,
  .tool-field input,
  .tool-field select,
  .req-field input,
  .req-field select,
  .req-field textarea,
  .alert-controls input,
  .alert-controls select {
    width: 100%;
    min-height: 44px;
    height: 44px;
  }

  .req-field textarea {
    height: auto;
    min-height: 96px;
  }

  .req-foot {
    flex-wrap: wrap;
  }

  .req-submit {
    min-height: 44px;
    padding: 0 16px;
    font-size: 13px;
  }

  .modal-back,
  .palette,
  .gate-screen {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .gate-screen {
    align-items: center;
  }

  .gate-card,
  .modal,
  .modal.regime-modal,
  .palette-card {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: auto;
    box-sizing: border-box;
  }

  .gate-card {
    padding: 24px 16px;
  }

  .gate-card h1 {
    font-size: 26px;
  }

  .gate-card p,
  .modal-sub {
    font-size: 15px;
  }

  .modal-x {
    top: 4px;
    right: 4px;
    width: 44px;
    height: 44px;
    font-size: 28px;
    line-height: 1;
  }

  .palette {
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .palette-input input {
    height: 48px;
  }

  .palette-item {
    min-height: 48px;
    align-items: center;
    font-size: 15px;
  }

  .palette-foot {
    font-size: 12px;
    line-height: 1.4;
  }

  /* Above the frosted backdrop (.max-back is 45). */
  body .panel.is-max {
    position: fixed !important;
    z-index: 46 !important;
    inset: 0 !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border: 0;
    box-shadow: none;
    overflow: auto;
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    background: var(--panel);
  }

  html.hmr-maxed,
  html.hmr-maxed body {
    overflow: hidden;
  }

  .panel.is-max > .panel-hd {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel-hd);
    min-height: 52px;
  }

  .panel.is-max .maxbtn {
    width: auto;
    min-width: 44px;
    height: 44px;
    margin-left: auto;
    padding: 0 12px;
    gap: 8px;
  }

  .panel.is-max .maxbtn::after {
    content: "CLOSE";
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.14em;
  }

  .panel.is-max .chart-box,
  .panel.is-max .perp-chart,
  .panel.is-max .max-chart,
  .panel.is-max .chart-host,
  .panel.is-max .viz-canvas {
    height: min(62dvh, 520px);
    min-height: 220px;
  }

  .legal {
    margin: 20px 12px max(24px, env(safe-area-inset-bottom));
    font-size: 12px;
    line-height: 1.55;
  }

  .wrap {
    width: min(1100px, calc(100% - 24px));
  }

  h1 {
    font-size: 30px;
  }

  .kicker,
  .section h2,
  .final h2 {
    overflow-wrap: anywhere;
  }

  .section {
    padding: 32px 0;
  }

  .section h2,
  .final h2 {
    font-size: 26px;
  }

  .final {
    padding: 36px 16px;
  }

  .enter,
  .head-actions .join {
    min-height: 44px;
  }

  .head-actions {
    gap: 8px;
  }

  .ctarow .enter,
  .ctarow .join {
    min-height: 44px;
    padding: 0 16px;
  }

  .sub,
  .lede,
  .feat p {
    font-size: 15px;
  }

  .score-card .gauge-labels {
    font-size: 9px;
    letter-spacing: 0;
  }

  #screen .table-wrap {
    overflow: visible;
  }

  #screen table,
  #screen thead,
  #screen tbody,
  #screen tr,
  #screen td {
    display: block;
    width: auto;
    min-width: 0;
  }

  #screen table {
    width: 100%;
  }

  #screen thead {
    display: none;
  }

  #screen tr {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    column-gap: 8px;
    row-gap: 4px;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid var(--line);
  }

  #screen td {
    padding: 0;
    border: 0;
    text-align: left;
    font-size: 14px;
  }

  #screen td:nth-child(1) { grid-column: 1; grid-row: 1 / span 2; }
  #screen td:nth-child(2) { grid-column: 2; grid-row: 1; }
  #screen td:nth-child(4) { grid-column: 2; grid-row: 2; color: var(--text-dim); font-size: 13px; }
  #screen td:nth-child(5) { grid-column: 3; grid-row: 1 / span 2; text-align: right; font-size: 16px; }
  #screen td:nth-child(3) { grid-column: 1 / -1; grid-row: 3; }
  #screen td:nth-child(6) { grid-column: 1; grid-row: 4; }
  #screen td:nth-child(7) { grid-column: 2; grid-row: 4; }
  #screen td:nth-child(8) { grid-column: 3; grid-row: 4; text-align: right; }

  #screen td:nth-child(4)::before { content: "Value "; color: var(--text-mute); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
  #screen td:nth-child(6)::before { content: "1W "; color: var(--text-mute); font-size: 11px; letter-spacing: 0.08em; }
  #screen td:nth-child(7)::before { content: "1M "; color: var(--text-mute); font-size: 11px; letter-spacing: 0.08em; }

  #screen td .lwc-mini {
    width: 100%;
    min-width: 0;
    max-width: none;
    height: 42px;
  }

  /* Scroll hides the phone chrome with transforms, so the page underneath does not reflow. */
  .chrome,
  .chrome .topbar,
  .chrome .free-banner,
  .chrome .ticker,
  .chrome .navrow,
  main.stage,
  footer.legal {
    transition: transform 200ms ease, opacity 200ms ease;
  }

  html.hmr-chrome-hide .chrome {
    transform: translate3d(0, calc(-1 * var(--hmr-chrome-h, 0px) - 2px), 0);
    opacity: 0;
    pointer-events: none;
  }

  html.hmr-chrome-hide .chrome * {
    pointer-events: none !important;
  }

  html.hmr-chrome-nav .chrome {
    background: transparent;
    pointer-events: none;
  }

  html.hmr-chrome-nav .chrome::before {
    content: "";
    position: absolute;
    z-index: 1;
    left: 0;
    right: 0;
    top: 0;
    height: calc(env(safe-area-inset-top, 0px) + 1px);
    background: var(--bg-2);
    pointer-events: none;
  }

  html.hmr-chrome-nav .chrome .topbar,
  html.hmr-chrome-nav .chrome .free-banner {
    opacity: 0;
    pointer-events: none;
    transform: translate3d(0, calc(-100% - env(safe-area-inset-top, 0px)), 0);
  }

  html.hmr-chrome-nav .chrome .ticker {
    opacity: 0;
    pointer-events: none;
    transform: translate3d(0, calc(-100% - var(--hmr-ticker-shift, 0px) - env(safe-area-inset-top, 0px)), 0);
  }

  html.hmr-chrome-nav .chrome .topbar *,
  html.hmr-chrome-nav .chrome .free-banner *,
  html.hmr-chrome-nav .chrome .ticker * {
    pointer-events: none !important;
  }

  html.hmr-chrome-nav .chrome .navrow {
    position: relative;
    z-index: 2;
    pointer-events: auto;
    transform: translate3d(0, calc(-1 * var(--hmr-nav-shift, 0px)), 0);
  }

  html.hmr-chrome-nav .chrome .navrow * {
    pointer-events: auto;
  }

  html.hmr-chrome-hide main.stage,
  html.hmr-chrome-hide footer.legal,
  html.hmr-chrome-nav main.stage,
  html.hmr-chrome-nav footer.legal {
    transform: translate3d(0, calc(-1 * var(--hmr-chrome-h, 0px)), 0);
  }

  html.hmr-maxed main.stage,
  html.hmr-maxed footer.legal,
  body.has-max main.stage,
  body.has-max footer.legal,
  body:has(.panel.is-max) main.stage,
  body:has(.panel.is-max) footer.legal,
  body:has(.modal-back.on) main.stage,
  body:has(.modal-back.on) footer.legal,
  body:has(#palette:not([hidden])) main.stage,
  body:has(#palette:not([hidden])) footer.legal {
    transform: none !important;
    transition: none !important;
  }

  .panel.is-max .draw-pop button {
    width: 32px;
    height: 32px;
    min-height: 0;
  }

  .panel.is-max .draw-colors button {
    width: 16px;
    height: 16px;
  }

  .chart-box.is-drawing,
  .chart-box.is-drawing * {
    touch-action: none !important;
  }
}

@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
  .chrome,
  .chrome .topbar,
  .chrome .free-banner,
  .chrome .ticker,
  .chrome .navrow,
  main.stage,
  footer.legal {
    transition: none !important;
  }
}
