/*
 * styles.css — all styling for Gradation.
 * Set dressing follows C:\Repo\Dev\DevilsEquationWordle (itself after
 * DevilsHeavy13, DevilsRoulette, MemoryPoker and The Devil's Plan): a lit
 * concrete cell wall, dark slabs with a gold hairline, purple game furniture,
 * gold for anything you act on, engraved Cinzel caps and Zilla Slab.
 *
 * used_by: index.html
 * related: offline.html (carries its own minimal copy of the palette);
 *          ui.js (builds the cups, tray, table and drawers this styles)
 * rules:
 *   - Mobile-first at ~380px. Every tappable control is at least 44px.
 *   - Colour has one meaning each: gold = you / act now, purple = game
 *     furniture, and the four CUP SHADES are the game itself. They are a
 *     departure from the purple-and-gold-only rule for the same reason the
 *     traffic lights were in Equation Traffic Light: they ARE the mechanic.
 *   - The four shades must stay clearly four. A player who cannot tell dark
 *     grey from light grey cannot play, so they are spaced wide and every cup
 *     also carries its tier name in the legend.
 *   - Controls are NOT purple. Every button is the near-black slab with a gold
 *     hairline and a gold light bleeding off its bottom edge. Purple is left
 *     to furniture that is only looked at: the masthead ribbon, the standings.
 *   - Text straight on the wall is dark ink; text on a slab is cream or gold.
 *   - Every character on a game piece — a cup, a tray cube — is set in the
 *     display face. Body face is for prose only.
 *   - Fonts are local files in fonts/. No url() to another origin, ever.
 *   - Anything not needed right now is display:none, not greyed out.
 *   - The page is exactly one screen tall (.shell is 100dvh) and never scrolls.
 *   - NEVER render an opponent cup value anywhere, in any state, until the
 *     round is revealed. The cup face is a shade and nothing else.
 * message: --cup-w and --cup-h are written by ui.js (sizeTable); the cups and
 *   the tray are measured from them.
 * wiki: README.md
 */
@font-face { font-family: "Cinzel"; font-weight: 400 700; font-style: normal; font-display: swap; src: url("fonts/cinzel-latin.woff2") format("woff2"); }
@font-face { font-family: "Zilla Slab"; font-weight: 400; font-style: normal; font-display: swap; src: url("fonts/zilla-slab-400.woff2") format("woff2"); }
@font-face { font-family: "Zilla Slab"; font-weight: 600; font-style: normal; font-display: swap; src: url("fonts/zilla-slab-600.woff2") format("woff2"); }
@font-face { font-family: "Zilla Slab"; font-weight: 700; font-style: normal; font-display: swap; src: url("fonts/zilla-slab-700.woff2") format("woff2"); }

:root {
  /* Concrete */
  --wall-lit: #a5a39e;
  --wall-mid: #7e7c78;
  --wall-dark: #5a5855;
  --wall-deep: #3e3d3b;

  /* Ink on the wall */
  --ink: #221e1b;
  --ink-soft: #3d3732;

  /* Slabs laid on the wall */
  --slab: #25211e;
  --slab-deep: #1a1816;
  --slab-bg: linear-gradient(180deg, rgba(48, 44, 41, 0.94), rgba(26, 24, 22, 0.96));
  --line: rgba(240, 220, 164, 0.2);
  --line-soft: rgba(240, 220, 164, 0.1);
  --cream: #d6cec2;
  --mute: #9c948a;
  --stock: #fbf9f4;

  /* Purple: the game furniture */
  --purple-900: #2d1245;
  --purple-700: #4a1d73;
  --purple-600: #5f2a94;
  --purple-300: #ad7ae0;

  /* The board: the flag's purple, knocked back and greyed so it is furniture
     rather than signage. It has to stay light enough that a BLACK cup still
     has an edge against it - that is the whole reason it is not near-black. */
  --board-lit: #3f3049;
  --board-mid: #312439;
  --board-deep: #261b2d;
  --board-glow: rgba(173, 122, 224, 0.1);

  /* Gold: you, and anything you act on */
  --gold-600: #9c7628;
  --gold-500: #c6992f;
  --gold-400: #d9b254;
  --gold-200: #f0dca4;

  /* The gradation: the game's one fact. Four shades over seven cups, so a
     shade always names a PAIR of positions. */
  --cup-0: #131110;
  --cup-0-lip: #2e2a26;
  --cup-1: #413a33;
  --cup-1-lip: #5c534a;
  --cup-2: #8c8278;
  --cup-2-lip: #a89d91;
  --cup-3: #e3dbcd;
  --cup-3-lip: #f4eee2;

  --win: #5cc487;
  --win-deep: #1f6a43;
  --lose: #e5594a;
  --lose-deep: #9c2a21;
  --draw: #e6c24d;

  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --body: "Zilla Slab", Rockwell, Georgia, serif;
  --ease: cubic-bezier(0.22, 0.61, 0.24, 1);
  --ease-snap: cubic-bezier(0.34, 1.46, 0.5, 1);
  --shadow-slab: 0 10px 24px -14px rgba(0, 0, 0, 0.9);

  /* Written by ui.js once the table is measured. */
  --cup-w: 44px;
  --cup-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: dark; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.4;
  color: var(--cream);
  background-color: var(--wall-dark);
  /* One overhead light on a concrete wall. */
  background-image: radial-gradient(120% 88% at 50% 12%, var(--wall-lit) 0%, var(--wall-mid) 42%, var(--wall-dark) 74%, var(--wall-deep) 100%);
  background-attachment: fixed;
  touch-action: manipulation;
  overflow-x: hidden;
  /* House rule: the sites are played, not read. Dragging across the cups must
     never paint a text selection. Form fields and .selectable are exempt. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

input, textarea, select, [contenteditable], .selectable {
  -webkit-user-select: text;
  user-select: text;
}

/* Concrete grain */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 8s steps(6) infinite;
}
@keyframes grain {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-2%, 1%); }
  50% { transform: translate(1%, -2%); }
  75% { transform: translate(2%, 1%); }
}

button, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

.shell {
  position: relative;
  z-index: 1;
  width: min(100%, 460px);
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.shell > * { flex: none; }

/* ---------------- masthead ---------------- */

.masthead { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }

.eyebrow {
  display: inline-block;
  padding: 3px 16px;
  font-family: var(--display);
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--gold-200);
  background: linear-gradient(180deg, var(--purple-700), var(--purple-900));
  box-shadow: inset 0 0 0 1px var(--gold-600), inset 0 1px 0 rgba(240, 220, 164, 0.3);
  clip-path: polygon(0 0, 100% 0, calc(100% - 9px) 50%, 100% 100%, 0 100%, 9px 50%);
}
.masthead .eyebrow { padding: 3px 12px; font-size: 0.44rem; letter-spacing: 0.1em; }

.wordmark {
  font-family: var(--display);
  font-size: clamp(1.15rem, 6.4vw, 1.6rem);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #171412;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.16), 0 -1px 1px rgba(0, 0, 0, 0.5);
}

/* Hamburger menu */
.menu { position: relative; flex: none; }
.menu-btn { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--line); border-radius: 0; background: var(--slab-bg); box-shadow: var(--shadow-slab); cursor: pointer; transition: background 0.2s ease; }
.menu-btn:hover, .menu-btn[aria-expanded="true"] { background: linear-gradient(180deg, #3a3228, #1c1916); border-color: var(--gold-400); }
.menu-btn:focus-visible, .menu-item:focus-visible { outline: 2px solid var(--gold-200); outline-offset: -3px; }
.menu-bars { position: relative; width: 16px; height: 12px; }
.menu-bars i { position: absolute; left: 0; width: 16px; height: 2px; background: var(--gold-200); border-radius: 1px; transition: transform 0.22s var(--ease), opacity 0.15s ease, top 0.22s var(--ease); }
.menu-bars i:nth-child(1) { top: 0; }
.menu-bars i:nth-child(2) { top: 5px; }
.menu-bars i:nth-child(3) { top: 10px; }
.menu-btn[aria-expanded="true"] .menu-bars i:nth-child(1) { top: 5px; transform: rotate(45deg); }
.menu-btn[aria-expanded="true"] .menu-bars i:nth-child(2) { opacity: 0; }
.menu-btn[aria-expanded="true"] .menu-bars i:nth-child(3) { top: 5px; transform: rotate(-45deg); }
.menu-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; width: 210px; display: flex; flex-direction: column; border: 1px solid var(--line); border-top: 2px solid var(--gold-400); background: var(--slab); box-shadow: 0 18px 34px -10px rgba(0, 0, 0, 0.9); animation: sheet-in 0.2s var(--ease) both; }
.menu-panel[hidden] { display: none; }
.menu-item { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 36px; padding: 0 12px 0 26px; border: 0; background: none; font-family: var(--display); font-size: 0.58rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; text-decoration: none; color: var(--gold-200); cursor: pointer; transition: background 0.18s ease, color 0.18s ease; }
.menu-item::before { content: ''; position: absolute; left: 11px; top: 50%; width: 5px; height: 5px; margin-top: -3px; background: var(--gold-400); transform: rotate(45deg); opacity: 0.55; transition: opacity 0.18s ease; }
.menu-item + .menu-item { border-top: 1px solid var(--line-soft); }
.menu-item:hover, .menu-item:active { background: rgba(240, 220, 164, 0.07); color: var(--stock); }
.menu-item:hover::before, .menu-item:active::before { opacity: 1; }
.menu-more { border-top: 1px solid var(--line); background: rgba(240, 220, 164, 0.04); }
.menu-more::after { content: '\2197'; font-size: 0.8rem; letter-spacing: 0; }

.opt-pills { display: flex; gap: 4px; font-family: var(--body); font-size: 0.72rem; letter-spacing: 0; line-height: 1; text-transform: none; }
.opt-pills i { padding: 2px 6px; border: 1px solid var(--line); font-style: normal; font-weight: 600; color: var(--mute); }
.opt-pills i.on { color: var(--slab-deep); background: var(--gold-200); border-color: var(--gold-200); }

/* ---------------- buttons ---------------- */

.btn {
  appearance: none;
  min-height: 46px;
  min-width: 46px;
  padding: 8px 12px;
  border: 1px solid rgba(240, 220, 164, 0.26);
  border-radius: 2px;
  background: linear-gradient(180deg, #332e2a, #191715);
  box-shadow: inset 0 1px 0 rgba(240, 220, 164, 0.1), inset 0 -14px 20px -16px var(--gold-400), 0 8px 18px -10px rgba(0, 0, 0, 0.95);
  font-family: var(--display);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-200);
  cursor: pointer;
  transition: transform 0.16s var(--ease-snap), filter 0.2s ease, box-shadow 0.25s ease, border-color 0.2s;
}
.btn:hover:not(:disabled) { filter: brightness(1.18); transform: translateY(-2px); border-color: rgba(240, 220, 164, 0.5); }
.btn:active:not(:disabled) { transform: translateY(0); filter: brightness(0.95); }
.btn:focus-visible { outline: 2px solid var(--gold-200); outline-offset: 2px; }
.btn:disabled { opacity: 0.38; cursor: not-allowed; box-shadow: none; }

.btn-ghost { background: rgba(24, 20, 18, 0.62); border-color: rgba(240, 220, 164, 0.28); box-shadow: none; }
.btn-ghost:hover:not(:disabled) { background: rgba(58, 50, 40, 0.75); border-color: rgba(240, 220, 164, 0.45); filter: none; }
/* Gold: the one button that moves the game on. */
.btn-primary { background: linear-gradient(180deg, var(--gold-200), var(--gold-500)); border-color: var(--gold-600); color: #1d1608; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 8px 18px -10px rgba(0, 0, 0, 0.95); }
.btn-wide { width: 100%; min-height: 52px; font-size: 0.76rem; letter-spacing: 0.22em; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; }

/* ---------------- status strip ---------------- */

.status { display: grid; grid-template-columns: 1fr 1.3fr 1fr; border: 1px solid var(--line); background: var(--slab-bg); box-shadow: var(--shadow-slab); }
.stat { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 5px 8px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line-soft); }
.stat-label { display: block; font-family: var(--display); font-size: 0.46rem; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-200); white-space: nowrap; }
.stat-value { font-size: 1.3rem; font-weight: 700; line-height: 1.05; color: var(--stock); font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); }
.stat-value small { font-size: 0.6rem; font-weight: 600; color: var(--mute); }
/* The score reads as yours-theirs, so your half is gold. */
.score-you { color: var(--gold-400); }
.score-sep { color: var(--mute); padding: 0 2px; }
/* The clock only goes red when it is nearly out, so it is quiet until it matters. */
.clock-low { color: var(--lose); animation: clock-pulse 1s steps(2) infinite; }
@keyframes clock-pulse { 50% { opacity: 0.45; } }

/* ---------------- the stage ---------------- */

/* Whatever phase is running takes the height that is left. */
.stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 10px; }

/* The one-line instruction above whatever you are doing. */
.prompt { min-height: 34px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 5px 10px; border: 1px solid var(--line); border-left: 4px solid var(--gold-400); background: var(--slab-deep); font-size: 0.9rem; font-weight: 600; color: var(--stock); text-align: center; }
.prompt-wait { border-left-color: var(--purple-600); color: var(--cream); }
.prompt b { color: var(--gold-200); }

/* ---------------- cups ---------------- */

/* A cup is drawn, not boxed: a tapered vessel with a lifted foot, shaded across
   its width so it reads as round, and capped by an elliptical rim with the dark
   of its own opening inside it. The shade is set from data-tier and is the ONLY
   thing an opponent sees - the drawing must never hint at a value.
   message: --cup-ground is the contact shadow that sits the cup ON the shelf;
   every other filter on .cup::before has to carry it, or the cup floats. */
.cup {
  --cup-ground: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.55));
  position: relative;
  width: var(--cup-w);
  height: var(--cup-h);
  padding: 0;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: calc(var(--cup-w) * 0.5);
  font-weight: 700;
  line-height: 1;
  cursor: default;
  transition: filter 0.18s ease;
}
/* The body. Four layers: the shadow cast down the inside of the mouth, the
   round-across-the-width shading with one specular streak, the darkened base
   with a lit foot, and the shade itself underneath. */
.cup::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 100% 0, 85% 90%, 77% 100%, 23% 100%, 15% 90%);
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.16) 11%, rgba(0, 0, 0, 0) 27%),
    linear-gradient(90deg,
      rgba(0, 0, 0, 0.5) 0%,
      rgba(0, 0, 0, 0.06) 13%,
      rgba(255, 255, 255, 0.2) 25%,
      rgba(255, 255, 255, 0.05) 38%,
      rgba(0, 0, 0, 0.1) 60%,
      rgba(0, 0, 0, 0.36) 87%,
      rgba(0, 0, 0, 0.58) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0) 68%, rgba(0, 0, 0, 0.42) 95%, rgba(255, 255, 255, 0.14) 100%),
    var(--shade);
  filter: var(--cup-ground);
  transition: filter 0.18s ease, transform 0.18s var(--ease-snap);
}
/* The rim: an ellipse overhanging the body, with the cup's own dark interior
   inside it. This is what makes it an open cup rather than a tile. */
.cup::after {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  height: clamp(7px, calc(var(--cup-w) * 0.26), 16px);
  border-radius: 50%;
  background:
    /* The far wall, catching the overhead light, so the opening has a back to
       it and does not read as a black disc stuck on the cup. */
    radial-gradient(closest-side at 50% 30%, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0) 56%),
    /* The inside. Translucent, never opaque: the cup's own shade has to tint it,
       or every cup ends up with the same black hole in the top. */
    radial-gradient(closest-side at 50% 58%,
      rgba(0, 0, 0, 0.72) 0%,
      rgba(0, 0, 0, 0.66) 50%,
      rgba(0, 0, 0, 0.38) 60%,
      rgba(0, 0, 0, 0) 68%),
    linear-gradient(180deg, var(--lip) 0%, var(--shade) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 2px 3px -1px rgba(0, 0, 0, 0.55);
  transition: transform 0.18s var(--ease-snap);
}
/* The number sits below the mouth, never across it. */
.cup span {
  position: relative;
  z-index: 1;
  padding-top: calc(var(--cup-h) * 0.16);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.cup[data-tier="0"] { --shade: var(--cup-0); --lip: var(--cup-0-lip); color: var(--stock); }
.cup[data-tier="1"] { --shade: var(--cup-1); --lip: var(--cup-1-lip); color: var(--stock); }
.cup[data-tier="2"] { --shade: var(--cup-2); --lip: var(--cup-2-lip); color: #1b1714; }
.cup[data-tier="3"] { --shade: var(--cup-3); --lip: var(--cup-3-lip); color: #1b1714; }
.cup[data-tier="2"] span, .cup[data-tier="3"] span { text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45); }

/* Yours, and choosable right now. The whole cup lifts, rim and all. */
.cup-live { cursor: pointer; }
.cup-live:hover::before { filter: var(--cup-ground) brightness(1.2); transform: translateY(-3px); }
.cup-live:hover::after { transform: translateY(-3px); }
.cup-live:active::before, .cup-live:active::after { transform: translateY(0); }
.cup-live:focus-visible { outline: 2px solid var(--gold-200); outline-offset: 2px; }
/* The slot the next cube drops into. The glow follows the cup's outline, so it
   cannot be an inset ring - clip-path would cut the slanted sides off one. */
.cup-here::before {
  filter: var(--cup-ground) drop-shadow(0 0 6px rgba(240, 220, 164, 0.95));
  animation: cup-blink 1.4s ease-in-out infinite;
}
@keyframes cup-blink {
  50% { filter: var(--cup-ground) drop-shadow(0 0 13px rgba(240, 220, 164, 1)); }
}
/* Already submitted: still standing in the row, but plainly out of the game.
   rules: the filter goes on .cup, not on .cup::before, so the rim and the
   number grey out with the body. Greying the body alone left a lit rim on a
   dead cup, which read as still playable. */
.cup-spent { filter: grayscale(0.95) brightness(0.62); opacity: 0.5; }
.cup-spent span { opacity: 0.45; }
.cup-empty span { color: var(--mute); opacity: 0.5; }

.cups { display: flex; gap: 4px; justify-content: center; }

/* A row of cups in play stands on a shelf rather than on the concrete: a lit
   top edge, a dark recess behind, and a front lip the feet sit on.
   message: the 8px side padding and the board's 10px are what sizeTable() in
   ui.js subtracts as BOARD_INSET. Change one and change the other. */
.side .cups, .dist .cups {
  position: relative;
  padding: 8px 8px 11px;
  background:
    linear-gradient(180deg,
      rgba(20, 13, 28, 0.5) 0%,
      rgba(196, 174, 221, 0.14) 38%,
      rgba(196, 174, 221, 0.1) 66%,
      rgba(20, 13, 28, 0.45) 100%);
  box-shadow: inset 0 1px 0 rgba(240, 220, 164, 0.14), inset 0 -1px 0 rgba(0, 0, 0, 0.5);
}
.side .cups::after, .dist .cups::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  background: linear-gradient(180deg, rgba(240, 220, 164, 0.22) 0%, rgba(120, 100, 60, 0.18) 34%, rgba(0, 0, 0, 0.6) 100%);
}

/* ---------------- distribution ---------------- */


/* The budget, which is the whole tension of the phase. */
.budget { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--line); background: var(--slab-deep); }
.budget-label { font-family: var(--display); font-size: 0.48rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-200); white-space: nowrap; }
.budget-bar { position: relative; flex: 1; height: 10px; background: rgba(240, 220, 164, 0.12); overflow: hidden; }
.budget-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-600), var(--gold-200)); transition: width 0.25s var(--ease), background 0.25s ease; }
.budget-over .budget-bar i { background: linear-gradient(90deg, var(--lose-deep), var(--lose)); }
.budget-num { font-size: 1rem; font-weight: 700; color: var(--stock); font-variant-numeric: tabular-nums; white-space: nowrap; }
.budget-over .budget-num { color: var(--lose); }

/* The 20 cubes, two of each number. Spent ones stay in place and go dim, so
   the player can see what they have left without counting. */
.tray { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.cube {
  min-height: 34px;
  padding: 2px 0;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(60, 55, 51, 0.95), rgba(32, 29, 26, 0.96));
  box-shadow: inset 0 1px 0 rgba(240, 220, 164, 0.14), 0 4px 10px -8px rgba(0, 0, 0, 0.9);
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  color: var(--stock);
  cursor: pointer;
  transition: transform 0.12s var(--ease-snap), filter 0.18s ease, border-color 0.2s ease;
}
.cube:hover:not(:disabled) { filter: brightness(1.25); border-color: var(--gold-400); }
.cube:active:not(:disabled) { transform: translateY(1px); }
.cube:focus-visible { outline: 2px solid var(--gold-200); outline-offset: -3px; }
.cube:disabled { opacity: 0.26; cursor: not-allowed; }
/* A cube that would break a rule if played into the live cup. */
.cube-illegal { opacity: 0.4; border-color: rgba(229, 89, 74, 0.4); }

.tray-rows { display: flex; flex-direction: column; gap: 3px; }
.tray-label { font-family: var(--display); font-size: 0.46rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.14); }

/* ---------------- the table ---------------- */

.table { display: flex; flex-direction: column; gap: 10px; }

/* The opponent row: shades and spent marks, never a number. */
.side { display: flex; flex-direction: column; gap: 5px; }
.side-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.side-name { font-family: var(--display); font-size: 0.54rem; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.14); }
.side-you .side-name { color: var(--gold-200); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); }
.side-note { font-size: 0.74rem; color: var(--ink-soft); }
.side-you .side-note { color: var(--mute); }

/* The foe row is smaller: it is read, not touched. */
.side-foe .cup { --cup-w: 34px; --cup-h: 40px; font-size: 0; }

/* The middle, where the two submitted cups face each other. */
/* The board carries both rows and the arena, so the table is one object laid on
   the wall instead of three slabs hanging in the air.
   rules: .side-name, .side-note and .tray-label are inked for the LIT concrete
   wall. Anything moved onto the board needs its colour restated here, or it
   turns into near-black on near-black. */
.board, .dist {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  background:
    radial-gradient(120% 74% at 50% 46%, var(--board-glow) 0%, rgba(173, 122, 224, 0) 72%),
    linear-gradient(180deg, var(--board-lit) 0%, var(--board-mid) 54%, var(--board-deep) 100%);
  box-shadow: var(--shadow-slab), inset 0 1px 0 rgba(240, 220, 164, 0.14);
}

.board .side-name, .dist .tray-label { color: var(--cream); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75); }
.board .side-you .side-name { color: var(--gold-200); }
.board .side-note { color: var(--mute); }

/* Inside the board the arena is a well sunk into the surface, not another slab
   sitting on top of it. */
.arena { position: relative; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; min-height: 88px; padding: 8px 10px; border: 1px solid var(--line-soft); background: linear-gradient(180deg, rgba(23, 14, 33, 0.52) 0%, rgba(173, 122, 224, 0.07) 100%); box-shadow: inset 0 3px 9px -2px rgba(0, 0, 0, 0.62); }
.arena-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.arena-slot .cup { --cup-w: 50px; --cup-h: 62px; }
.arena-who { font-family: var(--display); font-size: 0.46rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold-200); }
.arena-vs { font-family: var(--display); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.1em; color: var(--mute); }
/* An empty slot is a dashed outline, so the table always has two places. */
.arena-empty { width: 50px; height: 62px; background: linear-gradient(180deg, rgba(240, 220, 164, 0.075) 0%, rgba(240, 220, 164, 0.015) 100%); clip-path: polygon(0 0, 100% 0, 85% 90%, 77% 100%, 23% 100%, 15% 90%); }
.arena-out { outline: 2px solid var(--win); outline-offset: 3px; }
.arena-down { opacity: 0.72; }

.arena-verdict { position: absolute; top: -11px; left: 50%; transform: translateX(-50%); padding: 2px 12px; border: 1px solid var(--line); background: var(--slab-deep); font-family: var(--display); font-size: 0.5rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; white-space: nowrap; }
.verdict-won { color: var(--win); border-color: var(--win-deep); }
.verdict-lost { color: var(--lose); border-color: var(--lose-deep); }
.verdict-tied { color: var(--draw); }

/* The reveal: a cup turns over to show what was in it. */
.cup-turn { animation: cup-turn 0.42s var(--ease) both; }
@keyframes cup-turn {
  0% { transform: rotateX(0deg); }
  45% { transform: rotateX(92deg); }
  100% { transform: rotateX(0deg); }
}

/* The one-line complaint, over the stage. */
.toast {
  position: absolute;
  top: 4px;
  left: 50%;
  z-index: 15;
  max-width: 92%;
  padding: 8px 14px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold-400);
  background: linear-gradient(180deg, #302c29, #1a1816);
  box-shadow: 0 14px 28px -12px rgba(0, 0, 0, 0.95);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--stock);
  text-align: center;
  animation: toast-in 0.2s var(--ease) both;
}
.toast-good { border-left-color: var(--win); }
.toast-bad { border-left-color: var(--lose); }
@keyframes toast-in { from { transform: translate(-50%, -10px); opacity: 0; } }

.stage-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* ---------------- the round log ---------------- */

/* Off by default from the menu. There is deliberately NO inference panel:
   working out what is left is the game, so the app must not do it. */
.log { width: 100%; border-collapse: collapse; font-size: 0.78rem; border: 1px solid var(--line); background: var(--slab-deep); }
.log th { padding: 4px 6px; font-family: var(--display); font-size: 0.44rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold-200); text-align: center; }
.log td { padding: 3px 6px; text-align: center; font-variant-numeric: tabular-nums; }
.log tr + tr td { border-top: 1px solid var(--line-soft); }
.log-lead { color: var(--gold-400); font-weight: 700; }
.log-won { color: var(--win); font-weight: 700; }
.log-lost { color: var(--lose); font-weight: 700; }
.log-tied { color: var(--draw); font-weight: 700; }
/* A shade chip, so a logged round shows the colour rather than naming it. */
.chip { display: inline-block; width: 15px; height: 15px; vertical-align: -3px; border: 1px solid rgba(240, 220, 164, 0.4); }
.chip[data-tier="0"] { background: var(--cup-0); }
.chip[data-tier="1"] { background: var(--cup-1); }
.chip[data-tier="2"] { background: var(--cup-2); }
.chip[data-tier="3"] { background: var(--cup-3); }

.log-strip { max-height: 136px; overflow-y: auto; overscroll-behavior: contain; }

/* ---------------- drawer (the result) ---------------- */

.drawer {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  width: min(100%, 460px);
  max-height: 94dvh;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(240, 220, 164, 0.4);
  border-width: 0 1px;
  background: linear-gradient(180deg, #302c29, #1a1816);
  box-shadow: 0 -20px 44px -14px rgba(0, 0, 0, 0.9);
  transition: transform 0.34s var(--ease), box-shadow 0.34s ease;
  animation: drawer-in 0.36s var(--ease) backwards;
}
.drawer[data-open="false"] { transform: translateY(calc(100% - 46px - env(safe-area-inset-bottom))); box-shadow: 0 -6px 16px -8px rgba(0, 0, 0, 0.8); }
@keyframes drawer-in { from { transform: translateY(100%); } }

.drawer-handle {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  height: 46px;
  padding: 7px 14px 0;
  border: 0;
  border-top: 2px solid var(--gold-400);
  background: linear-gradient(180deg, #332e2a, #191715);
  box-shadow: inset 0 -16px 22px -18px var(--gold-400);
  text-align: left;
  cursor: pointer;
}
.drawer-handle::before { content: ""; position: absolute; top: 5px; left: 50%; width: 38px; height: 3px; margin-left: -19px; border-radius: 2px; background: rgba(240, 220, 164, 0.5); }
.drawer-handle:focus-visible { outline: 2px solid var(--gold-200); outline-offset: -3px; }
.drawer-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--display); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-200); }
.drawer-title.is-won { color: var(--win); }
.drawer-title.is-lost { color: var(--lose); }
.drawer-chev { flex: none; display: inline-flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 0.52rem; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--cream); }
.drawer-chev::after { content: ""; width: 7px; height: 7px; border: solid var(--gold-400); border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); transition: transform 0.3s var(--ease); }
.drawer[data-open="false"] .drawer-chev::after { transform: translateY(2px) rotate(-135deg); }
.drawer-body { flex: 1; display: flex; flex-direction: column; gap: 9px; padding: 11px 12px 12px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

/* ---------------- the verdict ---------------- */

.verdict { padding: 9px 10px 8px; text-align: center; border: 1px solid; background: var(--slab-deep); animation: slam 0.45s var(--ease) both; }
.verdict-word { font-family: var(--display); font-size: clamp(1.05rem, 7.2vw, 1.9rem); font-weight: 700; letter-spacing: 0.1em; line-height: 1.05; }
.verdict-sub { margin-top: 5px; font-size: 0.86rem; color: var(--cream); }
.verdict.is-won { border-color: var(--win); }
.verdict.is-won .verdict-word { color: var(--win); text-shadow: 0 0 24px rgba(92, 196, 135, 0.35); }
.verdict.is-lost { border-color: var(--lose); }
.verdict.is-lost .verdict-word { color: var(--lose); text-shadow: 0 0 24px rgba(229, 89, 74, 0.35); }
.verdict.is-drawn { border-color: var(--draw); }
.verdict.is-drawn .verdict-word { color: var(--draw); }
@keyframes slam { from { transform: scale(1.25); opacity: 0; } }

/* Both rows, laid open once the match is over. */
.reveal-rows { display: flex; flex-direction: column; gap: 7px; }
.reveal-row { display: flex; flex-direction: column; gap: 3px; }
.reveal-row .cups .cup { --cup-w: 36px; --cup-h: 44px; }
/* Same shelf as the table, and the same correction: .side-name is inked for the
   lit concrete wall, and the result drawer is not that. */
.reveal-row .side-name { color: var(--cream); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75); }
.reveal-row .cups {
  position: relative;
  padding: 7px 8px 10px;
  background: linear-gradient(180deg,
    rgba(20, 13, 28, 0.5) 0%,
    rgba(196, 174, 221, 0.14) 38%,
    rgba(196, 174, 221, 0.1) 66%,
    rgba(20, 13, 28, 0.45) 100%);
  box-shadow: inset 0 1px 0 rgba(240, 220, 164, 0.14), inset 0 -1px 0 rgba(0, 0, 0, 0.5);
}
.reveal-row .cups::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: linear-gradient(180deg, rgba(240, 220, 164, 0.22) 0%, rgba(120, 100, 60, 0.18) 34%, rgba(0, 0, 0, 0.6) 100%);
}

/* ---------------- standings ---------------- */

.standings { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); background: var(--slab-deep); }
.standings li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; min-height: 40px; padding: 5px 10px; }
.standings li + li { border-top: 1px solid var(--line-soft); }
.standings .who { font-size: 0.94rem; font-weight: 600; color: var(--stock); }
.standings .is-you .who { color: var(--gold-200); }
.standings .is-out .who { color: var(--mute); text-decoration: line-through; }
.standings .tag { font-family: var(--display); font-size: 0.46rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--purple-300); }
/* Two pips per player: the two wins that take you to the final. */
.pips { display: inline-flex; gap: 4px; }
.pips i { width: 11px; height: 11px; border: 1px solid var(--gold-600); transform: rotate(45deg); }
.pips i.on { background: var(--gold-400); box-shadow: 0 0 9px -1px var(--gold-400); }

/* A match you did not play, reported rather than shown. */
.offscreen { padding: 10px; border: 1px solid var(--line); border-left: 4px solid var(--purple-600); background: var(--slab-deep); }
.offscreen-head { font-family: var(--display); font-size: 0.5rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--purple-300); }
.offscreen-line { margin-top: 5px; font-size: 0.96rem; color: var(--stock); }
.offscreen-score { font-family: var(--display); font-weight: 700; color: var(--gold-200); }

/* ---------------- sheets ---------------- */

.modal-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: end center; padding: 16px; background: rgba(12, 10, 9, 0.72); }
.sheet-overlay { place-items: center; padding: 10px; }
.modal { width: min(100%, 420px); padding: 18px; border: 1px solid rgba(240, 220, 164, 0.4); background: linear-gradient(180deg, #302c29, #1a1816); box-shadow: 0 36px 70px -20px #000; outline: none; }
.modal-title { margin: 0 0 8px; font-family: var(--display); font-size: 0.86rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-200); }
.modal-body { margin: 0 0 16px; font-size: 0.92rem; color: var(--cream); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.sheet { display: flex; flex-direction: column; width: min(100%, 440px); max-height: min(92svh, 760px); padding: 0; animation: sheet-in 0.28s var(--ease) both; }
@keyframes sheet-in { from { transform: translateY(14px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); }
.sheet-head .modal-title { margin: 0; }
.sheet-body { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; overflow-y: auto; overscroll-behavior: contain; }

.section-title { margin-bottom: 5px; font-family: var(--display); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.26em; text-transform: uppercase; color: var(--gold-200); }

.stats-hero { padding: 12px; border: 1px solid var(--line); border-left: 5px solid var(--gold-400); background: var(--slab-deep); }
.stats-hero-rate { font-size: 2.5rem; font-weight: 700; line-height: 1; color: var(--stock); font-variant-numeric: tabular-nums; }
.stats-hero-sub { margin-top: 4px; font-size: 0.92rem; }
.stats-empty { padding: 28px 8px; text-align: center; color: var(--cream); }

.facts { display: grid; grid-template-columns: 1fr 1fr; margin: 0; border: 1px solid var(--line); background: var(--slab-deep); }
.fact { padding: 7px 10px; min-width: 0; border-bottom: 1px solid var(--line-soft); }
.fact:nth-child(odd) { border-right: 1px solid var(--line-soft); }
.fact dt { font-family: var(--display); font-size: 0.46rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-200); }
.fact dd { margin: 2px 0 0; font-size: 0.94rem; font-weight: 600; color: var(--stock); }

/* ---------------- rules ---------------- */

.rules-body { display: flex; flex-direction: column; gap: 10px; font-size: 0.88rem; line-height: 1.45; color: var(--cream); }
.rules-body p { margin: 0; }
.rules-body b, .rules-body strong { color: var(--gold-200); }
.rules-body em { color: var(--stock); font-style: italic; }
.rules-head { margin: 4px 0 -2px; font-family: var(--display); font-size: 0.54rem; font-weight: 700; letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold-200); }
.rules-note { font-size: 0.78rem; color: var(--mute); }

/* The gradation, spelled out. This is the one table a new player must read. */
.rules-legend { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); background: var(--slab-deep); }
.rules-legend li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; }
.rules-legend li + li { border-top: 1px solid var(--line-soft); }
.swatch { flex: none; width: 24px; height: 24px; border: 1px solid rgba(240, 220, 164, 0.45); }
.swatch[data-tier="0"] { background: var(--cup-0); }
.swatch[data-tier="1"] { background: var(--cup-1); }
.swatch[data-tier="2"] { background: var(--cup-2); }
.swatch[data-tier="3"] { background: var(--cup-3); }

.rules-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; border: 1px solid var(--line); background: var(--slab-deep); }
.rules-table th, .rules-table td { padding: 6px 9px; text-align: left; vertical-align: top; }
.rules-table tr + tr th, .rules-table tr + tr td { border-top: 1px solid var(--line-soft); }
.rules-table td:first-child { width: 24px; font-family: var(--display); font-weight: 700; color: var(--gold-400); }

/* A sample row, to show what non-decreasing looks like. */
.rules-cups { display: flex; gap: 3px; justify-content: center; padding: 9px 6px; border: 1px solid var(--line); background: var(--slab-deep); }
.rules-cups .cup { --cup-w: 34px; --cup-h: 42px; }

/* ---------------- footer ---------------- */

.site-footer { display: flex; align-items: center; justify-content: flex-end; height: 46px; font-size: 0.78rem; color: var(--ink-soft); }
.site-footer a { color: inherit; text-underline-offset: 3px; }
.site-footer a:hover { color: var(--purple-900); }

/* ---------------- reduced motion ---------------- */

@media (prefers-reduced-motion: reduce) {
  .grain { animation: none; }
  .cup-turn, .verdict, .drawer, .sheet, .menu-panel, .toast, .cup-here, .clock-low { animation: none; }
  .drawer { transition: none; }
  .cup-live:hover::before, .cup-live:hover::after { transform: none; }
}
