* { box-sizing: border-box; }

:root {
  --page: #f0ece3;
  --dot: #ddd6c8;
  --body-hi: #f4f1ea;
  --body: #e3dfd6;
  --body-lo: #c8c2b5;
  --ink: #1c1c1e;
  --muted: #8a8478;
  --screen: #121411;
  --lcd: #f3f0e6;
  --lcd-dim: #8d9088;
  --orange: #ff5b14;
  --led: #8dff6a;
  --panel: #faf8f3;
  color-scheme: light;
}

html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: var(--page) radial-gradient(var(--dot) 1.2px, transparent 1.4px) 0 0 / 22px 22px;
  color: var(--ink);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

.stage {
  min-height: 100dvh;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 32px 16px;
}

/* device */
.device {
  position: relative;
  width: min(372px, 100%);
  padding: 24px 20px 26px;
  border-radius: 36px;
  background: linear-gradient(170deg, var(--body-hi), var(--body) 60%);
  box-shadow:
    inset 0 1.5px 0 #fff,
    inset 0 -3px 0 var(--body-lo),
    0 2px 0 #b9b2a3,
    0 40px 60px -28px rgba(70, 55, 30, .45),
    0 10px 20px -8px rgba(70, 55, 30, .2);
}
.screw {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fafafa, #a9a397);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
}
.screw::after {
  content: '';
  position: absolute;
  inset: 4px 1.5px;
  background: rgba(0, 0, 0, .3);
  border-radius: 1px;
  transform: rotate(var(--a, 30deg));
}
.tl { top: 12px; left: 12px; }
.tr { top: 12px; right: 12px; --a: -20deg; }
.bl { bottom: 12px; left: 12px; --a: 75deg; }
.br { bottom: 12px; right: 12px; --a: 10deg; }

.brand { display: flex; justify-content: space-between; align-items: flex-start; padding: 6px 6px 0; }
.brand h1 { margin: 0; font-size: 44px; line-height: .85; letter-spacing: -.06em; font-weight: 700; }
.brand p { margin: 6px 0 0; font-size: 11px; color: var(--muted); letter-spacing: .02em; }
.badge { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.badge small { font: 9px 'Silkscreen', monospace; color: var(--muted); }
.grille { width: 46px; height: 18px; background: radial-gradient(#9c9588 1.4px, transparent 1.6px) 0 0 / 6px 6px; }
.snd {
  border: 0;
  padding: 3px 8px;
  border-radius: 999px;
  font: 9px 'Silkscreen', monospace;
  background: var(--orange);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 0 #b83d08;
}
.snd.off, #help { background: #bdb7aa; box-shadow: 0 2px 0 #9a9486; }
.snd:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 5px; }

.stickers { display: flex; gap: 6px; flex-wrap: wrap; min-height: 30px; padding: 10px 4px 0; }
.sticker {
  display: inline-block;
  min-width: 64px;
  text-align: center;
  cursor: pointer;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--c);
  color: var(--ink);
  font: 700 10px/1.2 'Space Grotesk', sans-serif;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .15), inset 0 0 0 2px rgba(255, 255, 255, .45);
}
.sticker.empty { min-height: 20px; background: none; box-shadow: none; border: 1.5px dashed var(--body-lo); cursor: default; }
.sticker.selling { background: var(--ink); color: #ffd60a; }

/* screen */
.screen {
  margin: 8px 0 18px;
  padding: 12px 14px 10px;
  border-radius: 16px;
  background: var(--screen);
  color: var(--lcd);
  font-family: 'Silkscreen', monospace;
  box-shadow: 0 0 0 5px #d3cdc0, 0 0 0 6px #bdb6a8, inset 0 3px 10px rgba(0, 0, 0, .7);
}
.row { display: flex; justify-content: space-between; align-items: center; min-height: 16px; font-size: 11px; color: var(--lcd-dim); }
#coins { color: #ffd60a; }
.expr { display: flex; justify-content: flex-end; align-items: center; gap: 4px; height: 54px; margin: 8px 0; }
.cell {
  position: relative;
  flex: 0 1 44px;
  min-width: 0;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font: 700 min(28px, calc(300px / var(--slots))) 'Space Grotesk', sans-serif;
}
.cell.d {
  background: var(--bg);
  color: var(--fg, #fff);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .15);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .22), inset 0 2px 0 rgba(255, 255, 255, .35);
}
.cell.o { color: var(--lcd); font-size: min(32px, calc(340px / var(--slots))); }
.cell.e { border: 1.5px dashed #33372f; }
.cell.cursor { border-color: #777b70; animation: blink 1s steps(1) infinite; }
.cell.fresh { animation: cell-in .18s cubic-bezier(.3, 1.6, .5, 1); }
/* A glowing bridge to the previous cell when their keys touch. */
.cell.join::before {
  content: '';
  position: absolute;
  left: -7px;
  top: calc(50% - 2px);
  width: 10px;
  height: 4px;
  border-radius: 2px;
  background: var(--led);
  box-shadow: 0 0 6px var(--led);
}
.msg { font-size: 26px; color: var(--orange); letter-spacing: .04em; white-space: nowrap; animation: blink 1.2s steps(1) infinite; }
#preview { color: #ffd60a; }
#preview.warn { color: var(--orange); }
.pips { display: flex; gap: 5px; }
.pip { width: 8px; height: 8px; border-radius: 2px; background: #2a2d27; transition: background .2s, box-shadow .2s; }
.pip.on { background: var(--led); box-shadow: 0 0 6px var(--led); }

/* score meter */
.meter {
  position: relative;
  height: 22px;
  margin: 0 2px 20px;
  border-radius: 999px;
  background: #cfc9bc;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, .22), 0 1px 0 #fff;
  overflow: hidden;
}
.fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #ff3b30, #ff9500, #ffd60a, #34c759, #32ade6, #7d5cff, #ff2d92);
  clip-path: inset(0 calc(100% - var(--p, 0%)) 0 0 round 999px);
  transition: clip-path .5s cubic-bezier(.3, 1.3, .5, 1) .35s;
}
.meter.full .fill { animation: shimmer .5s ease-in-out infinite alternate; }
#bank {
  position: absolute;
  right: 10px;
  top: 50%;
  translate: 0 -50%;
  font: 11px 'Silkscreen', monospace;
  color: #fff;
  text-shadow: 0 0 2px #000, 0 1px 0 #000;
}

/* play / arrange switch */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -8px 2px 14px;
  font: 9px 'Silkscreen', monospace;
  color: var(--muted);
}
.switch { display: flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.switch:disabled { cursor: default; opacity: .5; }
.switch i { position: relative; width: 34px; height: 16px; border-radius: 999px; background: #cfc9bc; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .25); transition: background .15s; }
.switch i::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: translate .15s cubic-bezier(.3, 1.5, .5, 1);
}
.switch:not(.on) span:first-child, .switch.on span:last-child { color: var(--ink); }
.switch.on i { background: var(--orange); }
.switch.on i::after { translate: 18px 0; }

/* keys */
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.key {
  --c: #f7f4ee;
  --edge: color-mix(in oklab, var(--c) 60%, #000);
  position: relative;
  height: 64px;
  border: 0;
  border-radius: 16px;
  background: var(--bg, var(--c));
  color: var(--fg, #fff);
  font-size: 26px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    0 6px 0 var(--edge),
    0 12px 16px -6px rgba(60, 45, 20, .45),
    inset 0 2px 0 rgba(255, 255, 255, .4),
    inset 0 -3px 0 rgba(0, 0, 0, .1);
  transition: transform .07s, box-shadow .07s, filter .15s, opacity .15s;
}
.key.down, .key:active {
  transform: translateY(5px);
  box-shadow:
    0 1px 0 var(--edge),
    0 3px 5px -2px rgba(60, 45, 20, .4),
    inset 0 2px 0 rgba(255, 255, 255, .3),
    inset 0 -2px 0 rgba(0, 0, 0, .1);
}
.key.digit { text-shadow: 0 1px 0 rgba(0, 0, 0, .18); }
.key.op { --c: #3b3e44; }
.key.fn { --c: #f7f4ee; --edge: #c9c3b6; color: var(--ink); font-size: 22px; }
.key.eq { --c: #1a1b1d; color: var(--orange); font-size: 36px; grid-column: span 2; }
/* the stored sum, printed on the = key */
.key.eq::after {
  content: attr(data-prog);
  position: absolute;
  right: 14px;
  top: 50%;
  translate: 0 -50%;
  max-width: calc(50% - 30px);
  text-overflow: ellipsis;
  overflow: hidden;
  font: 12px 'Silkscreen', monospace;
  color: var(--lcd);
  opacity: .7;
  white-space: nowrap;
}
/* A mod replaces the = key with its own. */
.key.eq[data-mod="die"] { --c: #f7f4ee; --edge: #c9c3b6; color: var(--ink); }
.key.eq[data-mod="die"] .cap { font-size: 1.6em; line-height: 1; }
.key.eq[data-mod="carry"] { --c: #32ade6; color: #fff; }
.key.eq[data-mod="tinker"] { --c: #c69cff; color: #fff; }
.key.eq[data-mod]:not([data-mod=""])::after { color: currentColor; }
.item .key.eq.mini { font-size: 24px; }
.key sup { font-size: .55em; }
.dots { position: absolute; top: 8px; left: 9px; display: grid; grid-template-columns: repeat(3, 5px); gap: 2px; }
.dots i { width: 5px; height: 5px; border-radius: 1.5px; background: currentColor; opacity: .5; }
/* Unpressable keys sink halfway into the body. */
.key.dim {
  transform: translateY(3px);
  filter: saturate(.55) brightness(.96);
  box-shadow: 0 3px 0 var(--edge), 0 5px 8px -4px rgba(60, 45, 20, .3), inset 0 2px 0 rgba(255, 255, 255, .25);
}
.key.dim .cap { opacity: .6; }
.key.socket {
  background: #d2ccbf;
  box-shadow: inset 0 3px 7px rgba(0, 0, 0, .22), inset 0 -1px 0 rgba(255, 255, 255, .7);
  transform: none;
  cursor: default;
  filter: none;
  opacity: 1;
}
.key.socket > * { visibility: hidden; }
.key.socket::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  margin: -3px;
  border-radius: 50%;
  background: #b8b1a3;
}
.key.new { animation: key-pop .6s cubic-bezier(.3, 1.5, .5, 1); }
/* Plate badge: belongs to the socket, so it stays put when keys swap. */
.key[data-mark]:not([data-mark=""])::before, .plate {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 20px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--plate);
  font: 11px 'Silkscreen', monospace;
  box-shadow: 0 0 0 2px var(--plate), 0 3px 0 1px rgba(0, 0, 0, .3);
}
.key[data-mark]:not([data-mark=""])::before { content: attr(data-mark); position: absolute; top: -7px; right: -7px; z-index: 1; text-shadow: none; }
.key.hot { animation: hot .9s ease-in-out infinite alternate; }
@keyframes hot { to { box-shadow: 0 6px 0 var(--edge), 0 0 0 3px #ffb000, 0 0 22px 4px rgba(255, 140, 0, .7); } }
.key.socket:not([data-plate=""]) { background: color-mix(in oklab, var(--plate) 22%, #d2ccbf); }
.item .plate { scale: 1.6; }
.placing .key[data-i] { outline: 2px dashed var(--orange); outline-offset: 3px; cursor: pointer; }
.arranging .key { touch-action: none; }
.arranging .key[data-i]:hover:not(.lifted) { outline: 2px solid rgba(255, 91, 20, .5); outline-offset: 2px; }
.key.linked { outline: 3px solid var(--led); outline-offset: 2px; }
.arranging .key[data-i]:not(.socket) { animation: jiggle .24s ease-in-out infinite alternate; }
.arranging .key[data-i]:nth-child(odd) { animation-delay: -.12s; }
.arranging .key.socket { box-shadow: inset 0 3px 7px rgba(0, 0, 0, .22), 0 0 0 2px rgba(255, 91, 20, .35); }
.key.lifted {
  z-index: 1;
  animation: none !important;
  transform: translateY(-8px) scale(1.06);
  box-shadow: 0 12px 0 -3px var(--edge), 0 24px 24px -8px rgba(60, 45, 20, .5), inset 0 2px 0 rgba(255, 255, 255, .4);
}
.key.mini { display: inline-grid; place-items: center; width: 64px; height: 58px; pointer-events: none; }
.idle .key.eq { animation: nudge 1.6s ease-in-out infinite; }

/* side panel */
.panel {
  width: min(340px, 100%);
  padding: 24px;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: inset 0 1px 0 #fff, 0 24px 40px -24px rgba(70, 55, 30, .35), 0 0 0 1px rgba(0, 0, 0, .04);
}
.panel h2 { margin: 0 0 12px; font-size: 26px; letter-spacing: -.03em; }
.chips { display: flex; align-items: baseline; gap: 8px; margin-bottom: 14px; }
.chips i {
  align-self: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: conic-gradient(#ff3b30 0 25%, #ffd60a 0 50%, #34c759 0 75%, #32ade6 0);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .6);
}
.chips b { font-size: 36px; letter-spacing: -.03em; }
.chips span { color: var(--muted); }
.last { margin: 0 0 16px; padding: 10px 12px; border-radius: 12px; background: #efe9dd; font-size: 14px; }
.last.won { background: #ffd60a; }
.perms { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 12px; }
.perms li { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.perms strong { display: block; font-size: 15px; }
.perms small { color: var(--muted); font-size: 12px; }
.lvl { display: flex; gap: 3px; margin-top: 5px; }
.lvl i { width: 14px; height: 5px; border-radius: 2px; background: #ddd6c8; }
.lvl i.on { background: var(--orange); }
.buy {
  min-width: 58px;
  height: 38px;
  border: 0;
  border-radius: 11px;
  background: var(--orange);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #b83d08;
  transition: transform .07s, box-shadow .07s;
}
.buy:active { transform: translateY(3px); box-shadow: 0 1px 0 #b83d08; }
.buy:disabled { background: #ddd6c8; color: #9a9486; box-shadow: 0 4px 0 #c3bcae; cursor: default; transform: none; }
.stat { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed #ddd6c8; font-size: 14px; }
.stat span { color: var(--muted); }
.how { margin: 16px 0; padding-left: 20px; font-size: 13px; line-height: 1.5; color: #4a463e; }
.cta { margin: 0; font-weight: 700; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border-radius: 6px;
  background: #1a1b1d;
  color: var(--orange);
  font: 700 .9em 'Space Grotesk', sans-serif;
  text-align: center;
  box-shadow: 0 2px 0 #000;
}

/* shop */
.shop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.shop-head h2 { margin: 0; }
.coins { display: flex; align-items: center; gap: 6px; font-size: 26px; font-weight: 700; letter-spacing: -.03em; }
.coins i { width: 18px; height: 18px; border-radius: 50%; background: #ffd60a; box-shadow: inset 0 0 0 3px #f0b400; }
.shelf { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 150px;
  padding: 10px 8px 12px;
  border: 0;
  border-radius: 18px;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 #ddd6c8, 0 14px 20px -12px rgba(60, 45, 20, .35);
  transition: transform .08s, box-shadow .08s;
}
.item:active { transform: translateY(4px); box-shadow: 0 1px 0 #ddd6c8; }
.item:disabled { cursor: default; opacity: .5; transform: none; }
.item b { font-size: 14px; }
.item small { font-size: 11px; line-height: 1.3; color: var(--muted); text-align: center; }
.item .face { height: 64px; }
.item .key.mini { width: 54px; height: 50px; font-size: 22px; }
.item.sold { display: grid; place-items: center; background: none; box-shadow: none; border: 2px dashed #ddd6c8; font: 11px 'Silkscreen', monospace; color: var(--muted); cursor: default; }
.price { margin-top: auto; padding: 2px 10px; border-radius: 999px; background: #1a1b1d; color: #ffd60a; font: 12px 'Silkscreen', monospace; }
.reroll, .svc {
  width: 100%;
  margin-top: 10px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform .07s, box-shadow .07s;
}
.reroll { height: 40px; background: var(--orange); color: #fff; font: 12px 'Silkscreen', monospace; box-shadow: 0 4px 0 #b83d08; }
.reroll:active { transform: translateY(3px); box-shadow: 0 1px 0 #b83d08; }
.svcs { margin-top: 6px; }
.svc { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: #efe9dd; text-align: left; box-shadow: 0 3px 0 #ddd6c8; }
.svc:active { transform: translateY(2px); box-shadow: 0 1px 0 #ddd6c8; }
.svc b { display: block; font-size: 14px; }
.svc small { font-size: 12px; color: var(--muted); }
.svc .price { margin: 0; }
.reroll:disabled, .svc:disabled { opacity: .5; cursor: default; transform: none; }

/* receipt between rounds */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(240, 236, 227, .72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.overlay[hidden] { display: none; }
.face { display: grid; place-items: center; }
.face .sticker { scale: 1.3; cursor: inherit; }
.receipt {
  position: relative;
  width: min(300px, 100%);
  padding: 22px 20px 26px;
  background: #fffdf7;
  font: 12px/1.6 'Silkscreen', monospace;
  box-shadow: 0 20px 40px -16px rgba(60, 45, 20, .45);
  animation: print .5s steps(8) both;
}
/* torn paper edge */
.receipt::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -8px;
  height: 8px;
  background: linear-gradient(135deg, #fffdf7 50%, transparent 50%) 0 0 / 12px 8px repeat-x,
    linear-gradient(225deg, #fffdf7 50%, transparent 50%) 0 0 / 12px 8px repeat-x;
}
.kicker { margin: 0 0 12px; font-size: 14px; color: var(--orange); text-align: center; }
.receipt.paid .kicker { color: #1f9e3a; }
.receipt ul { list-style: none; margin: 0; padding: 0 0 8px; border-bottom: 1.5px dashed #cfc9bc; }
.receipt li, .total { display: flex; justify-content: space-between; gap: 12px; }
.total { margin: 8px 0 4px; font-size: 18px; }
.next { margin: 0 0 16px; color: var(--muted); }
.go {
  width: 100%;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: #1a1b1d;
  color: #fff;
  font: 13px 'Silkscreen', monospace;
  cursor: pointer;
  box-shadow: 0 4px 0 #000;
}
.go:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.go kbd { background: #3b3e44; }
.help { width: min(340px, 100%); }
.help .how { margin: 0 0 16px; padding: 0 0 0 20px; border: 0; list-style: decimal; font-family: 'Space Grotesk', system-ui, sans-serif; }
.help .how li { display: list-item; margin-bottom: 4px; }
.help .how kbd { vertical-align: 1px; }
.again { display: block; margin: 10px auto 0; border: 0; background: none; font: 11px 'Silkscreen', monospace; color: var(--muted); text-decoration: underline; cursor: pointer; }

/* onboarding tip, positioned above its target by renderTip() */
.tip {
  position: fixed;
  max-width: 220px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  translate: -50% -100%;
  box-shadow: 0 10px 20px -8px rgba(0, 0, 0, .5);
  animation: bob 1.2s ease-in-out infinite;
}
.tip[hidden] { display: none; }
.tip::after {
  content: '';
  position: absolute;
  left: calc(50% + var(--ax, 0px));
  bottom: -6px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  rotate: 45deg;
  background: var(--ink);
  border-radius: 2px;
}
.tip.new { animation: tip-pop .4s cubic-bezier(.3, 1.5, .5, 1), bob 1.2s .5s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
@keyframes tip-pop { from { transform: scale(.4); opacity: 0; } }

/* effects */
#fx { position: fixed; inset: 0; z-index: 20; pointer-events: none; overflow: hidden; }
.cube {
  position: absolute;
  left: 0;
  top: 0;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--bg);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25), inset 0 2px 0 rgba(255, 255, 255, .4);
}
.pop { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 4px; white-space: nowrap; }
.pop b {
  font-size: 40px;
  letter-spacing: -.04em;
  text-shadow: 0 3px 0 #fff, 0 -3px 0 #fff, 3px 0 0 #fff, -3px 0 0 #fff, 0 7px 0 rgba(0, 0, 0, .12);
}
.pop span { padding: 3px 9px; border-radius: 999px; background: var(--ink); color: #ffd60a; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.device.broken .screen { animation: glitch .09s steps(1) infinite; }
/* Cracks stay on the glass for the rest of the run, one more per tier. */
.screen { position: relative; }
.device:is([data-cracks="1"], [data-cracks="2"], [data-cracks="3"]) .screen::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M78 0 L72 9 L80 15 L70 24 L74 31 L66 40 M72 9 L62 12 M70 24 L84 28' fill='none' stroke='%23fff' stroke-opacity='.35' stroke-width='.6' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") 0 0 / 100% 100% no-repeat;
}
.device[data-cracks="2"] .screen::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M78 0 L72 9 L80 15 L70 24 L74 31 L66 40 M72 9 L62 12 M70 24 L84 28' fill='none' stroke='%23fff' stroke-opacity='.35' stroke-width='.6' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E"), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M0 14 L10 17 L16 12 L27 19 L34 16 M16 12 L19 4 M27 19 L24 30' fill='none' stroke='%23fff' stroke-opacity='.35' stroke-width='.6' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E"); background-size: 100% 100%; }
.device[data-cracks="3"] .screen::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M78 0 L72 9 L80 15 L70 24 L74 31 L66 40 M72 9 L62 12 M70 24 L84 28' fill='none' stroke='%23fff' stroke-opacity='.35' stroke-width='.6' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E"), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M0 14 L10 17 L16 12 L27 19 L34 16 M16 12 L19 4 M27 19 L24 30' fill='none' stroke='%23fff' stroke-opacity='.35' stroke-width='.6' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E"), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M44 40 L47 31 L41 25 L49 18 L46 9 L52 0 M41 25 L32 27 M49 18 L58 21' fill='none' stroke='%23fff' stroke-opacity='.35' stroke-width='.6' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E"); background-size: 100% 100%; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes cell-in { from { transform: scale(.4) translateY(6px); } }
@keyframes shimmer { to { filter: brightness(1.25) saturate(1.3); } }
@keyframes key-pop { from { transform: translateY(-80px) scale(.3) rotate(-14deg); opacity: 0; } 60% { opacity: 1; } }
@keyframes nudge { 50% { box-shadow: 0 6px 0 var(--edge), 0 0 0 4px rgba(255, 91, 20, .35), 0 12px 22px -6px rgba(255, 91, 20, .6); } }
@keyframes print { from { clip-path: inset(0 0 100% 0); translate: 0 -30px; } }
@keyframes jiggle { from { rotate: -2deg; } to { rotate: 2deg; } }
@keyframes glitch {
  0% { transform: translate(2px, -1px); filter: hue-rotate(90deg); }
  33% { transform: translate(-3px, 1px); filter: invert(1); }
  66% { transform: translate(1px, 2px) skewX(6deg); filter: hue-rotate(200deg) saturate(3); }
}

@media (max-width: 420px) {
  .stage { gap: 24px; padding: 20px 16px; }
  .device { padding: 20px 14px 22px; border-radius: 30px; }
  .keys { gap: 10px; }
  .key { height: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* toy keys */
.key[data-k="D"] .cap {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 44px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--ink);
  color: #f7f4ee;
  font-size: 15px;
  text-shadow: none;
}
.key[data-k="¢"] { --c: #ffd60a; --edge: #c9a200; color: #6b4e00; }
.key[data-k="¢"] .cap {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #e8b10c;
  box-shadow: inset 0 0 0 3px #ffe27a, 0 2px 0 #b38600;
}
.key[data-k="P"] { --c: #ffb3c7; --edge: #d9849b; font-size: 30px; }
.key[data-k="?"] .cap {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #fff 0 34%, #1d1d22 36%);
  color: #1d1d22;
  font-size: 15px;
  text-shadow: none;
}
.key[data-k="?"].heads .cap { background: radial-gradient(circle at 50% 45%, #34c759 0 34%, #1d1d22 36%); color: #fff; }
.key[data-k="G"] { --c: #c69cff; --edge: #9a6fd6; font-size: 28px; }
.key[data-k="F"] { --c: #ffd2b8; --edge: #e0a07c; font-size: 28px; }
.key.shaking .cap { animation: shake .12s linear infinite; }
.key.armed { --c: #ffe27a; outline: 3px solid #ffd60a; outline-offset: 2px; }
.key.rolling .cap { animation: roll .2s linear infinite; }
.key.flipping .cap { animation: flip .16s linear infinite; }
.key.heads .cap { background: #34c759; color: #fff; }
.paw {
  position: absolute;
  display: grid;
  place-items: center;
  line-height: 1;
  filter: drop-shadow(0 10px 8px rgba(60, 45, 20, .35));
}
@keyframes roll { to { rotate: 360deg; } }
@keyframes shake { 25% { translate: -3px 0; rotate: -8deg; } 75% { translate: 3px 0; rotate: 8deg; } }
@keyframes flip { 50% { scale: 1 .1; } }
