/* Phone layout (<=700px), loaded last. Goal: the ranking starts on the first
   screen, text stays at 12px or more and every control is easy to tap. */
@media (max-width: 700px) {
  /* ---------- Masthead: 46px, the live dot stays, the words go to screen readers ---------- */
  html { scroll-padding-top: 54px; }
  body.v2 .manager-toolbar.v2-masthead { height: 46px; margin-bottom: 8px; }
  body.v2 .v2-masthead > .live-state { margin-left: auto; margin-right: 6px; padding: 10px; }
  body.v2 .v2-masthead > .live-state #status { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  body.v2 .v2-masthead > .live-state .live-dot { width: 8px; height: 8px; }

  /* Share, Undo and Redo leave their own row and sit in the masthead as icons. */
  body.v2 .shell > .site-actions { position: fixed; z-index: 61; top: calc(env(safe-area-inset-top, 0px) + 3px); right: 12px; display: flex; gap: 2px; margin: 0; padding: 0; border: 0; background: none; }
  body.v2 .shell > .site-actions button { display: grid; place-items: center; width: 40px; height: 40px; min-height: 40px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 0; }
  body.v2 .shell > .site-actions button:active { background: var(--panel-2); }
  body.v2 .shell > .site-actions button svg { width: 18px; height: 18px; }
  body.v2 .shell > .site-actions button span { display: none; }
  body.v2 .shell > .site-actions button:disabled { display: none; }
  body.v2 .v2-masthead > .live-state { margin-right: var(--v2-actions-width, 46px); }
  /* The language code sits before the live dot, clear of the fixed share button. */
  body.v2 .v2-masthead > .v2-lang { order: 0; margin-left: auto; }
  body.v2 .v2-lang-button { height: 32px; padding: 0 8px 0 7px; }
  body.v2 .v2-masthead > .v2-lang + .live-state, body.v2 .v2-masthead > .live-state { margin-left: 0; }

  /* ---------- Pinned assets: one slim line, three cards in view ---------- */
  /* Name and change on top, price below; the logo gives its room to a third card. */
  body.v2 #market-overview { height: 46px; }
  body.v2 #market-overview .overview-custom { min-width: 0; padding: 3px 0; }
  body.v2 #market-overview .overview-custom + .overview-custom::before { top: 11px; bottom: 11px; }
  body.v2 #market-overview .overview-item { grid-template-columns: auto auto; grid-template-areas: "name change" "price price"; justify-content: start; align-items: baseline; gap: 0 3px; padding: 0 5px; }
  body.v2 #market-overview .overview-name { grid-area: name; padding-right: 0; gap: 0; line-height: 16px; }
  body.v2 #market-overview .overview-logo { display: none; }
  body.v2 #market-overview .overview-label { max-width: 6.5em; color: var(--muted); font-size: 12px; }
  body.v2 #market-overview .overview-proxy { display: none; }
  body.v2 #market-overview .overview-item strong { grid-area: change; min-width: 0; font-size: 12px; line-height: 16px; }
  body.v2 #market-overview .overview-price { grid-area: price; font-size: 13px; line-height: 17px; }
  /* The fade at the right edge says more assets follow; the last visible card stops before it. */
  body.v2 #market-overview .overview-track { padding: 0 14px 0 2px; }
  body.v2 #market-overview .overview-viewport::before, body.v2 #market-overview .overview-viewport::after { width: 14px; }
  /* On a phone the row is swiped: the fade replaces the arrows, which would cover a card. */
  body.v2 #market-overview .overview-scroll { display: none; }
  /* One tool: Edit opens the sheet that also adds an asset (it presses the hidden + for it). */
  body.v2 #market-overview .mobile-overview-tools { flex-direction: row; width: auto; }
  body.v2 #market-overview .mobile-overview-tools .overview-add { display: none; }
  body.v2 #market-overview .mobile-overview-edit { flex: none; min-width: 44px; padding: 0 8px; border-top: 0; }

  /* ---------- Lists of the open region: one row that scrolls sideways ---------- */
  body.v2 .shell > .tabs.region-navigation { margin: 8px 0; }
  body.v2 .v2-region-tab { min-height: 40px; }
  body.v2 .shell > .tabs .region-watchlists { flex-wrap: nowrap; overflow-x: auto; margin: 4px -12px 0 0; padding: 6px 12px 2px 0; scrollbar-width: none; overscroll-behavior-x: contain; }
  body.v2 .shell > .tabs .region-watchlists::-webkit-scrollbar { display: none; }
  body.v2 .shell > .tabs .region-watchlists > * { flex: none; }
  /* mobile.css only lets a list button pan vertically (from when the lists wrapped): a swipe that
     starts on one must also scroll the row sideways. Touch drags start from handles only. */
  body.v2 .shell > .tabs .region-watchlists > * { touch-action: manipulation; }
  body.v2 .shell > .tabs.region-navigation .tab .mobile-list-menu { min-width: 36px; min-height: 36px; }


  /* ---------- List header: four short rows at most ----------
     1. title, count and (crypto) the display currency;
     2. (crypto) market cap, dominance and sentiment;
     3. the Table/Map switch and "+ Add" (on row 1 when they fit beside the title);
     4. the one sentence saying what the list is, one line until tapped. */
  body.v2 .panel-head { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 5px 10px; min-height: 0; padding: 8px 12px 7px; }
  body.v2 .panel-head > div:first-child { display: contents; }
  body.v2 .panel-head .title-row { flex: 1 1 auto; min-width: 0; gap: 4px 8px; }
  body.v2 .panel-head h2 { font-size: 17px; line-height: 22px; }
  body.v2 .result-count { font-size: 12px; }
  body.v2 .panel-head > div:first-child > :not(.title-row) { flex: 0 0 100%; }
  body.v2 .panel-head #list-meta:not(:empty) { display: -webkit-box; margin: 0; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1; color: var(--subtle); font-size: 12px; line-height: 17px; cursor: pointer; }
  body.v2 .panel-head #list-meta.is-open { -webkit-line-clamp: 6; line-clamp: 6; color: var(--muted); }
  /* The actions follow the title on its own line when they fit (a list without the map), otherwise on the next line. */
  body.v2 .panel-head > .panel-actions { order: 1; flex: 0 0 auto; margin-left: auto; justify-content: flex-end; gap: 8px; }
  body.v2 .panel-head #list-meta { order: 2; }
  body.v2 .panel-head .panel-actions .v2-view-switch { padding: 2px; }
  /* mobile.css sizes "+ Add" by id: match it. */
  body.v2 .panel-head .watchlist-actions .list-add-button, body.v2 .panel-head #add-asset.list-add-button { min-height: 40px; padding: 0 11px; }
  body.v2 .panel-head .panel-actions .v2-view-switch button { min-height: 34px; padding: 0 9px; font-size: 12px; }
  /* Index lists: the daily change next to the name, the session line under it, readable. */
  body.v2 #list-market-context .index-daily { font-size: 12px; }
  body.v2 #list-market-context .heading-session { padding: 1px 0; font-size: 11px; line-height: 15px; }

  /* Crypto: the currency switch closes the title row. The three market figures run as
     a strip of "label value" pairs: market cap and dominance on one line, sentiment
     with its credit on the next, each line 16px. */
  body.v2 .has-crypto-summary .title-row { flex-wrap: wrap; }
  body.v2 #crypto-currency-switch { margin-left: auto; padding: 2px; }
  body.v2 #crypto-currency-switch button { min-height: 32px; padding: 0 9px; font-size: 12px; }
  body.v2 .panel-head .crypto-market-summary:not([hidden]) { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; margin: 1px 0 0; padding-top: 5px; }
  body.v2 .crypto-market-summary :is(button, .crypto-summary-fear) { display: inline-flex; flex-wrap: nowrap; align-items: baseline; gap: 0 5px; line-height: 16px; white-space: nowrap; }
  body.v2 .crypto-market-summary :is(button, .crypto-summary-fear) > span { flex-basis: auto; font-size: 11px; line-height: 16px; }
  body.v2 .crypto-market-summary strong { font-size: 12.5px; line-height: 16px; }
  body.v2 .crypto-market-summary em { font-size: 11px; }
  body.v2 .crypto-summary-fear a { flex-basis: auto; font-size: 10px; }

  /* The methodology note follows the table instead of pushing it down. */
  body.v2 .panel { display: flex; flex-direction: column; }
  body.v2 .panel > #ranking-methodology { order: 1; border-top: 1px solid var(--line); border-bottom: 0; }

  /* ---------- Period row: 40px targets, less air around them ---------- */
  body.v2 .mobile-table-controls { gap: 6px; padding: 3px 8px 4px; }
  body.v2 .mobile-periods { padding: 2px; }
  body.v2 .mobile-periods button { min-height: 38px; }
  body.v2 .mobile-filter-button { min-height: 42px; padding: 0 9px; }

  /* ---------- Market pulse ---------- */
  body.v2 .v2-pulse { margin-bottom: 8px; }
  body.v2 .v2-pulse-toggle { width: 40px; height: 40px; }
  body.v2 .v2-pulse.is-collapsed .v2-pulse-head { min-height: 44px; }
  /* The masthead above is 46px: a list scrolled to the top stops under it and its pulse. */
  body.v2 .v2-pulse:not([hidden]) + .panel { scroll-margin-top: 176px; }
  body.v2 .v2-pulse.is-collapsed:not([hidden]) + .panel { scroll-margin-top: 54px; }

  /* ---------- Readable table text; a two-line header stays 36px ---------- */
  body.v2 .table-wrap thead th { padding-top: 2px; padding-bottom: 2px; line-height: 14px; vertical-align: middle; }
  body.v2 .table-wrap thead th, body.v2 .table-wrap thead .sort-button { font-size: 12px; }
  body.v2 .table-wrap thead .sort-button { padding: 2px 0; }
  body.v2 .table-wrap .quote-unit, body.v2 .table-wrap .ranking-metric, body.v2 .table-wrap .stock-date { font-size: 11px; line-height: 14px; }
  body.v2 #list-data-status, body.v2 .result-count { font-size: 12px; }
}

/* Chart dialog on phones: the TradingView link and the close cross sit apart, each a full-size target,
   so a thumb aiming at the cross does not open TradingView. */
@media (max-width: 700px) {
  body.v2 #asset-chart-dialog .chart-actions, body.v2 #asset-chart-dialog.chart-layout-compact .chart-actions { gap: 14px; }
  body.v2 #asset-chart-dialog .chart-actions #chart-external, body.v2 #asset-chart-dialog.chart-layout-compact .chart-actions #chart-external { width: 40px; min-width: 40px; height: 44px; min-height: 44px; margin-right: 4px; }
  body.v2 #asset-chart-dialog #close-asset-chart, body.v2 #asset-chart-dialog.chart-layout-compact #close-asset-chart { width: 44px; height: 44px; min-height: 44px; flex-basis: 44px; }
}

/* Chart facts on phones: a long value ("118,16 M actions · en cache") wraps inside its column instead of running over the next one. */
@media (max-width: 700px) {
  body.v2 #asset-chart-dialog .popup-inline-fact { min-width: 0; }
  body.v2 #asset-chart-dialog .popup-inline-fact dd { white-space: normal; overflow-wrap: anywhere; }
}
