:root {
  --ink: #14181f;
  --paper: #f7f5ef;
  --line: #d9d4c6;
  --muted: #6a6558;
  --felt: #2f3a31;
  --accent: #b3261e;
  --good: #1a7a4c;
  --warn: #9a6b13;
}

* { box-sizing: border-box; }

/* The tile sprite must stay in the rendering tree — display:none here stops
   <use> resolving in some browsers — so it is collapsed to nothing instead. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

[hidden] { display: none !important; }

body {
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  max-width: 64rem;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

header { border-bottom: 2px solid var(--ink); padding-bottom: .75rem; margin-bottom: 1.25rem; }
h1 { margin: 0; font-size: 1.9rem; letter-spacing: -.01em; }
.sub { margin: .2rem 0 0; color: var(--muted); font-size: .95rem; }

h2 { font-size: 1.05rem; margin: 1.4rem 0 .3rem; }

.notice {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: .8rem 1rem;
  font-size: .92rem;
  margin: 0 0 1.5rem;
}

/* ------------------------------------------------------------------ board */

.board {
  background: var(--felt);
  color: #eef1ec;
  border-radius: 12px;
  padding: 1.1rem 1.2rem 1.3rem;
}
.board h2 { color: #fff; margin-top: .9rem; }
.hint { margin: .1rem 0 .9rem; color: #b9c4b6; font-size: .9rem; }
.delta { margin: .9rem 0 0; color: #b9c4b6; font-size: .9rem; }

.steps { display: flex; gap: .35rem; flex-wrap: wrap; }
.step {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 700;
  padding: .28rem .6rem;
  border-radius: 99px;
  border: 1px solid #53614f;
  color: #93a38f;
}
.step.done { background: #445041; color: #dfe6dc; border-color: #445041; }
.step.now { background: #f2efe3; color: var(--felt); border-color: #f2efe3; }

/* ------------------------------------------------------------------- rack */

.rack { display: flex; flex-wrap: wrap; gap: .45rem; margin: .2rem 0 0; min-height: 5.6rem; }

.slot {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 7px;
  line-height: 0;
  transform: translateY(0);
  transition: transform .12s ease, opacity .12s ease, box-shadow .12s ease;
}
.slot:disabled { cursor: not-allowed; }
.slot:focus-visible { outline: 3px solid #e8b23a; outline-offset: 3px; }

.tile { width: 3.9rem; height: 5.2rem; display: block; }
.slot.small .tile { width: 3.1rem; height: 4.15rem; }

.slot.spare { opacity: .76; }
.slot.facedown { margin-left: .35rem; }
.slot.facedown .tile { filter: drop-shadow(0 0 0 transparent); }
.slot:hover:not(:disabled) { transform: translateY(-3px); }
.slot.picked {
  transform: translateY(-10px);
  box-shadow: 0 0 0 3px var(--accent), 0 8px 14px rgba(0, 0, 0, .35);
}

.received-row { display: flex; align-items: center; gap: .7rem; margin-top: 1rem; flex-wrap: wrap; }
.received { display: flex; gap: .4rem; }
.received-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .1em;
  font-weight: 700; color: #93a38f;
}

/* --------------------------------------------------------------- controls */

.controls { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.1rem; }

button {
  font: inherit;
  font-weight: 600;
  padding: .5rem 1rem;
  border-radius: 4px;
  border: 1px solid #7d8a79;
  background: transparent;
  color: #eef1ec;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #3d4a3e; }
button.primary { background: #f2efe3; border-color: #f2efe3; color: var(--felt); }
button.primary:hover:not(:disabled) { background: #fff; }
button:disabled { opacity: .4; cursor: not-allowed; }
button:focus-visible { outline: 3px solid #e8b23a; outline-offset: 2px; }

/* ----------------------------------------------------------------- tables */

table { border-collapse: collapse; width: 100%; font-size: .92rem; margin-top: .4rem; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.num { text-align: right; white-space: nowrap; }
.strong { font-weight: 700; }
.quiet { color: var(--muted); }
.good { color: var(--good); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
.bad { color: var(--accent); font-weight: 600; }
/* Coverage says the same thing as Away, read the other way round, so it sits
   secondary to it. Tabular figures keep the column's decimal-free percentages
   in a straight line. */
td.coverage { color: var(--muted); font-variant-numeric: tabular-nums; }
tbody tr:first-child { background: #fff; }
td.pattern { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }

/* One colour per suit slot, as the printed card does it. The colours do not
   name a suit — they say which groups share one and which must differ, so a
   two-suit line reads as two colours without consulting the note. */
.suit-0 { color: var(--ink); }
.suit-1 { color: var(--good); }
.suit-2 { color: var(--accent); }
.suit-0, .suit-1, .suit-2 { font-weight: 700; }
td.note { color: var(--muted); }
td.section {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--muted);
  white-space: nowrap;
}

.status { color: var(--muted); font-size: .85rem; margin-top: .6rem; }

footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }

@media (max-width: 720px) {
  body { padding: 1.25rem .8rem 3rem; }
  .tile { width: 3.2rem; height: 4.3rem; }
  /* The Note is the first thing to go when the table will not fit. Matched by
     class on both the header and the cells, so inserting a column cannot
     silently hide the wrong one — an nth-child index did exactly that. */
  td.note, th.note { display: none; }

  .modal-content {
    max-height: 95vh;
  }

  .modal-header {
    padding: 0.9rem 1rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .group-tiles .tile {
    width: 2.4rem;
    height: 3.2rem;
  }
}

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background: var(--paper);
  border-radius: 12px;
  max-width: 36rem;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 2px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ink);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--line);
  color: var(--ink);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.line-detail {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.detail-summary {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

.detail-summary p {
  margin: 0;
}

.detail-summary p:first-child {
  font-size: 1.1rem;
  margin-bottom: 0.4rem;
}

.detail-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.detail-groups {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.detail-group {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
}

.detail-group.complete {
  border-left: 4px solid var(--good);
}

.detail-group.incomplete {
  border-left: 4px solid var(--warn);
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.group-tiles {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

.group-tiles .tile {
  width: 2.8rem;
  height: 3.7rem;
}

.group-status {
  font-weight: 700;
  font-size: 0.95rem;
}

.detail-group.complete .group-status {
  color: var(--good);
}

.detail-group.incomplete .group-status {
  color: var(--warn);
}

.group-detail {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.have {
  color: var(--ink);
  font-weight: 600;
}

.missing {
  color: var(--accent);
  font-weight: 600;
}

.joker-ok {
  color: var(--good);
}

.joker-barred {
  color: var(--muted);
}

.detail-jokers {
  text-align: center;
  padding: 0.8rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.line-row {
  cursor: pointer;
}

.line-row:hover {
  background: #f2efe3;
}
