@font-face { font-family: 'Biolinum'; src: url('fonts/LinBiolinum_R.otf') format('opentype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Biolinum'; src: url('fonts/LinBiolinum_RB.otf') format('opentype'); font-weight: 700; font-display: swap; }

:root {
  --ink: #2b3440; --muted: #4e5866; --faint: #747d89;
  --blue: #3b82f6; --purple: #8b5cf6; --pink: #ec4899; --amber: #f59e0b; --green: #10a37f; --red: #e5484d;
  --you: #f59e0b; --a: #3b82f6; --b: #8b5cf6;
  --panel: #f5f6f8; --line: #e3e6eb;
  --bg1: #eef2fb; --bg2: #f8f1fb;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--ink); overflow: hidden;
  font: 18px/1.5 'Biolinum', 'Linux Biolinum O', Georgia, serif; -webkit-font-smoothing: antialiased;
  background: radial-gradient(1200px 700px at 20% 10%, #f3ecff 0%, transparent 60%),
              radial-gradient(1000px 700px at 90% 90%, #e6f0ff 0%, transparent 60%), linear-gradient(160deg, var(--bg1), var(--bg2));
}
button { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ 3D scene */
#bg { position: fixed; inset: 0; perspective: 1300px; perspective-origin: 50% 45%; overflow: hidden; pointer-events: none; transition: filter .6s; }
#bgcam { position: absolute; inset: 0; transform-style: preserve-3d; }
#viewport { position: fixed; inset: 0; perspective: 1300px; perspective-origin: 50% 45%; overflow-x: hidden; overflow-y: auto; }
#cam { position: relative; min-height: 100%; transform-style: preserve-3d; display: grid; place-items: center; padding: 28px 16px; pointer-events: none; }

#world { position: absolute; inset: 0; transform-style: preserve-3d; }
#world .wall { position: absolute; left: 50%; top: 50%; width: 4400px; height: 2300px; margin: -1150px 0 0 -2200px;
  transform: translateZ(-900px); display: grid; grid-template-columns: repeat(16, 1fr); gap: 22px; align-content: center; opacity: .2;
  filter: saturate(.7) blur(1.2px); transition: opacity 1.2s, filter 1.2s; }
#world .wall i { display: block; border-radius: 14px; background: #fff center / cover no-repeat; aspect-ratio: 3 / 2;
  box-shadow: 0 10px 30px rgba(31, 41, 55, .18); }
#world .floor { position: absolute; left: 50%; top: 50%; width: 5000px; height: 3000px; margin: -1500px 0 0 -2500px;
  transform: translateY(560px) rotateX(90deg); opacity: .35;
  background-image: linear-gradient(rgba(43, 52, 64, .18) 1.5px, transparent 1.5px), linear-gradient(90deg, rgba(43, 52, 64, .18) 1.5px, transparent 1.5px);
  background-size: 120px 120px; -webkit-mask-image: radial-gradient(closest-side, #000 30%, transparent 100%); mask-image: radial-gradient(closest-side, #000 30%, transparent 100%);
  transition: opacity 1.2s; }

/* ------------------------------------------------------------------ deck (glass card) */
#deck { position: relative; width: min(1160px, 100%); border-radius: 30px; padding: 18px 22px 14px;
  background: rgba(255, 255, 255, .62); -webkit-backdrop-filter: blur(26px) saturate(1.7); backdrop-filter: blur(26px) saturate(1.7);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .95), inset 0 0 0 1px rgba(255, 255, 255, .55), 0 40px 80px -20px rgba(31, 41, 55, .35), 0 12px 30px rgba(31, 41, 55, .12);
  transform-style: flat; will-change: transform; pointer-events: auto; }
#deck .glare { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; mix-blend-mode: soft-light;
  background: radial-gradient(600px 400px at var(--gx, 30%) var(--gy, 0%), rgba(255, 255, 255, .9), transparent 60%); }

.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 22px; letter-spacing: .2px; }
.logo { width: 30px; height: 30px; border-radius: 10px; position: relative; background: linear-gradient(135deg, var(--blue), var(--purple) 55%, var(--pink));
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, .7), 0 4px 10px rgba(139, 92, 246, .35); }
.logo i { position: absolute; left: 7px; right: 7px; top: 14px; height: 3px; border-radius: 2px; background: #fff; }
.logo i::before, .logo i::after { content: ''; position: absolute; top: -5px; width: 3px; height: 13px; border-radius: 2px; background: #fff; }
.logo i::before { left: 0; } .logo i::after { right: 0; }
.roundtag { color: var(--muted); font-size: 16px; font-variant-numeric: tabular-nums; }
.foot { margin-top: 12px; color: var(--faint); font-size: 13px; text-align: center; }

/* glass pills and buttons */
.btn { border: 0; cursor: pointer; border-radius: 999px; padding: 12px 28px; font-weight: 700; font-size: 18px; transition: transform .15s, box-shadow .2s, opacity .2s; }
.btn.primary { color: #fff; background: linear-gradient(135deg, #4f8df7, #8b5cf6 60%, #d946a8);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, .6), inset 0 -2px 6px rgba(0, 0, 0, .12), 0 8px 22px rgba(139, 92, 246, .35); }
.btn.primary:hover { transform: translateY(-1px) scale(1.02); }
.btn.primary:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.ghost { color: #fff; background: rgba(255, 255, 255, .14); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .55); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }

/* ------------------------------------------------------------------ menu */
.menu { text-align: center; padding: 18px 10px 6px; }
.menu h1 { font-size: clamp(34px, 5vw, 58px); line-height: 1.05; margin: 8px 0 12px; }
.menu h1 em { font-style: normal; background: linear-gradient(90deg, var(--blue), var(--purple), var(--pink)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lede { max-width: 640px; margin: 0 auto 22px; color: var(--muted); font-size: 19px; }
.versus { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 26px; }
.vs-card { min-width: 170px; padding: 12px 16px; border-radius: 18px; background: rgba(255, 255, 255, .75); display: flex; flex-direction: column;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 55%, transparent), 0 6px 16px rgba(31, 41, 55, .08); }
.vs-card b { color: var(--c); font-size: 20px; } .vs-card span { color: var(--faint); font-size: 14px; }
.vs-x { font-weight: 700; color: var(--faint); font-size: 20px; padding: 0 4px; }
.c-you { --c: var(--you); } .c-a { --c: var(--a); } .c-b { --c: var(--b); }

.pick { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 22px; }
.pick-label { color: var(--muted); font-size: 15px; text-transform: uppercase; letter-spacing: 1.5px; }
.seg { position: relative; display: inline-flex; padding: 5px; border-radius: 999px; background: rgba(120, 130, 150, .14);
  box-shadow: inset 0 1px 3px rgba(31, 41, 55, .12); }
.seg button { position: relative; z-index: 1; border: 0; background: none; cursor: pointer; padding: 9px 22px; border-radius: 999px; font-weight: 700; font-size: 18px; color: var(--muted);
  font-variant-numeric: tabular-nums; transition: color .25s; }
.seg button[aria-checked=true] { color: var(--ink); }
.seg-thumb { position: absolute; top: 5px; bottom: 5px; left: 0; width: 0; border-radius: 999px; background: rgba(255, 255, 255, .92);
  box-shadow: inset 0 1px 1px #fff, 0 3px 10px rgba(31, 41, 55, .15), 0 0 0 .5px rgba(31, 41, 55, .06);
  transition: left .45s cubic-bezier(.3, 1.5, .5, 1), width .45s cubic-bezier(.3, 1.5, .5, 1); }
/* loader: nothing shows until every image and font is in */
#loader { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  transition: opacity .6s, visibility .6s; }
#loader .brand { font-size: 26px; }
#loader .lbar { width: min(320px, 70vw); height: 8px; border-radius: 8px; background: rgba(120, 130, 150, .18); overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(31, 41, 55, .12); }
#loader .lbar i { display: block; height: 100%; width: 0; border-radius: 8px; background: linear-gradient(90deg, var(--blue), var(--purple), var(--pink)); transition: width .25s ease-out; }
#loader .lpct { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
body.loading #bg, body.loading #viewport { opacity: 0; visibility: hidden; }
#bg, #viewport { transition: opacity .8s ease-out; }
body:not(.loading) #loader { opacity: 0; visibility: hidden; pointer-events: none; }

/* ------------------------------------------------------------------ play */
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.player { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; border-radius: 16px; background: rgba(255, 255, 255, .72);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 35%, transparent); transition: transform .35s cubic-bezier(.3, 1.6, .5, 1), box-shadow .3s; }
.player .pname { font-weight: 700; color: var(--c); }
.player .pscore { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.player.won { transform: translateY(-2px) scale(1.04); box-shadow: inset 0 0 0 2.5px var(--c), 0 8px 20px color-mix(in srgb, var(--c) 35%, transparent); }
.player.bump .pscore { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.45); } }

.playgrid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 18px; align-items: start; }
.stage { position: relative; aspect-ratio: 3 / 2; border-radius: 20px; overflow: hidden; background: #dfe3ea;
  box-shadow: 0 18px 40px -12px rgba(31, 41, 55, .45); }
.stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: opacity .35s; user-select: none; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.stage .tag { position: absolute; left: 12px; bottom: 12px; padding: 3px 12px; border-radius: 999px; font-size: 13px; color: #fff;
  background: rgba(20, 24, 32, .45); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.ruler-halo { stroke: #fff; stroke-width: 10; stroke-linecap: round; opacity: .9; }
.ruler-line { stroke: var(--you); stroke-width: 5; stroke-linecap: round; stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw .6s .1s ease-out forwards; }
.ruler-end { fill: var(--you); stroke: #fff; stroke-width: 3.5; transform-box: fill-box; transform-origin: center; animation: pop .35s ease-out backwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop { from { transform: scale(0); } }
.gt-label rect { fill: rgba(16, 163, 127, .95); }
.gt-label text { fill: #fff; font: 700 26px 'Biolinum', Georgia, serif; }
.gt-label { animation: rise .4s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.ctl { padding: 16px 18px; border-radius: 22px; background: rgba(255, 255, 255, .6); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .8), 0 8px 24px rgba(31, 41, 55, .08); }
.ctl h2 { font-size: 24px; margin: 0 0 2px; line-height: 1.2; }
.big { font-size: 44px; font-weight: 700; color: var(--you); font-variant-numeric: tabular-nums; line-height: 1.2; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: none; cursor: pointer; margin: 4px 0 0; }
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 8px; background: linear-gradient(90deg, #fde7b8, var(--you)); }
input[type=range]::-moz-range-track { height: 8px; border-radius: 8px; background: linear-gradient(90deg, #fde7b8, var(--you)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; margin-top: -11px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 8px rgba(31, 41, 55, .3), inset 0 0 0 1px rgba(0, 0, 0, .05); }
input[type=range]::-moz-range-thumb { width: 30px; height: 30px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(31, 41, 55, .3); }
input[type=range]:disabled { opacity: .5; cursor: default; }
.scale { display: flex; justify-content: space-between; color: var(--faint); font-size: 13px; margin: 0 2px 12px; }
.ctl .btn { width: 100%; }

.ans { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 10px; align-items: center; margin-top: 14px; }
.ans:empty { display: none; }
.ans .n { font-weight: 700; font-size: 16px; color: var(--c); white-space: nowrap; }
.ans .n.win::after { content: ' ★'; color: var(--amber); }
.ans .bar { height: 10px; border-radius: 99px; background: rgba(120, 130, 150, .15); position: relative; overflow: hidden; }
.ans .bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 99px; background: var(--c); transition: width .7s cubic-bezier(.2, .8, .2, 1); }
.ans .v { font-weight: 700; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; font-size: 16px; }
.ans .v small { color: var(--faint); font-weight: 400; font-size: 13px; margin-left: 4px; }
.c-gt { --c: var(--green); }

/* ------------------------------------------------------------------ result */
.result { text-align: center; padding: 26px 10px 10px; }
.rtitle { font-size: clamp(32px, 5vw, 54px); font-weight: 700; line-height: 1.1; background: linear-gradient(90deg, var(--blue), var(--purple), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.rsub { color: var(--muted); margin: 8px 0 22px; font-size: 19px; }
.big-board { max-width: 720px; margin: 0 auto 18px; }
.big-board .player { flex-direction: column; padding: 14px; }
.big-board .pscore { font-size: 44px; }
.rstats { color: var(--muted); font-size: 16px; margin-bottom: 22px; }

/* ------------------------------------------------------------------ failure sequence */
body.dying #cam, body.dying #bgcam { animation: camera 4.2s cubic-bezier(.25, .1, .1, 1) forwards; }
body.dying #viewport, body.dying #bg { filter: grayscale(1) contrast(1.12) brightness(.82); transition: filter 1.6s ease-in .2s; }
body.dying #viewport { overflow: hidden; }
body.dying #deck { background: rgba(255, 255, 255, .88); transition: background 1s; }
body.dying #world .wall { opacity: .75; filter: blur(0); }
body.dying #world .floor { opacity: .8; }
#viewport { transition: filter .6s; }
@keyframes camera {
  0%   { transform: translate3d(0, 0, 0) rotateX(0) rotateY(0) rotateZ(0); }
  30%  { transform: translate3d(0, 0, 60px) rotateX(3deg) rotateY(-6deg) rotateZ(-.5deg); }
  100% { transform: translate3d(-40px, 10px, -260px) rotateX(12deg) rotateY(-24deg) rotateZ(-2.5deg); }
}
#wasted { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(0, 0, 0, .55) 100%); opacity: 0; animation: fadein 1.2s .3s forwards; }
#wasted .band { align-self: stretch; padding: 18px 0 10px; background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .55) 22%, rgba(0, 0, 0, .55) 78%, transparent);
  opacity: 0; animation: fadein .6s 1.5s forwards; }
#wasted .word { font-family: 'Anton', Impact, 'Arial Narrow Bold', sans-serif; font-size: clamp(72px, 13vw, 168px); line-height: 1; text-align: center; letter-spacing: 4px;
  color: #b3151b; -webkit-text-stroke: 3px #120404; paint-order: stroke fill; text-shadow: 0 4px 0 rgba(0, 0, 0, .45), 0 0 40px rgba(179, 21, 27, .35);
  opacity: 0; transform: scale(1.35); animation: stamp .55s 1.6s cubic-bezier(.2, .9, .25, 1) forwards; }
#wasted .wsub { color: #f2f2f2; font-size: 20px; text-shadow: 0 2px 8px #000; opacity: 0; animation: fadein .6s 2.6s forwards; text-align: center;
  padding: 6px 18px; border-radius: 999px; background: rgba(0, 0, 0, .45); }
#wasted .endbtns { opacity: 0; animation: fadein .6s 3.2s forwards; }
#wasted .btn { pointer-events: auto; }
@keyframes fadein { to { opacity: 1; } }
@keyframes stamp { 0% { opacity: 0; transform: scale(1.35); } 60% { opacity: 1; transform: scale(.97); } 100% { opacity: 1; transform: scale(1); } }

/* ------------------------------------------------------------------ win confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate3d(var(--dx), 110vh, 0) rotate(var(--rot)); } }

/* ------------------------------------------------------------------ small screens */
@media (max-width: 820px) {
  #viewport { perspective: none; }
  #bg { display: none; }
  #cam { padding: 16px; place-items: start center; }
  #deck { padding: 14px 14px 10px; border-radius: 24px; }
  .playgrid { grid-template-columns: 1fr; gap: 12px; }
  .board { gap: 6px; } .player { padding: 6px 10px; } .player .pscore { font-size: 22px; } .player .pname { font-size: 15px; }
  .big { font-size: 36px; }
  .seg button { padding: 8px 13px; font-size: 16px; }
  .vs-card { min-width: 0; flex: 1 1 40%; }
  .vs-x { display: none; }
  body.dying #cam, body.dying #bgcam { animation: none; }
}
@media (prefers-reduced-motion: reduce) {
  body.dying #cam, body.dying #bgcam { animation: none; }
  .ruler-line { animation: none; stroke-dashoffset: 0; }
}

/* ------------------------------------------------------------------ share */
.endbtns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn.secondary { color: var(--ink); background: rgba(255, 255, 255, .85); box-shadow: inset 0 1px 1px #fff, inset 0 0 0 1px rgba(31, 41, 55, .1), 0 6px 16px rgba(31, 41, 55, .1); }
.btn.secondary:hover { transform: translateY(-1px) scale(1.02); }
.btn.share::before { content: ''; display: inline-block; width: 15px; height: 15px; margin: 0 8px -2px 0; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V3M7 8l5-5 5 5M5 13v6a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-6'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V3M7 8l5-5 5 5M5 13v6a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-6'/%3E%3C/svg%3E") center / contain no-repeat; }
#toast { position: fixed; left: 50%; bottom: 28px; z-index: 70; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 10px 20px; border-radius: 999px;
  color: #fff; background: rgba(20, 24, 32, .82); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); font-size: 16px; transition: opacity .25s, transform .25s; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
