* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #050d0b; color: #efe6d0;
  font-family: system-ui, 'Segoe UI', Helvetica, Arial, sans-serif; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }
.nogame #wrap, .nogame #actions, .nogame #info { visibility: hidden; }
:root { --gold: #f3d386; --ink: #14100a; --serif: Georgia, 'Times New Roman', serif; }

/* ---------- the table ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
#felt { position: absolute; inset: 0; background: radial-gradient(ellipse 80% 72% at 50% 42%, #217359 0%, #165441 36%, #0a3026 68%, #04130f 100%); }
#lamp { position: absolute; inset: 0; background: radial-gradient(ellipse 52% 46% at 50% 42%, rgba(255, 208, 138, .34), rgba(255, 208, 138, .1) 55%, transparent 78%); }
#grain { position: absolute; inset: 0; opacity: .55; mix-blend-mode: overlay; }
#rail { position: absolute; inset: 2.5% 1.5%; border-radius: 50% / 46%; border: 1px solid rgba(255, 232, 180, .08); box-shadow: inset 0 0 140px rgba(0, 0, 0, .3); }
#vignette { position: absolute; inset: 0; background: radial-gradient(ellipse 78% 74% at 50% 46%, transparent 36%, rgba(0, 0, 0, .55) 74%, rgba(0, 0, 0, .9) 100%); }
.q-low #grain, .q-low #rail { display: none; }
.q-ultra #lamp { animation: breathe 7s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .86; } }

#wrap { position: absolute; left: 0; right: 0; top: 46px; bottom: 66px; perspective: 1500px; perspective-origin: 50% 30%; }
#table { position: absolute; inset: 0; transform-style: preserve-3d; transform: rotateX(9deg) scale(.965); transform-origin: 50% 58%; }
#table > * { position: absolute; left: 0; top: 0; }

.light { width: 200px; height: 200px; margin: -100px 0 0 -100px; border-radius: 50%; opacity: 0; pointer-events: none;
  background: radial-gradient(closest-side, rgba(255, 214, 140, .42), rgba(255, 206, 130, .16) 55%, transparent);
  transition: transform .55s cubic-bezier(.2, .8, .2, 1), opacity .45s; }
#goboLight { background: radial-gradient(closest-side, rgba(255, 150, 70, .5), rgba(255, 120, 50, .2) 55%, transparent); }
#turnLight.win { background: radial-gradient(closest-side, rgba(255, 232, 170, .8), rgba(255, 210, 130, .3) 55%, transparent); }

.pilebox { width: 160px; height: 224px; border-radius: 14px; pointer-events: auto; }
.pilebox::before { content: ''; position: absolute; inset: 0; border-radius: 14px; border: 2px dashed rgba(255, 236, 190, .16); }
#deckBox .stack { position: absolute; inset: 0; border-radius: 13px; background-size: 100% 100%; }
#deckBox.empty .stack { display: none; }
#deckCount { position: absolute; right: 100%; top: 50%; margin: -18px 16px 0 0; text-align: right; font-size: 26px; font-weight: 600; color: rgba(255, 240, 210, .5); }
#pileBox .hint { position: absolute; left: 100%; top: 50%; width: 170px; margin: -40px 0 0 18px; text-align: left; line-height: 1.15; font-size: 22px; color: rgba(255, 240, 210, .42); pointer-events: none; }
.pilebox.can { cursor: pointer; }
.pilebox.can::after, .zone.can::after { content: ''; position: absolute; inset: -6px; border-radius: 20px; box-shadow: 0 0 0 4px var(--rim, #ffe2a0), 0 0 30px 8px var(--rim, #ffe2a0); animation: rim 1.5s ease-in-out infinite; pointer-events: none; }
#pileBox.drop::after { content: ''; position: absolute; inset: -14px; border-radius: 26px; border: 4px solid #fff; opacity: .8; animation: rim 0.7s ease-in-out infinite; }
.zone { border-radius: 18px; pointer-events: none; }
.zone.can { pointer-events: auto; cursor: pointer; }
.zone.can::after { inset: 0; box-shadow: 0 0 0 2px var(--rim), 0 0 22px 2px var(--rim); }
@keyframes rim { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

/* ---------- cards ---------- */
.card { width: 160px; height: 224px; transform-style: preserve-3d; pointer-events: none; will-change: transform; touch-action: none; }
.card.hit { pointer-events: auto; }
.card.can { cursor: pointer; }
.face { position: absolute; inset: 0; border-radius: 13px; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; background-size: 100% 100%; }
.face::after { content: ''; position: absolute; inset: 0; background: linear-gradient(112deg, rgba(255, 255, 255, .26) 0%, rgba(255, 255, 255, 0) 34%, rgba(0, 0, 0, 0) 66%, rgba(0, 0, 0, .16) 100%); }
.back { transform: translateZ(2.5px); box-shadow: 0 0 9px rgba(255, 216, 150, .16); }
.front { transform: rotateY(180deg) translateZ(2.5px); background-color: #f4ecd8; box-shadow: 0 0 16px rgba(255, 240, 205, .38); }
.q-ultra .front { box-shadow: 0 0 26px rgba(255, 240, 205, .55); }
.q-ultra .back { box-shadow: 0 0 14px rgba(255, 216, 150, .28); }
.q-low .face { box-shadow: none; }
.edge { position: absolute; top: 9px; bottom: 9px; left: -2.5px; width: 5px; transform: rotateY(90deg); background: linear-gradient(#f6eedb, #c9bd9e); }
.edge.r { left: auto; right: -2.5px; }
.sheen { position: absolute; top: -10%; bottom: -10%; left: 0; width: 60%; opacity: 0; z-index: 2;
  background: linear-gradient(100deg, transparent 0%, rgba(255, 255, 255, .0) 20%, rgba(255, 255, 255, .8) 50%, rgba(255, 255, 255, 0) 80%, transparent 100%); }
.fl { position: absolute; inset: 0; background: var(--flash, #fff); opacity: 0; z-index: 3; }
.rim { position: absolute; inset: -4px; border-radius: 17px; opacity: 0; box-shadow: 0 0 0 4px var(--rim, #ffe2a0), 0 0 30px 8px var(--rim, #ffe2a0); }
.q-low .rim { box-shadow: 0 0 0 5px var(--rim, #ffe2a0); }
.card.can .rim { animation: rim 1.5s ease-in-out infinite; }
.card.sel .rim, .card.lit .rim { opacity: 1; animation: none; }
.shadow { width: 160px; height: 224px; border-radius: 18px; background: rgba(0, 0, 0, .62); filter: blur(9px); pointer-events: none; will-change: transform, opacity; }
.q-low .shadow { display: none !important; }

#fx { pointer-events: none; transform: translateZ(14px); }
#spot { pointer-events: none; opacity: 0; transition: opacity .3s; transform: translateZ(12px); inset: -20% !important; left: -20% !important; top: -20% !important; width: 140%; height: 140%;
  background: radial-gradient(circle at var(--sx, 50%) var(--sy, 50%), transparent 0, transparent var(--sr, 90px), rgba(0, 0, 0, .58) calc(var(--sr, 90px) * 2.4)); }
#spot.on { opacity: 1; }
#word { pointer-events: none; opacity: 0; font: italic 700 84px var(--serif); color: #ffe7ad; letter-spacing: 2px; white-space: nowrap;
  text-shadow: 0 0 28px rgba(255, 170, 70, .9), 0 4px 0 rgba(90, 40, 0, .7); }
#banner { transform: translate(-50%, -50%) translateZ(3px); text-align: center; font-size: 17px; line-height: 1.25; color: #f4ead2; padding: 7px 18px; border-radius: 999px;
  background: rgba(4, 14, 11, .62); border: 1px solid rgba(255, 232, 180, .14); max-width: 96%; pointer-events: none; text-wrap: balance; transition: opacity .2s; }
#banner:empty { opacity: 0; }
#banner b { color: var(--pc, var(--gold)); }
#banner.pow { border-color: var(--pc); box-shadow: 0 0 22px -4px var(--pc); }

.plate { transform: translate(-50%, -50%) translateZ(2px); display: flex; align-items: center; gap: 8px; padding: 4px 12px; border-radius: 999px; white-space: nowrap;
  font-size: 14px; font-weight: 600; color: #e9dfc8; background: rgba(4, 14, 11, .62); border: 1px solid rgba(255, 232, 180, .14); pointer-events: none; transition: background .3s, color .3s, box-shadow .3s; }
.plate.col { flex-direction: column; gap: 2px; border-radius: 14px; padding: 6px 8px; }
.plate .tot { font-variant-numeric: tabular-nums; padding: 0 7px; border-radius: 99px; background: rgba(255, 255, 255, .1); }
.plate.on { background: var(--gold); color: var(--ink); box-shadow: 0 0 22px rgba(255, 214, 140, .55); }
.plate.on .tot { background: rgba(0, 0, 0, .14); }
.plate .tag { display: none; font-size: 11px; font-weight: 800; letter-spacing: 1px; padding: 1px 7px; border-radius: 99px; background: #ff8a3c; color: #2a0f00; }
.plate.gobo .tag { display: inline-block; }
.plate .sum { display: none; font: 700 17px var(--serif); padding: 0 9px; border-radius: 99px; background: #fbf4e2; color: #1b2130; font-variant-numeric: tabular-nums; }
.plate.show .sum { display: inline-block; }
.plate.show .tot { display: none; }
.plate.low .sum { background: var(--gold); box-shadow: 0 0 18px rgba(255, 220, 140, .9); }
.plate.cutter { background: #fff; color: #111; box-shadow: 0 0 26px #fff; }
.note { transform: translate(-50%, -50%) translateZ(30px); pointer-events: none; font: 800 20px system-ui; letter-spacing: 2px; padding: 3px 12px; border-radius: 8px; white-space: nowrap; color: #111; background: #fff; box-shadow: 0 0 24px rgba(255, 255, 255, .8); }
.note.bad { background: #b43a32; color: #fff; box-shadow: 0 0 20px rgba(180, 58, 50, .7); }
.strike { transform: translate(-50%, -50%) translateZ(40px); pointer-events: none; font: 700 44px var(--serif); white-space: nowrap; }
.strike.good { color: #fff3c4; text-shadow: 0 0 24px #ffd24a, 0 0 6px #fff; }
.strike.bad { color: #e06a5c; text-shadow: 0 3px 0 #3a0d08; }

#dim { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .9s;
  background: radial-gradient(circle at var(--wx, 50%) var(--wy, 50%), transparent 0, rgba(0, 0, 0, .1) 110px, rgba(0, 0, 0, .78) 330px); }
#dim.on { opacity: 1; }
#fxScreen { position: absolute; inset: 0; pointer-events: none; }
#fps { position: absolute; left: 8px; bottom: 70px; font: 12px monospace; color: #9f9; pointer-events: none; }

/* ---------- chrome ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 10px; }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.logo { font: italic 700 24px var(--serif); color: var(--gold); }
#info { font-size: 13px; color: rgba(240, 230, 205, .62); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lap { position: absolute; left: 50%; top: 50px; transform: translateX(-50%); z-index: 5; font-size: 13px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; white-space: nowrap;
  padding: 5px 14px; border-radius: 99px; background: #ff8a3c; color: #2a0f00; box-shadow: 0 0 22px rgba(255, 138, 60, .6); opacity: 0; transition: opacity .3s; pointer-events: none; }
#lap.on { opacity: 1; }
#hud nav { display: flex; gap: 6px; }
#hud nav button { font-size: 13px; padding: 6px 11px; border-radius: 99px; background: rgba(4, 14, 11, .55); border: 1px solid rgba(255, 232, 180, .16); color: #e9dfc8; white-space: nowrap; }
#hud nav button:hover { border-color: rgba(255, 232, 180, .5); }
#actions { position: absolute; left: 0; right: 0; bottom: 0; height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px 6px; }
#ctx { display: flex; gap: 10px; justify-content: center; flex: 1; }
.act, #ctx button, .primary { font-size: 17px; font-weight: 700; padding: 11px 22px; border-radius: 14px; min-width: 96px; color: var(--ink); background: linear-gradient(#ffe6a6, #e9bf62);
  box-shadow: 0 3px 0 #8b6a22, 0 8px 18px rgba(0, 0, 0, .45); transition: transform .08s, filter .15s, opacity .2s; white-space: nowrap; }
.act:active, #ctx button:active, .primary:active { transform: translateY(2px); }
#ctx button.quiet { background: rgba(4, 14, 11, .6); color: #efe6d0; box-shadow: inset 0 0 0 1px rgba(255, 232, 180, .3); }
.act.cut { background: linear-gradient(#ffffff, #cfd6dd); box-shadow: 0 3px 0 #6c757d, 0 8px 18px rgba(0, 0, 0, .45); }
.act.cut.armed { background: #fff; box-shadow: 0 0 0 3px #fff, 0 0 26px #fff; }
.act.gobo { background: linear-gradient(#ffb066, #f0702c); box-shadow: 0 3px 0 #8a3207, 0 8px 18px rgba(0, 0, 0, .45); font-family: var(--serif); font-style: italic; font-size: 20px; }
.act.off { opacity: 0; pointer-events: none; }

.panel { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); width: min(380px, 92vw); padding: 12px 14px 14px; border-radius: 20px; text-align: center;
  background: rgba(6, 18, 14, .95); border: 1px solid rgba(255, 232, 180, .22); box-shadow: 0 24px 70px rgba(0, 0, 0, .6); animation: pop .35s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%) scale(.94); } }
.panel h2 { margin: 0 0 4px; font: italic 700 26px var(--serif); color: var(--gold); }
.panel p { margin: 0 0 10px; font-size: 14px; color: rgba(240, 230, 205, .75); }
.rows { position: relative; margin: 10px 0 14px; }
.row { position: absolute; left: 0; right: 0; top: 0; height: 36px; display: grid; grid-template-columns: 26px 1fr 64px 60px; align-items: center; gap: 6px; padding: 0 10px; border-radius: 10px;
  background: rgba(255, 255, 255, .05); transition: transform .6s cubic-bezier(.3, 1.2, .4, 1), background .4s; font-size: 16px; text-align: left; }
.row.me { background: rgba(255, 224, 150, .14); }
.row.win { background: rgba(255, 214, 120, .3); }
.row .rk { opacity: .55; font-size: 13px; }
.row .rs { text-align: right; font-size: 14px; color: rgba(240, 230, 205, .7); font-variant-numeric: tabular-nums; }
.row .tt { text-align: right; font: 700 20px var(--serif); font-variant-numeric: tabular-nums; }
#roundPanel p { margin: 0; font-size: 14px; }
#roundPanel p b { font: italic 700 21px var(--serif); color: var(--gold); margin-right: 10px; }
#roundPanel .primary { padding: 8px 22px; font-size: 16px; }
.tiles { position: relative; height: 66px; margin: 8px 0 12px; }
.row.tile { left: 3px; right: auto; height: 66px; display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 0 2px; text-align: center; }
.tile .nm { font-size: 13px; white-space: nowrap; }
.tile .rk { font-style: normal; opacity: .5; font-size: 11px; }
.tile .tt { text-align: center; font-size: 24px; line-height: 1; }
.tile .rs { text-align: center; font-size: 12px; }
.tile small { position: absolute; top: -8px; right: 4px; margin: 0 !important; }
.row small { margin-left: 6px; font-size: 10px; font-weight: 800; letter-spacing: 1px; padding: 1px 6px; border-radius: 99px; background: #ff8a3c; color: #2a0f00; vertical-align: middle; }
#roundPanel { transform: translate(-50%, 0); animation-name: pop2; }
@keyframes pop2 { from { opacity: 0; transform: translate(-50%, 12px) scale(.96); } }
#winPanel { top: 56%; }
#winPanel h2 { font-size: 34px; }

#start, .modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 14px; overflow: auto; }
#start { top: 46px; background: radial-gradient(ellipse at 50% 30%, rgba(6, 22, 17, .55), rgba(2, 8, 6, .93)); }
.modal { background: rgba(2, 8, 6, .78); z-index: 30; }
.sheet { position: relative; width: min(470px, 100%); max-height: 100%; overflow: auto; padding: 22px 24px 20px; border-radius: 24px; text-align: center;
  background: linear-gradient(rgba(14, 44, 35, .96), rgba(7, 24, 19, .97)); border: 1px solid rgba(255, 232, 180, .2); box-shadow: 0 30px 90px rgba(0, 0, 0, .7); }
#start h1 { margin: 0; font: italic 700 68px/1 var(--serif); color: var(--gold); text-shadow: 0 0 34px rgba(255, 190, 90, .5); }
.tag { margin: 6px 0 16px; color: rgba(240, 230, 205, .7); }
.fan { position: relative; height: 104px; margin-bottom: 2px; }
.fan i { position: absolute; left: 50%; top: 8px; width: 68px; height: 95px; margin-left: -34px; border-radius: 6px; background-size: 100% 100%; box-shadow: 0 8px 18px rgba(0, 0, 0, .5); transform-origin: 50% 160%; }
.set { display: grid; grid-template-columns: 104px 1fr; align-items: center; gap: 10px; margin: 8px 0; text-align: left; font-size: 14px; color: rgba(240, 230, 205, .8); }
.seg { display: flex; padding: 3px; border-radius: 12px; background: rgba(0, 0, 0, .35); }
.seg button { flex: 1; padding: 8px 4px; border-radius: 9px; font-size: 14px; color: rgba(240, 230, 205, .75); white-space: nowrap; }
.seg button.on { background: var(--gold); color: var(--ink); font-weight: 700; }
.primary.big { width: 100%; margin-top: 14px; font-size: 20px; padding: 14px; }
.link { margin-top: 10px; padding: 8px; color: var(--gold); text-decoration: underline; font-size: 15px; }
.modal .sheet { text-align: left; width: min(560px, 100%); font-size: 15px; line-height: 1.45; }
.modal h2 { margin: 0 0 8px; font: italic 700 30px var(--serif); color: var(--gold); }
.modal h3 { margin: 14px 0 4px; font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--gold); }
.modal p, .modal ul { margin: 4px 0; }
.modal ul { padding-left: 20px; }
.modal .powers { list-style: none; padding: 0; }
.modal .powers li { margin: 4px 0; }
.modal .powers b { display: inline-block; min-width: 92px; padding: 1px 8px; margin-right: 8px; border-radius: 99px; color: #14100a; text-align: center; font-size: 13px; }
.vals { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.vals span { padding: 3px 10px; border-radius: 99px; background: rgba(255, 255, 255, .08); font-size: 13px; }
.close { position: sticky; float: right; top: 0; padding: 6px 12px; border-radius: 99px; background: rgba(255, 255, 255, .1); font-size: 13px; }

/* wide windows: no strip under the table, the buttons sit in its corners */
@media (min-aspect-ratio: 1/1) {
  #wrap { bottom: 8px; }
  #actions { pointer-events: none; align-items: flex-end; height: auto; padding-bottom: 12px; }
  #actions button { pointer-events: auto; }
  #ctx { position: absolute; right: 12px; bottom: 72px; flex-direction: column; align-items: flex-end; }
  #fps { bottom: 76px; }
}
@media (max-width: 620px) {
  #info, .lblx { display: none; }
  #hud nav button { padding: 6px 8px; font-size: 12px; }
  #banner { font-size: 14px; padding: 5px 12px; border-radius: 16px; }
  .act, #ctx button { font-size: 15px; padding: 10px 12px; min-width: 70px; }
  #start h1 { font-size: 52px; }
  .set { grid-template-columns: 82px 1fr; }
  .seg button { font-size: 12.5px; }
  .plate { font-size: 12px; padding: 3px 8px; gap: 5px; }
}
@media (max-height: 560px) { .fan { display: none; } .sheet { padding: 12px 18px; } .tag { margin-bottom: 8px; } .set { margin: 5px 0; } }
