/* Tandem Pixel Party. Flat, square, Tandem colours: black, gold, red. */

:root {
  --bg: #000000;
  --panel: #0A0A0A;
  --raise: #141414;
  --line: #262626;
  --line-hi: #3D3D3D;
  --ink: #F8FAFD;
  --muted: #8A9099;
  --gold: #F5B800;
  --red: #E5161B;
  --green: #1F8A4C;
  --px: "Press Start 2P", ui-monospace, monospace;
  --mono: "Geist Mono", ui-monospace, monospace;
  --display: "Archivo", system-ui, sans-serif;
  --bar-h: 52px;
  --dock-w: 360px;
  --band: 34px; /* knit band: 17 stitches x 2 px */
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--mono);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 0; }
a { color: var(--gold); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }
.px { font-family: var(--px); font-weight: 400; letter-spacing: 0; }

#snow {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
}

canvas.sprite { image-rendering: pixelated; display: block; flex: none; }

/* --------------------------------------------------------------- layout -- */

.app {
  position: relative;
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: var(--bar-h) minmax(0, 1fr) auto;
  grid-template-areas: "bar" "stage" "dock";
}

.bar {
  grid-area: bar;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: var(--bg);
  border-bottom: 2px solid var(--line);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; min-width: 0; }
.wordmark { font: 800 20px/1 var(--display); font-variation-settings: "wdth" 110; letter-spacing: -.01em; }
.tag {
  font: 8px/1 var(--px);
  background: var(--red); color: var(--ink);
  padding: 5px 6px 4px;
  white-space: nowrap;
}
.countdown { margin-left: auto; display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.countdown .k { font: 8px/1 var(--px); color: var(--muted); }
.countdown .v { font: 11px/1 var(--px); color: var(--gold); font-variant-numeric: tabular-nums; }
.bar-right { display: flex; align-items: center; gap: 8px; }
.online { display: flex; align-items: center; font-size: 12px; color: var(--muted); white-space: nowrap; }
.online i { width: 8px; height: 8px; background: var(--green); margin-right: 6px; }
.online b { color: var(--ink); font-weight: 600; }
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--raise); border: 2px solid var(--line-hi);
  font: 10px/1 var(--px);
  padding: 0;
}
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }

/* Ugly-sweater knit band (pattern drawn in app.js). */
.bar { position: relative; border-bottom: 0; }
.bar::after, .join::before {
  content: "";
  position: absolute; left: 0; right: 0;
  height: var(--band);
  background: var(--knit) repeat-x var(--knit-x, 0px) top / 128px var(--band);
  image-rendering: pixelated;
  pointer-events: none;
}
.bar::after { top: 100%; z-index: 2; }
.app { grid-template-rows: var(--bar-h) minmax(0, 1fr) auto; }
.stage-wrap { margin-top: var(--band); }
.join { position: relative; padding-top: calc(var(--band) + 24px); }
.join::before { top: 0; }
.dock { position: relative; }

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

.stage-wrap { grid-area: stage; position: relative; min-height: 0; overflow: hidden; }
.stage {
  position: absolute; inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
  outline: none;
}
.stage.panning { cursor: grabbing; }
#board {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  image-rendering: pixelated;
}
#marks { position: absolute; left: 0; top: 0; transform-origin: 0 0; image-rendering: pixelated; pointer-events: none; }
.vote-box { position: absolute; left: 0; top: 0; pointer-events: none; border: 2px solid var(--gold); background: rgba(245, 184, 0, .18); box-shadow: 0 0 0 2px #000; }
.vote-box .dims { position: absolute; left: -2px; top: -22px; background: var(--gold); color: #000; font: 8px/1 var(--px); padding: 4px 5px 3px; white-space: nowrap; }
.voting .stage { cursor: cell; }
.vote-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 3; margin: 0;
  background: var(--gold); color: #000; border: 2px solid #000;
  padding: 7px 10px; font-size: 12px; font-weight: 600; text-align: center;
  width: max-content; max-width: calc(100% - 24px);
}
.chip.lockinfo { color: #9FE8FF; }
.day-line { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.day-line b { color: var(--ink); font-weight: 600; }
.vote-btn {
  margin-top: 8px; width: 100%; height: 36px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--raise); color: #9FE8FF; border: 2px solid var(--line-hi);
  font: 8px/1 var(--px);
}
.vote-btn svg { width: 12px; height: 12px; }
.vote-btn:hover { border-color: #9FE8FF; }
.vote-btn[aria-pressed="true"] { background: #9FE8FF; color: #000; border-color: #9FE8FF; }
.vote-bar .vb-actions { display: flex; gap: 6px; margin-top: 10px; }
.vote-bar .btn.small { border-color: #000; }
.vote-bar .btn:not(.gold) { background: #fff; color: #000; }
.frame { position: absolute; left: 0; top: 0; pointer-events: none; border: 2px solid var(--line-hi); }
.reticle {
  position: absolute; left: 0; top: 0;
  pointer-events: none;
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 2px #000;
}
.reticle.pick { border-color: var(--gold); }

.hud { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; pointer-events: none; }
/* people online: in the header on desktop, on the board everywhere else */
.chip.people { display: none; align-items: center; gap: 6px; }
.chip.people svg { width: 10px; height: 10px; color: var(--gold); }
.chip.people b { font-weight: 600; }
@media (max-width: 959px) {
  .chip.people { display: inline-flex; }
  .bar .online { display: none; }
}
.chip {
  background: #000; border: 2px solid var(--line-hi);
  padding: 4px 8px; font-size: 12px; white-space: nowrap;
}
.chip.owner { color: var(--gold); }
.zoom { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; }
.zoom button {
  width: 36px; height: 36px; padding: 0;
  background: #000; border: 2px solid var(--line-hi);
  font: 14px/1 var(--px);
}
.zoom button#zoomFit { font-size: 7px; }
.zoom svg { width: 14px; height: 14px; display: block; margin: auto; }
.zoom button:hover { border-color: var(--gold); color: var(--gold); }

.frozen {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: var(--gold); color: #000;
  padding: 12px 16px; text-align: center;
  border: 2px solid #000; box-shadow: 4px 4px 0 #000;
}
.frozen p { margin: 0; }
.frozen .px { font-size: 11px; margin-bottom: 6px; }
.frozen .btn { margin: 10px 4px 0; background: #000; color: var(--gold); border-color: #000; font: 8px/1 var(--px); }

/* ----------------------------------------------------------------- dock -- */

.dock {
  grid-area: dock;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-top: 2px solid var(--line);
  padding-bottom: var(--safe-b);
  min-height: 0;
}
.card { background: var(--panel); padding: 10px 12px; border-bottom: 2px solid var(--line); }

.you-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.you-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bank-text { font: 9px/1 var(--px); color: var(--gold); }
.bank { display: grid; grid-template-columns: repeat(var(--n, 10), 1fr); gap: 3px; margin-top: 8px; }
.bank span { height: 10px; background: var(--line); }
.bank span.on { background: var(--gold); }
.bank span.charging { background: var(--line); position: relative; overflow: hidden; }
.bank span.charging::after {
  content: ""; position: absolute; inset: 0;
  background: var(--gold); opacity: .45;
  transform-origin: left; transform: scaleX(var(--p, 0));
}
.bank-next { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.palette { display: grid; grid-template-columns: repeat(var(--cols, 8), 1fr); gap: 4px; }
/* the recent row sits apart from the quick colours */
.palette .recent:nth-child(-n + 8) { margin-bottom: 4px; }
.palette .tool {
  aspect-ratio: 1; min-height: 28px; padding: 0;
  display: grid; place-items: center;
  background: var(--raise); color: var(--ink);
  border: 2px solid var(--line-hi);
}
.palette .tool svg { width: 14px; height: 14px; }
.palette .tool:hover, .palette .tool[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); }
.palette .tool.holding { border: 2px solid var(--gold); color: #000; }
.picking .stage { cursor: copy; }
.live-line { margin: 4px 0 10px; color: var(--gold); font-size: 9px; letter-spacing: .04em; }
.live-line b { color: var(--ink); font-weight: 400; }

/* first load */
.loader { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: #05030A; }
.loader::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: var(--band); background: var(--knit) repeat-x var(--knit-x, 0px) top / 128px var(--band); image-rendering: pixelated; }
.loader.done { animation: loader-out .36s steps(4) forwards; }
@keyframes loader-out { to { opacity: 0; visibility: hidden; } }
.loader-card { text-align: center; padding: 24px; }
/* The dark cover is there from the first frame so the page never flashes;
   the band and the card only appear if loading takes more than a moment. */
.loader::before, .loader-card { animation: loader-slow 0s .25s both; }
@keyframes loader-slow { from { visibility: hidden; } to { visibility: visible; } }
.loader-card .sprite { display: block; margin: 0 auto 18px; }
.loader-title { color: var(--gold); font-size: 14px; margin: 0 0 18px; }
.cane { width: min(280px, 70vw); height: 16px; margin: 0 auto; border: 2px solid var(--ink); background: #000; padding: 2px; }
.cane span { display: block; height: 100%; background: var(--cane) repeat-x 0 0 / 32px 16px; image-rendering: pixelated; animation: cane 1s steps(8) infinite; }
@keyframes cane { to { background-position: 32px 0; } }
.loader-line { margin: 14px 0 0; color: var(--muted); font-size: 13px; min-height: 1.4em; }

/* reconnecting / refreshing chip */
.buffering { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 6; margin: 0;
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #000; color: #9FE8FF;
  border: 2px solid #9FE8FF; font: 9px/1 var(--px); }
.buffering svg { width: 12px; height: 12px; animation: flake 1.2s steps(4) infinite; }
@keyframes flake { to { transform: rotate(90deg); } }
@media (prefers-reduced-motion: reduce) { .cane span, .buffering svg { animation: none; } }
.zoom button:disabled { opacity: .35; cursor: default; border-color: var(--line-hi); color: inherit; }
.wish { width: min(460px, calc(100vw - 16px)); text-align: center; padding: calc(var(--band) + 20px) 22px 22px; position: relative; }
.wish::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: var(--band); background: var(--knit) repeat-x var(--knit-x, 0px) top / 128px var(--band); image-rendering: pixelated; }
.wish .sprite { display: block; margin: 0 auto; }
.wish .px { color: var(--gold); font-size: 18px; margin: 10px 0; }
.wish p { margin: 0 0 16px; }
.wish-actions { display: grid; gap: 8px; }
.wish-x { position: absolute; top: calc(var(--band) + 8px); right: 8px; }
.push-card .push-text { margin: 6px 0 10px; font-size: 13px; }
.push-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.push-actions .btn.gold { border-color: #000; }
.push-actions .btn.ghost { background: #fff; color: #000; border-color: #000; }
.painters { width: min(440px, calc(100vw - 16px)); }
.painters-count { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.painters-search { width: 100%; height: 40px; padding: 0 10px; background: #000; border: 2px solid var(--line-hi); font-size: 16px; }
.painters-search:focus { outline: none; border-color: var(--gold); }
.painters-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: min(60dvh, 480px); overflow-y: auto; }
.painters-list li { display: flex; gap: 10px; align-items: baseline; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.painters-list li.me { background: var(--raise); }
.painters-list .rank { width: 44px; flex: none; color: var(--muted); font-size: 12px; }
.painters-list .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.painters-list .px-count { color: var(--gold); font: 9px/1 var(--px); }
.painters-list .muted { color: var(--muted); border: 0; }
.captcha { margin: 0 0 14px; min-height: 65px; }
.picker {
  width: min(560px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow: auto;
  padding: 0 14px 14px;
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--gold); box-shadow: 6px 6px 0 var(--red);
}
.picker::backdrop { background: rgba(0, 0, 0, .75); }
.picker .sheet-head { padding: 12px 0 10px; }
.picker .sheet-x { display: grid; place-items: center; }
.picker-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.picker-panel { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.picker-panel button { aspect-ratio: 1; padding: 0; border: 0; min-width: 0; }
.picker-panel button[aria-checked="true"] { outline: 2px solid var(--ink); outline-offset: 1px; position: relative; z-index: 1; }
.palette button {
  aspect-ratio: 1; min-height: 28px; padding: 0;
  border: 2px solid #000;
  box-shadow: 0 0 0 1px var(--line-hi);
}
.palette button[aria-checked="true"] { box-shadow: 0 0 0 2px var(--gold); border-color: #000; position: relative; }
.palette button[aria-checked="true"]::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 6px; height: 6px; margin: -3px 0 0 -3px;
  background: #000; outline: 1px solid #fff;
}
/* Controller: D-pad with a paint button in the middle. Touch screens only. */
.pad-card { display: none; }
.touch .pad-card { display: grid; place-items: center; }
.dpad {
  --b: 50px;
  display: grid; gap: 4px;
  grid-template-columns: repeat(3, var(--b));
  grid-template-rows: repeat(3, var(--b));
  grid-template-areas: "ul up ur" "left a right" "dl down dr";
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.dp {
  padding: 0; border: 2px solid #000;
  background: var(--raise); color: var(--ink);
  box-shadow: 0 4px 0 var(--line-hi);
  display: grid; place-items: center;
  touch-action: none;
}
.dp svg { width: 18px; height: 18px; }
.dp.up { grid-area: up; } .dp.down { grid-area: down; }
.dp.left { grid-area: left; } .dp.right { grid-area: right; }
/* diagonals sit in the corners, a little smaller and quieter */
.dp.ul { grid-area: ul; } .dp.ur { grid-area: ur; } .dp.dl { grid-area: dl; } .dp.dr { grid-area: dr; }
.dp.diag { color: var(--muted); }
.dp.diag svg { width: 12px; height: 12px; }
.dp.ur svg { transform: scaleX(-1); } .dp.dl svg { transform: scaleY(-1); } .dp.dr svg { transform: scale(-1, -1); }
.dp.pressed { transform: translateY(4px); box-shadow: none; background: var(--line-hi); }
.dp.a {
  grid-area: a;
  background: var(--paint, var(--red));
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 #000, 0 0 0 2px #000;
}
.dp.a.pressed { box-shadow: 0 0 0 2px #000; background: var(--paint, var(--red)); }
.dp.a.empty { background: var(--raise); border-color: var(--line-hi); }
.a-label {
  font: 9px/1 var(--px); color: #000;
  background: var(--ink); padding: 3px 3px 2px;
}
.a-label:empty { display: none; }

.dock-tabs { display: none; }

/* chat */
.chat { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 8px; }
.sheet-head h2 { margin: 0; font-size: 10px; color: var(--gold); }
.sheet-x { display: none; width: 32px; height: 32px; padding: 0; background: var(--raise); border: 2px solid var(--line-hi); font-size: 18px; line-height: 1; }
.pin { margin: 0 12px 6px; padding: 6px 8px; background: var(--raise); border-left: 4px solid var(--red); font-size: 12px; color: var(--muted); }
.pin b { color: var(--ink); margin-right: 4px; }
.msgs { list-style: none; margin: 0; padding: 4px 12px; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.msgs li { padding: 3px 0; overflow-wrap: anywhere; }
.msgs .who { font-weight: 600; margin-right: 8px; }
.msgs .sys { color: var(--muted); font-style: italic; }
.msgs .del, .msgs .ban { float: right; background: none; border: 0; font-size: 11px; padding: 2px 0 0 8px; color: var(--muted); }
.msgs .del { color: var(--red); }
.say { display: flex; border-top: 2px solid var(--line); position: relative; }
.msgs .who { cursor: pointer; }
.msgs .mention { color: var(--gold); font-weight: 600; }
.msgs .mention.me { background: var(--gold); color: #000; padding: 0 3px; }
.msgs li.pinged { background: #1c1600; box-shadow: inset 3px 0 0 var(--gold); padding-left: 8px; margin-left: -8px; }
.mentions { position: absolute; left: 0; bottom: 100%; z-index: 5; margin: 0; padding: 0; list-style: none; min-width: 180px; background: #000; border: 2px solid var(--gold); }
.mentions li { padding: 8px 10px; font-weight: 600; cursor: pointer; }
.mentions li[aria-selected="true"] { background: #1c1600; box-shadow: inset 3px 0 0 var(--gold); }
#chatBadge.ping { background: var(--gold); color: #000; }
.say input {
  flex: 1; min-width: 0;
  background: #000; border: 0; padding: 12px;
  font-size: 16px; /* stops iOS zooming on focus */
}
.say input:focus { outline: none; background: #050505; }
.say button { background: var(--gold); color: #000; border: 0; padding: 0 14px; font: 10px/1 var(--px); }

/* promo */
.promo { padding: 0 0 12px; }
.promo-body { display: flex; gap: 12px; align-items: center; padding: 0 12px; }
.promo-body p { margin: 0; color: var(--muted); font-size: 13px; }
.promo-actions { display: flex; gap: 8px; padding: 10px 12px 0; }
.promo-actions .btn { flex: 1; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 14px;
  background: var(--raise); color: var(--ink);
  border: 2px solid var(--line-hi);
  font: 600 13px/1 var(--mono);
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn.gold { background: var(--gold); color: #000; border-color: var(--gold); }
.btn.gold:hover { background: #FFC81F; border-color: #FFC81F; }
.btn svg { width: 14px; height: 14px; }
.btn .count { padding-left: 8px; margin-left: 2px; border-left: 2px solid rgba(0,0,0,.35); font-variant-numeric: tabular-nums; }
.btn.small { height: 32px; padding: 0 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.big { height: 48px; width: 100%; font: 12px/1 var(--px); }

/* ---------------------------------------------------------- join dialog -- */

.join {
  width: min(400px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 24px 22px 22px;
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--gold);
  box-shadow: 6px 6px 0 var(--red);
}
.join::backdrop { background: rgba(0, 0, 0, .8); }
.join form { display: flex; flex-direction: column; }
.join .sprite { margin: 0 auto 14px; }
.join .eyebrow { margin: 0; font-size: 8px; color: var(--muted); text-align: center; }
.join h1 { margin: 8px 0 12px; font-size: 22px; line-height: 1.2; color: var(--gold); text-align: center; }
.join .lede { margin: 0 0 18px; color: var(--muted); text-align: center; }
.join label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.join input:not([type]) , .join input[name="name"] {
  height: 48px; padding: 0 12px;
  background: #000; border: 2px solid var(--line-hi);
  font-size: 18px; font-weight: 600;
}
.join input[name="name"]:focus { outline: none; border-color: var(--gold); }
.join .hint { margin: 6px 0 14px; font-size: 12px; color: var(--muted); }
.join .err { margin: 8px 0 0; color: #FF5A5E; font-size: 13px; }
.join .fs-opt { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; margin: 0 0 14px; cursor: pointer; }
.join .fs-opt input { appearance: none; width: 18px; height: 18px; margin: 0; border: 2px solid var(--line-hi); background: #000; display: grid; place-items: center; }
.join .fs-opt input:checked { background: var(--gold); border-color: var(--gold); }
.join .fs-opt input:checked::after { content: ""; width: 6px; height: 6px; background: #000; }

.join .watch { margin-top: 10px; align-self: center; background: none; border: 0; padding: 8px; color: var(--muted); font-size: 13px; text-decoration: underline; }
.join .watch:hover { color: var(--ink); }

/* ------------------------------------------- buy me a chai / coffee -- */
/* Same dialog as the Tandem site (GitHub Sponsors, Buy me a coffee, then UPI),
   framed like the rest of the party. */
.is-phone .say-coffee, :root:not(.is-phone) .say-chai { display: none !important; }
.chai-btn { width: auto; padding: 0 10px; gap: 7px; display: flex; align-items: center; color: var(--ink); text-decoration: none; font: 600 12px/1 var(--mono); }
.chai-btn svg { width: 16px; height: 16px; flex: none; }
.chai-btn svg.bmc-cup { width: auto; height: 17px; }
.chai-wide { display: flex; margin: 8px 12px 0; }
.chai-wide svg.bmc-cup { width: auto; height: 17px; }
.chai {
  position: relative;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); overflow-y: auto;
  padding: calc(var(--band) + 24px) 24px 24px;
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--gold); box-shadow: 6px 6px 0 var(--red);
}
.chai::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: var(--band); background: var(--knit) repeat-x var(--knit-x, 0px) top / 128px var(--band); image-rendering: pixelated; }
.chai::backdrop { background: rgba(0, 0, 0, .8); }
.chai h2 { margin: 0; font: 14px/1.3 var(--px); color: var(--gold); }
.chai p { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.chai-x { position: absolute; top: calc(var(--band) + 8px); right: 10px; width: 36px; height: 36px; display: grid; place-items: center; padding: 0; background: var(--raise); border: 2px solid var(--line-hi); color: var(--ink); }
.chai-x svg { width: 14px; height: 14px; }
.chai-x:hover { border-color: var(--gold); }
.chai-ways { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 20px; }
/* GitHub's Sponsor button and Buy me a coffee's button keep their own looks. */
.chai .gh-sponsor { display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 16px; border: 1px solid rgb(31 35 40 / .15); border-radius: 6px; background: #f6f8fa; color: #24292f; font: 500 15px -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif; text-decoration: none; }
.chai .gh-sponsor:hover { background: #eef1f4; }
.chai .gh-sponsor svg { width: 16px; height: 16px; color: #bf3989; }
.chai .bmc { display: block; line-height: 0; }
.chai .bmc img { width: auto; height: 42px; }
.chai > .btn { margin-top: 20px; width: 100%; }
.chai .btn[data-upi][aria-expanded="true"] { display: none; }
.chai-upi img { display: block; width: min(100%, 220px); height: auto; margin: 16px auto 0; background: #fff; }
.chai-upi .btn { margin-top: 16px; width: 100%; }
.chai-id { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; }
.chai-id code { font: 600 15px var(--mono); }
.chai-id .copy { background: var(--gold); color: #000; border: 0; padding: 8px 14px; font: 9px/1 var(--px); }

/* ----------------------------------------------------------------- tour -- */

.tour { position: fixed; inset: 0; z-index: 40; }
.tour-hole {
  position: absolute;
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .72);
  transition: left .25s, top .25s, width .25s, height .25s;
  pointer-events: none;
}
.tour-pop {
  position: absolute;
  width: min(300px, calc(100vw - 24px));
  background: var(--ink); color: #000;
  padding: 14px 14px 12px;
  border: 2px solid #000;
  box-shadow: 4px 4px 0 var(--red);
  transition: left .25s, top .25s;
}
.tour-step { margin: 0 0 8px; font-size: 8px; color: var(--red); }
.tour-pop h3 { margin: 0 0 8px; font-size: 11px; line-height: 1.4; }
.tour-pop p:not(.tour-step) { margin: 0; font-size: 13px; }
.tour-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.tour-actions .link { background: none; border: 0; padding: 6px 0; color: #444; text-decoration: underline; font-size: 13px; }
.tour-actions .btn.gold { height: 34px; border-color: #000; font: 9px/1 var(--px); }

/* --------------------------------------------------------------- toasts -- */

.toasts {
  position: fixed; z-index: 30;
  left: 50%; transform: translateX(-50%);
  bottom: calc(16px + var(--safe-b));
  width: min(420px, calc(100vw - 24px));
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--ink); color: #000;
  border: 2px solid #000; box-shadow: 4px 4px 0 var(--gold);
  padding: 10px 12px;
  font-size: 13px;
  animation: toast-in .18s steps(3) both;
}
.toast.err { box-shadow: 4px 4px 0 var(--red); }
.toast.out { animation: toast-out .15s steps(3) both; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(12px); opacity: 0; } }
.promo-toast { display: flex; gap: 12px; align-items: flex-start; position: relative; padding-right: 36px; }
.promo-toast .sprite { margin-top: 2px; }
.toast-title { margin: 0 0 6px; font-size: 9px; color: var(--red); line-height: 1.4; }
.toast-text { margin: 0; }
.toast-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.toast-actions .btn:not(.gold) { background: #fff; color: #000; border-color: #000; }
.toast-actions .btn.gold { border-color: #000; }
.toast-actions .btn .count { border-left-color: rgba(0,0,0,.35); }
.toast-x { position: absolute; right: 6px; top: 6px; width: 26px; height: 26px; padding: 0; background: none; border: 0; font-size: 20px; line-height: 1; color: #000; }

.demo-ribbon {
  position: absolute; left: 10px; bottom: 10px; z-index: 5; margin: 0;
  background: var(--red); color: var(--ink);
  font: 7px/1 var(--px); padding: 5px 6px 4px;
  pointer-events: none;
}

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 19; }

/* sparkles when you place a pixel */
.spark { position: absolute; width: 4px; height: 4px; pointer-events: none; animation: spark .5s steps(5) forwards; }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)); opacity: 0; } }

/* ============================================================ breakpoints */

/* Phone, portrait (default above): compact bar, dock under the canvas,
   chat and Tandem as bottom sheets. */
@media (max-width: 959px) {
  :root { --bar-h: 48px; }
  .bar { gap: 8px; padding: 0 10px; }
  .wordmark { font-size: 17px; }
  .online .lbl { display: none; }
  .chai-btn { width: 32px; padding: 0; justify-content: center; }
  .chai-btn span { display: none; }
  .you { padding: 8px 12px; }
  .bank { margin-top: 6px; }
  .bank span { height: 8px; }
  .bank-next { margin-top: 4px; }
  .colors { padding: 8px 12px; }
  .dock-tabs { display: grid; grid-template-columns: 1fr 1fr; }
  .tab {
    height: 44px; background: var(--panel); border: 0;
    border-right: 2px solid var(--line);
    font: 9px/1 var(--px);
    display: flex; align-items: center; justify-content: center; gap: 8px;
  }
  .tab:last-child { border-right: 0; color: var(--gold); }
  .badge { background: var(--red); color: var(--ink); padding: 3px 4px 2px; font-size: 7px; }

  .sheet {
    position: fixed; z-index: 20;
    left: 0; right: 0; bottom: 0;
    height: min(70dvh, 560px);
    border-top: 2px solid var(--gold);
    border-bottom: 0;
    padding-bottom: var(--safe-b);
    transform: translateY(100%);
    visibility: hidden;
    transition: transform .2s steps(4), visibility 0s .2s;
  }
  .sheet.promo { height: auto; padding-bottom: calc(16px + var(--safe-b)); }
  .sheet.open { transform: none; visibility: visible; transition: transform .2s steps(4); }
  .sheet-x { display: grid; place-items: center; }
  /* the vote hint sits at the top on phones so it never hides the box */
  .vote-hint { top: 10px; bottom: auto; left: 10px; right: 56px; transform: none; width: auto; max-width: none; font-size: 11px; }
  /* toasts drop from the top so they never cover the palette */
  .toasts { top: calc(var(--bar-h) + var(--band) + 8px); bottom: auto; flex-direction: column-reverse; }
  .toast { animation-name: toast-in-top; }
  .toast.out { animation-name: toast-out-top; }
}
@keyframes toast-in-top { from { transform: translateY(-12px); opacity: 0; } }
@keyframes toast-out-top { to { transform: translateY(-12px); opacity: 0; } }

/* very narrow phones: the header holds the brand, countdown and four buttons */
@media (max-width: 389px) {
  .bar-right { gap: 4px; }
  .icon-btn { width: 28px; height: 28px; }
  .icon-btn svg { width: 12px; height: 12px; }
  .wordmark { font-size: 15px; }
  .brand .sprite { display: none; }
}
@media (max-width: 420px) {
  .tag, .countdown .k, .countdown .sec, .online { display: none; }
  .countdown .v { font-size: 10px; }
  .bar-right { gap: 6px; }
}

/* Phone, landscape: canvas on the left, a narrow rail on the right. */
@media (max-width: 959px) and (orientation: landscape) and (max-height: 560px) {
  :root { --bar-h: 40px; --dock-w: 228px; }
  .app {
    grid-template-columns: minmax(0, 1fr) var(--dock-w);
    grid-template-rows: var(--bar-h) minmax(0, 1fr);
    grid-template-areas: "bar bar" "stage dock";
  }
  .bar { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .tag { display: inline-block; }
  .dock {
    border-top: 0; border-left: 2px solid var(--line);
    margin-top: var(--band); padding-top: 0;
    overflow-y: auto;
    padding-right: env(safe-area-inset-right);
  }
  .palette { gap: 3px; }
  .palette button { min-height: 22px; }
  .dock-tabs { margin-top: auto; }
  .tab { height: 40px; }
  .sheet {
    left: auto; top: 0; width: min(360px, 60vw); height: 100dvh;
    border-top: 0; border-left: 2px solid var(--gold);
    transform: translateX(100%);
  }
  .sheet.promo { height: 100dvh; }
  .sheet.open { transform: none; }
  .toasts { left: auto; right: calc(var(--dock-w) + 12px); transform: none; width: min(380px, calc(100vw - var(--dock-w) - 24px)); }
}

/* Phone with the controller, portrait: D-pad left, 4x4 palette right. */
@media (max-width: 959px) {
  .touch .dock {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "you you" "pad colors" "tabs tabs";
  }
  .touch #youCard { grid-area: you; }
  .touch #padCard { grid-area: pad; padding: 10px 12px 14px; border-right: 2px solid var(--line); }
  .touch #colorsCard { grid-area: colors; display: grid; align-content: center; }
  .touch .dock-tabs { grid-area: tabs; }
  .touch .palette { gap: 4px; }
  .touch .palette button { min-height: 0; }
  .touch .vote-btn { height: 32px; margin-top: 6px; }
  .day-line { margin-top: 2px; font-size: 11px; }
}
@media (max-width: 359px) { .dpad { --b: 42px; } }

/* Phone with the controller, landscape: a handheld console.
   D-pad and pixels on the left, canvas in the middle, palette on the right. */
@media (max-width: 959px) and (orientation: landscape) and (max-height: 560px) {
  .touch { --rail-l: 172px; --dock-w: 188px; }
  .touch .app {
    grid-template-columns: var(--rail-l) minmax(0, 1fr) var(--dock-w);
    grid-template-rows: var(--bar-h) var(--band) auto minmax(0, 1fr) auto;
    grid-template-areas: "bar bar bar" ". . ." "you stage colors" "pad stage colors" "pad stage tabs";
  }
  .touch .dock { display: contents; }
  .touch .stage-wrap { margin-top: 0; }
  .touch #youCard { grid-area: you; border-right: 2px solid var(--line); padding-left: max(12px, env(safe-area-inset-left)); }
  .touch #padCard { grid-area: pad; border-right: 2px solid var(--line); border-bottom: 0; padding: 6px 0 10px env(safe-area-inset-left); }
  .touch #youCard .bank-next { font-size: 11px; }
  .touch #colorsCard { align-content: start; }
  .touch #colorsCard { grid-area: colors; border-left: 2px solid var(--line); padding-right: max(12px, env(safe-area-inset-right)); }
  .touch .dock-tabs {
    grid-area: tabs; display: flex; flex-direction: column; justify-content: flex-end;
    background: var(--panel); border-left: 2px solid var(--line);
    padding-right: env(safe-area-inset-right);
  }
  .touch .tab { border-right: 0; border-top: 2px solid var(--line); flex: none; }
  .touch .palette { gap: 3px; }
  .touch .palette button { min-height: 0; }
  .touch .palette .recent:nth-child(-n + 8) { margin-bottom: 2px; }
  .touch .dpad { --b: 44px; }
}

/* Desktop and tablets: board and a full side panel. */
@media (min-width: 960px) {
  .app {
    grid-template-columns: minmax(0, 1fr) var(--dock-w);
    grid-template-rows: var(--bar-h) minmax(0, 1fr);
    grid-template-areas: "bar bar" "stage dock";
  }
  .dock { border-top: 0; border-left: 2px solid var(--line); margin-top: var(--band); padding-top: 0; }
  .chat { flex: 1; }
  .card.promo { border-bottom: 0; border-top: 2px solid var(--line); padding-top: 0; }
  .toasts { left: calc((100vw - var(--dock-w)) / 2); }
  /* give the chat room: the Tandem card becomes a compact 2 x 2 of buttons */
  .dock { overflow-y: auto; }
  .chat { flex: 1 1 260px; min-height: 240px; }
  .card.promo { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 12px 12px; }
  .card.promo > .sheet-head, .card.promo > .promo-body { grid-column: 1 / -1; }
  .card.promo .promo-body { margin: 0; }
  .card.promo .promo-body p { font-size: 12px; line-height: 1.45; }
  .card.promo .promo-actions { display: contents; }
  .card.promo .btn { width: 100%; margin: 0; min-height: 36px; padding: 6px 8px; font-size: 12px; justify-content: center; }
  .touch .pad-card { padding: 14px 0 18px; }
}

@media (min-width: 960px) and (max-height: 860px) {
  .card.promo .promo-body { display: none; }
}

/* Short screens (phones in landscape): a compact join card. */
@media (max-height: 560px) {
  .join { padding: calc(var(--band) + 14px) 18px 14px; width: min(520px, calc(100vw - 24px)); }
  .join .sprite, .join .lede { display: none; }
  .join h1 { font-size: 16px; margin: 6px 0 12px; }
  .join input[name="name"] { height: 42px; }
  .join .hint { margin-bottom: 10px; }
  .btn.big { height: 42px; }
  .join .watch { margin-top: 4px; padding: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}
