/* Cards on a baize table: red for the cards, green for the felt, ink for text. */
:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --border: #ddd8cd;
  --text: #1c1b19;
  --muted: #6d6a62;
  --accent: #bf3b2f;          /* card red */
  --accent-soft: #fbe7e3;
  --ok: #1f7a58;              /* baize green */
  --gold: #b07d22;
  --danger: #b5462f;
  --felt: #eaf1e9;            /* the table the cards sit on */
  --felt-edge: #cfe0d2;
  --radius: 10px;
  --ord-ink: #ffffff;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1f242a;
    --border: #333a42;
    --text: #edeff1;
    --muted: #9aa3ac;
    --accent: #ff7d6b;
    --accent-soft: #3a211d;
    --ok: #55c99b;
    --gold: #d6a445;
    --danger: #ff8566;
    --felt: #16241e;
    --felt-edge: #294036;
    --ord-ink: #1a1613;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem 1rem 4rem;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header, main, footer { max-width: 60rem; margin: 0 auto; }

h1 { font-size: 1.7rem; margin: 0 0 .2rem; }
.tagline {
  margin: 0 0 .9rem;
  font-size: .95rem;
  color: var(--accent);
  letter-spacing: .01em;
}
h2 { font-size: 1.05rem; margin: 0 0 1rem; text-transform: uppercase; letter-spacing: .07em; color: var(--accent); }
h3 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }

.lede { color: var(--muted); margin: 0 0 1.5rem; }
header { border-bottom: 2px solid var(--accent-soft); margin-bottom: 1.5rem; }

/* An aside the reader should notice but not trip over. */
.note {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  margin: 0 0 1.5rem;
  padding: .75rem .95rem;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.note::before {
  content: "i";
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: .12rem;
  display: grid;
  place-items: center;
  border-radius: 99px;
  background: var(--accent);
  color: var(--ord-ink);
  font: italic 700 .78rem/1 Georgia, "Times New Roman", serif;
}
.note p {
  margin: 0;
  font-size: .9rem;
  color: var(--text);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
}

label { display: block; font-weight: 600; font-size: .9rem; }
label.inline { display: inline-flex; align-items: center; gap: .45rem; font-weight: 400; font-size: .9rem; }

.hint { display: block; font-weight: 400; font-size: .8rem; color: var(--muted); margin: .15rem 0 .4rem; }

textarea, input[type="number"] {
  width: 100%;
  font: inherit;
  font-size: .9rem;
  padding: .5rem .6rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
}
input[type="number"] { width: 4.5rem; }

.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .9rem;
  margin-top: 1rem;
}
.spacer { flex: 1 1 auto; }

button {
  font: inherit;
  font-size: .9rem;
  padding: .5rem .9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(191, 59, 47, .35);
}
button.primary:hover { filter: brightness(1.07); }
button:disabled { opacity: .5; cursor: progress; }

.progress {
  height: 7px;
  background: var(--accent-soft);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 1rem;
}
#progressBar { height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

#status { font-size: .9rem; color: var(--muted); margin: .6rem 0 0; }
#status.error { color: var(--danger); }

table { border-collapse: collapse; width: 100%; font-size: .9rem; margin-bottom: .5rem; }
th, td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--border); }
th { color: var(--ok); font-weight: 600; background: var(--felt); }
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  font-size: .75rem;
  padding: .1rem .5rem;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: .5rem;
  vertical-align: middle;
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: .9rem; }
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem .9rem;
  background: var(--bg);
}
.card h4 { margin: 0 0 .4rem; font-size: .95rem; }
.card ul { margin: 0; padding-left: 1.1rem; }
.card li { font-size: .9rem; }

pre {
  background: var(--felt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .8rem;
  overflow-x: auto;
  font-size: .82rem;
  margin: 0;
}

footer p { color: var(--muted); font-size: .85rem; }

/* ---- setup decks ---- */

.deck {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--felt-edge);
  border-radius: var(--radius);
  padding: .8rem .85rem .7rem;
  background: var(--felt);
}

.deck-head { display: flex; align-items: baseline; gap: .55rem; flex-wrap: wrap; }
.deck-head h3 { margin: 0; font-size: .95rem; }
.deck .hint { margin: 0; }

.count {
  margin-left: auto;
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0 .45rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  align-content: flex-start;
  margin: .6rem 0;
}
.chips:empty::after {
  content: "nothing here yet";
  font-size: .82rem;
  color: var(--muted);
  font-style: italic;
}

/* Each entry is drawn as a little playing card: poker proportions, every card
   the same width (set from the longest name by equaliseChips()). */
:root { --chip-font: .8rem; --chip-w: 5rem; }

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: var(--chip-font);
  line-height: 1.22;
  overflow-wrap: anywhere;      /* long names flow onto more lines */
  border: 1px solid var(--chip-edge, var(--border));
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .06);
  transition: transform .12s ease, box-shadow .12s ease;
}
.deck--table .chip,
.deck--people .chip {
  width: var(--chip-w);
  aspect-ratio: 5 / 7;          /* 2.5in x 3.5in, as a poker card */
  padding: 1.1rem .3rem .9rem;
}
.chip:hover { transform: translateY(-2px); box-shadow: 0 3px 7px rgba(0, 0, 0, .12); }
.chip .pip {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--chip-pip, var(--muted));
}
.chip .pip.flipped {            /* mirrored index, like a real card */
  top: auto;
  left: auto;
  right: 5px;
  bottom: 3px;
  transform: rotate(180deg);
}
.chip button {
  all: unset;
  position: absolute;
  top: 1px;
  right: 4px;
  cursor: pointer;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1;
  padding: 0 .1rem;
  border-radius: 3px;
  opacity: .55;
}
.chip button:hover { color: var(--danger); opacity: 1; }
.chip button:focus-visible { opacity: 1; outline: 1px solid var(--accent); }

/* Off-screen ruler used to find the longest name. */
.chip-probe {
  position: absolute;
  visibility: hidden;
  white-space: nowrap;
  font-size: var(--chip-font);
  top: -999px;
  left: -999px;
}
.chip.dup { animation: nudge .3s ease; border-color: var(--danger); }

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.deck--table  { --chip-edge: #e6bfb8; --chip-pip: var(--accent); }
.deck--people { --chip-edge: #b3cfbf; --chip-pip: var(--ok); }
/* People are drawn as figures, not cards: they hold a card, they aren't one. */
.deck--person .chip {
  flex-direction: column;
  gap: .3rem;
  width: var(--chip-w);
  padding: .5rem .3rem .45rem;
  font-size: .8rem;
  border-color: transparent;
  background: none;
  box-shadow: none;
}
.deck--person .chip:hover { box-shadow: none; }
.chip .ord {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 1.1rem;
  height: 1.1rem;
  display: grid;
  place-items: center;
  padding: 0 .15rem;
  font-size: .64rem;
  font-weight: 700;
  color: var(--ord-ink);
  background: var(--accent);
  border-radius: 99px;
}

.chip .figure {
  font-size: 1.6rem;
  line-height: 1.1;
}
.deck--person { --chip-pip: var(--accent); }
.deck--person .chip button { top: 0; right: 0; }

@media (prefers-color-scheme: dark) {
  .deck--table  { --chip-edge: #57342e; }
  .deck--people { --chip-edge: #2b4a3c; }
  .chip { box-shadow: none; }
}

.deck-foot {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.add { display: flex; gap: .35rem; }
.add input {
  width: 13rem;
  min-width: 0;
  font: inherit;
  font-size: .85rem;
  padding: .35rem .5rem;
  color: var(--text);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.add input:focus { border-style: solid; outline: none; border-color: var(--accent); }
.add button { padding: .25rem .6rem; font-size: 1rem; line-height: 1.2; }

button.link {
  all: unset;
  cursor: pointer;
  margin-left: auto;
  font-size: .78rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.link:hover { color: var(--accent); }

.deck textarea { margin-top: .5rem; }

/* The site masthead, styled exactly as on the landing page: the wordmark, the
   italic strapline, and the horizon from timhodson.com beneath. The whole
   block is the way back. */
.sitebar {
  display: block;
  max-width: 60rem;
  margin: 0 auto 1.4rem;
  text-decoration: none;
  color: var(--text);
}
.sitebar-name { display: block; font-size: 1.25rem; font-weight: 700; margin: 0 0 .1rem; }
.sitebar-sub {
  display: block;
  font: italic 13px Georgia, "Times New Roman", serif;
  color: var(--muted);
  letter-spacing: 0;
}
.sitebar:hover .sitebar-name { color: var(--accent); }
.sitebar-horizon {
  display: block;
  width: 100%;
  height: auto;
  margin: .5rem 0 0;
}
@media (prefers-color-scheme: dark) { .sitebar-horizon { filter: invert(1); } }
