@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: dark;

  --bg: #0b0a09;
  --cell: #050404;
  --cell-hover: #1e1b16;
  --tray: #1a1611;
  --edge: #6d685d;
  --frame: #7a6645;
  --line: #2b261e;

  --text: #ece5d6;
  --muted: #a39a85;
  --ink: #0b0a09;
  --accent: #ffff77;
  --error: #ff9c85;
  --void: #000;
  --shade: rgba(0, 0, 0, 0.12);
  --shade-edge: rgba(0, 0, 0, 0.3);
  --lip: rgba(255, 240, 210, 0.07);

  --k-normal: #8f97ff;
  --k-nnn: #32b5ad;
  --k-excl: #e0823a;
  --k-frac: #b9a56e;

  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.9375rem;
  --fs-lg: 1.1875rem;
  --fs-xl: 1.5rem;
  --fs-figure: 2rem;
  --fs-big: 5.5rem;
  --fs-big-narrow: 4rem;

  --cell-w: 6rem;
  --cell-h: 5.75rem;
  --strip-h: 1.625rem;
  --gap: 6px;
  --group-gap: 20px;
  --head-w: 11rem;
  --pad: 6px;
  --group-w: calc(var(--cell-w) * 3 + var(--gap) * 2 + var(--pad) * 2 + 2px);

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html { scrollbar-color: var(--frame) var(--bg); scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 57.5rem;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-md)/1.45 "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  accent-color: var(--accent);
  caret-color: var(--accent);
}

::selection { background: var(--accent); color: var(--ink); }

.top, main, footer { max-width: 1280px; margin: 0 auto; padding-inline: 32px; }

h1, h2, p, dl, dd, fieldset { margin: 0; }
h1 { font-size: var(--fs-xl); font-weight: 650; }
h2 { font-size: var(--fs-lg); font-weight: 650; }

.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

a { color: var(--text); text-underline-offset: 3px; text-decoration-color: var(--edge); }
a:hover { text-decoration-color: var(--accent); }

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  border: 1px solid var(--edge);
  font: var(--fs-xs)/1.5 ui-monospace, "SFMono-Regular", Consolas, monospace;
  text-align: center;
  color: var(--text);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-block: 20px;
  border-bottom: 1px solid var(--line);
}

.toolbar { display: flex; gap: 8px; }

button { font: inherit; color: inherit; cursor: pointer; }

.toolbar button, .rowacts button {
  height: 2rem;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--edge);
  color: var(--text);
  font-size: var(--fs-sm);
  white-space: nowrap;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.toolbar button:hover, .rowacts button:hover { background: var(--cell-hover); }
.toolbar button:active, .rowacts button:active { background: var(--line); }
.toolbar button:disabled { color: var(--muted); border-color: var(--line); cursor: default; background: transparent; }
.rowacts button[aria-expanded="true"] { background: var(--text); color: var(--ink); border-color: var(--text); }

/* Workspace */

.work {
  display: grid;
  grid-template-columns: max-content minmax(320px, 1fr);
  gap: 44px;
  align-items: start;
  padding-block: 28px 48px;
}

.row {
  display: grid;
  grid-template-columns: var(--head-w) max-content max-content;
  column-gap: var(--group-gap);
  align-items: stretch;
}

.heads { margin-bottom: 8px; }
.grouphead { width: var(--group-w); font-size: var(--fs-sm); color: var(--muted); }

/* The stash frame: a bronze hairline around a lighter tray, with the cells sunk into it */
.group { display: grid; grid-template-columns: repeat(3, var(--cell-w)); gap: var(--gap); padding: var(--pad); background: var(--tray); border: 1px solid var(--frame); }
.result .group { background: transparent; }

.rowhead { display: flex; flex-direction: column; min-width: 0; padding-right: 4px; }
.rowhead h2 { line-height: 1.2; }
.short { display: block; margin-top: 4px; font: var(--fs-sm)/1.3 ui-monospace, "SFMono-Regular", Consolas, monospace; color: var(--text); white-space: nowrap; }
.base { font-size: var(--fs-sm); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowacts { display: flex; gap: 6px; margin-top: auto; }
.rowacts button { height: 1.75rem; padding: 0 10px; }

.row[data-item="1"] { margin-top: 24px; }

.result { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }

.under {
  margin: 8px 0 0 calc(var(--head-w) + var(--group-gap));
  width: calc(var(--group-w) * 2 + var(--group-gap));
  font-size: var(--fs-sm);
}
.itemnote { color: var(--muted); }
.import label { display: block; color: var(--muted); margin-bottom: 6px; }

textarea {
  display: block;
  width: 100%;
  font: var(--fs-sm)/1.45 ui-monospace, "SFMono-Regular", Consolas, monospace;
  color: var(--text);
  background: var(--cell);
  border: 1px solid var(--edge);
  padding: 8px 10px;
  resize: vertical;
}
textarea::placeholder { color: var(--muted); }
textarea:focus-visible { outline-offset: 0; }
.error { color: var(--error); margin-top: 8px; }

/* Cells: one size for both items and the result, so they compare by eye */

.cell {
  --k: var(--void);
  position: relative;
  display: flex;
  flex-direction: column;
  width: var(--cell-w);
  height: var(--cell-h);
  background: var(--cell);
  border: 1px solid var(--k);
  box-shadow: inset 0 3px 6px var(--void), 0 1px 0 var(--lip);
}

.k-normal { --k: var(--k-normal); }
.k-nnn { --k: var(--k-nnn); }
.k-excl { --k: var(--k-excl); }
.k-frac { --k: var(--k-frac); }

.cell button { background: transparent; border: 0; color: inherit; }

.cell .cell-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 7px 9px 0;
  text-align: left;
  min-height: 0;
}
.cell-top { display: flex; justify-content: space-between; gap: 4px; font-size: var(--fs-xs); line-height: 1.3; }
.cell-state { font-weight: 700; }
.cell-main .cell-value { margin-top: 5px; font-size: var(--fs-lg); font-weight: 650; line-height: 1.1; }

.cell-foot { display: flex; border-top: 1px solid color-mix(in srgb, var(--k) 45%, transparent); }
.cell .cell-kind { flex: 1; height: var(--strip-h); padding: 0 9px; text-align: left; font-size: var(--fs-xs); }

.cell .cell-tag { width: 2.125rem; height: var(--strip-h); padding: 0; border-left: 1px solid color-mix(in srgb, var(--k) 45%, transparent); font-size: var(--fs-xs); font-weight: 700; text-align: center; }
.is-want .cell-tag { border-color: var(--shade-edge); }
.is-want .cell-tag:hover { background: var(--shade); }
.is-junk .cell-tag:hover { background: color-mix(in srgb, var(--k) 14%, transparent); }
.cell-pad { height: var(--strip-h); padding: 0 9px; font-size: var(--fs-xs); line-height: var(--strip-h); }
.cell-body { flex: 1; display: flex; flex-direction: column; padding: 7px 9px 0; }
.cell-body .cell-value { margin-top: 5px; font-size: var(--fs-lg); font-weight: 650; line-height: 1.1; }
.simrow .rowacts { margin-top: 12px; }
.simrow button:disabled { color: var(--muted); border-color: var(--line); cursor: default; background: transparent; }
.simnote { color: var(--text); min-height: 1.45em; }
.simnote.is-idle { color: var(--muted); }
.cell :focus-visible { outline-offset: -3px; }

.is-want { background: var(--k); color: var(--ink); box-shadow: none; }
.is-want .cell-foot { border-color: var(--shade-edge); }
.is-want .cell-main:hover, .is-want .cell-kind:hover { background: var(--shade); }
.is-want :focus-visible { outline-color: var(--ink); }

.is-junk {
  color: var(--k);
  background:
    repeating-linear-gradient(135deg, transparent 0 7px, color-mix(in srgb, var(--k) 16%, transparent) 7px 8px),
    var(--cell);
}
.is-junk .cell-main:hover, .is-junk .cell-kind:hover { background: color-mix(in srgb, var(--k) 14%, transparent); }

.is-empty { border-color: var(--void); }
.cell.is-empty .cell-main { align-items: center; justify-content: center; padding: 0; color: var(--muted); }
.is-empty .cell-main:hover { background: var(--cell-hover); color: var(--text); }

.is-result { padding: 7px 9px; box-shadow: none; background: var(--bg); border-color: var(--line); color: var(--muted); }
.is-result.is-blank { border-style: dashed; }

/* Under the grid */

.notice { min-height: 1.45em; margin-top: 14px; font-size: var(--fs-sm); color: var(--text); max-width: 70ch; }

.legend { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 14px; max-width: calc(var(--head-w) + var(--group-w) * 2 + var(--group-gap) * 2); }
.legend dt { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); font-weight: 600; }
.legend dd { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }
.sw { width: 12px; height: 12px; background: var(--k); }

.hint { margin-top: 4px; font-size: var(--fs-sm); color: var(--muted); max-width: 75ch; }

/* Odds */

.results { position: sticky; top: 20px; }

.base-switch { border: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0; }
.base-switch legend { padding: 0; margin-bottom: 8px; font-size: var(--fs-sm); color: var(--muted); }
.base-switch label { position: relative; cursor: pointer; }
.base-switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.base-switch span {
  display: block;
  padding: 6px 16px;
  border: 1px solid var(--edge);
  margin-left: -1px;
  font-size: var(--fs-sm);
  color: var(--muted);
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.base-switch label:first-of-type span { margin-left: 0; }
.base-switch label:hover span { color: var(--text); background: var(--cell-hover); }
.base-switch input:checked + span { background: var(--text); color: var(--ink); border-color: var(--text); font-weight: 600; }
.base-switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; position: relative; z-index: 1; }

.convention { margin-top: 10px; }

.parts { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 28px; }
.part dt { font-size: var(--fs-md); font-weight: 600; white-space: nowrap; }
.part dt span { font-weight: 400; font-size: var(--fs-sm); color: var(--muted); margin-left: 6px; }
.part dd { font-size: var(--fs-figure); font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; }
.part.is-none dd { color: var(--muted); }

.both { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.both h2 { font-size: var(--fs-md); }
.big { font-size: var(--fs-big); font-weight: 700; line-height: 1; letter-spacing: -0.035em; color: var(--accent); margin: 6px 0 8px -4px; }
.odds { color: var(--text); }
.note { font-size: var(--fs-sm); color: var(--muted); margin-top: 8px; max-width: 60ch; }

.lines { margin-top: 24px; border-top: 1px solid var(--line); }
.lines div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lines dt { color: var(--muted); }
.lines dd { font-weight: 600; }
.lines + .note { margin-top: 16px; }

.empty { margin-top: 28px; color: var(--muted); max-width: 44ch; line-height: 1.7; }

/* Help */

.help { padding-block: 36px 16px; border-top: 1px solid var(--line); scroll-margin-top: 16px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 56px; margin-top: 16px; }
.help p, .help li { max-width: 65ch; }
.help p { margin-top: 12px; color: var(--muted); }
.help p b { color: var(--text); font-weight: 600; }
.help ol { margin: 0; padding-left: 20px; }
.help li { margin-bottom: 6px; }

table { border-collapse: collapse; width: 100%; max-width: 440px; }
caption { text-align: left; font-weight: 600; padding-bottom: 8px; }
th, td { padding: 6px 0; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
thead th { font-size: var(--fs-xs); color: var(--muted); }
th.num, td.num { text-align: right; }

footer { padding-block: 24px 40px; font-size: var(--fs-sm); color: var(--muted); }

/* The one authored moment: a figure that changed fades up into place */
@keyframes settle { from { opacity: 0.25; transform: translateY(3px); } }
.changed { animation: settle 420ms var(--ease); }

/* Half-width window beside the game: the odds move above the grid so they stay in view */
@media (max-width: 79.9rem) {
  .work { grid-template-columns: max-content; gap: 28px; padding-top: 20px; }
  .results {
    order: -1;
    position: static;
    display: grid;
    grid-template-columns: auto auto 1fr;
    column-gap: 40px;
    align-items: start;
    width: calc(var(--head-w) + var(--group-w) * 2 + var(--group-gap) * 2);
    padding-bottom: 20px;
    border-bottom: 1px solid var(--line);
  }
  .base-switch, .convention { grid-column: 1; }
  .convention { max-width: 22ch; }
  .parts { grid-column: 2; grid-row: 1 / span 3; grid-template-columns: 1fr; gap: 12px; margin-top: 0; }
  .both { grid-column: 3; grid-row: 1 / span 3; margin-top: 0; padding-top: 0; border-top: 0; }
  .big { font-size: var(--fs-big-narrow); }
  .lines, .lines + .note, .empty { grid-column: 1 / -1; }
  .lines { margin-top: 16px; }
  .help-cols { grid-template-columns: 1fr; gap: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .changed { animation: none; }
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
