/* Desktop retains the full table. Phone cards reuse those same labelled cells. */
.mobile-card-summary, .mobile-card-sort { display: none; }

@media (max-width: 760px) {
  .market-shell .toolbar {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 8px;
    padding: 12px 10px 8px;
    overflow: visible;
  }
  .market-watchlist-picker, .market-watchlist-picker-toggle { width: 100%; min-width: 0; }
  .market-shell .toolbar > .search-box,
  .market-shell .toolbar > .toolbar-pagination { grid-column: 1 / -1; min-width: 0; }
  .search-box input { width: 100%; min-width: 0; }
  .toolbar-pagination { flex-wrap: wrap; justify-content: space-between; gap: 6px; }
  .page-size-control { gap: 5px; }
  .page-size-control > span { font-size: 10px; }
  .toolbar-pagination .pagination { gap: 3px; }
  .toolbar-pagination .pagination button { min-width: 30px; height: 36px; padding: 0 6px; }
  .market-shell .table-meta, .recipe-shell .table-meta {
    flex-wrap: wrap; gap: 4px 8px; padding: 5px 10px; font-size: 10px;
  }
  .table-meta-leading { flex: 1 1 auto; }
  .table-config-toggle { min-height: 32px; }
  .table-config-menu { max-width: calc(100vw - 32px); }
  .recipe-shell .recipe-search-row {
    grid-template-columns: 44px minmax(0, 1fr);
    padding: 12px 10px 8px;
    gap: 8px;
  }
  .recipe-search-row > .search-box { grid-column: 2; grid-row: 1; min-width: 0; }
  .recipe-search-options { grid-column: 1 / -1; grid-row: 2; flex-wrap: wrap; gap: 6px; }
  .recipe-search-options label { min-width: 0; }
  .recipe-search-options select { max-width: 100%; padding-inline: 8px 24px; font-size: 12px; }
  .recipe-search-options label:has(#recipe-sort) { display: none; }
  .recipe-search-options .recipe-level-field input { width: 56px; }
  .recipe-search-row > #recipe-source-state,
  .recipe-search-row > .toolbar-pagination { grid-column: 1 / -1; }
  .recipe-search-row > .toolbar-pagination { grid-row: 3; }
  .recipe-search-row > #recipe-source-state { grid-row: 4; }
  #recipe-source-state:empty { display: none; }

  .mobile-card-sort {
    display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between;
    gap: 8px; padding: 5px 10px 9px; font-size: 11px;
  }
  .mobile-card-sort label { display: flex; align-items: center; gap: 7px; min-width: 0; color: var(--muted); }
  .mobile-card-sort select { min-width: 0; max-width: 165px; }
  .mobile-card-sort select, .mobile-card-sort button {
    height: 36px; border: 1px solid #66502d; border-radius: 3px;
    padding: 0 8px; background: #11140f; color: #e1d4b7; font-size: 11px;
  }
  .mobile-card-sort button { flex-shrink: 0; }
  .market-shell .table-wrap, .recipe-shell .table-wrap {
    padding: 0 8px 8px; overflow-x: hidden; overflow-y: auto; scrollbar-width: thin;
  }
  .table-viewport .table-rail, .table-viewport .table-rail-cap { display: none !important; }
  .market-table, .recipe-table { display: block; min-width: 0 !important; width: 100%; }
  .market-table colgroup, .recipe-table colgroup,
  #market-header-row, #recipe-header-row { display: none; }
  .market-table thead, .recipe-table thead { display: block; position: static; }
  #market-body, #recipe-body { display: grid; gap: 8px; }
  #market-body > tr, #recipe-body > tr { min-width: 0; }
  #market-body > .mobile-card, #recipe-body > .mobile-card {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    border: 1px solid #514329; border-radius: 5px; overflow: hidden;
    background: linear-gradient(120deg, #202016, #141811);
    box-shadow: inset 0 1px rgba(238, 203, 130, .05);
  }
  #market-body > .card-expanded, #recipe-body > .card-expanded { border-color: #967038; }
  .mobile-card > td { display: none; }
  .mobile-card > .mobile-card-summary {
    display: block; grid-column: 1 / -1; width: auto; padding: 0; border: 0; background: transparent;
  }
  .mobile-card-toggle {
    display: grid; grid-template-columns: 32px minmax(0, 1fr) auto 12px;
    width: 100%; min-height: 76px; align-items: center; gap: 9px;
    padding: 12px 10px; border: 0; border-radius: 0; box-shadow: none;
    color: var(--text); background: transparent; text-align: left;
  }
  .mobile-card-toggle:not(:has(> img)) { grid-template-columns: minmax(0, 1fr) auto 12px; }
  .mobile-card-toggle > img { width: 32px; height: 32px; object-fit: contain; }
  .mobile-card-copy { display: grid; gap: 5px; min-width: 0; white-space: normal; }
  .mobile-card-copy > strong { font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
  .mobile-card-hint { color: #b0a084; font-size: 10px; }
  .mobile-card-value { display: grid; gap: 5px; text-align: right; }
  .mobile-card-value > small { color: #b0a084; font-size: 9px; }
  .mobile-card-value > strong { color: #efcb7d; font-size: 12px; }
  .mobile-card-value > strong.positive { color: var(--green); }
  .mobile-card-value > strong.negative { color: var(--red); }
  .mobile-card-chevron { color: #d6b165; font-size: 18px; }
  .card-expanded .mobile-card-chevron { transform: rotate(180deg); }
  .mobile-card-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: -3px; }
  .mobile-card.card-expanded > td[data-card-label]:not([hidden]) {
    display: block;
    gap: 6px; min-width: 0; width: auto; height: auto; padding: 10px 12px;
    white-space: normal; overflow-wrap: anywhere; font-size: 12px; text-align: left;
    border: 0; border-top: 1px solid #343425; background: #11160f;
  }
  .mobile-card.card-expanded > td[data-card-label]::before {
    content: attr(data-card-label); display: block; margin-bottom: 6px;
    color: #aa9d83; font-size: 10px; font-weight: 500;
  }
  .mobile-card [data-column="item"], .mobile-card [data-recipe-column="recipe"],
  .mobile-card [data-recipe-column="inputs"], .mobile-card [data-recipe-column="output"] { grid-column: 1 / -1; }
  .mobile-card .item-cell, .mobile-card .recipe-product { width: 100%; min-height: 36px; }
  .mobile-card .item-cell strong, .mobile-card .recipe-product strong { white-space: normal; }
  .mobile-card .quick-chart-button, .mobile-card .watch-button, .mobile-card .wiki-link { min-height: 40px; min-width: 44px; }
  .mobile-card .recipe-inputs { flex-wrap: wrap; min-width: 0; }
  .mobile-card .recipe-input { max-width: 100%; white-space: normal; min-height: 36px; }
  #market-body > tr:not(.mobile-card), #recipe-body > tr:not(.mobile-card) { display: block; }
  #market-body > tr:not(.mobile-card) > td, #recipe-body > tr:not(.mobile-card) > td {
    display: block; width: 100%; white-space: normal;
  }
  /* Crafting's optional column filters remain reachable above the cards. */
  #recipe-filter-panel:not([hidden]) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #recipe-filter-panel > th { display: block; min-width: 0; width: auto; height: auto; }
  #recipe-filter-panel > [data-card-label]::before {
    content: attr(data-card-label); display: block; margin: 0 0 5px;
    color: #aa9d83; font-size: 10px; text-align: left; text-transform: none;
  }
  #recipe-filter-panel > .filter-row-spacer { display: none; }
  #recipe-filter-panel > [data-recipe-column="recipe"] { display: block; grid-column: 1 / -1; }
}

/* Landscape phones must still have a usable list below the controls. Let the
   document scroll when the chrome cannot fit alongside a useful card viewport. */
@media (max-width: 760px) and (max-height: 600px) {
  #market-view, #recipe-view, .market-shell, .recipe-shell { height: auto; }
  .market-shell .table-viewport, .recipe-shell .table-viewport { flex: none; height: 60dvh; min-height: 260px; }
}
