:root {
  --bg: #140a26;
  --panel: rgba(28, 14, 52, 0.94);
  --ink: #fff;
  --muted: #c9b8ea;
  --gold: #ffc93c;
  --pink: #ff4fa3;
  --cyan: #7bdff2;
  --red: #ff2a3a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 600 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
#c { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.top { position: absolute; top: calc(10px + var(--safe-t)); left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r));
  display: flex; align-items: center; gap: 8px; }
.pill { display: flex; align-items: center; gap: 7px; height: 42px; padding: 0 14px 0 9px; border-radius: 21px;
  background: rgba(10, 4, 22, 0.62); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14); font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
#winsPill { margin-left: auto; }
.round { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: rgba(10, 4, 22, 0.62); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid rgba(255, 255, 255, 0.14); }
.timer { position: absolute; left: 50%; top: 54px; transform: translateX(-50%); min-width: 64px; height: 50px; padding: 0 14px;
  border-radius: 14px; display: grid; place-items: center; background: #120404; border: 2px solid #3a1010;
  box-shadow: 0 0 18px rgba(255, 59, 47, 0.35) inset; }
.timer span { font: 800 32px/1 ui-monospace, Menlo, Consolas, monospace; color: #ff3b2f; text-shadow: 0 0 10px #ff3b2f; }
.timer.urgent span { animation: blink 0.5s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
.hidden { display: none !important; }

.hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(176px + var(--safe-b)); max-width: calc(100% - 24px);
  padding: 7px 14px; border-radius: 12px; background: rgba(10, 4, 22, 0.55); color: var(--muted); font-size: 13px; text-align: center; white-space: nowrap; }
.toast { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(0.8); opacity: 0; transition: 0.25s;
  padding: 12px 22px; border-radius: 16px; background: rgba(10, 4, 22, 0.8); font-size: 20px; font-weight: 800; text-align: center;
  max-width: calc(100% - 40px); pointer-events: none !important; }
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.good { color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.toast.bad { color: #ffb3c6; }

.bottom { position: absolute; left: calc(18px + var(--safe-l)); right: calc(18px + var(--safe-r)); bottom: calc(18px + var(--safe-b));
  display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; pointer-events: none; }
.bottom > * { pointer-events: auto; }
#stick { position: relative; width: 148px; height: 148px; border-radius: 50%; touch-action: none; flex: none;
  background: radial-gradient(circle, rgba(255,255,255,0.08) 0 38%, rgba(10, 4, 22, 0.55) 39% 100%);
  border: 2px solid rgba(255, 255, 255, 0.18); transition: opacity 0.3s; }
#stick::before { content: ""; position: absolute; inset: 14px; border-radius: 50%;
  background: conic-gradient(from -22.5deg, rgba(255,255,255,.14) 0 45deg, transparent 0 90deg, rgba(255,255,255,.14) 0 135deg, transparent 0 180deg, rgba(255,255,255,.14) 0 225deg, transparent 0 270deg, rgba(255,255,255,.14) 0 315deg, transparent 0); opacity: .5; }
#stick.off { opacity: 0.45; }
#knob { position: absolute; left: 50%; top: 50%; width: 66px; height: 66px; margin: -33px 0 0 -33px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff8a95, #d7263d 55%, #7d0d1d); box-shadow: 0 6px 14px rgba(0,0,0,.5), inset 0 -3px 6px rgba(0,0,0,.35); }
.cam { font-size: 14px; padding: 0 12px; gap: 6px; }
@media (max-width: 420px) { .cam span { display: none; } .cam { padding: 0 11px; } }
.arcade { width: 132px; height: 132px; border-radius: 50%; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 40% 32%, #ff7b86, var(--red) 52%, #a3000f); color: #fff; font-weight: 900; font-size: 21px; letter-spacing: 0.5px;
  box-shadow: 0 0 0 7px #d8dde3, 0 0 0 9px #8a9099, 0 10px 22px rgba(0,0,0,.6), 0 0 34px rgba(255, 42, 58, 0.55), inset 0 -6px 10px rgba(0,0,0,.3);
  text-shadow: 0 2px 2px rgba(0,0,0,.35); transition: transform 0.08s, filter 0.2s; touch-action: none; }
.arcade small { font-size: 12px; font-weight: 700; opacity: 0.9; }
.arcade:active { transform: scale(0.94); }
.arcade.busy { filter: saturate(0.25) brightness(0.65); }

#shakeBtn:active { transform: rotate(-12deg) scale(0.92); }
#shakeBtn.locked { opacity: 0.35; }
/* TILT scare: blackout, red strobe, slam-in text, screen jolt */
#tiltFx { position: fixed; inset: 0; z-index: 30; pointer-events: none; display: grid; place-items: center;
  animation: tiltBg 4s linear forwards; }
@keyframes tiltBg {
  0% { background: #000; } 7% { background: #000; }
  8%, 18%, 28%, 38%, 48%, 58% { background: rgba(255, 0, 20, 0.55); }
  13%, 23%, 33%, 43%, 53%, 63% { background: rgba(60, 0, 0, 0.25); }
  85% { background: rgba(60, 0, 0, 0.2); } 100% { background: transparent; } }
.tiltBox { display: flex; flex-direction: column; align-items: center; gap: 8px; animation: tiltSlam 4s cubic-bezier(.2,1.8,.4,1) forwards; }
.tiltBox b { font: 900 min(34vw, 190px)/0.9 Impact, "Arial Black", system-ui, sans-serif; color: #ff1a2e; letter-spacing: 4px;
  text-shadow: 0 0 30px #ff0010, 0 0 80px #ff0010, 0 6px 0 #5a0008; -webkit-text-stroke: 3px #fff; }
.tiltBox span { padding: 6px 14px; border-radius: 10px; background: #000c; font-size: 16px; font-weight: 800; color: #fff; text-align: center; }
@keyframes tiltSlam {
  0%, 7% { transform: scale(4); opacity: 0; } 9% { transform: scale(0.9); opacity: 1; }
  11% { transform: scale(1.08) rotate(-3deg); } 13% { transform: scale(1) rotate(2deg); } 15% { transform: rotate(0); }
  85% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(0.96); } }
body.jolt #c, body.jolt #hud { animation: jolt 0.5s linear; }
@keyframes jolt { 10% { transform: translate(-14px, 8px) rotate(-1deg); } 25% { transform: translate(12px, -10px) rotate(1deg); }
  40% { transform: translate(-9px, 6px); } 60% { transform: translate(6px, -4px); } 80% { transform: translate(-3px, 2px); } }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: rgba(6, 2, 14, 0.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); z-index: 10; animation: fade 0.2s; }
@keyframes fade { from { opacity: 0; } }
.panel { position: relative; width: min(380px, 100%); max-height: 100%; overflow: auto; padding: 22px 20px; border-radius: 22px;
  background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.12); box-shadow: 0 20px 60px rgba(0,0,0,.55); text-align: center; touch-action: pan-y; }
.panel.wide { width: min(560px, 100%); }
.panel h2 { margin: 0 0 12px; font-size: 24px; font-weight: 900; }
.panel p { margin: 0 0 12px; text-align: left; font-weight: 500; color: #eee4ff; }
.panel .muted, .muted { color: var(--muted); font-size: 14px; text-align: center; }
.primary { display: block; width: 100%; margin-top: 14px; height: 50px; border-radius: 14px; font-weight: 800; font-size: 17px;
  background: linear-gradient(180deg, var(--gold), #f08c00); color: #2a0640; }
.win { overflow: hidden; }
.win h2 { font-size: 30px; color: var(--gold); position: relative; }
.win img { width: 190px; height: 190px; position: relative; filter: drop-shadow(0 10px 18px rgba(0,0,0,.5)); animation: pop 0.6s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(0.2) rotate(-20deg); } }
.win p { text-align: center; font-size: 22px; font-weight: 800; margin: 4px 0 8px; position: relative; }
.rays { position: absolute; inset: -50%; background: repeating-conic-gradient(rgba(255, 201, 60, 0.12) 0 10deg, transparent 10deg 20deg); animation: spin 14s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.rarity { display: inline-block; position: relative; padding: 3px 10px; border-radius: 10px; font-size: 12px; font-weight: 800; letter-spacing: .3px; background: #3b2d5c; color: #d9ccf5; }
.rarity.rare { background: #0d4f6b; color: var(--cyan); }
.rarity.epic { background: linear-gradient(90deg, #ff4fa3, #ffc93c); color: #2a0640; }

.sheet { text-align: left; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 50px; padding: 0 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-weight: 600; text-align: left; }
.row.btn::after { content: "›"; font-size: 24px; color: var(--muted); margin-left: 8px; }
.row.btn b { margin-left: auto; color: var(--gold); }
.row input { display: none; }
.sw { position: relative; width: 48px; height: 28px; border-radius: 14px; background: #4a3a6b; transition: 0.2s; flex: none; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: 0.2s; }
.row input:checked + .sw { background: var(--pink); }
.row input:checked + .sw::after { transform: translateX(20px); }
.flags { display: flex; gap: 8px; }
.flags button { padding: 6px; border-radius: 8px; line-height: 0; opacity: 0.55; border: 2px solid transparent; }
.flags button.on { opacity: 1; border-color: var(--gold); }
.legal { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; margin: 16px 0 6px; font-size: 13px; }
.legal a { color: var(--muted); text-decoration: underline; cursor: pointer; }
.link { display: block; margin: 6px auto 0; font-size: 13px; color: #ff8fab; text-decoration: underline; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; margin-top: 8px; }
.card { position: relative; padding: 8px 6px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.card img { width: 96px; height: 96px; }
.card b { font-size: 14px; }
.card .count { position: absolute; top: 6px; right: 8px; color: var(--gold); font-weight: 900; }
.card.locked img { filter: brightness(0) opacity(0.45); }
.card.locked b { color: var(--muted); }

#loading { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 16px; background: var(--bg);
  transition: opacity 0.5s; font-size: 28px; font-weight: 900; letter-spacing: 3px; color: var(--gold); }
#loading.done { opacity: 0; pointer-events: none; }
.spin { width: 54px; height: 54px; border-radius: 50%; border: 5px solid rgba(255,255,255,.15); border-top-color: var(--pink); animation: spin 0.9s linear infinite; }

/* landscape phones: controls to the sides, smaller */
@media (orientation: landscape) { .hint { bottom: auto; top: calc(64px + var(--safe-t)); } }
@media (orientation: landscape) and (max-height: 520px) {
  #stick { width: 128px; height: 128px; }
  .arcade { width: 112px; height: 112px; font-size: 18px; }
  .hint { display: none; }
}
@media (max-width: 380px) {
  #stick { width: 128px; height: 128px; }
  .arcade { width: 116px; height: 116px; font-size: 19px; }
}
@media (min-width: 900px) and (pointer: fine) {
  .bottom { left: 50%; right: auto; transform: translateX(-50%); width: 760px; }
}
