:root {
  --ink: #0a0909;
  --bone: #ece6d8;
  --red: #e0222c;
  --ok: #7dff4a;
  --head: 'Dela Gothic One', Impact, sans-serif;
  --body: 'Rubik', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--bone); font: 500 16px/1.3 var(--body); overflow: hidden; }
button, a, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- background: tilted rows of covers drifting ---------- */
#bg { position: fixed; inset: -40vmax; transform: rotate(-14deg); display: flex; flex-direction: column; justify-content: center; gap: 18px; z-index: 0; }
.row { display: flex; gap: 18px; width: max-content; animation: drift var(--t, 90s) linear infinite; }
.row.rev { animation-direction: reverse; }
.row img { width: 170px; height: 170px; object-fit: cover; border-radius: 6px; filter: grayscale(.85) contrast(1.15) brightness(.42); }
.row img.hot { filter: saturate(1.2) contrast(1.1) brightness(.55); }
@keyframes drift { to { transform: translateX(-50%); } }
.fx { position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.25) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 50% 45%, rgba(10,9,9,.15) 0%, rgba(10,9,9,.7) 65%, #050404 100%); }
.fx::before { content: ''; position: absolute; inset: 0; background: url(tex/dust.png) center/700px; mix-blend-mode: screen; opacity: .6; }
.fx::after { content: ''; position: absolute; inset: -100px; background: url(tex/grain.png) 0 0/180px; mix-blend-mode: overlay; opacity: .22; animation: grain .5s steps(4) infinite; }
@keyframes grain { 25% { background-position: 40px 70px } 50% { background-position: -60px 20px } 75% { background-position: 90px -40px } }

/* ---------- textured building blocks (9-slice PNGs from tools/make_textures.py) ---------- */
.screen { position: relative; z-index: 2; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.panel { border: 34px solid transparent; border-image: url(tex/panel.png) 80 fill / 34px stretch; padding: 4px 8px; filter: drop-shadow(0 18px 30px rgba(0,0,0,.7)); }
.paper { border: 16px solid transparent; border-image: url(tex/paper.png) 36 fill / 16px stretch; color: #151212; }

.slab { --img: url(tex/btn0.png); border: 26px solid transparent; border-image: var(--img) 56 fill / 26px stretch;
  background: none; padding: 0 6px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  font: 400 22px/1 var(--head); letter-spacing: .02em; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.55), 0 0 1px #000;
  transform: rotate(var(--r, 0deg)); transition: transform .12s cubic-bezier(.3,1.8,.5,1), filter .12s; user-select: none; -webkit-tap-highlight-color: transparent; }
.slab:hover { transform: rotate(var(--r, 0deg)) translateY(-3px) scale(1.02); filter: brightness(1.12); }
.slab:active { transform: rotate(var(--r, 0deg)) translateY(3px) scale(.97); filter: brightness(.9); }
.slab.s0 { --img: url(tex/btn0.png); } .slab.s1 { --img: url(tex/btn1.png); } .slab.s2 { --img: url(tex/btn2.png); }
.slab.s3 { --img: url(tex/btn3.png); }
.slab.s4 { --img: url(tex/btn4.png); }
.slab.s5 { --img: url(tex/btn5.png); color: #141111; text-shadow: 0 1px 0 rgba(255,255,255,.5); }
.slab:disabled { filter: grayscale(.8) brightness(.8); cursor: wait; }
.slab.big { font-size: 40px; padding: 6px 30px; --r: -1.5deg; }
.slab.small { font-size: 16px; border-width: 20px; border-image-width: 20px; padding: 0 4px; }

/* ---------- start ---------- */
.logo { margin: 0 0 6px; font: 400 clamp(54px, 11vw, 128px)/.86 var(--head); text-align: center; letter-spacing: -.02em; transform: rotate(-4deg);
  -webkit-mask: url(tex/erode.png) 0 0/340px; mask: url(tex/erode.png) 0 0/340px; }
.logo span { display: block; color: var(--bone); text-shadow: 5px 5px 0 var(--red), 10px 10px 0 #000; }
.logo span + span { color: var(--red); text-shadow: 5px 5px 0 var(--bone), 10px 10px 0 #000; margin-left: .5em; }
.tag { margin: 8px 0 22px; font: 700 18px var(--body); text-transform: uppercase; letter-spacing: .08em; transform: rotate(2deg); }
.setup { width: min(460px, 96vw); display: flex; flex-direction: column; gap: 16px; align-items: stretch; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font: 900 12px var(--body); letter-spacing: .25em; text-transform: uppercase; opacity: .6; }
.field input { border: 14px solid transparent; border-image: url(tex/paper.png) 36 fill / 14px stretch; background: none; color: #151212;
  font: 400 24px var(--head); padding: 2px 6px; outline: none; }
.seg { display: flex; gap: 8px; }
.seg .slab { flex: 1; height: 72px; opacity: .45; filter: grayscale(.7); }
.seg .slab.on { opacity: 1; filter: none; --r: -1deg; }
.hint { margin: 0; font-size: 13px; opacity: .55; text-align: center; }
.life { margin: 14px 0 0; font-size: 13px; opacity: .6; text-align: center; letter-spacing: .04em; }

/* ---------- game ---------- */
#game { justify-content: flex-start; gap: 6px; }
.hud { width: min(1100px, 100%); display: flex; align-items: center; justify-content: space-between; }
.hud b { display: block; font: 400 34px/1 var(--head); }
.hud small { font: 900 11px var(--body); letter-spacing: .25em; text-transform: uppercase; opacity: .55; }
.hud-r { text-align: right; }
.hud-c { position: relative; z-index: 0; font: 400 22px/1 var(--head); color: var(--bone); text-shadow: 2px 2px 0 #000; padding: 10px 26px; transform: rotate(-3deg); }
.hud-c:empty { visibility: hidden; }
.hud-c::before { content: ''; position: absolute; inset: 0 -6px; z-index: -1; background: var(--red); -webkit-mask: url(tex/brush.png) center/100% 100%; mask: url(tex/brush.png) center/100% 100%; }
.hud-c.bump { animation: bump .35s cubic-bezier(.3,1.8,.5,1); }
@keyframes bump { from { transform: rotate(-3deg) scale(1.35); } }
.stage { margin-top: 5vh; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.disc { position: relative; width: min(34vh, 300px); aspect-ratio: 1; }
#viz { position: absolute; inset: -14%; width: 128%; height: 128%; }
.q { position: absolute; inset: 18%; border-radius: 50%; display: grid; place-items: center; font: 400 min(13vh, 110px)/1 var(--head); color: var(--bone);
  background: radial-gradient(circle, #1b1717 0 55%, #0c0b0b 56% 100%); box-shadow: inset 0 0 0 3px rgba(255,255,255,.08), 0 0 0 6px #000;
  -webkit-mask: url(tex/erode.png) center/260px; mask: url(tex/erode.png) center/260px; }
.disc.playing .q { animation: thump .21s ease-out infinite alternate; }
@keyframes thump { to { transform: scale(1.06) rotate(2deg); } }
#reveal { position: absolute; inset: 4%; width: 92%; height: 92%; object-fit: cover; border: 6px solid var(--bone); transform: rotate(-4deg) scale(.6); opacity: 0;
  transition: transform .35s cubic-bezier(.2,1.6,.4,1), opacity .2s; box-shadow: 0 14px 30px #000; }
#reveal.on { transform: rotate(-4deg) scale(1); opacity: 1; }
.stamp { position: absolute; left: 50%; top: 58%; width: 115%; transform: translate(-50%, -50%) rotate(-12deg) scale(2.2); opacity: 0; pointer-events: none; }
.stamp.on { animation: stamp .32s cubic-bezier(.3,1.5,.6,1) forwards; }
@keyframes stamp { to { transform: translate(-50%, -50%) rotate(-12deg) scale(1); opacity: 1; } }
.pts { position: absolute; left: 104%; top: 38%; white-space: nowrap; z-index: 3; font: 400 40px var(--head); color: var(--ok); text-shadow: 3px 3px 0 #000; opacity: 0; transform: rotate(8deg); }
.pts.on { animation: pts 1.2s ease-out forwards; }
@keyframes pts { 0% { opacity: 0; transform: translateY(20px) rotate(8deg) scale(.5) } 20% { opacity: 1; transform: rotate(8deg) scale(1.15) } 100% { opacity: 1; transform: translateY(-10px) rotate(8deg) } }
.timer { width: min(520px, 86vw); height: 26px; position: relative; background: rgba(255,255,255,.08);
  -webkit-mask: url(tex/brush.png) center/100% 100%; mask: url(tex/brush.png) center/100% 100%; }
.timer i { position: absolute; inset: 0; transform-origin: left; background: linear-gradient(90deg, var(--red), #ff7a1a); }

.opts { width: min(1100px, 100%); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 10px; margin-top: auto; }
.opt { min-height: 132px; justify-content: flex-start; gap: 12px; text-align: left; padding: 0 8px; }
.opt img.ico { width: clamp(56px, 6.5vw, 86px); height: clamp(56px, 6.5vw, 86px); flex: none; object-fit: cover; border: 3px solid #0a0909; box-shadow: 3px 3px 0 rgba(0,0,0,.6); transform: rotate(-3deg); }
.opt span { display: flex; flex-direction: column; gap: 4px; min-width: 0; overflow-wrap: break-word; }
.opt b { font: 400 clamp(16px, 1.9vw, 25px)/1.05 var(--head); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.opt small { font: 700 16px var(--body); opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: none; }
.opts.done .opt { pointer-events: none; filter: grayscale(1) brightness(.4); }
.opts.done .opt.right { filter: none; transform: rotate(var(--r)) scale(1.04); z-index: 1; }
.opts.done .opt.picked:not(.right) { filter: grayscale(.3) brightness(.65); animation: shake .35s; }
@keyframes shake { 25% { translate: -8px } 50% { translate: 7px } 75% { translate: -4px } }
.banner { position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; pointer-events: none; font: 400 clamp(60px, 14vw, 160px)/1 var(--head); color: var(--bone);
  text-shadow: 6px 6px 0 var(--red), 12px 12px 0 #000; animation: banner .8s ease-out forwards; -webkit-mask: url(tex/erode.png) 0 0/300px; mask: url(tex/erode.png) 0 0/300px; }
@keyframes banner { 0% { transform: scale(2) rotate(-6deg); opacity: 0 } 25% { transform: scale(1) rotate(-6deg); opacity: 1 } 80% { opacity: 1 } 100% { transform: scale(.9) rotate(-6deg); opacity: 0 } }

/* ---------- results ---------- */
.res { width: min(640px, 98vw); display: flex; flex-direction: column; align-items: center; gap: 10px; max-height: calc(100vh - 20px); overflow-y: auto; scrollbar-width: none; }
.rank { text-align: center; }
.rank small { font: 900 11px var(--body); letter-spacing: .3em; text-transform: uppercase; opacity: .55; }
.rank b { display: block; font: 400 clamp(34px, 7vw, 54px)/1 var(--head); color: var(--red); text-shadow: 3px 3px 0 #000; transform: rotate(-2deg); }
.rank em { font-style: normal; opacity: .7; }
.big-score { position: relative; text-align: center; padding: 6px 40px; }
.big-score::before { content: ''; position: absolute; inset: 10% -10%; background: var(--red); -webkit-mask: url(tex/brush.png) center/100% 100%; mask: url(tex/brush.png) center/100% 100%; z-index: -1; transform: rotate(-3deg); }
.big-score b { display: block; font: 400 64px/1 var(--head); text-shadow: 4px 4px 0 #000; }
.big-score small { font: 900 12px var(--body); letter-spacing: .3em; text-transform: uppercase; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }
.stats div { text-align: center; padding: 6px 2px; background: rgba(255,255,255,.04); border-top: 2px solid rgba(255,255,255,.08); }
.stats b { display: block; font: 400 26px var(--head); }
.stats small { font: 700 11px var(--body); text-transform: uppercase; letter-spacing: .12em; opacity: .55; }
.list { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 4px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 4px; background: rgba(255,255,255,.03); }
.list img { width: 40px; height: 40px; object-fit: cover; }
.list span { flex: 1; min-width: 0; }
.list b { display: block; font: 700 14px var(--body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list small { opacity: .6; font-size: 12px; }
.list i { font: 400 15px var(--head); font-style: normal; }
.list li.ok i { color: var(--ok); } .list li.no i { color: var(--red); }
.actions, .socials { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.actions .slab { min-width: 190px; height: 76px; }

/* ---------- share sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(0,0,0,.78); padding: 10px; }
.sheet-in { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; max-height: 98vh; }
#card { max-height: calc(98vh - 260px); max-width: 86vw; box-shadow: 0 10px 40px #000; transform: rotate(-1deg); }
.socials .slab, .sheet .actions .slab { height: 58px; min-width: 120px; }
.x-close { position: absolute; top: -26px; right: -26px; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--red); font: 400 20px var(--head); cursor: pointer; box-shadow: 3px 3px 0 #000; }

@media (max-width: 760px) {
  .opts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 4px; }
  .opt { min-height: 100px; gap: 8px; border-width: 20px; border-image-width: 20px; }
  .opt img.ico { width: 58px; height: 58px; }
  .opt b { font-size: 17px; } .opt small { font-size: 12px; }
  .disc { width: min(26vh, 220px); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row img { width: 110px; height: 110px; }
  .hud b { font-size: 26px; }
}
