/* Infinite Automatic Catan — page chrome.
 *
 * The palette is not written here. theme.js publishes every color, type step
 * and space step onto :root at load, so the stylesheet and the Three.js
 * materials cannot drift apart; the fallbacks in each var() are only there to
 * keep the page legible in the instant before the script runs.
 *
 * One family, real weights, and the same panel vocabulary as /infautuno: a
 * dark sheet on the felt, a tracked eyebrow title, a hairline rule, then the
 * mark.
 */

@font-face { font-family: 'Archia'; src: url('../../assets/fonts/Archia-Light.woff')    format('woff'); font-weight: 300; font-display: swap; }
@font-face { font-family: 'Archia'; src: url('../../assets/fonts/Archia-Regular.woff')  format('woff'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Archia'; src: url('../../assets/fonts/Archia-Medium.woff')   format('woff'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Archia'; src: url('../../assets/fonts/Archia-SemiBold.woff') format('woff'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Archia'; src: url('../../assets/fonts/Archia-Bold.woff')     format('woff'); font-weight: 700; font-display: swap; }

:root {
  --ink: #f4f1e8;
  --gold: #f5c542;
  --felt: #12503a;
  --sheet: rgba(10, 44, 31, 0.86);
  --hair: rgba(244, 241, 232, 0.16);
  --hair-strong: rgba(244, 241, 232, 0.32);
  --ink-2: rgba(244, 241, 232, 0.74);
  --ink-3: rgba(244, 241, 232, 0.5);
  --ink-4: rgba(244, 241, 232, 0.28);
  --radius-md: 8px;
  --radius-sm: 4px;
  /* Fallbacks only. theme.js overwrites every --fs-* and --sp-* on :root at
     load with the phi ladder; these keep the page legible for the one paint
     before the script runs. */
  --fs-1: 17.14px; --fs-0: 15.2px; --fs-n1: 13.48px; --fs-n2: 11.95px;
  --fs-n3: 10.6px; --fs-n4: 9.4px; --fs-n5: 8.33px; --fs-n6: 7.39px;
  /* The scale of everything over the island (palette.js), as a factor:
     the rails, the bar, the keys and the title are zoomed by it, the way a
     browser's Ctrl and plus would, and the island keeps its own size. */
  --hud: 1;
  /* The window's share is of the window as the scale sees it (scale.js),
     so a rail grows with the scale the way it does under a browser's zoom. */
  --rail-l: clamp(214px, calc(18.5vw / var(--hud)), 330px);
  --rail-r: clamp(246px, calc(21vw / var(--hud)), 386px);
  --gap: var(--sp-1, 10px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--felt);
  color: var(--ink);
  font-family: 'Archia', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* The table the island sits on: a warm pool of light in the middle, falling
   away to the corners, so the 3D canvas can stay transparent. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 92% at 50% 34%, rgba(255, 255, 255, 0.09), transparent 62%),
    radial-gradient(150% 120% at 50% 50%, transparent 38%, rgba(0, 0, 0, 0.46) 100%);
  pointer-events: none;
}

button, input, select, label, a {
  font-family: inherit;
  font-weight: 500;
}

/* ============================================================== layout */

#app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns:
    calc(var(--rail-l) * var(--hud)) minmax(0, 1fr) calc(var(--rail-r) * var(--hud));
  gap: var(--gap);
  padding: var(--gap);
}

/* Zoomed, a rail lays itself out at its usual width and is drawn at the
   scale, which is why its column above is widened by the same factor. A
   fixed control is placed in its own zoomed units, so the edges it keeps to
   are divided back down (#chrome, #keys-col). */
.rail,
#chrome,
#keys-col,
#title,
#banner { zoom: var(--hud); }

.rail {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 0;
  overflow: hidden;
}

/* The three readouts that size to their content, and two histograms that share
   whatever the rail has left between them, evenly.

   They are the same eleven columns measured two ways — how often each number
   came up, and what it paid the table when it did — so a difference in height
   between them would read as a difference in importance that is not there. */
#panel-yield, #panel-roll, #panel-standings { flex: 0 0 auto; }
#panel-rolls, #panel-payout { flex: 1 1 0; min-height: 132px; }
#rolls-body, #payout-body { display: flex; flex-direction: column; }
#standings-body { display: flex; flex-direction: column; }

/* The rail runs the whole height of the window. It used to stop a hundred and
   thirty pixels short, holding a slot for a control bar that is now over the
   board, and five panels in what was left meant scrolling a page nobody is
   standing at. The overflow rule stays as a floor for a window shorter than
   anything on this list is designed for; at any ordinary height it never
   engages. */
#rail-left { overflow-y: auto; }

#stage-wrap { position: relative; min-width: 0; min-height: 0; }
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

/* ============================================================== panels */

.panel {
  background: var(--sheet);
  border: 1px solid var(--hair);
  border-radius: var(--radius-md);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.26);
  padding: var(--sp-1, 10px) var(--sp-1, 10px) var(--sp-1, 10px);
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel > h2 {
  margin: 0 0 7px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--hair);
  font-size: var(--fs-n3);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex: none;
}

.panel > h2 .note {
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--ink-3);
  font-size: var(--fs-n4);
  white-space: nowrap;
}

.panel-body { min-height: 0; flex: 1; }

/* ======================================================== player cards */

#players {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  flex: none;
}

/* The seat's color goes all the way round.
   A two-pixel stripe down the left said whose card it was and made one edge of
   every card heavier than the other three, which reads as a stack of little
   flags rather than a column of cards. Whose move it is is said by that
   outline getting heavier and picking up a haze off it — and the weight is
   added as a shadow rather than as border width, so nothing moves by two
   pixels every time the turn passes, which at twelve times speed it does
   several times a second. */
.pcard {
  background: var(--sheet);
  border: 1px solid var(--pc-line, var(--hair));
  border-radius: var(--radius-md);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  padding: 7px 9px 8px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
}

/* Whose move it is, said by the border going from the seat's color at
   two-fifths to the seat's color, and by the wash behind it coming up. Not by
   the border getting thicker.

   It used to add `0 0 0 2px` of the seat color outside the border, which is a
   second ring with its own corner radius pressed against the first: at every
   corner the two curves disagree and the gap between them shows as a stray
   bracket of color. That is the artifact, and it was there because the ring
   was trying to be a thicker border without moving the layout. A color is
   enough, and it is the same answer /catan's opponent cards now give. */
.pcard.is-turn {
  background: linear-gradient(90deg, var(--pc-soft), var(--sheet) 62%);
  border-color: var(--pc);
}

/* A win outranks a turn and reads differently from it: the accent rather than
   the seat. Same one border. */
.pcard.is-winner,
.pcard.is-winner.is-turn { border-color: var(--gold); }

.pcard-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.pcard-name {
  font-size: var(--fs-n2);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--pc);
}

.pcard-persona {
  font-size: var(--fs-n4);
  letter-spacing: 0.06em;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.pcard-vp {
  font-size: var(--fs-1);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.pcard-vp small {
  font-size: var(--fs-n5);
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin-left: 2px;
}
.pcard-vp.is-bumped { animation: vp-bump 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes vp-bump {
  0% { transform: scale(1); }
  38% { transform: scale(1.32); color: var(--gold); }
  100% { transform: scale(1); }
}

.vpbar {
  display: flex;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  margin: 5px 0 6px;
  background: rgba(0, 0, 0, 0.3);
}
.vpbar span { display: block; height: 100%; }

.chiprow {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hair);
  font-size: var(--fs-n4);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-2);
  line-height: 1.5;
}
.chip.is-zero { opacity: 0.34; }
.chip i { font-style: normal; opacity: 0.8; }
.chip b { font-weight: 700; color: var(--ink); }

.chip.res-wood  { border-color: color-mix(in srgb, var(--res-wood) 46%, transparent); }
.chip.res-brick { border-color: color-mix(in srgb, var(--res-brick) 46%, transparent); }
.chip.res-sheep { border-color: color-mix(in srgb, var(--res-sheep) 46%, transparent); }
.chip.res-wheat { border-color: color-mix(in srgb, var(--res-wheat) 46%, transparent); }
.chip.res-ore   { border-color: color-mix(in srgb, var(--res-ore) 46%, transparent); }

.chip.is-award {
  border-color: var(--gold);
  color: var(--gold);
}

.pcard-meta {
  margin-top: 5px;
  font-size: var(--fs-n5);
  letter-spacing: 0.05em;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

/* ====================================================== yield / crops */

/* One grid for the panel, not one per row.
   Four separate grids can only agree on a column width by being told the same
   number, and that number was 3.4em — decided before anybody was named, which
   is why the names were cut short in script. The rows are `display: contents`
   now and the panel owns the tracks, so every name is measured against the
   same column and the column is measured against the panel.

   The name column takes a third of whatever the rail has been dragged to and
   stops at the width of the longest name plus a little air. CSS cannot know
   that ceiling — a clipped span reports its full width whether or not it fits
   — so `panels.js` measures it once, when the seats are named, and publishes
   it. Custom properties still inherit through a contents element, so `--yc` on
   the row still colors the name inside it. */
#yield-body {
  display: grid;
  grid-template-columns:
    max(2.6em, min(34%, var(--yield-name-max, 3.4em)))
    minmax(0, 1fr)
    3.1em;
  align-items: center;
  gap: 5px 6px;
}

.yield-row { display: contents; }

.yield-name {
  font-size: var(--fs-n4);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--yc, var(--ink-2));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.yield-track {
  display: flex;
  height: 9px;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.32);
}
.yield-track span {
  display: block;
  height: 100%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.yield-total {
  font-size: var(--fs-n3);
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* The key to the bars starts where the bars start.
   Under the whole panel it put the green square that stands for wood a name's
   width to the left of the wood segment it is a key to. */
.yield-legend {
  grid-column: 2 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--hair);
  font-size: var(--fs-n5);
  letter-spacing: 0.06em;
  color: var(--ink-3);
  text-transform: uppercase;
}
.yield-legend b { display: inline-block; width: 7px; height: 7px; border-radius: 1px; margin-right: 3px; }

/* The arithmetic is a footnote to the panel rather than to the bars, so it
   keeps the full width. */
.yield-foot {
  grid-column: 1 / -1;
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--hair);
  font-size: var(--fs-n5);
  line-height: 1.6;
  color: var(--ink-3);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.yield-foot b { color: var(--ink); font-weight: 600; }

/* ========================================================= standings */

.stand-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 1px 7px;
  align-items: baseline;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.stand-name {
  font-size: var(--fs-n4);
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--sc, var(--ink-2));
  overflow: hidden;
  text-overflow: ellipsis;
}

.stand-wins { font-size: var(--fs-n3); font-weight: 700; color: var(--ink); }
.stand-pct { font-size: var(--fs-n5); color: var(--ink-3); min-width: 2.4em; text-align: right; }

.stand-track {
  grid-column: 1 / -1;
  display: block;
  height: 3px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.32);
  overflow: hidden;
  margin-top: 2px;
}
.stand-track i {
  display: block;
  height: 100%;
  width: 0;
  opacity: 0.6;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.stand-row.is-leader .stand-track i { opacity: 1; }
.stand-row.is-leader .stand-wins { color: var(--gold); }

.stand-recent {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 2px;
  margin-top: 5px;
  max-height: 42px;
  overflow: hidden;
}
.stand-recent i {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 1px;
  opacity: 0.85;
}
.stand-recent i:last-child {
  outline: 1px solid var(--gold);
  outline-offset: 1px;
}

.stand-foot {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px solid var(--hair);
  font-size: var(--fs-n5);
  line-height: 1.5;
  color: var(--ink-4);
  letter-spacing: 0.03em;
}

/* ========================================================= histogram */

.hist {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 2px;
  align-items: end;
  flex: 1;
  min-height: 74px;
}

.hist-col {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.hist-bar {
  background: linear-gradient(180deg, var(--hair-strong), rgba(244, 241, 232, 0.14));
  border-radius: 1px 1px 0 0;
  transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 1px;
}
.hist-col.is-seven .hist-bar { background: linear-gradient(180deg, var(--robber), var(--robber-soft)); }
.hist-col.is-last .hist-bar { background: linear-gradient(180deg, var(--gold), var(--gold-soft)); }

/* The theoretical share, drawn as a rule across the column. */
.hist-tick {
  position: absolute;
  left: -1px;
  right: -1px;
  height: 0;
  border-top: 1px dashed var(--gold-line);
  pointer-events: none;
}

/* The eleven numerals along the foot are the whole key to both charts, and
   they were set at the smallest step on the ladder. Three rungs up, and a
   shade less faint with it. */
.hist-axis {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 2px;
  margin-top: 4px;
  font-size: var(--fs-n3);
  font-weight: 600;
  text-align: center;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* Six and eight in the ink a printed board prints them in, and seven in the
   robber's, which is a different red on purpose: one is set in type and never
   means trouble, the other is a warning light. It is the same distinction the
   tokens on the island are already making, said again where the numbers are
   being counted. */
.hist-axis span.is-hot { color: var(--token-lit); }
.hist-axis span.is-seven { color: var(--robber); }
.hist-axis span.is-last { color: var(--gold); font-weight: 700; }

.hist-key {
  margin-top: 6px;
  font-size: var(--fs-n5);
  color: var(--ink-4);
  letter-spacing: 0.04em;
}

/* ------------------------------------------------------ paid by number */

/* The twin chart. Same eleven columns, and each one stacked in resource
   colors: everything the island has put on the table on that number, for
   every seat, all game.

   The chart next door counts rolls, which is the argument every Catan table
   has and settles nothing, because a number that comes up constantly and pays
   one sheep is not the number winning the game. This counts cards. On an
   exhibit that deals a fresh island every few minutes it is the readout that
   answers "is this one lopsided?", which is exactly the question a watched
   game raises and a played one has no time for. */
.hist-stack {
  display: flex;
  flex-direction: column-reverse;
  /* Full height, and the segments measured against it. A stack sized by its
     own contents cannot give those contents a percentage height to be sized
     by, and the browser resolves that circle by drawing nothing. */
  justify-content: flex-start;
  height: 100%;
  border-radius: 1px 1px 0 0;
  overflow: hidden;
}

.hist-stack i {
  display: block;
  width: 100%;
  height: 0;
  flex: none;
  transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* The column already carries five colors and has none left to spare, so the
   number that has just come up is marked by the floor it stands on. Drawn as
   its own layer rather than as an inset shadow, which the stack standing on it
   would paint straight over. */
.hist.is-stacked .hist-col.is-last::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--gold);
}

/* =============================================================== log */

#panel-log { flex: 1; min-height: 0; }

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-right: 3px;
}
/* A scrollbar drawn by the browser is the one piece of this page nobody chose:
   a light gray slab on a felt table, in whatever shape the operating system
   thinks a scrollbar is. Said twice because the two ways of saying it are
   different standards and neither is universal, and everything on this page
   that scrolls is listed in one place so there is one answer rather than
   several. */
.log,
#rail-left {
  scrollbar-width: thin;
  scrollbar-color: var(--hair-strong) rgba(0, 0, 0, 0.24);
}

.log::-webkit-scrollbar,
#rail-left::-webkit-scrollbar { width: 7px; height: 7px; }

.log::-webkit-scrollbar-track,
#rail-left::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.24);
  border-radius: 999px;
}

.log::-webkit-scrollbar-thumb,
#rail-left::-webkit-scrollbar-thumb {
  background: var(--hair-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.log::-webkit-scrollbar-thumb:hover,
#rail-left::-webkit-scrollbar-thumb:hover {
  background: var(--ink-3);
  background-clip: content-box;
}

.log-line {
  font-size: var(--fs-n3);
  line-height: 1.45;
  letter-spacing: 0.01em;
  color: var(--ink-2);
  padding: 1px 0 1px 7px;
  border-left: 2px solid transparent;
  animation: log-in 0.32s ease both;
}
@keyframes log-in {
  from { opacity: 0; transform: translateX(-4px); }
  to { opacity: 1; transform: none; }
}
.log-line.t-accent { color: var(--gold); font-weight: 600; }
.log-line.t-gold   { color: var(--gold); }
.log-line.t-warn   { color: var(--robber-lit); }
.log-line.t-faint  { color: var(--ink-4); }
.log-line.t-win {
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: var(--fs-n4);
}

/* =========================================================== the roll */

/* What the last roll paid, and to whom (roll-panel.js). The same drawing as
   /catan's panel of the same name (catan/css/style.css); the one difference
   is that a crowded table is a class on the body here rather than an
   attribute on the root. */

/* Four and three make seven, written as that: the dice the same size as the
   total, because they are the same kind of thing, and lighter, because they
   are the given and the total is the answer. */
.roll-head {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--hair);
}

.roll-n,
.roll-d {
  font-size: var(--fs-3, 25px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.roll-d { font-weight: 500; color: var(--ink-3); min-width: 0.62em; text-align: center; }
.roll-n { font-weight: 700; min-width: 1.25em; }

.roll-op {
  font-size: var(--fs-0);
  font-weight: 500;
  color: var(--ink-4);
  padding: 0 1px;
}

/* Six and eight take the ink a printed token prints them in; seven takes the
   robber's, which is a different red on purpose. */
.roll-head.is-hot .roll-n { color: var(--token-lit); }
.roll-head.is-hot .roll-d { color: var(--token-line); }
.roll-head.is-seven .roll-n { color: var(--robber); }
.roll-head.is-seven .roll-d { color: var(--robber-line); }
.roll-head.is-seven .roll-op { color: var(--robber-line); }

.roll-list { display: flex; flex-direction: column; gap: 2px; }

/* Past rolls, to the right of the current one, on their way off the panel.
   The body reaches out to the panel's border so a card goes behind the edge
   rather than stopping short of it at the padding. */
#roll-body {
  container: roll / inline-size;
  overflow: hidden;
  margin-right: calc(-1 * var(--sp-1, 10px));
}

.roll-strip {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.roll-card {
  position: relative;
  flex: 0 0 min(176px, 100%);
  min-width: 0;
}

/* A past roll is the sum and the payouts, as narrow as they are. The rows
   keep their seat's color down the left, which is the name said in ink. */
.roll-card.is-past { flex: 0 0 auto; }
.roll-card.is-past .roll-d,
.roll-card.is-past .roll-op,
.roll-card.is-past .roll-who { display: none; }
.roll-card.is-past .roll-row { grid-template-columns: minmax(0, 1fr); }
.roll-card.is-past .roll-none { font-size: 0; }
.roll-card.is-past .roll-none::after { content: '\2013'; font-size: var(--fs-n4); }

.roll-card.is-dim { opacity: 0.62; }
.roll-card.is-new { opacity: 0; }

/* A hairline between one roll and the one before, in the middle of the gap. */
.roll-card.is-past::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 2px;
  bottom: 2px;
  border-left: 1px solid var(--hair);
}

.roll-strip.is-sliding > .roll-card {
  transition: transform 520ms cubic-bezier(0.22, 0.7, 0.25, 1), opacity 360ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .roll-strip.is-sliding > .roll-card { transition: none; }
}

/* Megacatan's eight seats in two columns where the panel is wide enough,
   seats down the first and on down the second. */
@container roll (min-width: 280px) {
  .is-crowd .roll-list {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(var(--roll-rows, 4), auto);
    grid-auto-columns: minmax(0, 1fr);
    column-gap: 10px;
  }
  .is-crowd .roll-row { grid-template-columns: 30px minmax(0, 1fr); gap: 5px; }
  .is-crowd .roll-got { gap: 5px; }
  .is-crowd .roll-card:not(.is-past) { flex-basis: min(228px, 100%); }
  .is-crowd .roll-card.is-past .roll-list { grid-auto-columns: max-content; column-gap: 6px; }
  .is-crowd .roll-card.is-past .roll-row { grid-template-columns: minmax(0, 1fr); }
}

.roll-row {
  display: grid;
  /* "P1" to "P8", and not a pixel more: the rest goes to what was paid. */
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 2px 0 2px 6px;
  border-left: 2px solid var(--sc, var(--hair));
}

/* A seat that got nothing still gets a line, at half ink. */
.roll-row.is-empty { opacity: 0.48; }

.roll-who {
  font-size: var(--fs-n4);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sc, var(--ink-2));
  overflow: hidden;
  text-overflow: ellipsis;
}

.roll-got { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.roll-gain { display: inline-flex; align-items: center; gap: 3px; }
.roll-gain i { display: block; width: 7px; height: 8px; border-radius: 1px; }

.roll-gain b {
  font-size: var(--fs-n3);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.roll-none { font-size: var(--fs-n4); color: var(--ink-4); letter-spacing: 0.05em; }

/* =========================================================== overlays */

#title {
  position: absolute;
  top: 4px;
  right: 8px;
  text-align: right;
  pointer-events: none;
  z-index: 2;
}
#title h1 {
  margin: 0;
  font-size: var(--fs-n2);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.92;
}
/* MEGA, in red, opening in front of CATAN on the big island.
   It is unfolded rather than faded on: the word widens from nothing, so the
   rest of the right-aligned title is pushed along by it instead of jumping,
   and the letters rise into place as it opens. */
.title-mega {
  display: inline-block;
  vertical-align: top;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-0.5em);
  color: #FF4A3A;              /* the overlay's robber red (heat-legend.js) */
  transition:
    max-width 0.6s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.4s ease,
    transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.is-mega .title-mega {
  max-width: 5em;
  opacity: 1;
  transform: none;
  transition:
    max-width 0.6s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.4s ease 0.15s,
    transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s;
}

#title p {
  margin: 3px 0 0;
  font-size: var(--fs-n4);
  letter-spacing: 0.09em;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* The title block lets the pointer through to the board; the one link in it
   does not. */
#title-play a {
  pointer-events: auto;
  color: var(--ink-3);
  text-decoration: none;
  border-bottom: 1px solid var(--ink-4);
}
#title-play a:hover { color: var(--gold); border-bottom-color: var(--gold); }

/* The house rules the island in play was dealt by, when it was. */
#title #title-rules { color: var(--gold); letter-spacing: 0.06em; }
#title #title-rules[hidden] { display: none; }

#banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.9);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 3;
}
#banner.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
/* A soft pool of shade so the name holds against whatever tile it lands on. */
#banner::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 150%;
  height: 320%;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, rgba(6, 22, 15, 0.72), transparent 72%);
  z-index: -1;
}

#banner .who {
  font-size: clamp(1.6rem, 4.6vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
  text-shadow: 0 3px 26px rgba(0, 0, 0, 0.6);
}
#banner .what {
  margin-top: 8px;
  font-size: var(--fs-n2);
  font-weight: 600;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* ============================================================= chrome */

/* One row over the board, centered on the board rather than on the window, so
   it stays in the middle of the thing it controls whichever way the two rails
   are sized. The same rounded rectangle as every panel on this page: it is a
   different kind of thing from a readout, and it says so by floating over the
   board and coming and going, which is enough. A pill on a page of rectangles
   is a second vocabulary for one element. */
#chrome {
  position: fixed;
  left: calc((var(--rail-l) * var(--hud) + var(--gap) * 2) / var(--hud));
  right: calc((var(--rail-r) * var(--hud) + var(--gap) * 2) / var(--hud));
  bottom: calc(var(--gap) / var(--hud));
  margin-inline: auto;
  /* One line, as wide as it needs and no wider than the room between the
     rails. Left to wrap on its own, a rounding error of half a pixel in
     sizing the bar to its content was enough to drop the last control onto a
     second row, so it only wraps when it truly does not fit, which hud.js
     measures and says with `is-wrapping` (a narrow board, or a large HUD
     scale), rather than run into a rail. */
  width: fit-content;
  max-width: calc(100% - (var(--rail-l) * var(--hud) + var(--rail-r) * var(--hud) + var(--gap) * 4) / var(--hud));
  z-index: 6;
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 7px var(--sp-2, 13px);
  padding: 8px 14px;
  background: var(--sheet);
  border: 1px solid var(--hair);
  border-radius: var(--radius-md);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.34);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

#chrome.is-wrapping { flex-wrap: wrap; }

/* Gone until the pointer moves, and gone again a couple of seconds after it
   stops. `hud.js` owns the timer and never sets this while the pointer is
   inside the bar or something in it has focus. The bar is untouchable while it
   is out of sight, so a pointer moved over where it was wakes it rather than
   pressing whatever it was covering. */
#chrome.is-idle {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

/* `h` still takes it away entirely, and outranks the timer. */
#chrome.is-hidden { display: none; }

/* The eyebrow, on the line rather than over it: it is a label for the row now
   rather than a title for a panel. */
.chrome-title {
  margin: 0;
  padding: 0 2px 0 0;
  font-size: var(--fs-n4);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}

#ctl-ms {
  font-size: var(--fs-n4);
  letter-spacing: 0.05em;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
  min-width: 3.6em;
  text-align: right;
}

.row { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }

/* The three groups keep their own shape. Left to the base rule they wrap
   inside themselves as the bar is sized, and "new game" ends up on a line of
   its own in a bar that has six hundred pixels of board to sit on. */
#chrome .row { flex: none; flex-wrap: nowrap; }

/* Wide enough to aim at, and it does not grow into the rest of the row.
   When the bar is short of room (a narrow board, or a large HUD scale) the
   pace slider is what gives, down to a width still worth aiming at, so the
   bar stays between the rails rather than running into one. */
#chrome .field { flex: 0 1 210px; min-width: 96px; }
#chrome .field input { min-width: 0; }

button {
  font-weight: 600;
  font-size: var(--fs-n3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(244, 241, 232, 0.07);
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  padding: 4px 7px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}
button:hover { border-color: var(--gold); color: var(--gold); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-soft);
}

.field { display: flex; align-items: center; gap: 6px; flex: 1; }
.field label {
  font-weight: 600;
  font-size: var(--fs-n4);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.5;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 46px;
  height: 16px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--hair-strong); border-radius: 1px; }
input[type="range"]::-moz-range-track { height: 2px; background: var(--hair-strong); border-radius: 1px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px; height: 10px; margin-top: -4px;
  border-radius: 50%; background: var(--gold); border: none;
}
input[type="range"]::-moz-range-thumb {
  width: 10px; height: 10px; border-radius: 50%; background: var(--gold); border: none;
}
input[type="range"]:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.readout {
  font-weight: 700;
  font-size: var(--fs-n3);
  min-width: 36px;
  text-align: right;
  opacity: 0.92;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------- keys */

/* The two keys no button mentions, in the board's top left, on the playback
   bar's timer (`hud.js`): up when the pointer moves, gone when it stops, gone
   for good with `c`. Read-only, so it never takes the pointer. */
/* The keys and the row of tools under them, in one column. The column is
   transparent to the pointer; the tools take their clicks back. */
#keys-col {
  position: fixed;
  left: calc((var(--rail-l) * var(--hud) + var(--gap) * 2) / var(--hud));
  top: calc(var(--gap) / var(--hud));
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}
#keys-col.is-hidden { display: none; }

/* The keys and the row under them (the palette, the heatmap square and,
   while the overlay is up, its readout) fade together, on the same idle
   timer as the bar, overlay or no overlay. The overlay is a view worth
   leaving up while the island plays itself, and the controls for it have no
   more reason to stay over it than the bar does; a move of the pointer
   brings them all back. */
#keys,
#keys-tools { transition: opacity 0.28s ease, transform 0.28s ease; }
#keys-col.is-idle #keys,
#keys-col.is-idle #keys-tools { opacity: 0; transform: translateY(-8px); }
#keys-col:not(.is-idle) #keys-tools { pointer-events: auto; }
#keys-tools { display: flex; align-items: center; gap: 6px; }

/* The overlay's readout, in the row rather than over the board. */
#keys-tools .heat-legend.is-hosted {
  position: static;
  flex-direction: row;
  padding: 3px 6px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.34);
}

/* Megacatan's button is in the red the title opens in, chosen or not. */
#ctl-mega { color: #FF4A3A; font-weight: 700; }
#ctl-mega:hover { border-color: #FF4A3A; color: #FF4A3A; }
#ctl-mega[aria-pressed="true"] {
  border-color: #FF4A3A;
  color: #FF4A3A;
  background: rgba(255, 74, 58, 0.14);
}

/* /catan's heatmap square, beside the palette under the keys. */
#heat-key {
  width: 26px;
  height: 26px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hair);
  background: var(--sheet-soft);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.34);
  transition: border-color 0.2s ease;
}
#heat-key svg { display: block; width: 80%; height: 80%; }
#heat-key:hover { border-color: var(--ink-3); background: var(--sheet-strong); }
#heat-key[aria-pressed="true"] { border-color: var(--gold); background: var(--sheet-strong); }

#keys {
  display: grid;
  gap: 5px;
  padding: 7px 11px;
  background: var(--sheet);
  border: 1px solid var(--hair);
  border-radius: var(--radius-md);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.34);
  pointer-events: none;
  font-size: var(--fs-n4);
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
#keys p { margin: 0; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
#keys span { margin-left: 4px; }
#keys i { font-style: normal; color: var(--ink-4); }
#keys kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 16px;
  padding: 0 4px;
  border-radius: 3px;
  border: 1px solid var(--hair-strong);
  background: rgba(244, 241, 232, 0.07);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
}
/* ------------------------------------------------------------ palette */

/* /catan's pill and card (catan/css/style.css), under the keys. */
#look { position: relative; }

#palette-open {
  display: flex;
  gap: 5px;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--sheet-soft);
  border: 1px solid var(--hair);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.34);
  cursor: pointer;
}
#palette-open i {
  display: block;
  width: 14px;
  height: 9px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}
#palette-open:hover { border-color: var(--ink-3); background: var(--sheet-strong); }
#palette-open.is-open { border-color: var(--gold); }

#palette-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  /* Wide enough for all seven grounds in one row. */
  width: 196px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--sheet-strong);
  border: 1px solid var(--hair);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
#palette-pop[hidden] { display: none; }

.pal-label {
  font-size: var(--fs-n5);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}
.pal-row { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.pal-row:last-child { margin-bottom: 0; }
.pal-chip {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.45);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  cursor: pointer;
}
.pal-chip:hover { transform: translateY(-1px); }
.pal-chip.is-on { outline: 2px solid var(--gold); outline-offset: 2px; }

/* The scale: a label with its figure at the far end, and the slider under. */
.pal-label-row { display: flex; justify-content: space-between; align-items: baseline; }
.pal-said { color: var(--ink); letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.pal-range { width: 100%; margin: 0; accent-color: var(--gold); cursor: pointer; }

/* The land pattern and the weather: a word rather than a color, because
   "on" is not a shade of anything. */
.pal-toggle {
  flex: 1;
  justify-content: center;
  align-items: center;
  /* Letter spacing trails the last letter too, which sets a word left of
     center by that much; the same again on the left puts it back. */
  padding: 4px 0 4px 0.12em;
  font-size: var(--fs-n5);
  font-weight: 700;
  letter-spacing: 0.12em;
}
/* A season in force is choosing the felt and the accent (palette.js), so
   the two rows that choose them step back; a pick from them is kept. */
#palette-pop.is-seasonal .is-color { opacity: 0.4; }

.pal-toggle.is-on {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--on-accent);
}

/* ---------------------------------------------------------- hold H */

/* The overlay's readout and its pointer tip, as /catan sets them
   (`heat-legend.js`, `heat.js`). Here there is one lens, so the readout is its
   name and no key to press. */
.heat-legend {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  padding: 5px 11px;
  border-radius: var(--radius-md);
  background: var(--sheet);
  border: 1px solid var(--hair);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  color: var(--ink-2);
  font-size: var(--fs-n2);
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.heat-legend[hidden] { display: none; }
.heat-legend-keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.heat-key {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px;
  line-height: 1;
  font-size: var(--fs-n3);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.heat-key.is-on { color: var(--lc); }
/* A lens key that is a button: the readout lets the pointer through to its
   keys and nowhere else, so a click on the rest of it still falls through. */
button.heat-key {
  pointer-events: auto;
  cursor: pointer;
  font-family: inherit;
  background: transparent;
  margin: 0;
}
button.heat-key:hover:not(.is-on) { color: var(--ink); border-color: var(--hair); }
/* The exhibit's buttons carry a frame; a lens key is a word until it is on. */
.heat-legend button.heat-key { border: 1px solid transparent; padding: 2px 4px; letter-spacing: 0.12em; }
.heat-legend button.heat-key.is-on { border-color: color-mix(in srgb, var(--lc) 45%, transparent); }
.heat-legend-note { margin: 0; color: var(--gold); }
.heat-legend-note[hidden] { display: none; }

.heat-tip {
  position: fixed;
  z-index: 41;
  pointer-events: none;
  max-width: 320px;
  padding: 5px 9px;
  border-radius: 7px;
  background: rgba(6, 14, 20, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--ink);
  font-size: var(--fs-n3);
  line-height: 1.35;
}

/* ------------------------------------------------------- Megacatan */

/* Eight seats, four cards: whoever is moving on top and the three after them
   (`panels.js`). The cards are placed in slots by script and slide up one
   each time the turn passes; the column clips the card leaving over the top
   and the ones waiting under the bottom. */
#players.is-revolving {
  position: relative;
  display: block;
  overflow: hidden;
}
#players.is-revolving .pcard {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transition:
    border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease,
    transform var(--revolve-ms, 420ms) cubic-bezier(0.4, 0, 0.2, 1),
    opacity var(--revolve-ms, 420ms) ease;
}
#players.is-revolving .pcard.is-off { opacity: 0; }
#players.is-revolving .pcard.is-snap { transition: none; }

/* Eight rows in the yield panel and eight in the standings push everything
   under them down, so on the big island the left rail gives up its small
   print: the arithmetic under the yield bars and the line under each chart
   saying what solid and dashed mean. The charts read without them. */
.is-mega .yield-foot,
.is-mega .hist-key { display: none; }
.is-mega #panel-rolls,
.is-mega #panel-payout { min-height: 96px; }

/* And eight seats' standings go two abreast, so the panel is as tall as the
   printed island's four. */
.is-mega #standings-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 14px;
}
.is-mega .stand-recent,
.is-mega .stand-foot { grid-column: 1 / -1; }

/* ========================================================= responsive */

/* The breakpoints are classes rather than media queries: they are crossed
   by the window divided by the HUD scale, which only script can measure
   (scale.js). Each says the width or height it stands for. */

/* 1280 wide */
:root.max-w-1280 #app { grid-template-columns: minmax(0, 1fr) calc(var(--rail-r) * var(--hud)); }
:root.max-w-1280 #rail-left { display: none; }
/* The board starts at the left edge now, so the bar centers on that. */
:root.max-w-1280 #chrome {
  left: calc(var(--gap) / var(--hud));
  max-width: calc(100% - (var(--rail-r) * var(--hud) + var(--gap) * 3) / var(--hud));
}
:root.max-w-1280 #keys-col { left: calc(var(--gap) / var(--hud)); }

/* Short viewports: the four player cards and the log have to share a rail
   that is not tall enough for both at full size. Tighten the cards; the log
   keeps a floor so it never collapses to a single line. */
/* 860 tall */
/* Below this the five panels want more column than a laptop has, even with
   the control bar off the rail. What can be given up is the arithmetic under
   the yield bars, which is a footnote to a panel that is legible without it,
   and the floor under the two charts: they shrink to whatever is left rather
   than holding a height and pushing the standings off the bottom. */
:root.max-h-860 .yield-foot { display: none; }
:root.max-h-860 #panel-rolls,
:root.max-h-860 #panel-payout { min-height: 0; }
:root.max-h-860 .hist { min-height: 44px; }

/* 820 tall */
:root.max-h-820 .pcard { padding: 5px 8px 6px; }
:root.max-h-820 .pcard-vp { font-size: var(--fs-n1); }
:root.max-h-820 .vpbar { margin: 4px 0 5px; }
:root.max-h-820 #panel-log { min-height: 118px; }
:root.max-h-820 .stand-recent { max-height: 22px; }

/* 860 wide */
:root.max-w-860 #app { grid-template-columns: minmax(0, 1fr); }
:root.max-w-860 #rail-right { display: none; }
:root.max-w-860 #chrome {
  left: calc(var(--gap) / var(--hud));
  right: calc(var(--gap) / var(--hud));
  max-width: calc(100% - var(--gap) * 2 / var(--hud));
}
:root.max-w-860 #title { top: 6px; right: 10px; }

@media (prefers-reduced-motion: reduce) {
  .yield-track span, .hist-bar, .hist-stack i, #banner, .stand-track i { transition: none; }
  .log-line, .pcard-vp.is-bumped { animation: none; }
  /* Still fades, because the alternative is a bar that blinks in and out of
     existence over the board, which is worse for the same person. */
  #chrome, #keys, #keys-tools { transition: opacity 0.12s linear; transform: none; }
  #chrome.is-idle, #keys-col.is-idle #keys, #keys-col.is-idle #keys-tools { transform: none; }
  #players.is-revolving .pcard { transition: none; }
  .title-mega, .is-mega .title-mega { transition: opacity 0.2s linear; transform: none; }
}

/* ========================================================= house rules */

/* The form behind the rules button (house-form.js): a card over a dimmed
   page, scrolling inside itself, in the panels' own vocabulary. Over the
   chrome and the rails; the island keeps playing underneath. */
.house-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: var(--sp-3, 21px);
  background: rgba(2, 14, 9, 0.6);
}
.house-panel[hidden] { display: none; }

.house-card {
  width: min(600px, 100%);
  max-height: calc(100dvh - 2 * var(--sp-3, 21px));
  display: flex;
  flex-direction: column;
  background: rgba(8, 36, 25, 0.97);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: left;
  overflow: hidden;
}

/* The head: what this is and who it is for on the left; on the right, how
   much is changed and the two ways out, on one line with the title. */
.house-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2, 13px);
  padding: var(--sp-2, 13px) var(--sp-3, 21px);
  border-bottom: 1px solid var(--hair);
}
.house-titles { min-width: 0; }
.house-titles h2 {
  margin: 0;
  font-size: var(--fs-1);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.04em;
  color: var(--ink);
}
.house-titles p {
  margin: 4px 0 0;
  max-width: 44ch;
  font-size: var(--fs-n2);
  line-height: 1.45;
  color: var(--ink-3);
}
.house-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.house-count {
  padding: 2px 9px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  font-size: var(--fs-n3);
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  white-space: nowrap;
}
.house-tools .primary { border-color: var(--gold); color: var(--gold); }
.house-panel .linky { background: none; border-color: transparent; color: var(--ink-3); }

/* One small label in capitals names each part of the card: the presets
   here, and every group of rules below. */
.house-presets::before,
.house-group h3 {
  font-size: var(--fs-n3);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* Ready-made sets of rules, above the boxes they fill in, on a band a shade
   darker than the rules so they read as a place to start rather than as one
   more rule. The chosen one is lit, and the line under them says what it
   does. */
.house-presets {
  padding: 13px var(--sp-3, 21px);
  border-bottom: 1px solid var(--hair);
  background: rgba(0, 0, 0, 0.14);
}
.house-presets::before {
  content: 'Start from';
  display: block;
  margin-bottom: 8px;
}
.house-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.house-panel .house-preset { padding: 4px 10px; letter-spacing: 0.04em; text-transform: none; }
.house-panel .house-preset.is-chaos { border-style: dashed; }
.house-preset-say {
  margin: 8px 0 0;
  min-height: 1.5em;
  font-size: var(--fs-n2);
  line-height: 1.5;
  color: var(--ink-3);
}

/* The rules scroll inside the card, under a scrollbar drawn in the page's
   own hair rather than the operating system's light slab. */
.house-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--sp-3, 21px) var(--sp-3, 21px);
}
/* Firefox draws its own from these two. Chrome and Safari would too, arrows
   and all, so they are left to the WebKit rules below instead. */
@supports not selector(::-webkit-scrollbar) {
  .house-body {
    scrollbar-width: thin;
    scrollbar-color: var(--hair-strong) transparent;
  }
}
.house-body::-webkit-scrollbar { width: 10px; }
.house-body::-webkit-scrollbar-track { background: transparent; }
.house-body::-webkit-scrollbar-thumb {
  background: var(--hair-strong);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}
.house-body::-webkit-scrollbar-thumb:hover { background: var(--ink-3); background-clip: content-box; }

/* A group's name stays pinned at the top while its rules scroll under it,
   and a hairline runs from it to the edge, so where one group ends and the
   next begins is never in doubt. */
.house-group h3 {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 13px;
  margin: 0;
  padding: var(--sp-2, 13px) 0 6px;
  background: rgb(8, 36, 25);
}
.house-group h3::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--hair);
}

/* A rule: its name, and under it in small type what the number means; the
   box on the right, in one column for the whole card, so the eye runs down
   the names on one side and the values on the other. */
.house-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  grid-template-areas: 'label box' 'note box';
  align-items: center;
  column-gap: var(--sp-2, 13px);
  row-gap: 1px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(244, 241, 232, 0.06);
}
.house-row:last-child { border-bottom: 0; }
.house-row > .house-label { grid-area: label; }
.house-row > .house-note { grid-area: note; }
.house-row > .house-note:empty { display: none; }
/* With nothing to say under it, a rule is one line, its name level with its box. */
.house-row:has(> .house-note:empty) { grid-template-areas: 'label box'; }
.house-panel .house-row > .house-n,
.house-panel .house-row > .house-toggle { grid-area: box; }

.house-label {
  font-size: var(--fs-n1);
  font-weight: 600;
  color: var(--ink);
}
.house-note {
  font-size: var(--fs-n3);
  line-height: 1.4;
  color: var(--ink-4);
}
/* A table's note is part of its label: under it, like any other rule's. */
.house-label .house-note {
  display: block;
  margin-top: 1px;
  font-weight: 400;
}

.house-panel input.house-n {
  width: 100%;
  min-width: 0;
  padding: 5px 6px;
  font: inherit;
  font-size: var(--fs-n1);
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
  background: rgba(244, 241, 232, 0.06);
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  -moz-appearance: textfield;
}
.house-panel input.house-n::-webkit-outer-spin-button,
.house-panel input.house-n::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.house-panel input.house-n::placeholder { color: var(--ink-4); }
.house-panel input.house-n:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.house-panel input.house-n.is-set { border-color: rgba(245, 197, 66, 0.55); color: var(--gold); font-weight: 700; }
.house-panel input.house-n.is-bad { border-color: #ff4a3a; }
.house-panel .house-toggle { width: 100%; padding: 5px 6px; }
/* A toggle is pressed when it says yes, which is not the same as changed:
   only a changed one is gold. */
.house-panel .house-toggle[aria-pressed="true"]:not(.is-set) {
  color: var(--ink);
  background: rgba(244, 241, 232, 0.07);
  border-color: var(--hair);
}
.house-panel .house-toggle.is-set { border-color: rgba(245, 197, 66, 0.55); color: var(--gold); }

/* The tables: costs, a starting hand, the deck. Each is set in a well of
   its own under its name, the columns named across the top. */
.house-row.is-table {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: 'label' 'grid';
  row-gap: 8px;
}
.house-row.is-table > .house-grid { grid-area: grid; }
.house-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 10px 10px;
  border: 1px solid rgba(244, 241, 232, 0.06);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.16);
}
.house-grid-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  align-items: center;
}
.house-grid-row:has(.house-grid-label) {
  grid-template-columns: 76px repeat(5, minmax(0, 1fr));
}
.house-grid-row.is-head .house-grid-col {
  font-size: var(--fs-n4);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  color: var(--ink-3);
}
.house-grid-label {
  font-size: var(--fs-n2);
  color: var(--ink-2);
}

@media (max-width: 560px) {
  .house-panel { padding: 8px; }
  .house-head { flex-direction: column; align-items: stretch; }
  .house-tools { justify-content: flex-start; flex-wrap: wrap; }
  .house-row { grid-template-columns: minmax(0, 1fr) 64px; }
  .house-grid { padding: 6px; }
  .house-grid-row:has(.house-grid-label) { grid-template-columns: 58px repeat(5, minmax(0, 1fr)); }
}

/* No double-tap zoom (../js/still.js has the rest). */
html, body, button, [role="button"], a, input, select, label { touch-action: manipulation; }
