/* ==========================================================================
   Kings in the Corner - "How to Play Every Card Rank"
   Loaded only by /card-ranks/, after styles.css, pages.css and rules.css.

   The page is a vertical deck from King down to Ace: a narrow rank rail
   beside the copy, and a differently shaped figure for every rank. Flat
   felt and paper, no gradients - the figures have to read the same on a
   printed page as on screen.

   1. Three-column layout with the rank rail
   2. The rail itself
   3. Figure shell
   4. Figure parts (runs, slots, arrows, marks, braces)
   5. Per-rank shapes
   6. Responsive
   7. Print
   ========================================================================== */

/* -------------------- 1. Layout: rail, article, sidebar ----------------- */
.ranklayout {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 300px;
  align-items: start;
  gap: 30px;
  padding-block: 30px 44px;
}
.ranklayout > * { min-width: 0; }

/* ------------------------------- 2. Rail -------------------------------- */
.rankrail {
  position: sticky; top: 86px;
  padding: 10px 0;
  background: var(--ipanel);
  border: 1px solid var(--iline);
  border-radius: 12px;
}
.rankrail__h {
  margin: 0 0 6px;
  text-align: center;
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  /* var(--muted) measures 4.23:1 on the white panel, just under the mark */
  color: #5F6C81;
}
.rankrail ol { list-style: none; margin: 0; padding: 0; display: grid; }
.rankrail a {
  display: grid; place-items: center;
  min-height: 30px; padding: 2px 0;
  font-family: var(--serif); font-size: 17px; font-weight: 700;
  color: var(--ink);
  border-bottom: 2px solid transparent;
}
.rankrail a:hover { color: var(--gold-b-dk); }
/* the reader's place in the deck, marked in muted gold */
.rankrail a[data-current="true"] {
  color: var(--gold-b-dk);
  border-bottom-color: var(--gold-b-dk);
}
.rankrail a:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; border-radius: 4px; }

/* --------------------------- 3. Figure shell ---------------------------- */
.rankfig {
  --cw: 46px;
  --ch: calc(var(--cw) * 1.44);
  --cr: calc(var(--cw) * .1);
  margin: 18px 0 22px;
  padding: 16px 18px 14px;
  background: #0C2E1E;
  border: 1px solid #123D28;
  border-radius: 10px;
}
.rankfig__h {
  margin: 0 0 12px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--gold-light);
}
.rankfig__cap {
  margin: 12px 0 0;
  font-size: 13px; line-height: 1.45; color: #D7E7DE;
}
.rankfig .card { box-shadow: 0 6px 14px rgba(0, 0, 0, .38); }

/* ---------------------------- 4. Figure parts --------------------------- */
.run { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.run--tight { gap: 4px; }
.run--center { justify-content: center; }
/* a built pile: cards overlap downwards the way they sit on a table */
.pilecol { display: flex; flex-direction: column; align-items: center; }
.pilecol .card + .card { margin-top: calc(var(--ch) * -.72); }

/* The label decides the width. Pinning the slot to one card width pushed
   "Empty original position" out over the dashed border on phones, where the
   glyphs then sat on the border colour at 2.2:1. */
.slotx {
  display: grid; place-items: center;
  width: auto; min-width: var(--cw); height: var(--ch);
  flex: none;
  border: 1.5px dashed rgba(214, 236, 224, .55);
  border-radius: var(--cr);
  color: #C3DCCF; font-size: 10.5px; line-height: 1.2; text-align: center;
  padding: 4px 7px;
}

.arrow { flex: none; width: 26px; height: 16px; color: #7FDCAC; }
.arrow path { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.arrow polygon { fill: currentColor; }
.arrow--down { width: 16px; height: 26px; }

.mark { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; }
.mark svg { width: 15px; height: 15px; }
.mark svg path { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.mark--ok { color: #7FDCAC; box-shadow: inset 0 0 0 2px currentColor; }
.mark--no { color: #E8918C; box-shadow: inset 0 0 0 2px currentColor; }

/* the bracket has to hug the connected cards, not the whole panel */
.braced { display: grid; gap: 5px; }
.brace__bar { height: 8px; border: 2px solid rgba(214, 236, 224, .45); border-top: 0; border-radius: 0 0 6px 6px; }
.brace__label { margin: 6px 0 0; font-size: 12.5px; line-height: 1.45; color: #C3DCCF; }

/* a card with nowhere to go sits apart from the run it cannot join */
.stranded { display: flex; align-items: center; gap: 7px; margin-left: 16px; }

.figpair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.figcell {
  display: grid; gap: 9px; align-content: start;
  padding: 12px;
  border: 1px solid rgba(214, 236, 224, .22);
  border-radius: 8px;
}
.figcell__h {
  margin: 0;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--gold-light);
}
.figcell__note { margin: 0; font-size: 12.5px; line-height: 1.45; color: #D7E7DE; }

.figrow { display: grid; gap: 10px; }
/* a fixed label column, so stacked rows line their cards up with each other */
.figline { display: grid; grid-template-columns: 160px minmax(0, 1fr); align-items: center; gap: 10px; }
.figline__label {
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--gold-light);
}

/* ---------------------------- 5. Per-rank shapes ------------------------ */
/* King: the four reserved corners around the centre */
.corners {
  --cw: 40px;
  --ch: calc(var(--cw) * 1.44);
  --cr: calc(var(--cw) * .1);
  display: grid; grid-template-columns: repeat(3, auto); gap: 6px;
  justify-content: center; justify-items: center; align-items: center;
}
.corners__mid { display: grid; place-items: center; width: var(--cw); height: var(--ch); }
.corners__stock { position: relative; width: var(--cw); height: var(--ch); }
.corners__stock i {
  position: absolute; inset: 0; border-radius: var(--cr);
  background: #24407F; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .45);
}
.corners__stock i:first-child { transform: translate(-3px, -3px); }

/* Ace: a single card, centred and larger, and nothing after it */
.closeup {
  --cw: 88px;
  --ch: calc(var(--cw) * 1.44);
  --cr: calc(var(--cw) * .1);
  display: grid; justify-items: center; gap: 12px;
  padding-block: 6px;
}
.closeup__rule { width: 120px; height: 1px; background: rgba(214, 236, 224, .35); }

/* --------------------------- 6. Responsive ------------------------------ */
@media (max-width: 1080px) {
  .ranklayout { grid-template-columns: 68px minmax(0, 1fr); gap: 20px; }
  .ranklayout > .layout__side { grid-column: 1 / -1; }
}

@media (max-width: 860px) {
  /* the rail becomes a scrollable strip under the title and stays in reach */
  .ranklayout { grid-template-columns: minmax(0, 1fr); gap: 18px; padding-block: 18px 30px; }
  .rankrail {
    position: sticky; top: 62px; z-index: 40;
    padding: 4px 6px;
    border-radius: 10px;
  }
  .rankrail__h { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .rankrail ol {
    /* wide enough for "Queen", which needs 48px at this size - at 38px the
       labels ran into each other */
    grid-auto-flow: column; grid-auto-columns: minmax(58px, 1fr);
    overflow-x: auto;
    scrollbar-width: none;
    padding-inline: 2px;
  }
  .rankrail ol::-webkit-scrollbar { display: none; }
  .rankrail a { min-height: 40px; font-size: 16px; }

  /* an anchored rank must clear the header and the strip together */
  html { scroll-padding-top: 118px; }
  .rsec { scroll-margin-top: 118px; }

  .figpair { grid-template-columns: minmax(0, 1fr); }
  .figline { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .stranded { margin-left: 0; }
  .rankfig { --cw: 40px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); padding: 14px 12px 12px; }
  .corners { --cw: 34px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); }
  .closeup { --cw: 74px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); }
}

@media (max-width: 420px) {
  .rankfig { --cw: 34px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); }
}

/* ------------------------------ 7. Print -------------------------------- */
@media print {
  .rankrail { display: none; }
  .ranklayout { grid-template-columns: minmax(0, 1fr); }
  /* keep a rank and its figure together, and never split a run of cards */
  .rsec { break-inside: avoid; page-break-inside: avoid; }
  .rankfig, .run, .pilecol, .figcell, .figline, .braced, .corners, .closeup {
    break-inside: avoid; page-break-inside: avoid;
  }
  .rankfig { background: #FFF; border-color: #666; }
  .rankfig__h, .figcell__h, .figline__label { color: #6B5A2E; }
  .rankfig__cap, .figcell__note, .brace__label, .slotx { color: #1A1A1A; }
  .slotx, .brace__bar, .figcell, .closeup__rule { border-color: #777; }
  .closeup__rule { background: #777; }
  .arrow { color: #555; }
  .mark--ok { color: #2F6B4C; }
  .mark--no { color: #9B3B36; }
  .corners__stock i { background: #FFF; box-shadow: inset 0 0 0 1.5px #555; }
}
