/* The `hidden` attribute defaults to `display: none` only via the UA
   stylesheet, which loses to any author rule with higher specificity
   (e.g. `#menu-screen { display: flex }`). Force it to win so JS-toggled
   `el.hidden = true` actually hides the element everywhere. */
[hidden] { display: none !important; }

:root {
  --bg: #1e3a2f;
  --bg-2: #112019;
  --felt: #2d5a44;
  --felt-2: #244a38;
  --gold: #f5c542;
  --white: #fafafa;
  --red: #e07060;
  --green: #6fcf80;
  --blue: #5b9bd5;
  --shadow: rgba(0,0,0,0.4);
  /* Table-theme tokens (#38). Defaults reproduce today's look; cosmetic
     slugs override these via applyTableTokens() to retheme felt / border /
     edge / ambient / decals without touching DOM. */
  --zk-table-felt: linear-gradient(180deg, var(--felt) 0%, var(--felt-2) 100%);
  --zk-table-border: 4px solid #050a08;
  --zk-table-edge: rgba(255,255,255,0.05);
  --zk-table-ambient: transparent;
  --zk-table-decals: none;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  color: var(--white);
  background: var(--bg);
}
#app { height: 100%; width: 100%; display: flex; flex-direction: column; }

header {
  background: var(--bg-2);
  padding: 8px 16px;
  display: flex; align-items: center; gap: 14px;
  border-bottom: 2px solid #050a08;
  flex-shrink: 0;
}
header h1 { font-size: 20px; color: var(--gold); letter-spacing: 0.05em; }
header .turn-info { flex: 1; display: flex; gap: 18px; font-size: 15px; align-items: baseline; flex-wrap: wrap; }
header .turn-info .who { color: var(--gold); font-weight: 700; font-size: 17px; }
header .turn-info strong { color: var(--gold); font-size: 22px; margin-left: 4px; }
header .hint { font-size: 13px; opacity: 0.85; }
header .hint.ready { color: var(--green); font-weight: 700; opacity: 1; }
header button {
  padding: 11px 20px; font-size: 16px; font-weight: 700;
  border: none; border-radius: 8px; cursor: pointer;
  background: var(--gold); color: #1a1a1a;
  touch-action: manipulation;
}
header button:disabled { background: #444; color: #888; cursor: not-allowed; }
header button.ghost { background: transparent; color: #aaa; border: 1px solid #444; padding: 8px 12px; font-size: 13px; }

/* Player strip */
#player-strip {
  background: #0a1813;
  display: flex; gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: 2px solid #050a08;
}
.player-tile {
  flex: 1 1 0; min-width: 90px;
  background: #1a2a22;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
  border: 2px solid transparent;
  position: relative;
  transition: background 0.2s, transform 0.2s, border-color 0.2s;
}
.player-tile.current {
  background: linear-gradient(180deg, #4a3a10, #3a2a08);
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(245, 197, 66, 0.3);
}
.player-tile.current::after {
  content: "▼"; position: absolute; top: -16px; left: 50%;
  transform: translateX(-50%); color: var(--gold);
  font-size: 14px; animation: bob 1.2s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(4px); }
}
.player-tile .pname {
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: #ddd;
}
.player-tile.current .pname { color: var(--gold); }
.player-tile .pscore { font-size: 18px; font-weight: 700; color: var(--white); }
.player-tile .order-badge {
  position: absolute; top: 4px; right: 6px;
  font-size: 10px; color: #888; font-weight: 700;
}

main { flex: 1; display: flex; overflow: hidden; min-height: 0; }

#cup-area {
  flex: 1.5;
  display: flex; flex-direction: column;
  background: var(--zk-table-felt, linear-gradient(180deg, var(--felt) 0%, var(--felt-2) 100%));
  padding: 18px;
  position: relative;
  border-right: var(--zk-table-border, 4px solid #050a08);
}
#cup-area::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 30% 25%, var(--zk-table-edge, rgba(255,255,255,0.05)), transparent 65%);
  pointer-events: none;
}

#dice-zone {
  flex: 1;
  display: flex; flex-wrap: wrap; gap: 16px;
  align-content: flex-start; justify-content: flex-start;
  padding: 12px 4px;
  min-height: 110px;
  position: relative;
}

#cup-button {
  align-self: center;
  width: 240px; min-height: 110px;
  background: linear-gradient(180deg, #6b4422 0%, #3a2410 100%);
  border: 4px solid #1a0e05;
  border-radius: 16px;
  color: var(--white);
  font-size: 18px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px var(--shadow), inset 0 2px 4px rgba(255,255,255,0.12);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 12px 16px;
  touch-action: manipulation;
  transition: transform 0.08s;
}
#cup-button:active:not(:disabled) { transform: scale(0.97); }
#cup-button:disabled { opacity: 0.35; cursor: not-allowed; }
#cup-button .icon { font-size: 38px; line-height: 1; }

#message {
  text-align: center;
  margin-top: 10px;
  min-height: 26px;
  font-size: 15px;
  font-weight: 600;
  padding: 0 12px;
}
#message.invalid { color: var(--red); }
#message.valid { color: var(--green); }
#message.bust { color: var(--red); font-size: 19px; }
#message.success { color: var(--gold); font-size: 19px; }

#cache-area {
  flex: 1;
  background: var(--bg-2);
  display: flex; flex-direction: column;
  transition: background 0.15s, box-shadow 0.15s;
  position: relative;
}
#cache-area.drop-active {
  background: #1d3a2c;
  box-shadow: inset 6px 0 0 var(--gold);
}
#cup-area.drop-active::after {
  content: ""; position: absolute; inset: 0;
  box-shadow: inset 6px 0 0 var(--gold);
  background: rgba(245, 197, 66, 0.06);
  pointer-events: none;
}
#cache-area h2 {
  padding: 12px 18px; font-size: 15px; font-weight: 700;
  background: #050a08; color: var(--gold);
  text-transform: uppercase; letter-spacing: 0.15em;
  display: flex; justify-content: space-between; align-items: center;
}
#score-display {
  background: rgba(0,0,0,0.28);
  padding: 22px 18px 16px;
  text-align: center;
  border-bottom: 1px solid #2a3e36;
  flex-shrink: 0;
}
.score-big {
  font-size: 76px;
  font-weight: 800;
  color: var(--gold);
  line-height: 1;
  letter-spacing: 0.01em;
  text-shadow: 0 0 24px rgba(245, 197, 66, 0.25);
  transition: transform 0.18s, color 0.18s;
}
.score-big.bump { transform: scale(1.08); }
.score-hint {
  margin-top: 8px;
  font-size: 14px;
  color: #aaa;
  letter-spacing: 0.04em;
}
.score-hint.ready { color: var(--green); font-weight: 700; }
#score-display.bankable {
  cursor: pointer;
  background: linear-gradient(180deg, rgba(111, 207, 128, 0.18) 0%, rgba(0,0,0,0.28) 100%);
  box-shadow: inset 0 0 0 2px rgba(111, 207, 128, 0.55);
}
#score-display.bankable .score-big {
  color: var(--green);
  text-shadow: 0 0 28px rgba(111, 207, 128, 0.55);
  animation: bankable-pulse 1.4s ease-in-out infinite;
}
#score-display.bankable .score-hint {
  color: var(--green); font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.18em;
}
@keyframes bankable-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}
#score-display.bankable:active .score-big { transform: scale(0.96); }

#cache-zone {
  flex: 1; padding: 14px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
}
.cache-group {
  background: #1f3329;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  border-left: 4px solid var(--green);
  animation: slideIn 0.2s ease-out;
  transition: transform 0.12s, box-shadow 0.12s;
}
.cache-group.committed { border-left-color: var(--green); }
.cache-group.pending {
  border-left-color: var(--gold);
  background: linear-gradient(90deg, #3a2f10 0%, #1f3329 70%);
  cursor: grab;
  touch-action: none;
  position: relative;
}
.cache-group.pending .pending-hint {
  position: absolute; top: 4px; right: 10px;
  font-size: 9px; color: var(--gold); opacity: 0.6;
  letter-spacing: 0.1em; font-weight: 700;
}
.cache-group.dragging {
  transition: none; z-index: 1000;
  box-shadow: 0 18px 30px rgba(0,0,0,0.6);
  cursor: grabbing;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.cache-group .mini-dice { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.mini-die {
  width: 26px; height: 26px;
  background: white; color: #222;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.group-score { font-size: 17px; font-weight: 700; color: var(--gold); white-space: nowrap; }

/* Dice */
.die {
  width: 84px; height: 84px;
  background: white;
  border-radius: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 11px;
  box-shadow: 0 4px 10px var(--shadow);
  position: relative;
  cursor: pointer;
  touch-action: none;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
}
.die.scoreable {
  background: #ffe082;
  transform: translateY(-10px);
  box-shadow: 0 14px 18px var(--shadow);
}
.die.scoreable:not(.dragging) { cursor: grab; }
.die:not(.scoreable) { opacity: 0.55; cursor: default; }
.die.dragging { transition: none; z-index: 1000; box-shadow: 0 18px 30px rgba(0,0,0,0.55); cursor: grabbing; }

.die .pip {
  width: 13px; height: 13px;
  background: #1a1a1a;
  border-radius: 50%;
  align-self: center; justify-self: center;
}
.die.scoreable .pip { background: #5a3e00; }

/* Issue #40 — launch dice skins. Skins repaint background / pip color via
   class hooks on the die element. Pip placement (grid-area) is unchanged so
   every skin shares the canonical pip layout from cosmetics.js. */
.die.die-skin-wood {
  background: linear-gradient(160deg, #c08a4d 0%, #8a5a2c 55%, #6b3f1a 100%);
  border: 1px solid #4a2a10;
  box-shadow:
    inset 0 0 0 1px rgba(255,235,200,0.18),
    inset 0 6px 14px rgba(255,235,200,0.10),
    inset 0 -6px 14px rgba(0,0,0,0.35),
    0 4px 10px var(--shadow);
  /* Faint grain via two repeating gradients for warp + weft. */
  background-image:
    repeating-linear-gradient(98deg,
      rgba(60,30,10,0.18) 0 1px,
      transparent          1px 6px),
    repeating-linear-gradient(2deg,
      rgba(120,70,30,0.12) 0 1px,
      transparent          1px 9px),
    linear-gradient(160deg, #c08a4d 0%, #8a5a2c 55%, #6b3f1a 100%);
}
.die.die-skin-wood .pip { background: #1a0e04; box-shadow: inset 0 1px 0 rgba(255,255,255,0.18); }
.die.die-skin-wood.scoreable { background-image: none; background: linear-gradient(160deg, #e0a868 0%, #b07840 100%); }
.die.die-skin-wood.scoreable .pip { background: #2a1404; }

.die.die-skin-marble {
  background: #f8f6f0;
  border: 1px solid #cfc7b6;
  background-image:
    radial-gradient(ellipse 70% 40% at 25% 30%, rgba(180,170,160,0.38), transparent 70%),
    radial-gradient(ellipse 55% 55% at 78% 70%, rgba(150,140,130,0.30), transparent 70%),
    radial-gradient(ellipse 30% 80% at 60% 20%, rgba(120,110,100,0.20), transparent 70%),
    linear-gradient(140deg, #ffffff 0%, #ece6d8 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.6),
    inset 0 -6px 14px rgba(120,110,100,0.18),
    0 4px 10px var(--shadow);
}
.die.die-skin-marble .pip { background: #2a2826; }
.die.die-skin-marble.scoreable {
  background-image:
    radial-gradient(ellipse 70% 40% at 25% 30%, rgba(200,160,80,0.45), transparent 70%),
    linear-gradient(140deg, #fff4d0 0%, #f0d486 100%);
}
.die.die-skin-marble.scoreable .pip { background: #3a2a08; }

.die.die-skin-holographic {
  background: linear-gradient(135deg, #ffaad5, #aaffe5, #d5aaff, #ffeaaa, #ffaad5);
  background-size: 400% 400%;
  animation: zk-skin-holo-shift 6s ease-in-out infinite;
  border: 1px solid rgba(255,255,255,0.55);
  box-shadow:
    inset 0 0 14px rgba(255,255,255,0.55),
    0 0 16px rgba(180,140,255,0.45),
    0 4px 10px var(--shadow);
}
.die.die-skin-holographic .pip {
  background: #1a1a2a;
  box-shadow: 0 0 4px rgba(255,255,255,0.65), inset 0 1px 0 rgba(255,255,255,0.4);
}
.die.die-skin-holographic.scoreable { animation-duration: 2.4s; transform: translateY(-10px); }
@keyframes zk-skin-holo-shift {
  0%   { background-position:   0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position:   0% 50%; }
}

.pip-tl { grid-area: 1 / 1; }
.pip-tc { grid-area: 1 / 2; }
.pip-tr { grid-area: 1 / 3; }
.pip-ml { grid-area: 2 / 1; }
.pip-mc { grid-area: 2 / 2; }
.pip-mr { grid-area: 2 / 3; }
.pip-bl { grid-area: 3 / 1; }
.pip-bc { grid-area: 3 / 2; }
.pip-br { grid-area: 3 / 3; }

/* ----- Overlays ----- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(5, 12, 9, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 500;
  padding: 20px;
  overflow: hidden;
  animation: fadeIn 0.25s ease-out;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay h2 {
  font-size: 30px; color: var(--gold);
  margin-bottom: 18px; text-align: center;
  letter-spacing: 0.04em;
}
.overlay .panel {
  background: rgba(20, 32, 26, 0.95);
  border: 2px solid #2a3e36;
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 560px; width: 100%;
  max-height: 90vh; overflow-y: auto;
}

/* Settings overlay */
.setup-section-label {
  font-size: 12px; color: #999;
  text-transform: uppercase; letter-spacing: 0.18em;
  font-weight: 700; margin: 4px 0 8px;
}
.player-list {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 8px;
}
.player-row {
  display: flex; align-items: center; gap: 8px;
}
.player-row .ord {
  width: 26px; color: #888; font-weight: 700; font-size: 14px; text-align: right;
}
.player-row input {
  flex: 1;
  background: #1a2a22;
  border: 2px solid #2a3e36;
  border-radius: 8px;
  padding: 11px 13px;
  color: var(--white);
  font-size: 16px;
  font-family: inherit;
  -webkit-user-select: text; user-select: text;
}
.player-row input:focus { outline: none; border-color: var(--gold); }
.player-row .del-player {
  width: 36px; height: 36px;
  background: #2a1a1a; color: #d77;
  border: 1px solid #4a2a2a; border-radius: 8px;
  font-size: 18px; font-weight: 700;
  cursor: pointer; touch-action: manipulation;
  display: inline-flex; align-items: center; justify-content: center;
}
.player-row .del-player:active { transform: scale(0.92); }
.add-player {
  width: 100%; margin-bottom: 14px;
  background: transparent !important;
  border: 1px dashed #4a5e56 !important;
  color: #aaa !important;
}
.goal-row {
  display: flex; align-items: center; gap: 10px;
  background: #1a2a22; border-radius: 8px; padding: 10px 14px;
  margin: 12px 0 6px;
}
.goal-row label { flex: 1; font-size: 15px; color: #ccc; font-weight: 600; }
.goal-row input {
  width: 110px;
  background: #0a1813;
  border: 2px solid #2a3e36;
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--gold);
  font-size: 18px; font-weight: 700;
  font-family: inherit;
  text-align: right;
  -webkit-user-select: text; user-select: text;
}
.goal-row input:focus { outline: none; border-color: var(--gold); }
.goal-range-hint { font-size: 11px; color: #888; margin: -2px 0 14px; text-align: right; }
.mode-picker {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-bottom: 14px;
}
.mode-btn {
  background: #1a2a22;
  border: 2px solid #2a3e36;
  border-radius: 10px;
  padding: 12px 14px;
  color: #ddd;
  font-family: inherit;
  text-align: left;
  cursor: pointer; touch-action: manipulation;
  transition: all 0.15s;
}
.mode-btn .mname { font-size: 16px; font-weight: 700; }
.mode-btn .mdesc { font-size: 12px; color: #888; margin-top: 2px; }
.mode-btn.selected {
  background: linear-gradient(180deg, #4a3a10, #2a1f08);
  border-color: var(--gold);
}
.mode-btn.selected .mname { color: var(--gold); }
.mode-btn.selected .mdesc { color: #d8b870; }
.mode-btn:active { transform: scale(0.97); }

.single-input-row {
  display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px;
}
.single-input-row label {
  font-size: 12px; color: #999; text-transform: uppercase;
  letter-spacing: 0.12em; font-weight: 700;
}
.single-input-row input {
  background: #1a2a22;
  border: 2px solid #2a3e36;
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--white);
  font-size: 17px;
  font-family: inherit;
  -webkit-user-select: text; user-select: text;
}
.single-input-row input:focus { outline: none; border-color: var(--gold); }
.single-input-row input.code-input {
  font-size: 28px; font-weight: 800; letter-spacing: 0.4em;
  text-align: center; color: var(--gold); padding: 14px;
}

/* Lobby waiting room */
.lobby-code-display {
  text-align: center;
  background: #0a1813;
  padding: 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  border: 2px dashed #2a3e36;
}
.lobby-code-label {
  font-size: 12px; color: #999; text-transform: uppercase; letter-spacing: 0.18em;
  margin-bottom: 6px;
}
.lobby-code-value {
  font-size: 48px; font-weight: 900; color: var(--gold);
  letter-spacing: 0.3em;
  text-shadow: 0 0 24px rgba(245, 197, 66, 0.4);
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
}
.lobby-player-list {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px;
}
.lobby-player {
  background: #1a2a22;
  padding: 10px 14px;
  border-radius: 8px;
  display: flex; align-items: center; gap: 8px;
  font-size: 15px;
}
.lobby-player.host { border-left: 3px solid var(--gold); }
.lobby-player.you { background: linear-gradient(90deg, #2a3a26, #1a2a22); }
.lobby-player .nm { font-weight: 600; flex: 1; }
.lobby-player .badge {
  font-size: 10px; color: var(--gold); font-weight: 800;
  letter-spacing: 0.1em; text-transform: uppercase;
}
.lobby-status {
  text-align: center; color: #aaa;
  font-size: 14px; margin: 12px 0 16px;
  font-style: italic;
}
/* Per-die badge: who is playing right now */
.turn-badge {
  background: rgba(245, 197, 66, 0.15);
  color: var(--gold);
  border-left: 3px solid var(--gold);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: center;
}
.turn-badge.observer { background: rgba(91, 155, 213, 0.15); color: var(--blue); border-left-color: var(--blue); }

/* Auto-play toggle on the next-turn banner */
.nt-auto {
  margin: 0 auto 18px;
  max-width: 320px;
  background: rgba(91, 155, 213, 0.1);
  border: 1px solid rgba(91, 155, 213, 0.4);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; touch-action: manipulation;
  transition: all 0.15s;
}
.nt-auto.on {
  background: rgba(91, 155, 213, 0.25);
  border-color: var(--blue);
}
.nt-auto .switch {
  width: 36px; height: 20px;
  background: #2a3e36;
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.nt-auto .switch::after {
  content: ""; position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #ddd; border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.nt-auto.on .switch { background: var(--blue); }
.nt-auto.on .switch::after { transform: translateX(16px); background: white; }
.nt-auto .label {
  flex: 1; text-align: left;
  font-weight: 700; color: #ddd; font-size: 14px;
}
.nt-auto.on .label { color: var(--blue); }
.nt-auto .hint {
  font-size: 11px; color: #888;
  text-align: left; line-height: 1.3;
}
.nt-auto .label-wrap { flex: 1; }
.player-tile .auto-mark {
  position: absolute; bottom: 2px; right: 4px;
  font-size: 9px; font-weight: 800;
  color: var(--blue);
  letter-spacing: 0.06em;
  background: rgba(91,155,213,0.12);
  border-radius: 3px; padding: 1px 4px;
}
.player-tile .pturns {
  font-size: 11px; color: #888;
  margin-top: 1px; font-weight: 600;
}
.player-tile.current .pturns { color: #c8a850; }
.player-tile.done-turns { opacity: 0.55; }
.new-best-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  background: var(--gold); color: #1a1a1a;
  border-radius: 4px;
  font-size: 11px; font-weight: 800;
  letter-spacing: 0.08em;
  animation: badge-pop 0.5s ease-out;
}
@keyframes badge-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  70%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
.overlay .actions {
  display: flex; gap: 10px; justify-content: center;
  margin-top: 8px; flex-wrap: wrap;
}
.btn-primary {
  padding: 14px 28px; font-size: 17px; font-weight: 700;
  border: none; border-radius: 10px; cursor: pointer;
  background: var(--gold); color: #222;
  touch-action: manipulation;
}
.btn-primary:disabled { background: #444; color: #888; cursor: not-allowed; }
.btn-secondary {
  padding: 14px 22px; font-size: 16px; font-weight: 600;
  border: 1px solid #555; border-radius: 10px; cursor: pointer;
  background: transparent; color: #ddd;
  touch-action: manipulation;
}

/* Intro overlay */
.order-list { display: flex; flex-direction: column; gap: 6px; margin: 16px 0; }
.order-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: #1a2a22;
  border-radius: 8px;
  font-size: 16px;
}
.order-row.first {
  background: linear-gradient(90deg, #4a3a10, #2a3e36);
  border-left: 4px solid var(--gold);
}
.order-row .ordn {
  font-size: 12px; color: #999; font-weight: 700;
  min-width: 36px;
}
.order-row.first .ordn { color: var(--gold); }
.order-row .nm { font-weight: 600; color: white; }

/* Turn-end overlay */
#turn-end-panel { text-align: center; }
.te-name {
  font-size: 32px; font-weight: 700;
  color: var(--gold); margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.te-tag {
  font-size: 17px; color: var(--green); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  margin-bottom: 22px;
}
.te-tag.bust { color: var(--red); }
.te-math {
  font-size: 22px; font-weight: 700;
  margin-bottom: 6px;
  color: #ddd;
}
.te-math .plus, .te-math .eq { color: #888; margin: 0 8px; }
.te-math .turn-pts { color: var(--green); }
.te-math .turn-pts.bust { color: var(--red); }
.te-new {
  font-size: 56px; font-weight: 800;
  color: var(--gold); margin: 4px 0 18px;
  line-height: 1;
}
.te-rank {
  font-size: 14px; color: #999; text-transform: uppercase; letter-spacing: 0.12em;
  margin-top: 6px; margin-bottom: 10px;
}
.te-board {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 18px;
}
.te-board-row {
  display: flex; gap: 12px; align-items: center;
  padding: 8px 12px;
  background: #1a2a22;
  border-radius: 6px;
  font-size: 15px;
}
.te-board-row.you {
  background: linear-gradient(90deg, #2a3e36, #1f3329);
  border-left: 3px solid var(--gold);
}
.te-board-row .place {
  width: 28px; color: #888; font-weight: 700;
}
.te-board-row.p1 .place { color: var(--gold); }
.te-board-row .nm { flex: 1; font-weight: 600; }
.te-board-row .sc { color: var(--gold); font-weight: 700; font-size: 16px; }
.te-tap {
  font-size: 14px; color: #888; font-style: italic;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

/* Win overlay */
#win-overlay {
  background: radial-gradient(ellipse at center, rgba(40, 60, 30, 0.9), rgba(5, 12, 9, 0.95));
}
.win-trophy {
  font-size: 90px;
  animation: trophy-bounce 1.6s ease-in-out infinite;
  filter: drop-shadow(0 0 28px rgba(245, 197, 66, 0.7));
}
@keyframes trophy-bounce {
  0%, 100% { transform: scale(1) rotate(-4deg); }
  50%      { transform: scale(1.08) rotate(4deg); }
}
.win-title {
  font-size: 56px; font-weight: 800;
  color: var(--gold); text-align: center;
  margin: 12px 0;
  text-shadow: 0 0 24px rgba(245, 197, 66, 0.6);
  animation: win-glow 2s ease-in-out infinite;
}
@keyframes win-glow {
  0%, 100% { text-shadow: 0 0 16px rgba(245, 197, 66, 0.5); transform: scale(1); }
  50%      { text-shadow: 0 0 36px rgba(245, 197, 66, 0.9); transform: scale(1.03); }
}
.win-subtitle { font-size: 22px; color: #ddd; margin-bottom: 18px; }
.win-board { width: 100%; max-width: 420px; }

/* Bust overlay — transparent backdrop so the dice that caused the bust stay readable */
#bust-overlay {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  /* .overlay is flex-direction: column, so align-items = horizontal axis */
  align-items: flex-start;
  justify-content: flex-end;
  padding: 0 0 3vh 3vw;
  pointer-events: auto;
}
#bust-overlay .panel {
  max-width: 380px;
  border: 3px solid var(--red);
  background: rgba(20, 12, 12, 0.96);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(224,112,96,0.3);
}
.bust-title {
  font-size: 64px; font-weight: 900;
  color: var(--red); text-align: center;
  letter-spacing: 0.06em;
  text-shadow: 0 0 26px rgba(224, 112, 96, 0.7);
  animation: bust-shake 0.9s ease-out;
}
@keyframes bust-shake {
  0%   { transform: translateX(0)    scale(0.6); opacity: 0; }
  35%  { transform: translateX(-12px) scale(1.1); opacity: 1; }
  55%  { transform: translateX(12px)  scale(1.05); }
  75%  { transform: translateX(-6px)  scale(1); }
  100% { transform: translateX(0)     scale(1); }
}
.bust-name {
  font-size: 22px; color: var(--gold);
  text-align: center; margin: 6px 0 18px;
}
.bust-msg {
  text-align: center; color: #ddd; font-size: 17px;
  margin-bottom: 20px; line-height: 1.5;
}

/* Next-turn banner */
#next-turn-overlay { background: radial-gradient(ellipse at center, rgba(20, 50, 36, 0.9), rgba(5, 12, 9, 0.96)); }
.nt-label {
  font-size: 13px; color: #999; text-align: center;
  text-transform: uppercase; letter-spacing: 0.32em;
  margin-bottom: 14px;
}
.nt-name {
  font-size: 72px; font-weight: 800;
  color: var(--gold); text-align: center;
  margin-bottom: 14px; line-height: 1.1;
  text-shadow: 0 0 32px rgba(245, 197, 66, 0.45);
  animation: nt-pop 0.45s cubic-bezier(.22,1.4,.36,1);
}
@keyframes nt-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}
.nt-score {
  font-size: 18px; color: #ccc; text-align: center;
  margin-bottom: 32px;
}
.nt-order {
  font-size: 13px; color: #888; text-align: center;
  margin-bottom: 22px; opacity: 0.75;
}

.confetti {
  position: absolute;
  width: 10px; height: 14px;
  top: -30px;
  z-index: 1;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0)     rotate(0);    opacity: 1; }
  100% { transform: translateY(115vh) rotate(900deg); opacity: 0.85; }
}

/* Portrait orientation */
@media (max-aspect-ratio: 1/1) {
  main { flex-direction: column; }
  #cup-area { border-right: none; border-bottom: 4px solid #050a08; flex: 1.4; }
  #cache-area.drop-active { box-shadow: inset 0 6px 0 var(--gold); }
}
/* Smaller dice on cramped screens */
@media (max-width: 720px) {
  .die { width: 70px; height: 70px; padding: 9px; }
  .die .pip { width: 11px; height: 11px; }
  #dice-zone { gap: 12px; }
  .te-new { font-size: 44px; }
  .win-title { font-size: 40px; }
  .win-trophy { font-size: 70px; }
  .bust-title { font-size: 60px; }
  .nt-name { font-size: 52px; }
  .score-big { font-size: 56px; }
  #score-display { padding: 16px 14px 12px; }
  header h1 { font-size: 17px; }
  .player-tile { min-width: 76px; padding: 6px 8px; }
}

/* ---- Main menu screen (#12) -------------------------------------------- */
#menu-screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  background-color: var(--bg-2);
  color: var(--white);
  overflow-y: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#menu-screen.zk-wallpaper { background-repeat: no-repeat; }

.menu-account {
  position: absolute; top: 12px; right: 14px;
  display: flex; align-items: center; gap: 12px;
  z-index: 2;
}
.menu-account .menu-user {
  font-weight: 700; color: var(--gold); letter-spacing: 0.02em;
  text-shadow: 0 1px 4px var(--shadow);
}
.menu-account .ghost { background: rgba(0,0,0,0.35); color: #ddd; border: 1px solid #555; }
.menu-account .btn-primary { padding: 10px 16px; font-size: 14px; font-weight: 700; }

.menu-stage {
  margin: auto;
  padding: 64px 24px;
  width: 100%;
  max-width: 720px;
  text-align: center;
}
.menu-title {
  font-size: 56px;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 4px 16px rgba(0,0,0,0.55);
}
.menu-tagline {
  margin-top: 4px;
  font-size: 14px;
  color: #cdd;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.8;
}

.menu-grid {
  margin-top: 36px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.menu-btn {
  display: flex; flex-direction: column; align-items: flex-start;
  gap: 4px;
  text-align: left;
  background: linear-gradient(180deg, rgba(45, 90, 68, 0.92), rgba(36, 74, 56, 0.96));
  color: var(--white);
  border: 1px solid rgba(245, 197, 66, 0.2);
  border-radius: 14px;
  padding: 18px 18px;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--shadow);
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
  touch-action: manipulation;
}
.menu-btn:hover { border-color: var(--gold); }
.menu-btn:active { transform: translateY(1px); }
.menu-btn.primary {
  background: linear-gradient(180deg, #4a3a10, #3a2a08);
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 6px 18px rgba(245, 197, 66, 0.28);
}
.menu-btn.gated {
  opacity: 0.7;
}
.menu-btn.gated .menu-lock {
  margin-left: 6px;
  font-size: 14px;
  filter: grayscale(0.4);
}
.menu-btn.back {
  grid-column: 1 / -1;
  align-items: center;
  background: transparent;
  border-color: #555;
  color: #ddd;
  font-weight: 600;
}
.menu-label { font-size: 18px; }
.menu-sub {
  font-weight: 500;
  font-size: 12px;
  color: #cdd;
  opacity: 0.78;
  letter-spacing: 0.02em;
}

@media (max-width: 520px) {
  .menu-stage { padding: 48px 18px; }
  .menu-title { font-size: 40px; }
  .menu-grid { grid-template-columns: 1fr; gap: 10px; }
  .menu-btn { padding: 14px 16px; font-size: 16px; }
  .menu-account { position: static; padding: 12px 14px; justify-content: flex-end; }
}

/* Honor reduced-motion: button transform feedback is fine, but no float
   animations here today; placeholder for future wallpaper animation. */
@media (prefers-reduced-motion: reduce) {
  .menu-btn { transition: none; }
}

/* The placeholder screen (used by stub routes) inherits the wallpaper. */
#placeholder-screen {
  background-color: var(--bg-2);
}

/* ---- Standalone screens (history, leaderboards) ----------------------- */
.zk-screen {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg-2); color: var(--white);
  overflow-y: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.zk-screen .screen-header {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 18px; border-bottom: 1px solid #1d3a2c;
  background: rgba(0,0,0,0.25);
}
.zk-screen .screen-header h2 {
  font-size: 18px; color: var(--gold); margin: 0;
  letter-spacing: 0.04em;
}
.zk-screen .back-link {
  color: #aaa; text-decoration: none; font-size: 14px;
  padding: 6px 10px; border: 1px solid #444; border-radius: 8px;
}
.zk-screen .back-link:hover { color: var(--gold); border-color: var(--gold); }
.zk-screen .screen-body { padding: 18px; max-width: 960px; margin: 0 auto; }

.zk-screen .muted { color: #888; }
.zk-screen .muted a { color: var(--gold); }

.zk-screen .hm-table {
  width: 100%; border-collapse: collapse; margin-top: 12px;
}
.zk-screen .hm-table th, .zk-screen .hm-table td {
  padding: 10px 12px; border-bottom: 1px solid #1d3a2c; text-align: left;
}
.zk-screen .hm-table th { color: #888; font-weight: 600; font-size: 12px;
                           text-transform: uppercase; letter-spacing: 0.06em; }
.zk-screen .hm-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.zk-screen .hm-win  { color: var(--green); font-weight: 700; }
.zk-screen .hm-loss { color: #666; }

.zk-screen .load-more {
  margin-top: 18px; padding: 10px 18px; font-size: 14px;
  background: transparent; color: var(--gold); border: 1px solid var(--gold);
  border-radius: 8px; cursor: pointer;
}
.zk-screen .load-more:hover { background: rgba(245, 197, 66, 0.08); }

.zk-screen .lb-scopes, .zk-screen .lb-tabs {
  display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap;
}
.zk-screen .lb-scope, .zk-screen .lb-tab {
  background: rgba(45, 90, 68, 0.65); color: #ddd;
  border: 1px solid rgba(245, 197, 66, 0.18); border-radius: 8px;
  padding: 8px 14px; font-family: inherit; font-size: 13px; cursor: pointer;
  font-weight: 600;
}
.zk-screen .lb-scope.selected, .zk-screen .lb-tab.selected {
  background: var(--gold); color: #1a1a1a; border-color: var(--gold);
}

/* ---- Account screen --------------------------------------------------- */
.ac-section {
  background: rgba(0,0,0,0.22); border: 1px solid #1d3a2c; border-radius: 12px;
  padding: 18px 20px; margin-top: 16px;
}
.ac-section h3 {
  margin: 0 0 12px 0; font-size: 14px; color: var(--gold);
  letter-spacing: 0.06em; text-transform: uppercase;
}
.ac-section.danger h3 { color: var(--red); }
.ac-grid {
  display: grid; grid-template-columns: 160px 1fr; gap: 10px 14px;
  align-items: center;
}
.ac-grid label { color: #aaa; font-size: 13px; }
.ac-grid input[type="text"] {
  background: #0a1813; border: 1px solid #2a4738; border-radius: 8px;
  padding: 8px 10px; color: var(--white); font: inherit; font-size: 14px;
}
.ac-actions { margin-top: 14px; }
.ac-banner {
  margin-bottom: 14px; padding: 10px 14px; border-radius: 8px;
  font-size: 13px;
}
.ac-banner.ok  { background: rgba(111, 207, 128, 0.12); color: var(--green);
                 border: 1px solid rgba(111, 207, 128, 0.3); }
.ac-banner.err { background: rgba(224, 112, 96, 0.12);  color: var(--red);
                 border: 1px solid rgba(224, 112, 96, 0.3); }
.btn-danger {
  background: rgba(224, 112, 96, 0.16); color: var(--red);
  border: 1px solid var(--red); border-radius: 8px;
  padding: 10px 16px; font: inherit; font-weight: 700;
  cursor: pointer;
}
.btn-danger:hover { background: rgba(224, 112, 96, 0.26); }
@media (max-width: 520px) {
  .ac-grid { grid-template-columns: 1fr; }
}

/* ---- Settings screen toggles ----------------------------------------- */
.toggle-row {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; user-select: none;
}
.toggle-row input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--gold); cursor: pointer;
}
.ac-grid input[type="number"] {
  background: #0a1813; border: 1px solid #2a4738; border-radius: 8px;
  padding: 8px 10px; color: var(--white); font: inherit; font-size: 14px;
  text-align: right;
}
.ac-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- Solo screen bot rows -------------------------------------------- */
.bot-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.bot-row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.18); border: 1px solid #2a4738;
  border-radius: 8px; padding: 8px 12px;
}
.bot-label { color: #aaa; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.bot-diff {
  flex: 1; background: #0a1813; color: var(--white);
  border: 1px solid #2a4738; border-radius: 6px; padding: 6px 8px;
  font: inherit; font-size: 14px;
}
.del-bot {
  background: transparent; border: 1px solid #555; color: #aaa;
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 16px;
}
.del-bot:hover { color: var(--red); border-color: var(--red); }

/* ---- Lobby host controls + bot rows ---------------------------------- */
.lobby-host-controls { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.lobby-host-hint { color: #cdd; font-size: 13px; }
.lobby-add-bot {
  display: flex; gap: 8px; align-items: stretch;
}
.lobby-add-bot .bot-diff {
  flex: 1; background: #0a1813; color: var(--white);
  border: 1px solid #2a4738; border-radius: 6px; padding: 6px 8px;
  font: inherit; font-size: 14px;
}
.lobby-add-bot .btn-secondary {
  padding: 8px 12px; font-size: 13px;
  background: rgba(245, 197, 66, 0.12); color: var(--gold);
  border: 1px solid rgba(245, 197, 66, 0.4); border-radius: 8px; cursor: pointer;
}
.lobby-player .badge.bot {
  background: rgba(91, 155, 213, 0.18); color: var(--blue);
  border: 1px solid rgba(91, 155, 213, 0.45);
  font-size: 10px; letter-spacing: 0.08em; padding: 2px 6px; border-radius: 4px;
  margin-left: 6px;
}
.lobby-remove-bot {
  margin-left: auto;
  background: transparent; border: 1px solid #555; color: #aaa;
  border-radius: 6px; padding: 2px 8px; cursor: pointer; font-size: 14px;
  line-height: 1;
}
.lobby-remove-bot:hover { color: var(--red); border-color: var(--red); }

/* ---- Cosmetics ------------------------------------------------------- */
.zk-avatar.sm { width: 22px; height: 22px; border-radius: 50%; vertical-align: middle; margin-right: 6px; object-fit: cover; }
.zk-avatar.md { width: 32px; height: 32px; border-radius: 50%; vertical-align: middle; object-fit: cover; }
.zk-avatar.placeholder { display: inline-block; background: rgba(255,255,255,0.08); border: 1px dashed #555; }
/* Avatar compositor frame (#38). Inline-block so the inner <img> keeps its
   sizing rules; relative positioning so registered borders can layer an
   absolutely-positioned overlay on top without touching the image element. */
.zk-avatar-frame { position: relative; display: inline-block; line-height: 0; vertical-align: middle; }
.zk-avatar-frame.sm { margin-right: 6px; }
/* Default highlight (#38). The pre-existing `.scoreable` rules above are the
   default highlight — this alias gives cosmetic slugs a stable target to
   override without colliding with `.scoreable`'s scoring semantics. */
.zk-highlight-default { /* alias of .die.scoreable visuals */ }

/* Launch highlight effects (#42). Each rule below is the broadcast visual
   the rolling player wears when one of their dice is currently scoreable.
   Pure CSS — no rAF tick — so observers see exactly the same animation as
   the rolling player without any JS coordination. The class is added/
   removed by `applyHighlight()` (cosmetics.js) on each render pass. */

/* hl_pulse_glow — gentle box-shadow pulse, ~1s loop. */
@keyframes hl-pulse-glow-kf {
  0%   { box-shadow: 0 14px 18px var(--shadow), 0 0 0   0   rgba(245, 197, 66, 0.0); }
  50%  { box-shadow: 0 14px 18px var(--shadow), 0 0 18px 4px rgba(245, 197, 66, 0.55); }
  100% { box-shadow: 0 14px 18px var(--shadow), 0 0 0   0   rgba(245, 197, 66, 0.0); }
}
.die.hl-pulse-glow {
  background: #ffe082;
  transform: translateY(-10px);
  animation: hl-pulse-glow-kf 1s ease-in-out infinite;
  cursor: grab;
}
.die.hl-pulse-glow .pip { background: #5a3e00; }

/* hl_gold_shimmer — diagonal gradient sweep across the face, ~1.6s loop. */
@keyframes hl-gold-shimmer-kf {
  0%   { background-position: -120% 0; }
  100% { background-position:  220% 0; }
}
.die.hl-gold-shimmer {
  transform: translateY(-10px);
  box-shadow: 0 14px 18px var(--shadow);
  background-color: #ffe082;
  background-image: linear-gradient(
    115deg,
    rgba(255, 224, 130, 0) 0%,
    rgba(255, 224, 130, 0) 35%,
    rgba(255, 245, 200, 0.95) 50%,
    rgba(255, 224, 130, 0) 65%,
    rgba(255, 224, 130, 0) 100%
  );
  background-size: 220% 100%;
  background-repeat: no-repeat;
  animation: hl-gold-shimmer-kf 1.6s linear infinite;
  cursor: grab;
}
.die.hl-gold-shimmer .pip { background: #5a3e00; }

/* hl_electric_arc — quick blue/white pulse with a brighter outline edge. */
@keyframes hl-electric-arc-kf {
  0%, 100% {
    box-shadow:
      0 14px 18px var(--shadow),
      0 0 0 1px rgba(140, 200, 255, 0.6),
      0 0 12px 2px rgba(120, 180, 255, 0.4);
    background: #ffe082;
  }
  45% {
    box-shadow:
      0 14px 18px var(--shadow),
      0 0 0 2px rgba(255, 255, 255, 0.95),
      0 0 22px 6px rgba(120, 180, 255, 0.95);
    background: #f5fbff;
  }
  55% {
    box-shadow:
      0 14px 18px var(--shadow),
      0 0 0 1px rgba(140, 200, 255, 0.7),
      0 0 14px 3px rgba(120, 180, 255, 0.5);
    background: #ffe082;
  }
}
.die.hl-electric-arc {
  transform: translateY(-10px);
  animation: hl-electric-arc-kf 0.7s steps(8, end) infinite;
  cursor: grab;
}
.die.hl-electric-arc .pip { background: #173b66; }

/* hl_neon_trace — outline-draw effect via a conic-gradient masked border.
   The gradient angle rotates so the bright wedge appears to chase around
   the die's edge. Pure CSS, no clip-path animation needed. */
@keyframes hl-neon-trace-kf {
  0%   { --hl-angle:   0deg; }
  100% { --hl-angle: 360deg; }
}
@property --hl-angle {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}
.die.hl-neon-trace {
  background: #ffe082;
  transform: translateY(-10px);
  box-shadow: 0 14px 18px var(--shadow);
  position: relative;
  cursor: grab;
}
.die.hl-neon-trace .pip { background: #5a3e00; }
.die.hl-neon-trace::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  padding: 3px;
  background: conic-gradient(
    from var(--hl-angle, 0deg),
    rgba(255, 90, 200, 0.0)   0deg,
    rgba(255, 90, 200, 0.0)  300deg,
    rgba(255, 90, 200, 1.0)  340deg,
    rgba(120, 240, 255, 1.0) 360deg,
    rgba(255, 90, 200, 0.0)  360deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
  animation: hl-neon-trace-kf 1.4s linear infinite;
}

/* ---- Avatar borders (#45) ----
   Overlay layer composited on top of the avatar img inside `.zk-avatar-frame`.
   Animations are pure CSS (no JS rAF). */
.zk-border {
  position: absolute; inset: 0;
  border-radius: 50%;
  pointer-events: none;
}
/* Gold: simple metallic ring with a soft inner glow. */
.zk-border-gold {
  box-shadow:
    0 0 0 2px var(--gold) inset,
    0 0 4px rgba(245, 197, 66, 0.55);
}
/* Rainbow: conic-gradient stroke faked via two stacked rings — the outer
   gradient ring rotates, the inner solid ring punches the avatar shape
   back out so the gradient reads as a thin border, not a fill. */
.zk-border-rainbow {
  background: conic-gradient(from 0deg,
    #ff0058, #ff8a00, #f5c542, #6fcf80, #5b9bd5, #a070ff, #ff0058);
  -webkit-mask:
    radial-gradient(circle, transparent 60%, #000 62%);
          mask:
    radial-gradient(circle, transparent 60%, #000 62%);
  animation: zk-border-spin 3.6s linear infinite;
}
@keyframes zk-border-spin {
  to { transform: rotate(360deg); }
}
/* Prestige: gold ring + four compass notches + a slow pulse. The notches
   are inner spans so they can be positioned independently inside the ring. */
.zk-border-prestige {
  box-shadow:
    0 0 0 2px #f5c542 inset,
    0 0 0 3px rgba(245, 197, 66, 0.25),
    0 0 6px rgba(245, 197, 66, 0.45);
  animation: zk-border-pulse 2.4s ease-in-out infinite;
}
@keyframes zk-border-pulse {
  0%, 100% { filter: brightness(1)   drop-shadow(0 0 0 rgba(245, 197, 66, 0)); }
  50%      { filter: brightness(1.2) drop-shadow(0 0 3px rgba(245, 197, 66, 0.6)); }
}
.zk-border-notch {
  position: absolute;
  width: 4px; height: 4px;
  background: #f5c542;
  border-radius: 50%;
  box-shadow: 0 0 3px rgba(245, 197, 66, 0.85);
}
.zk-border-notch.n { top: -2px;    left: 50%;   transform: translateX(-50%); }
.zk-border-notch.s { bottom: -2px; left: 50%;   transform: translateX(-50%); }
.zk-border-notch.e { right: -2px;  top: 50%;    transform: translateY(-50%); }
.zk-border-notch.w { left: -2px;   top: 50%;    transform: translateY(-50%); }
.menu-avatar  { width: 28px; height: 28px; border-radius: 50%; margin-right: 8px; vertical-align: middle; object-fit: cover; }
.ac-avatar-cell { display: inline-flex; align-items: center; gap: 10px; }
.ac-avatar-link { color: var(--gold); text-decoration: none; font-size: 13px; }
.ac-avatar-link:hover { text-decoration: underline; }
.cos-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin-top: 12px;
}
.cos-card {
  background: rgba(0,0,0,0.22); border: 1px solid #1d3a2c; border-radius: 12px;
  padding: 14px; text-align: center;
}
.cos-card.on    { border-color: var(--gold); }
.cos-card.locked { opacity: 0.85; }
.cos-thumb { display: flex; justify-content: center; align-items: center; height: 80px; }
.cos-thumb img { max-width: 80px; max-height: 80px; }
.cos-name { margin: 8px 0 10px 0; font-weight: 600; font-size: 13px; }
.cos-btn {
  background: rgba(245, 197, 66, 0.12); color: var(--gold);
  border: 1px solid rgba(245, 197, 66, 0.4); border-radius: 8px;
  padding: 6px 12px; font-family: inherit; font-size: 12px; cursor: pointer;
  font-weight: 600;
}
.cos-btn.equipped { background: var(--gold); color: #1a1a1a; cursor: default; }
.cos-btn.buy      { color: #ddd; border-color: #555; background: transparent; }

/* ---- Achievements ---------------------------------------------------- */
.ac-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px; margin-top: 12px;
}
.ac-card {
  background: rgba(0,0,0,0.22); border: 1px solid #1d3a2c; border-radius: 12px;
  padding: 14px; text-align: center;
}
.ac-card.on     { border-color: var(--gold); }
.ac-card.locked { opacity: 0.6; filter: grayscale(0.6); }
.ac-thumb { display: flex; justify-content: center; align-items: center; height: 80px; }
.ac-thumb img { max-width: 80px; max-height: 80px; }
.ac-name { margin: 8px 0 4px 0; font-weight: 600; font-size: 14px; }
.ac-desc { font-size: 12px; color: #bbb; min-height: 32px; }
.ac-reward { color: var(--gold); font-size: 12px; margin-top: 6px; }
.ac-state  { margin-top: 8px; font-size: 11px; }
.ac-locked-label   { color: #888; }
.ac-unlocked-label { color: #6abf69; }
.ac-progress {
  height: 6px; background: #1d3a2c; border-radius: 3px; margin: 8px 0; position: relative;
}
.ac-progress-bar { height: 100%; background: var(--gold); border-radius: 3px; }
.ac-progress-label { font-size: 10px; color: #aaa; margin-top: 2px; }

.ac-toast-host {
  position: fixed; right: 16px; bottom: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.ac-toast {
  background: rgba(20,20,20,0.95); color: var(--gold);
  border: 1px solid var(--gold); border-radius: 10px;
  padding: 10px 14px; font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  transition: opacity 0.4s ease, transform 0.4s ease; pointer-events: auto;
}
.ac-toast-out { opacity: 0; transform: translateY(8px); }

/* ===== Launch roll animations (#41) =====================================
 * Each .die.<anim-class> drives a one-shot keyframe animation while the
 * dice-roll promise is in flight. Durations MUST stay below
 * AUTO_STEP_DELAY (700ms in screens/game.js) — autoplay schedules the
 * next step on that interval. Animations target `transform` only so they
 * compose with the .scoreable lift (which uses translateY) by ending at
 * the natural identity transform: scoreable-state is reapplied by the
 * post-animation render(). */

.die.anim-classic-tumble {
  animation: zk-roll-classic-tumble 400ms ease-out 1;
}
@keyframes zk-roll-classic-tumble {
  0%   { transform: rotate(0deg)   scale(1); }
  35%  { transform: rotate(-22deg) scale(1.05); }
  65%  { transform: rotate(18deg)  scale(1.05); }
  100% { transform: rotate(0deg)   scale(1); }
}

.die.anim-spin-flick {
  animation: zk-roll-spin-flick 350ms cubic-bezier(0.4, 0.0, 0.2, 1) 1;
}
@keyframes zk-roll-spin-flick {
  0%   { transform: rotateY(0deg);   }
  100% { transform: rotateY(360deg); }
}

.die.anim-slow-mo {
  animation: zk-roll-slow-mo 650ms cubic-bezier(0.22, 0.61, 0.36, 1) 1;
}
@keyframes zk-roll-slow-mo {
  0%   { transform: rotate(0deg)    scale(1); }
  20%  { transform: rotate(-90deg)  scale(1.08); }
  50%  { transform: rotate(180deg)  scale(1.10); }
  80%  { transform: rotate(330deg)  scale(1.04); }
  100% { transform: rotate(360deg)  scale(1); }
}

.die.anim-confetti-pop {
  animation: zk-roll-confetti-pop 500ms ease-out 1;
}
@keyframes zk-roll-confetti-pop {
  0%   { transform: scale(1)    rotate(0deg); }
  30%  { transform: scale(1.18) rotate(-8deg); }
  60%  { transform: scale(0.96) rotate(6deg); }
  100% { transform: scale(1)    rotate(0deg); }
}

/* Confetti particles spawned by anim_confetti_pop. The particle's
 * --zk-conf-dx / --zk-conf-dy custom props are set per-particle so each
 * one drifts in a different direction. Pointer-events disabled so they
 * never steal clicks from the dice underneath. */
.zk-roll-particle {
  position: absolute;
  left: 50%; top: 50%;
  width: 8px; height: 8px;
  margin-left: -4px; margin-top: -4px;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0;
  transform: translate(0, 0) scale(0.6);
  animation: zk-roll-particle-fly 500ms ease-out 1;
}
@keyframes zk-roll-particle-fly {
  0%   { opacity: 0;
         transform: translate(0, 0) scale(0.6) rotate(0deg); }
  20%  { opacity: 1; }
  100% { opacity: 0;
         transform: translate(var(--zk-conf-dx, 0), var(--zk-conf-dy, 0))
                    scale(1) rotate(180deg); }
}

/* ---- Replay screen (#51) --------------------------------------------- */
#replay-screen { padding-bottom: 80px; /* leave room for sticky controls */ }
#replay-screen .replay-meta {
  margin-left: auto; display: flex; gap: 8px; align-items: center;
  color: #aaa; font-size: 13px; flex-wrap: wrap;
}
#replay-screen .rp-badge.ranked {
  background: var(--gold); color: #1a1a1a; padding: 2px 8px;
  border-radius: 6px; font-size: 11px; font-weight: 700;
}
#replay-screen .replay-stage {
  display: flex; flex-direction: column; gap: 14px;
}
#replay-screen .replay-player-strip {
  display: flex; gap: 10px; flex-wrap: wrap;
}
#replay-screen .replay-player-strip .player-tile {
  background: rgba(0,0,0,0.35); border: 1px solid #1d3a2c;
  border-radius: 10px; padding: 8px 12px; min-width: 130px;
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
}
#replay-screen .replay-player-strip .player-tile.current {
  border-color: var(--gold); box-shadow: 0 0 0 1px rgba(245,197,66,0.25);
}
#replay-screen .replay-player-strip .player-tile.winner {
  background: rgba(245, 197, 66, 0.12);
}
#replay-screen .replay-player-strip .order-badge {
  font-size: 11px; color: #888; letter-spacing: 0.06em;
}
#replay-screen .replay-player-strip .pname { font-weight: 600; }
#replay-screen .replay-player-strip .pscore {
  font-size: 18px; font-variant-numeric: tabular-nums; color: var(--gold);
}
#replay-screen .replay-player-strip .auto-mark {
  font-size: 10px; color: #9bd3a8; letter-spacing: 0.08em;
}
#replay-screen .replay-dice-zone {
  display: flex; gap: 12px; flex-wrap: wrap; min-height: 60px;
  background: var(--zk-table-felt, rgba(45, 90, 68, 0.35));
  border: 1px solid var(--zk-table-border, #1d3a2c);
  border-radius: 12px; padding: 14px;
}
#replay-screen .replay-cache-zone {
  display: flex; flex-direction: column; gap: 6px;
}
#replay-screen .replay-cache-zone .cache-group {
  display: flex; align-items: center; gap: 12px;
  background: rgba(0,0,0,0.3); border: 1px solid #1d3a2c;
  border-radius: 8px; padding: 8px 12px;
}
#replay-screen .replay-cache-zone .cache-group.committed { opacity: 0.85; }
#replay-screen .replay-cache-zone .mini-dice { display: flex; gap: 4px; }
#replay-screen .replay-cache-zone .mini-die {
  width: 22px; height: 22px; background: #fff; color: #1a1a1a;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; font-weight: 700; font-size: 13px;
}
#replay-screen .replay-cache-zone .group-score {
  margin-left: auto; color: var(--gold); font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#replay-screen .replay-status {
  color: #ccc; font-size: 14px;
}
#replay-screen .replay-error {
  background: rgba(180, 60, 60, 0.15); border: 1px solid #6a2a2a;
  color: #f5c5c5; padding: 14px 18px; border-radius: 8px;
}

.replay-controls {
  display: flex; gap: 12px; padding: 8px 12px;
  background: #0a1813; border-top: 2px solid #050a08;
  position: sticky; bottom: 0; z-index: 60;
  align-items: center; flex-wrap: wrap;
}
.replay-controls button {
  background: transparent; color: var(--gold);
  border: 1px solid #2d5a44; border-radius: 6px;
  padding: 6px 12px; font-size: 14px; cursor: pointer;
  font-family: inherit;
}
.replay-controls button:hover { border-color: var(--gold); }
.replay-controls .rp-speed {
  display: flex; gap: 8px; color: #ccc; font-size: 13px;
}
.replay-controls .rp-speed label {
  display: inline-flex; gap: 3px; align-items: center;
}
.replay-controls .replay-scrub {
  flex: 1; min-width: 200px;
}
.replay-controls select {
  background: #0a1813; color: #ddd; border: 1px solid #2d5a44;
  border-radius: 6px; padding: 6px 8px; font-family: inherit;
}

.replay-icon-btn {
  display: inline-block; text-decoration: none;
  color: var(--gold); border: 1px solid #2d5a44;
  border-radius: 50%; width: 26px; height: 26px;
  text-align: center; line-height: 24px; font-size: 14px;
}
.replay-icon-btn:hover { border-color: var(--gold); background: rgba(245,197,66,0.08); }

.hm-replay-btn {
  display: inline-block; text-decoration: none;
  padding: 4px 10px; font-size: 12px;
  color: var(--gold); border: 1px solid #2d5a44; border-radius: 6px;
}
.hm-replay-btn:hover { border-color: var(--gold); background: rgba(245,197,66,0.08); }

