/* ==========================================================================
   Kings in the Corner - "Pile Strategy: A Pile Has Two Working Ends"
   Loaded only by /pile-anatomy/, after styles.css, pages.css and rules.css.

   An anatomical study of one pile. The specimen sits on a muted green-grey
   felt with square corners and keeps its annotations as notes in the margin;
   everything else on the page is text or a compact ruled table.

   1. Dark page: the interior tokens, flipped
   2. The specimen felt
   3. The vertical pile and its annotations
   4. Base / Top selector
   5. X-ray sequences
   6. Ruled tables and the examination insert
   7. The two empty-space choices
   8. Responsive
   9. Print
   ========================================================================== */

/* ------------------- 1. Dark page: tokens, flipped ---------------------- */
.pilepage {
  --ipage:   #14120E;
  --ipanel:  #1D1A14;
  --iline:   #343026;
  --ilink:   #E8C784;
  --ink:     #F3ECDC;
  --text:    #DAD2C2;
  --muted:   #ADA491;

  --p-felt:  #2A3831;   /* muted green-grey, not a casino green */
  --p-edge:  #3A4A41;
  --p-taupe: #9C8F79;   /* annotation lines */
  --p-brick: #A8332B;
  --p-char:  #33302A;
  --p-mark:  #E3C07C;
}
.pilepage .prose p, .pilepage .prose li { color: var(--text); }
.pilepage .rsec h2, .pilepage .rsec h3 { color: var(--ink); }
.pilepage .prose strong, .pilepage .prose b { color: var(--ink); }
.pilepage .layout__main a { color: var(--ilink); }
.pilepage .factstrip__inner { background: var(--ipanel); border-color: var(--iline); }
.pilepage .factstrip b { color: var(--ink); }
.pilepage .factstrip span { color: var(--muted); }
.pilepage .sources__list a { color: #7CC79B; }
.pilepage .sources__list a:hover { color: #A6DDBE; }
/* cream faces, brick-red suits, warm charcoal blacks */
.pilepage .felt .card { border-color: var(--p-char); }
.pilepage .felt .card--red { color: var(--p-brick); }

/* -------------------------- 2. The specimen felt ------------------------ */
.felt {
  --cw: 62px;
  --ch: calc(var(--cw) * 1.44);
  --cr: calc(var(--cw) * .1);
  margin: 20px 0 24px;
  padding: 22px 24px 20px;
  background: var(--p-felt);
  border: 1px solid var(--p-edge);
  border-radius: 0;                 /* square corners, as briefed */
}
.felt__h {
  margin: 0 0 16px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--p-mark);
}
.felt__cap { margin: 16px 0 0; font-size: 13px; line-height: 1.5; color: #DCE6E0; }
.felt .card { box-shadow: 0 5px 12px rgba(0, 0, 0, .45); }

/* ------------------ 3. The vertical pile and its notes ------------------ */
/* the first column has to hold the pile AND its margin notes, or the notes
   run over the table beside them */
.specimen { display: grid; grid-template-columns: minmax(300px, 340px) minmax(0, 1fr); gap: 0 30px; align-items: start; }
/* --step lives on the wrapper: the bracket is a sibling of the list and would
   not inherit it from there */
.specimen__pile { position: relative; --step: calc(var(--ch) * .46); }

.pile-v {
  position: relative;
  list-style: none;
  margin: 0; padding: 0;
  width: var(--cw);
  height: calc(var(--step) * 5 + var(--ch));
}
.pile-v__item { position: absolute; left: 0; width: var(--cw); }
.pile-v__item:nth-child(1) { top: 0; }
.pile-v__item:nth-child(2) { top: calc(var(--step) * 1); }
.pile-v__item:nth-child(3) { top: calc(var(--step) * 2); }
.pile-v__item:nth-child(4) { top: calc(var(--step) * 3); }
.pile-v__item:nth-child(5) { top: calc(var(--step) * 4); }
.pile-v__item:nth-child(6) { top: calc(var(--step) * 5); }

/* the note in the margin, joined to its card by a thin taupe leader */
.annot {
  position: absolute; left: calc(var(--cw) + 26px); top: 6px;
  width: max-content; max-width: 230px;
  margin: 0;
  font-size: 13px; line-height: 1.4; color: #E4EDE7;
}
.annot b { display: block; font-family: var(--serif); font-size: 15px; color: #FFF6E2; }
.annot::before {
  content: ""; position: absolute; left: -26px; top: 11px;
  width: 22px; height: 1px; background: var(--p-taupe);
}

/* the quiet bracket beside the four middle cards */
.bracket {
  position: absolute; left: calc(var(--cw) + 8px);
  top: calc(var(--step) * 1 + 6px);
  height: calc(var(--step) * 3 + var(--ch) - 12px);
  width: 9px;
  border: 1px solid var(--p-taupe); border-left: 0;
}
.bracket__label {
  position: absolute; left: 17px; top: 50%;
  transform: translateY(-50%);
  width: max-content;
  font-size: 12.5px; color: #CFDCD4;
}

/* a highlighted card while a selector is pressed */
.pile-v__item.is-lit .card,
.card.is-lit { box-shadow: 0 0 0 3px var(--p-mark), 0 5px 12px rgba(0, 0, 0, .45); }
/* dim the card, never its note - a faded label is just hard to read */
.pile-v__item.is-dim .card { opacity: .55; }

/* ---------------------- 4. Base / Top selector -------------------------- */
.ends { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.ends button {
  min-height: 40px; padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--p-taupe); border-radius: 3px;
  font-family: var(--sans); font-size: 14px; font-weight: 600; color: #EDF3EF;
  cursor: pointer;
}
.ends button:hover { border-color: var(--p-mark); }
.ends button[aria-pressed="true"] { background: var(--p-mark); border-color: var(--p-mark); color: #241C08; }
.ends button:focus-visible { outline: 2px solid #FFF6E2; outline-offset: 2px; }
.ends__note { margin: 0 0 14px; font-size: 13px; line-height: 1.5; color: #DCE6E0; }

/* --------------------------- 5. X-ray sequences ------------------------- */
.xray { --cw: 46px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); }

/* one: a downward step sequence */
.stepdown { display: grid; gap: 0; justify-items: start; }
.stepdown li { position: relative; list-style: none; margin: 0; }
.stepdown li + li { margin-top: calc(var(--ch) * -.52); }
.stepdown li:nth-child(n+7) { margin-left: 0; }
.stepdown__added .card { box-shadow: 0 0 0 2px var(--p-mark), 0 5px 12px rgba(0, 0, 0, .45); }

/* two and three: a row of stages joined by numbered arrows */
.stages { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 14px; }
.stage-b { display: grid; gap: 7px; justify-items: center; }
.stage-b__h {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--p-mark);
}
.stage-b__cards { display: flex; align-items: center; gap: 5px; }
.stage-b__pile { display: grid; }
.stage-b__pile .card + .card { margin-top: calc(var(--ch) * -.56); }
.slotline {
  display: grid; place-items: center;
  min-width: var(--cw); height: var(--ch);
  padding: 4px 8px;
  border: 1.5px dashed var(--p-taupe);
  color: #D3DED8; font-size: 10.5px; line-height: 1.2; text-align: center;
}
/* a thin numbered arrow between stages */
.arrowstep { display: grid; justify-items: center; gap: 3px; flex: none; }
.arrowstep svg { width: 34px; height: 12px; color: var(--p-taupe); }
.arrowstep svg path { fill: none; stroke: currentColor; stroke-width: 1.4; }
.arrowstep svg polygon { fill: currentColor; }
.arrowstep b {
  display: grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid var(--p-taupe);
  font-size: 11.5px; color: #E4EDE7;
}
/* the numbered steps written out, so the arrows are never the only account */
/* the numbers are the point: they pair with the numbered arrows above */
.steplist { margin: 14px 0 0; padding-left: 26px; display: grid; gap: 5px; list-style: decimal; }
.steplist li::marker { color: var(--p-mark); font-weight: 700; }
.steplist li { font-size: 13px; line-height: 1.45; color: #DCE6E0; }

/* ------------- 6. Ruled tables and the examination insert --------------- */
.pwrap { overflow-x: auto; margin: 18px 0 22px; }
.ptab {
  width: 100%; min-width: 320px;
  border-collapse: collapse;
  font-size: 14.5px; color: var(--text);
}
.ptab caption {
  padding: 0 0 8px; text-align: left;
  font-size: 13px; color: var(--muted);
}
.ptab th, .ptab td {
  padding: 11px 16px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--iline);
}
.ptab thead th {
  border-bottom: 1.5px solid var(--p-taupe);
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted);
}
.ptab tbody th { color: var(--ink); font-weight: 700; white-space: nowrap; }
.ptab tr:last-child th, .ptab tr:last-child td { border-bottom: 0; }

.exam {
  margin: 20px 0 24px;
  padding: 16px 20px 14px;
  background: var(--ipanel);
  border: 1px solid var(--p-taupe);
  border-radius: 2px;
}
.exam h3 { margin: 0 0 4px; font-size: 17px; }
.exam p { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); }
.exam ol { margin: 0; padding-left: 22px; display: grid; gap: 6px; }
.exam li { font-size: 14.5px; line-height: 1.45; color: var(--text); }

/* --------------------- 7. The two empty-space choices ------------------- */
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 18px 0 22px; }
.pair__side {
  --cw: 44px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1);
  display: grid; gap: 10px; align-content: start;
  padding: 14px;
  border: 1px solid var(--iline);
}
.pair__h {
  margin: 0;
  font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ilink);
}
.pair__cards { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pair__result { margin: 0; font-size: 13.5px; line-height: 1.45; color: var(--text); }

/* ----------------------------- 8. Responsive ---------------------------- */
@media (max-width: 900px) {
  /* the pile stays vertical; each note drops beneath the card it belongs to */
  .specimen { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .specimen__pile { position: static; }
  .felt { --cw: 54px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); padding: 18px 16px 16px; }
  .pile-v { --step: calc(var(--ch) * .52); width: 100%; height: auto; }
  .pile-v__item { position: static; width: auto; display: grid; grid-template-columns: var(--cw) minmax(0, 1fr); gap: 12px; align-items: center; }
  .pile-v__item + .pile-v__item { margin-top: 8px; }
  .annot { position: static; max-width: none; }
  .annot::before { content: none; }
  .bracket { position: static; width: auto; height: auto; border: 0; border-left: 2px solid var(--p-taupe); padding-left: 12px; margin: 4px 0 8px; }
  .bracket__label { position: static; transform: none; }

  .pair { grid-template-columns: minmax(0, 1fr); }
  .xray { --cw: 40px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); }
}

@media (max-width: 420px) {
  /* still large enough to read every rank and suit */
  .felt { --cw: 46px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); }
  .xray { --cw: 36px; --ch: calc(var(--cw) * 1.44); --cr: calc(var(--cw) * .1); }
}

@media (prefers-reduced-motion: reduce) {
  .pilepage * { transition: none !important; animation: none !important; }
}

/* ------------------------------- 9. Print ------------------------------- */
@media print {
  .pilepage { --ipage: #FFF; --ipanel: #FFF; --iline: #999; --ink: #14120E; --text: #23201A; --muted: #4E4838; }
  .pilepage .factstrip__inner { background: #FFF; }
  .felt { background: #FFF; border-color: #777; break-inside: avoid; page-break-inside: avoid; }
  .felt__h, .stage-b__h { color: #6B5A2E; }
  .felt__cap, .annot, .bracket__label, .slotline, .steplist li, .pair__result { color: #1A1A1A; }
  .annot b { color: #14120E; }
  .slotline, .bracket, .arrowstep b { border-color: #777; }
  .arrowstep svg { color: #666; }
  /* both annotations print at once, and the controls do not print at all */
  .ends { display: none !important; }
  .pile-v__item.is-dim { opacity: 1 !important; }
  .pile-v__item.is-lit .card, .card.is-lit { box-shadow: none; outline: 2px solid #6B5A2E; }
  .xray, .pair, .exam, .pwrap { break-inside: avoid; page-break-inside: avoid; }
  .rsec h2, .rsec h3 { break-after: avoid; page-break-after: avoid; }
  .pilepage .felt .card--red { color: #A8332B; }
  .pile-v__item.is-dim .card { opacity: 1 !important; }
}
