:root {
  --ink: #111;
  --skin: #f1c27d;
  --body: #d9d4c7;
  --lcd: #9bbc0f;
  --lcd-ink: #0f380f;
  --num: #f3ead3;
  --op: #ff8c42;
  --fn: #e63946;
  --eq: #2a9d8f;
  --prem: #7b2cbf;
  --gold: #ffd23f;
  --px: "Press Start 2P", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8fd3ff;
  font-family: var(--px);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#arena {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
}

/* ---------- calculator + hands ---------- */
#rig {
  position: fixed;
  left: 50%;
  bottom: 4vh;
  width: min(88vw, 340px, 44vh);
  aspect-ratio: 0.6;
  transform: translateX(-50%);
  transition: transform .6s cubic-bezier(.5, -0.3, .4, 1.2);
  container-type: inline-size;
  z-index: 5;
}
#rig.lowered { transform: translate(-50%, calc(100% - 7vh)) rotate(-3deg); }

#back, #front {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
}
#front { z-index: 2; }

.ol * { fill: var(--ink); stroke: var(--ink); stroke-width: 9; stroke-linejoin: round; }
.fl * { fill: var(--skin); stroke: none; }
.ol .th { fill: none; stroke-width: 44; stroke-linecap: round; }
.fl .th { fill: none; stroke: var(--skin); stroke-width: 34; stroke-linecap: round; }
.fl .sleeve { fill: #d62828; }
.nail { fill: #ffe3d6; stroke: var(--ink); stroke-width: 3; }

#calc {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 3cqw;
  padding: 5cqw 5cqw 3cqw;
  background: var(--body);
  border: 5px solid var(--ink);
  border-radius: 6cqw 6cqw 22cqw 6cqw;
  box-shadow: inset -8px -8px 0 rgba(0,0,0,.12), inset 6px 6px 0 rgba(255,255,255,.5);
}

.brand { display: flex; justify-content: space-between; align-items: baseline; font-size: 3.6cqw; }
.brand i { color: var(--fn); font-size: 2.6cqw; }

#screen {
  height: 19cqw;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 4cqw;
  background: var(--lcd);
  color: var(--lcd-ink);
  border: 4px solid var(--ink);
  border-radius: 3cqw;
  box-shadow: inset 4px 4px 0 rgba(0,0,0,.25);
  overflow: hidden;
  white-space: nowrap;
  background-image: repeating-linear-gradient(0deg, rgba(0,0,0,.05) 0 2px, transparent 2px 4px);
}
#display { font-size: 8cqw; line-height: 1; }

#keys {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 3cqw;
}
#keys button {
  font: inherit;
  font-size: 6cqw;
  color: var(--ink);
  background: var(--num);
  border: 3px solid var(--ink);
  border-radius: 2.5cqw;
  box-shadow: 0 1.6cqw 0 var(--ink);
  cursor: pointer;
  transition: transform .05s, box-shadow .05s;
  position: relative;
  padding: 0;
}
#keys button:active, #keys button.pressed { transform: translateY(1.3cqw); box-shadow: 0 .3cqw 0 var(--ink); }
#keys button:focus-visible { outline: 4px dashed var(--gold); outline-offset: 3px; }
#keys .op { background: var(--op); }
#keys .fn { background: var(--fn); color: #fff; font-size: 5cqw; }
#keys .eq { background: var(--eq); color: #fff; grid-row: span 2; }
#keys .zero { grid-column: span 2; }
#keys .prem { background: var(--prem); color: #fff; }
#keys .prem::after { content: "🔒"; position: absolute; top: -2.2cqw; right: -2cqw; font-size: 3.6cqw; }
#keys button.want { animation: want .6s steps(2) infinite; }
@keyframes want { 50% { background: var(--gold); color: var(--ink); } }

.grille { display: flex; justify-content: center; gap: 2cqw; padding-bottom: 2cqw; transform: rotate(-25deg) translate(18cqw, 0); }
.grille i { width: 1.4cqw; height: 7cqw; background: rgba(0,0,0,.35); border-radius: 1cqw; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 16px; left: 16px; right: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 6;
  opacity: 0;
  transform: translateY(-30px);
  transition: .3s;
  pointer-events: none;
}
#hud.show { opacity: 1; transform: none; }
.side { flex: 1; min-width: 0; }
.name { font-size: clamp(10px, 2.4vw, 16px); color: #fff; text-shadow: 2px 2px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink); margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r .name { text-align: right; }
.bar { height: clamp(14px, 3vw, 24px); background: #d62828; border: 4px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); display: flex; }
.r .bar { justify-content: flex-end; }
.bar i { display: block; width: 100%; background: var(--gold); transition: width .35s steps(8); box-shadow: inset 0 -4px 0 #e0a800; }
.vs { font-size: clamp(14px, 3.5vw, 28px); color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }

/* ---------- banner ---------- */
#banner {
  position: fixed;
  left: 16px; right: 16px;
  top: 32%;
  text-align: center;
  font-size: clamp(28px, 10vw, 110px);
  color: var(--gold);
  letter-spacing: .05em;
  text-shadow:
    4px 0 0 var(--ink), -4px 0 0 var(--ink), 0 4px 0 var(--ink), 0 -4px 0 var(--ink),
    4px 4px 0 var(--ink), -4px -4px 0 var(--ink), 4px -4px 0 var(--ink), -4px 4px 0 var(--ink),
    10px 10px 0 #d62828;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  font-style: italic;
}
#banner.pop { animation: pop .35s steps(4) forwards; }
#banner.small { font-size: clamp(20px, 6vw, 64px); }
@keyframes pop {
  0% { opacity: 0; transform: scale(3) skewX(-10deg); }
  100% { opacity: 1; transform: scale(1) skewX(-10deg); }
}

#mute {
  position: fixed;
  left: 16px; bottom: 16px;
  z-index: 8;
  width: 44px; height: 44px;
  font-size: 20px;
  background: var(--num);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
#mute:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- finisher cut-in ---------- */
#cutin {
  position: fixed;
  left: -5vw; right: -5vw;
  top: 22%;
  z-index: 7;
  padding: 14px 16px;
  text-align: center;
  background: repeating-linear-gradient(135deg, #111 0 14px, #1d1d1d 14px 28px);
  border-block: 5px solid var(--gold);
  box-shadow: 0 8px 0 #d62828;
  transform: skewY(-4deg) translateX(-115%);
  transition: transform .25s steps(5);
  pointer-events: none;
}
#cutin.show { transform: skewY(-4deg) translateX(0); }
#cutin .who { color: var(--gold); font-size: clamp(9px, 1.8vw, 14px); margin-bottom: 10px; }
#cutin .move { color: #fff; font-size: clamp(16px, 4.6vw, 56px); font-style: italic; text-shadow: 4px 4px 0 #d62828; }

/* ---------- premium dialog ---------- */
#premium {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 20px;
  font-family: var(--px);
  font-size: 11px;
  line-height: 1.7;
  background: var(--num);
  border: 5px solid var(--ink);
  border-radius: 10px;
  box-shadow: 8px 8px 0 var(--ink);
  text-align: center;
}
#premium::backdrop { background: rgba(20, 0, 40, .7); }
#premium h2 { font-size: 15px; color: var(--prem); margin: 0 0 12px; }
#premium p { margin: 0 0 10px; }
#premium ul { list-style: none; padding: 0; margin: 12px 0; text-align: left; font-size: 10px; }
#premium .fine { font-size: 8px; line-height: 1.6; color: #777; text-align: left; }
#premium li { padding: 4px 0; border-bottom: 2px dashed rgba(0,0,0,.2); }
.qr img { width: 180px; height: 180px; margin: 6px auto; display: block; border: 4px solid var(--ink); background: #fff; object-fit: contain; image-rendering: pixelated; }

#premium form button, #tutOk {
  font-family: var(--px);
  font-size: 12px;
  padding: 12px 18px;
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
}
#premium form button:active, #tutOk:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- tutorial ---------- */
#tut { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#blocker { position: absolute; inset: 0; pointer-events: auto; }
#tut.typing #blocker { display: none; }
#spot {
  position: fixed;
  border: 4px dashed var(--gold);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .7);
  transition: all .35s;
}
#bubble {
  position: fixed;
  width: min(380px, calc(100vw - 32px));
  padding: 16px;
  background: #fff;
  border: 4px solid var(--ink);
  border-radius: 8px;
  box-shadow: 6px 6px 0 var(--ink);
  font-size: 11px;
  line-height: 1.8;
  pointer-events: auto;
  transition: top .35s, left .35s;
}
#bubble p { margin: 0 0 12px; }
#tut.typing #tutOk { display: none; }
#tut.typing #bubble p { margin: 0; }
#tutOk { display: block; margin-left: auto; }
