/* =====================================================================
   Selvage - fixed "tailor's table" theme.
   A walnut worktable under a brass rail: undyed linen for the chrome,
   woven swatches in madder, indigo, saffron and olive, brass pins and
   running stitches. No glass, no neon, no glow. The shared base.css is
   loaded (back chip + resets) but glass.css deliberately is not: this
   game keeps its own paper-free chrome (.c-bar, .c-btn, .c-modal).
   ===================================================================== */

:root {
  --table-hi: #6b4a30;
  --table: #513823;
  --table-lo: #321f0e;

  --linen-hi: #f8f0e1;
  --linen: #ecdfc7;
  --linen-lo: #d5c3a5;

  --ink: #2e2820;
  --ink-soft: #6b5d4c;
  --thread: #f7ecd9;

  --brass: #c9a227;
  --brass-hi: #efd685;
  --brass-lo: #7d6210;

  --madder: #a83f2e;
  --indigo: #2f5675;

  --font-body: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;

  /* One swatch wide. Grows with the window, but the vh term caps it so the
     rival band, the rail and your band all fit one screen with no scroll. */
  --u: clamp(46px, min(8.2vw, calc((100vh - 268px) / 3.2)), 124px);

  /* Frayed selvedge: a 1.6% zigzag along the top and bottom of every swatch.
     A clip-path (not a mask) so it reveals whatever cloth or wood is behind. */
  --fray: polygon(
    0 1.6%, 5% 0, 10% 1.6%, 15% 0, 20% 1.6%, 25% 0, 30% 1.6%, 35% 0,
    40% 1.6%, 45% 0, 50% 1.6%, 55% 0, 60% 1.6%, 65% 0, 70% 1.6%, 75% 0,
    80% 1.6%, 85% 0, 90% 1.6%, 95% 0, 100% 1.6%,
    100% 98.4%,
    95% 100%, 90% 98.4%, 85% 100%, 80% 98.4%, 75% 100%, 70% 98.4%,
    65% 100%, 60% 98.4%, 55% 100%, 50% 98.4%, 45% 100%, 40% 98.4%,
    35% 100%, 30% 98.4%, 25% 100%, 20% 98.4%, 15% 100%, 10% 98.4%,
    5% 100%, 0 98.4%
  );
}

/* ---------- The worktable ---------- */
body.b-page {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background-color: #4a3321;
  background-image:
    repeating-linear-gradient(3deg,
      rgba(0, 0, 0, .075) 0 2px, transparent 2px 9px,
      rgba(255, 255, 255, .018) 9px 10px, transparent 10px 27px),
    radial-gradient(120% 78% at 50% -14%, rgba(255, 214, 148, .17), transparent 58%),
    radial-gradient(95% 70% at 50% 116%, rgba(0, 0, 0, .55), transparent 66%),
    linear-gradient(180deg, var(--table-hi), var(--table) 58%, var(--table-lo));
  background-attachment: fixed;
}
body.b-page *,
body.b-page *::before,
body.b-page *::after { box-sizing: border-box; }

.b-app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar: a stitched strip of linen ---------- */
.c-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px clamp(12px, 3vw, 26px) 12px;
  color: var(--ink);
  background:
    repeating-linear-gradient(90deg, rgba(120, 96, 64, .06) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(0deg, rgba(120, 96, 64, .05) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, var(--linen-hi), var(--linen) 60%, var(--linen-lo));
  border-bottom: 2px solid rgba(90, 70, 44, .35);
  box-shadow: 0 8px 22px rgba(26, 14, 4, .42), inset 0 1px 0 rgba(255, 255, 255, .85);
}
/* the running stitch along the hem */
.c-bar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 3px;
  border-bottom: 2px dashed rgba(150, 124, 86, .42);
  pointer-events: none;
}

.c-bar__brand { display: flex; align-items: center; gap: 9px; }
.c-bar__brand svg { display: block; filter: drop-shadow(0 1px 0 rgba(255, 255, 255, .7)); }
.c-bar__title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(19px, 3vw, 26px);
  font-weight: 700;
  letter-spacing: -.01em;
  color: #2f2820;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .7);
}
.c-bar__stats { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.stat {
  font-size: 11.5px;
  letter-spacing: .02em;
  color: var(--ink-soft);
}
.stat b {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.c-bar__controls { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* Buttons read as small linen tabs with a hard bottom edge. */
.c-btn {
  appearance: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .01em;
  padding: 6px 12px;
  border-radius: 3px;
  color: #3a3227;
  background: linear-gradient(180deg, #fffaef, #e9dbc1);
  border: 1px solid rgba(120, 96, 64, .45);
  box-shadow: 0 2px 0 rgba(120, 96, 64, .22), 0 4px 10px rgba(26, 14, 4, .18);
  cursor: pointer;
  transition: transform .06s ease, box-shadow .12s ease, filter .12s ease;
}
.c-btn:hover { filter: brightness(1.03); }
.c-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(120, 96, 64, .22); }
.c-btn:focus-visible { outline: 2px solid #7f6412; outline-offset: 2px; }
.c-btn--primary {
  color: #f4ecdb;
  background: linear-gradient(180deg, #3f6d8f, #2b4f6b);
  border-color: #1d3a4f;
  box-shadow: 0 2px 0 #16303f, 0 4px 12px rgba(6, 20, 30, .34);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .3);
}

/* ---------- The table ---------- */
.b-table {
  width: min(96vw, calc(var(--u) * 11 + 28px));
  margin: 0 auto;
  padding: clamp(10px, calc(var(--u) * .11), 22px) 0 clamp(14px, calc(var(--u) * .14), 26px);
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(6px, calc(var(--u) * .06), 12px);
}
/* Rail and its caption travel together in the middle of the table; the two
   bands sit at the top and bottom edges, one per seat. */
.b-centre {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(4px, calc(var(--u) * .045), 8px);
}

/* ---------- Bands ---------- */
.b-band { display: flex; flex-direction: column; gap: max(3px, calc(var(--u) * .03)); }
.b-band__head {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  min-height: max(17px, calc(var(--u) * .15));
  padding: 0 2px;
}
.b-band__tag {
  font-size: max(9px, calc(var(--u) * .072));
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: rgba(247, 236, 213, .5);
}
.b-band__score {
  margin-left: 2px;
  font-family: var(--font-mono);
  font-size: max(13px, calc(var(--u) * .115));
  font-weight: 700;
  color: var(--thread);
  font-variant-numeric: tabular-nums;
}
.b-band__score small { font-size: .78em; font-weight: 600; opacity: .55; }
.b-band__score.is-lead { color: var(--brass-hi); }
.b-band__foot {
  margin-left: 10px;
  font-size: max(10px, calc(var(--u) * .082));
  color: rgba(247, 236, 213, .45);
  white-space: nowrap;
}
.b-band__row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * .07);
  min-height: calc(var(--u) * .78);
}

/* ---------- The swatch ---------- */
.b-swatch {
  position: relative;
  display: block;
  width: var(--w, var(--u));
  height: calc(var(--w, var(--u)) * 1.2);
  background-color: var(--yarn, #8a6a4a);
  background-image:
    repeating-linear-gradient(90deg,
      rgba(255, 255, 255, .07) 0 1px, rgba(0, 0, 0, .045) 1px 2px, transparent 2px 4px),
    repeating-linear-gradient(0deg,
      rgba(0, 0, 0, .075) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, rgba(255, 255, 255, .09), rgba(0, 0, 0, .2));
  border-radius: 2px;
  clip-path: var(--fray);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, .22),
    inset 0 1px 0 rgba(255, 255, 255, .16);
}
/* running stitch just inside the selvedge */
.b-swatch::before {
  content: "";
  position: absolute;
  inset: calc(var(--w, var(--u)) * .075);
  border: 1px dashed rgba(255, 255, 255, .2);
  border-radius: 1px;
  pointer-events: none;
}
/* the cream number tag, stitched on by hand */
.b-tag {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--w, var(--u)) * .46);
  height: calc(var(--w, var(--u)) * .46);
  transform: translate(-50%, -50%) rotate(-1.4deg);
  display: grid;
  place-items: center;
  border-radius: 1px;
  background: linear-gradient(180deg, #fdf6e6, #eee1c8);
  color: #2c251c;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: calc(var(--w, var(--u)) * .26);
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3), inset 0 0 0 1px rgba(120, 96, 64, .22);
}
.b-tag::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 1px dashed rgba(120, 96, 64, .42);
  pointer-events: none;
}

/* ---------- The rail ---------- */
.b-rail {
  position: relative;
  width: min(100%, calc(var(--u) * 5.9));
  margin: 0 auto;
  padding-top: calc(var(--u) * .085);
}
.b-rail__rod {
  position: relative;
  height: 7px;
  margin: 0 8px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass) 46%, var(--brass-lo));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .3),
    0 5px 12px rgba(0, 0, 0, .38);
}
.b-rail__finial {
  position: absolute;
  left: -7px;
  top: 50%;
  width: 11px;
  height: 11px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fbeeb8, var(--brass) 58%, var(--brass-lo));
  box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
.b-rail__finial--r { left: auto; right: -7px; }

.b-rail__row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: calc(var(--u) * .075);
  padding-top: calc(var(--u) * .045);
}

/* One hanging swatch: a brass ring, a cloth panel, clickable only at the ends. */
.b-hang {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  position: relative;
  display: block;
  transform: rotate(var(--rot, 0deg));
  filter: drop-shadow(0 6px 7px rgba(18, 8, 0, .45));
  transform-origin: 50% 0;
  transition: transform .16s ease, opacity .16s ease, filter .16s ease;
  cursor: default;
}
.b-hang::before {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(var(--u) * -.055);
  width: calc(var(--u) * .13);
  height: calc(var(--u) * .13);
  margin-left: calc(var(--u) * -.065);
  border-radius: 50%;
  border: 2px solid #d8b24a;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .28), 0 1px 2px rgba(0, 0, 0, .4);
  pointer-events: none;
}
.b-hang.is-end {
  cursor: pointer;
  /* The wrapper is not clipped, so this halo traces the frayed edge itself:
     a brass glow marks the two swatches you can actually reach. */
  filter: drop-shadow(0 0 4px rgba(239, 214, 133, .55)) drop-shadow(0 6px 7px rgba(18, 8, 0, .45));
}
.b-hang.is-end:hover,
.b-hang.is-end:focus-visible {
  transform: translateY(calc(var(--u) * -.06)) rotate(var(--rot, 0deg));
  filter: drop-shadow(0 0 9px rgba(247, 226, 150, .85))
    drop-shadow(0 12px 14px rgba(18, 8, 0, .55)) brightness(1.06);
}
.b-hang.is-end:focus-visible { outline: none; }
.b-hang.is-end:active { transform: translateY(calc(var(--u) * -.02)) rotate(var(--rot, 0deg)); }
/* middle swatches sit back and hang higher: not yours to take yet */
.b-hang.is-inner {
  opacity: .62;
  transform: translateY(calc(var(--u) * -.012)) scale(.91) rotate(var(--rot, 0deg));
}
.b-hang.is-inner .b-swatch { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .28); }
.b-hang.is-new { animation: bSlide .3s cubic-bezier(.2, .8, .3, 1.05) both; }

/* ---------- Bands of cloth ---------- */
.b-patch {
  position: relative;
  display: flex;
  align-items: center;
  gap: calc(var(--u) * .035);
}
/* Only the patch that just changed gets the settle/sew animation. */
.b-patch.is-new { animation: bSew .34s cubic-bezier(.2, .8, .3, 1.08) both; }
.b-patch .b-swatch { --w: calc(var(--u) * .66); }
/* one clashing thread pulled through both copies */
.b-patch.is-pair::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 14%;
  bottom: 14%;
  width: 2px;
  margin-left: -1px;
  background: repeating-linear-gradient(180deg, rgba(247, 236, 213, .9) 0 3px, transparent 3px 6px);
  opacity: .85;
  pointer-events: none;
}
.b-patch.is-single { opacity: .68; }
.b-patch__pts {
  position: absolute;
  right: calc(var(--u) * -.09);
  top: calc(var(--u) * -.09);
  padding: 0 4px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: max(9px, calc(var(--u) * .085));
  font-weight: 700;
  color: #2b2113;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass));
  box-shadow: 0 1px 2px rgba(0, 0, 0, .38);
}

/* ---------- Verdict line ---------- */
.b-verdict {
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  font-family: var(--font-serif);
  font-size: max(12px, calc(var(--u) * .112));
  color: rgba(247, 236, 213, .76);
}
.b-verdict b { color: var(--brass-hi); }
.b-verdict.is-you b { color: #bfe3c4; }
.b-verdict.is-them b { color: #f0b3a2; }
.b-verdict.is-flash { animation: bFlash .45s ease; }

/* ---------- Modals ---------- */
/* The overlay scrolls, never the card: no inner scrollbar gutter on Windows.
   Above .gc-back (400) so the back chip cannot sit over the backdrop. */
.c-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 12, 4, .62);
  cursor: pointer;
}
.c-modal__panel {
  position: relative;
  z-index: 1;
  margin: auto;
  width: min(94vw, 520px);
  color: var(--ink);
  background:
    repeating-linear-gradient(90deg, rgba(120, 96, 64, .05) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(0deg, rgba(120, 96, 64, .045) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #fdf7ea, #eee0c7);
  border-radius: 3px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .8),
    0 0 0 1px rgba(118, 98, 68, .38),
    0 30px 70px rgba(0, 0, 0, .52);
  animation: bSheet .26s ease-out both;
}
/* a seam allowance stitched around the panel */
.c-modal__panel::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px dashed rgba(140, 118, 84, .38);
  border-radius: 2px;
  pointer-events: none;
}
.b-rules { width: min(94vw, 600px); }
.c-modal__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 10px;
  border-bottom: 1px solid rgba(140, 118, 84, .28);
}
.c-modal__head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 20px;
  letter-spacing: -.01em;
  color: #322c24;
}
.c-modal__x {
  margin-left: auto;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 2px;
  border: 1px solid rgba(120, 96, 64, .4);
  background: linear-gradient(180deg, #fffaef, #e9dbc1);
  color: #4a4236;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.c-modal__x:hover { filter: brightness(1.03); }
.c-modal__x[hidden] { display: none; }
.c-modal__body { padding: 12px 20px 4px; font-size: 13px; line-height: 1.55; color: #443c31; }
.c-modal__body h3 {
  margin: 14px 0 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: rgba(70, 60, 46, .62);
}
.c-modal__body ul { margin: 0 0 8px; padding-left: 16px; }
.c-modal__body li { margin-bottom: 4px; }
.c-modal__body li::marker { color: rgba(168, 63, 46, .6); }
.c-modal__body b { color: #2d2820; }
.c-modal__body kbd {
  padding: 0 4px;
  border-radius: 2px;
  border: 1px solid rgba(120, 96, 64, .4);
  background: rgba(255, 255, 255, .55);
  font-family: var(--font-mono);
  font-size: 11px;
}
.c-modal__lead { margin: 0 0 10px; font-size: 13px; }
.c-modal__note {
  margin: 12px 0 2px;
  font-size: 11px;
  color: rgba(80, 68, 52, .72);
}
.c-modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 18px 14px;
}

/* ---------- Flow contents ---------- */
.b-flow-lead { margin: 0 0 12px; font-size: 13px; }
.b-end { text-align: center; padding: 4px 0 2px; }
.b-end__big {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 700;
  color: #332d25;
}
.b-end__sub { margin: 0 0 12px; font-size: 12.5px; color: var(--ink-soft); }
.b-end__stats { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.b-end__stat {
  min-width: 88px;
  padding: 7px 10px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .5);
  border: 1px dashed rgba(120, 96, 64, .38);
}
.b-end__stat b { display: block; font-family: var(--font-mono); font-size: 17px; line-height: 1.2; }
.b-end__stat span { font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.b-mini {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 4px 0 10px;
  flex-wrap: wrap;
}

/* ---------- Toast ---------- */
.c-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 560;
  padding: 8px 16px;
  transform: translateX(-50%) rotate(-1deg);
  border-radius: 3px;
  background: linear-gradient(180deg, var(--linen-hi), var(--linen-lo));
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 0 0 1px rgba(120, 96, 64, .38), 0 12px 26px rgba(0, 0, 0, .42);
  animation: bToast .22s ease-out both;
}
.c-toast[hidden] { display: none; }

/* ---------- Motion ---------- */
@keyframes bSheet {
  from { opacity: 0; transform: translateY(10px) rotate(-.8deg); }
}
@keyframes bSew {
  from { opacity: 0; transform: translateY(-6px) scale(.9); }
}
@keyframes bSlide {
  from { opacity: 0; transform: translateX(calc(var(--u) * .5)) rotate(6deg); }
}
@keyframes bToast {
  from { opacity: 0; transform: translate(-50%, 10px) rotate(-1deg); }
}
@keyframes bFlash {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

/* ---------- Responsive ---------- */
/* Sizes are fluid through --u; these only trim chrome on narrow phones. */
@media (max-width: 640px) {
  .b-band__foot { display: none; }
  .b-rail__row { gap: calc(var(--u) * .055); }
  .b-patch { gap: calc(var(--u) * .025); }
}

@media (max-width: 470px) {
  .c-bar { gap: 8px; padding: 8px 10px 10px; }
  .c-bar__title { font-size: 18px; }
  .c-bar__stats { gap: 9px; }
  .stat { font-size: 10.5px; }
  .c-bar__controls { gap: 4px; }
  .c-btn { padding: 5px 8px; font-size: 11px; }
  .c-modal__body { padding: 10px 14px 4px; }
  .c-modal__head { padding: 12px 14px 9px; }
  .c-modal__foot { padding: 8px 14px 12px; }
  .b-verdict { font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .b-hang,
  .c-modal__panel,
  .c-toast,
  .b-patch { animation: none; transition: none; }
  .b-hang.is-end:hover,
  .b-hang.is-end:focus-visible { transform: rotate(var(--rot, 0deg)); }
  .b-verdict.is-flash { animation: none; }
}
