:root {
  --bg: #14121c;
  --panel: #241f33;
  --ink: #f4efe2;
  --muted: #b9b0cc;
  --line: #000;
  --gold: #f5c542;
  --mint: #5fd6a4;
  --red: #e2574c;
  --felt: #1f7a5a;
  --font: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }

#app {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  gap: 8px;
}

.hud, .play { touch-action: none; } /* a second finger cancels a shot; never zoom or scroll */
.hud { display: flex; flex-direction: column; gap: 6px; }
.hud-row { display: flex; gap: 6px; align-items: center; }
.chip {
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 2px 2px 0 var(--line);
  padding: 3px 8px;
  font-weight: 800;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.chip.money { color: var(--gold); }
#hud-mult { color: var(--mint); }
.icon-btn {
  margin-left: auto;
  width: 36px; height: 32px;
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 2px 2px 0 var(--line);
  cursor: pointer;
}
.icon-btn[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }

.score-bar {
  position: relative;
  height: 22px;
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 2px 2px 0 var(--line);
}
.score-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--mint); transition: width 0.3s steps(6); }
.score-text { position: relative; display: block; text-align: center; font-weight: 800; font-size: 13px; line-height: 18px; text-shadow: 1px 1px 0 #000; font-variant-numeric: tabular-nums; }
.score-bar.done .score-fill { background: var(--gold); }

.shots { display: flex; gap: 4px; flex-wrap: wrap; min-height: 12px; }
.shot-pip { width: 12px; height: 12px; background: var(--ink); border: 2px solid var(--line); }
.shot-pip.used { background: #3a3448; }

.table-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#table {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
  display: block;
  /* width and height are set by fitTable() in app.js so the table never stretches; the rail's corners are round */
  filter: drop-shadow(4px 4px 0 var(--line));
}

.toast {
  position: absolute;
  left: 50%; top: 40%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 3px 3px 0 var(--line);
  padding: 6px 12px;
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.toast.show { opacity: 1; animation: pop 0.25s steps(3); }
.toast.big { color: var(--gold); font-size: 20px; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.7); } to { transform: translate(-50%, -50%) scale(1); } }

.controls { display: flex; flex-direction: column; gap: 6px; }
.aim-row { display: flex; gap: 6px; align-items: stretch; }
.btn {
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 3px 3px 0 var(--line);
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  min-height: 48px;
}
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: #1a1408; }
.btn.small { min-width: 52px; }
.btn.wide { width: 100%; }
.hint { flex: 1; margin: 0; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); line-height: 1.3; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 8, 16, 0.82);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 10;
}
.overlay[hidden] { display: none; }
.panel {
  width: min(420px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 6px 6px 0 var(--line);
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
h1, h2 { margin: 0; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; text-shadow: 2px 2px 0 #000; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
.lead { margin: 0; color: var(--ink); line-height: 1.5; }
.rule, .best { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.map { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.map li { display: flex; justify-content: space-between; border: 2px solid var(--line); padding: 6px 10px; background: #1b1726; font-weight: 700; font-variant-numeric: tabular-nums; }
.map li.boss { color: var(--red); }
.offers { display: flex; flex-direction: column; gap: 8px; }
.offer {
  text-align: left;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 2px 10px;
  background: #1b1726;
  border: 2px solid var(--line);
  box-shadow: 3px 3px 0 var(--line);
  padding: 10px 12px;
  cursor: pointer;
  min-height: 56px;
}
.offer:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }
.offer:disabled { opacity: 0.45; cursor: not-allowed; }
.offer .t { font-weight: 800; }
.offer .p { color: var(--gold); font-weight: 800; grid-row: span 2; align-self: center; }
.offer .d { color: var(--muted); font-size: 12px; }
.offer.sold .p { color: var(--mint); }
.shop-actions { display: flex; gap: 8px; }
.shop-actions .btn { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .btn, .chip, .power, .offer { border-color: ButtonText; }
}

.chip-btn { cursor: pointer; color: var(--ink); min-height: 32px; }

/* score count-up: shot type, then Points × Mult ticking up, then the total */
.theatre {
  position: absolute;
  left: 50%; top: 38%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 4px 4px 0 var(--line);
  padding: 10px 14px;
  pointer-events: none;
  min-width: 210px;
}
.theatre[hidden] { display: none; }
.theatre-type { font-weight: 900; font-size: 18px; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; text-shadow: 2px 2px 0 #000; }
.theatre-boxes { display: flex; align-items: center; gap: 6px; }
.th-box { min-width: 76px; text-align: center; font-weight: 900; font-size: 22px; padding: 4px 8px; border: 2px solid var(--line); font-variant-numeric: tabular-nums; color: #fff; text-shadow: 2px 2px 0 #000; }
.th-points { background: #2f5fd0; }
.th-mult { background: #d8392f; }
.th-x { font-weight: 900; font-size: 20px; }
.th-box.bump { animation: bump 0.12s steps(2); }
@keyframes bump { 50% { transform: scale(1.15); } }
.theatre-total { font-weight: 900; font-size: 26px; min-height: 30px; font-variant-numeric: tabular-nums; text-shadow: 2px 2px 0 #000; }
.theatre-total.fire { color: #ffb02e; text-shadow: 0 0 6px #ff5a1f, 2px 2px 0 #000; animation: flicker 0.18s steps(2) infinite; }
@keyframes flicker { 50% { color: #ffd34e; } }

.shot-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.shot-list li { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; border: 2px solid var(--line); background: #1b1726; padding: 6px 10px; }
.shot-list .n { font-weight: 800; }
.shot-list .v { font-weight: 800; font-variant-numeric: tabular-nums; }
.shot-list .v b { color: #6f9bff; }
.shot-list .v i { color: #ff7a6e; font-style: normal; }
.shot-list .r { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }

/* modifier icons: 12×12 pixel art scaled up crisply */
.icon { width: 36px; height: 36px; image-rendering: pixelated; image-rendering: crisp-edges; flex: none; }
.offer .icon { grid-row: span 2; align-self: center; }
.shot-list li { grid-template-columns: auto 1fr auto; align-items: center; }
.shot-list .icon { grid-row: span 2; }
.shot-list .r { grid-column: 2 / -1; }
.theatre-type { display: flex; align-items: center; gap: 8px; }
.theatre-type .icon { width: 30px; height: 30px; }

/* coin tray: one area holding the coins (modifier section, then special section); only held coins are shown */
.mods {
  display: flex; gap: 0; align-items: stretch; touch-action: none;
  background: #1b1726; border: 2px solid var(--line); box-shadow: 2px 2px 0 var(--line);
  padding: 4px; min-height: 56px;
}
.tray-section { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; justify-content: center; min-width: 0; }
.tray-specials { flex: 0 0 auto; min-width: 46px; margin-left: 4px; padding-left: 6px; border-left: 2px dashed #3a3448; }
.coin-slot {
  flex: none; width: 42px; height: 42px; padding: 0; display: grid; place-items: center;
  background: transparent; border: 3px solid var(--fx, #888); border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line), 0 0 10px -2px var(--fx, transparent);
  cursor: pointer; animation: deal 0.25s steps(4);
}
.coin-slot .icon { width: 32px; height: 32px; }
.coin-slot.effect-pts { --fx: #3f7bff; }
.coin-slot.effect-mult { --fx: #e2403a; }
.coin-slot.effect-shot { --fx: #3fbf6a; }
.coin-slot:active { transform: translate(1px, 1px); }
@keyframes deal { from { transform: translateY(-8px) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
.coin-slot.idle { animation: sway 3s steps(6) infinite; }
@keyframes sway { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-1.5deg); } }
@media (forced-colors: active) { .coin-slot { border-color: ButtonText; } }

/* info pop-up for balls and cards: pops in, and its title letters wave gently like Balatro's */
.tip {
  position: fixed;
  z-index: 20;
  max-width: 260px;
  background: #f4efe2;
  color: #1a1622;
  border: 3px solid var(--line);
  box-shadow: 4px 4px 0 var(--line);
  padding: 8px 10px;
  transform-origin: 50% 100%;
  animation: tipin 0.18s steps(3);
}
.tip[hidden] { display: none; }
@keyframes tipin { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tip-title { font-weight: 900; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; white-space: nowrap; }
.tip-title span { display: inline-block; animation: wave 1.2s steps(4) infinite; }
@keyframes wave { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
.tip-text { font-size: 12px; line-height: 1.45; font-weight: 700; }
.tip-text span { opacity: 0; animation: letter 0.01s forwards; }
@keyframes letter { to { opacity: 1; } }
.tip-actions { display: flex; gap: 6px; margin-top: 6px; }
.tip-actions:empty { display: none; }
.tip-actions .btn { min-height: 40px; padding: 6px 10px; flex: 1; }
.tip::after { content: ""; position: absolute; left: var(--arrow, 50%); bottom: -9px; width: 12px; height: 12px; background: #f4efe2; border-right: 3px solid var(--line); border-bottom: 3px solid var(--line); transform: translateX(-50%) rotate(45deg); }
.tip.below::after { top: -9px; bottom: auto; transform: translateX(-50%) rotate(225deg); }
.offer.unavailable .p { color: var(--muted); }
#btn-undo:disabled { opacity: 0.4; cursor: not-allowed; }

.tip-actions .btn { background: #241f33; color: var(--ink); }
.tip-actions .btn:first-child { background: var(--gold); color: #1a1408; }

/* ---------------- layout: score bar on top; stats | table | cards below; a carpet under everything */
body { background-color: #3a1420; background-size: 192px 192px; image-rendering: pixelated; }
#app { gap: 6px; padding-left: 6px; padding-right: 6px; }
.play { flex: 1; min-height: 0; display: flex; gap: 6px; align-items: stretch; }
.side { width: 52px; flex: none; display: flex; flex-direction: column; gap: 5px; }
.side .chip { display: flex; align-items: center; justify-content: center; text-align: center; font-size: 11px; padding: 4px 2px; min-height: 30px; line-height: 1.1; }
.side .chip-btn { min-height: 36px; font-size: 13px; }
.side .chip.mult { color: var(--mint); }
.side-right .mods { flex-direction: column; flex: 1; padding: 4px 2px; }
.side-right .tray-section { flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; }
.side-right .tray-specials { flex: none; margin: 6px 0 0; padding: 6px 0 0; border-left: 0; border-top: 2px dashed #3a3448; min-height: 46px; }
.power-btn {
  margin-top: auto;
  min-height: 92px;
  background: #e2574c;
  color: #fff;
  font: 900 28px/1 var(--font);
  border: 2px solid var(--line);
  box-shadow: 3px 3px 0 var(--line);
  touch-action: none;
  cursor: grab;
}
.power-btn.pulling { background: #f5c542; color: #1a1408; transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }
.power-btn:disabled { opacity: 0.4; }
.table-wrap { min-width: 0; }
@media (pointer: fine) { .power-btn { display: none; } }

/* disabled controls stay solid over the carpet */
.power-btn:disabled { opacity: 1; background: #4a2a2a; color: #8a6a6a; }
#btn-undo:disabled { opacity: 1; color: #5a5468; background: #1b1726; }

/* goo strand overlay (touch pull) */
#goo { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 15; image-rendering: pixelated; image-rendering: crisp-edges; }
/* coins */
.icon.coin { border-radius: 50%; }
/* highlighted keywords in descriptions */
.hl { font-weight: 900; }
.hl-pts { color: #2f5fd0; }
.hl-mult { color: #d8392f; }
.hl-money { color: #b8860b; }
.hl-shot { color: #1f8a4a; }
.hl-pocket { color: #c0601a; }
.hl-type { color: #1a1622; text-decoration: underline; text-decoration-thickness: 2px; }
.offer .hl-pts { color: #6f9bff; } .offer .hl-mult { color: #ff7a6e; } .offer .hl-shot { color: #5fd67e; } .offer .hl-pocket { color: #f0a060; } .offer .hl-type { color: var(--ink); }
