/* Grantha Storefront — /ranking
 *
 * Loaded only by cms_page_view_id_ranking.xml, so no other page pays for it. Everything here
 * is expressed in the --g-* tokens, which already flip for dark mode, so there is not a single
 * colour literal below and the page follows the theme switch for free.
 */

.ranking-page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 16px 64px;
}

/* Header ------------------------------------------------------------------ */

.ranking-header {
  margin-bottom: 20px;
}

.ranking-heading {
  font-family: var(--font-heading, inherit);
  font-size: 30px;
  font-weight: var(--font-heading-weight, 600);
  margin: 0 0 6px;
  color: var(--g-text);
}

.ranking-standfirst {
  margin: 0;
  font-size: 14px;
  color: var(--g-muted);
}

/* Tabs --------------------------------------------------------------------
 *
 * Links, not buttons — one URL per ranking. Styled as the same segmented control the homepage
 * trending widget uses, because they do the same job and looking different would imply they
 * do not. It scrolls horizontally rather than wrapping: five wrapped pills on a phone read as
 * two rows of unrelated links.
 */

.ranking-tabs {
  display: flex;
  width: fit-content;
  max-width: 100%;
  gap: 2px;
  padding: 3px;
  margin-bottom: 10px;
  border-radius: var(--radius-md, 8px);
  background: var(--g-hover);
  border: 1px solid var(--g-line-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.ranking-tabs::-webkit-scrollbar {
  display: none;
}

.ranking-tab {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: var(--radius-sm, 6px);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--g-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--transition-fast, 120ms), color var(--transition-fast, 120ms);
}

.ranking-tab:hover {
  color: var(--g-text);
}

.ranking-tab.is-active {
  background: var(--g-surface);
  color: var(--g-text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.ranking-tab:focus-visible {
  outline: 2px solid var(--g-accent);
  outline-offset: 1px;
}

/* The kind of ranking is the bigger decision, so it gets the heavier control; the time period
   within it is a refinement and reads as one. */
.ranking-tabs--primary .ranking-tab {
  font-size: 13.5px;
  padding: 7px 18px;
}

.ranking-tabs--window {
  margin-bottom: 18px;
  background: transparent;
  border-color: transparent;
  padding: 0;
  gap: 4px;
}

.ranking-tabs--window .ranking-tab {
  border: 1px solid var(--g-line-2);
  padding: 4px 12px;
  font-size: 12px;
}

.ranking-tabs--window .ranking-tab.is-active {
  border-color: var(--g-accent);
  color: var(--g-accent);
  background: var(--g-accent-tint, var(--g-hover));
  box-shadow: none;
}

/* Names the ranking on screen in full, because "This month" cannot do that on its own. */
.ranking-view-title {
  font-family: var(--font-heading, inherit);
  font-size: 19px;
  font-weight: var(--font-heading-weight, 600);
  margin: 0 0 4px;
  color: var(--g-text);
}

/* Caption ------------------------------------------------------------------ */

.ranking-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 14px;
  margin-bottom: 22px;
}

.ranking-hint {
  margin: 0;
  font-size: 13px;
  color: var(--g-text);
}

.ranking-asof {
  margin: 0;
  font-size: 12px;
  color: var(--g-muted);
}

/* Chart -------------------------------------------------------------------- */

/*
 * The chart's viewBox is 2.25:1, so left to fill a 1050px content column it renders 460px tall
 * and stretches every line flat — the homepage gets away with the same SVG because it sits in
 * a narrower split column. Capping the width keeps the aspect the chart was drawn for.
 */
.ranking-chart .trending-graph {
  max-width: 860px;
  margin-inline: auto;
}

.ranking-chart {
  margin-bottom: 32px;
  padding: 16px;
  border: 1px solid var(--g-line);
  border-radius: var(--radius-md, 10px);
  background: var(--g-card);
}

/* Says which window the chart's legend deltas cover — see the note in ranking.phtml. */
.ranking-chart-window {
  margin: 0 0 10px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--g-muted);
}

/* The same, for the list's own movement column. */
.ranking-movement-legend {
  margin: 0 0 12px;
  font-size: 11.5px;
  font-weight: 500;
  text-align: right;
  color: var(--g-muted);
}

.ranking-chart-note {
  margin: 10px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--g-muted2, var(--g-muted));
}

/* Podium -------------------------------------------------------------------
 *
 * Three cards, then the list picks up at four. Not a visual medal stand — the ranks are already
 * on the cards' own badges, and staggering the heights would cost more than it says.
 */

/* List ---------------------------------------------------------------------
 *
 * CSS columns, not a grid. Sixty single-file rows was six thousand pixels of scrolling to read
 * a list whose content needs about a fifth of the page width. Columns keep the reading order a
 * ranking needs — 1..30 down the first, 31..60 down the second — which a two-column grid would
 * not: that lays out 1, 2 across, then 3, 4.
 */

.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  column-count: 2;
  column-gap: 40px;
}

.ranking-row {
  /* Without this a row splits across the column break, cover in one and price in the other. */
  break-inside: avoid;
  page-break-inside: avoid;
  display: grid;
  grid-template-columns: 26px 64px minmax(0, 1fr) auto auto auto;
  grid-template-areas: "pos cover meta move price action";
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--g-line-2);
}

.ranking-row > .ranking-position { grid-area: pos; }
.ranking-row > .ranking-cover    { grid-area: cover; }
.ranking-row > .ranking-meta     { grid-area: meta; }
.ranking-row > .ranking-move     { grid-area: move; }
.ranking-row > .ranking-price    { grid-area: price; }
.ranking-row > .ranking-action   { grid-area: action; }

.ranking-row:hover {
  background: var(--g-hover);
}

.ranking-position {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  color: var(--g-muted);
  font-variant-numeric: tabular-nums;
}

.ranking-cover {
  display: block;
  line-height: 0;
}

/*
 * 64x96, not the 40x60 this started at. A book cover is the thing a reader recognises a title
 * by, and at thumbnail size it stops doing that job — the row saves a few pixels of height and
 * loses the only picture on it. 2:3 matches every other cover on the site.
 */
.ranking-cover img {
  width: 64px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius-xs, 3px);
  background: var(--g-cover-bg, var(--g-hover));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.ranking-meta {
  min-width: 0;
}

.ranking-title {
  margin: 0 0 2px;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.3;
}

.ranking-title a {
  color: var(--g-text);
  text-decoration: none;
  /* Two lines at most: a long Sinhala title must not make its row twice its neighbours' height
     and knock the two columns out of step. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ranking-title a:hover {
  color: var(--g-accent);
}

.ranking-author {
  font-size: 11px;
  color: var(--g-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-price {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.ranking-price-now {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--g-text);
  white-space: nowrap;
}

.ranking-price-was {
  font-size: 10.5px;
  color: var(--g-muted);
  text-decoration: line-through;
  white-space: nowrap;
}

/* Icon only. At half the page width the word "Add" costs more than it earns. */
.ranking-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--g-line-2);
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--g-muted);
  font-size: 14px;
  cursor: pointer;
  transition: color var(--transition-fast, 120ms), border-color var(--transition-fast, 120ms);
}

.ranking-add:hover {
  color: var(--g-accent);
  border-color: var(--g-accent);
}

.ranking-add:focus-visible {
  outline: 2px solid var(--g-accent);
  outline-offset: 1px;
}

.ranking-unavailable {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 14px;
  color: var(--g-muted2, var(--g-muted));
}

/* Movement -----------------------------------------------------------------
 *
 * A fixed-width slot in both the list and the podium, so the numbers form a column instead of
 * jittering with each label's length.
 */

.ranking-move {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 42px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--g-hover);
  color: var(--g-muted);
}

/*
 * The same colour vocabulary the homepage chart's legend uses, so the two views agree about
 * what a rise looks like. Note that a fall is deliberately neutral rather than red there — a
 * book slipping two places is not an error, and the caret already carries the direction.
 */
.ranking-move--up {
  color: var(--g-positive);
  background: var(--g-positive-tint, var(--g-hover));
}

.ranking-move--down {
  color: var(--g-muted);
}

.ranking-move--new {
  color: var(--g-accent-text, var(--g-accent));
  background: var(--g-accent-tint, var(--g-hover));
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.ranking-move--hold {
  color: var(--g-faint, var(--g-muted2));
}

/* Nothing to compare against: holds the column open without making a claim. */
.ranking-move--unknown {
  background: transparent;
}

.ranking-move-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Empty state and footnote -------------------------------------------------- */

.ranking-empty {
  margin: 40px 0;
  padding: 28px;
  text-align: center;
  font-size: 14px;
  color: var(--g-muted);
  border: 1px dashed var(--g-line);
  border-radius: var(--radius-md, 10px);
}

.ranking-footnote {
  margin-top: 26px;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--g-muted);
}

.ranking-footnote p {
  margin: 0;
}

/* Responsive ----------------------------------------------------------------
 *
 * The row collapses in two steps rather than one. At tablet width the publisher and the price's
 * struck-through original go first, because they are the least load-bearing. At phone width the
 * row becomes two columns — cover, then everything else stacked — with the rank overlaid on the
 * cover, since a 40px rank gutter is a tenth of the screen.
 */

@media (max-width: 1000px) {
  /* Two columns stop being denser than one once each is too narrow for a title. */
  .ranking-list {
    column-count: 1;
  }

  .ranking-row {
    grid-template-columns: 30px 72px minmax(0, 1fr) auto auto auto;
    gap: 14px;
  }

  .ranking-cover img {
    width: 72px;
    height: 108px;
  }
}

@media (max-width: 600px) {
  .ranking-page {
    padding: 20px 12px 48px;
  }

  .ranking-heading {
    font-size: 24px;
  }

  .ranking-view-title {
    font-size: 17px;
  }

  .ranking-movement-legend {
    text-align: left;
  }

  /*
   * Two rows: the book above, what it costs and how to buy it below, with the cover spanning
   * both. Add to Cart stays — dropping it on the smallest screen would remove the action from
   * the visitors most likely to be browsing one-handed.
   */
  .ranking-row {
    position: relative;
    grid-template-columns: 60px minmax(0, 1fr) auto;
    grid-template-areas:
      "cover meta  move"
      "cover price action";
    align-items: start;
    gap: 4px 12px;
    padding: 10px 6px;
  }

  .ranking-row > .ranking-price,
  .ranking-row > .ranking-action {
    align-self: center;
  }

  /* Out of flow, so it needs no area — laid over the cover, where a rank gutter cannot go. */
  .ranking-position {
    position: absolute;
    top: 8px;
    left: 0;
    z-index: 1;
    grid-area: auto;
    min-width: 18px;
    padding: 0 3px;
    font-size: 10.5px;
    line-height: 15px;
    text-align: center;
    color: var(--g-badge-text, #fff);
    background: var(--g-badge-bg, var(--g-accent));
    border-radius: var(--radius-xs, 3px);
  }

  .ranking-cover img {
    width: 60px;
    height: 90px;
  }

  .ranking-price {
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
  }
}
