:root {
  --bone: #F3EFE6;
  --ink: #07060F;
  --bg: #12101F;
  --card: #221F3A;
  --raise: #2E2A4E;
  --cobalt: #3A5BFF;
  --coral: #FF5A4E;
  --S: 480px;
  --side: 200px;
  --gap: 48px;
  --disc: 64px;
  --sun: #FFD23F;
  --teal: #2EC4B6;
  --violet: #8E5CF7;
  --pink: #FF6FB5;
  --bw: 4px;
  --drop: 6px;
  --shadow: 0 var(--drop) 0 var(--ink);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background-color: var(--bg); color: var(--bone);
  background-image:
    radial-gradient(ellipse at 50% 45%, rgba(58,91,255,0.10) 0%, rgba(18,16,31,0) 55%, rgba(0,0,0,0.45) 100%),
    repeating-linear-gradient(-45deg, rgba(243,239,230,0.025) 0 22px, rgba(243,239,230,0) 22px 44px);
  font-family: 'Lilita One', 'Arial Rounded MT Bold', sans-serif; font-weight: 400; letter-spacing: 0.01em;
  -webkit-user-select: none; user-select: none;
  touch-action: none; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
b { font-weight: 400; color: var(--coral); }

#app { position: fixed; inset: 0; z-index: 1; display: flex; flex-direction: column; }
#game { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#game canvas { display: block; }
#fx { position: fixed; inset: 0; z-index: 6; pointer-events: none; }

/* ---------- title + top buttons ---------- */
#top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(2.6vh, 14px) max(3vw, 16px) 0; pointer-events: none; }
#top > * { pointer-events: auto; }
.title {
  margin: 0; font-family: 'Bungee', sans-serif; font-weight: 400;
  font-size: clamp(22px, 5vh, 60px); line-height: 1.02; letter-spacing: 0.01em;
  color: var(--sun); -webkit-text-stroke: 0.09em var(--ink); paint-order: stroke fill;
  text-shadow: 0 0.09em 0 var(--ink);
}
.title .tw + .tw { color: var(--coral); margin-left: 0.35em; }
.title .tw { display: block; white-space: nowrap; }
.title .o {
  display: inline-block; width: 0.5em; height: 0.5em; margin: 0 0.035em 0 0.03em;
  border: 0.1em solid var(--ink); border-radius: 0.12em; transform: rotate(-12deg) translateY(-0.02em);
  vertical-align: 0.02em; background: var(--teal); box-shadow: inset 0 -0.08em 0 rgba(0,0,0,0.18);
}
.tbtns { display: flex; gap: 14px; }

.disc {
  width: var(--disc); height: var(--disc); border-radius: 50%; background: var(--raise);
  border: var(--bw) solid var(--ink);
  box-shadow: inset 0 calc(var(--disc) * -0.08) 0 rgba(0,0,0,0.18), 0 var(--drop) 0 var(--ink);
  display: grid; place-items: center; padding: 0;
  transition: transform 70ms ease-out, box-shadow 70ms ease-out;
  touch-action: none;
}
.disc[data-act="left"], .disc[data-act="right"] { background: var(--teal); }
.disc[data-act="rotate"] { background: var(--sun); }
.disc[data-act="soft"] { background: var(--pink); }
.disc[data-act="hold"] { background: var(--violet); }
.disc[data-act="hold"] svg { fill: #fff; stroke: #fff; }
#bPause { background: var(--sun); }
#bRestart { background: var(--coral); }
#bRestart svg { fill: #fff; stroke: #fff; }
.disc svg { width: 46%; height: 46%; fill: var(--ink); stroke: var(--ink); }
.disc svg [fill="none"] { fill: none; }
.disc.sm { width: clamp(42px, 6.4vh, 60px); height: clamp(42px, 6.4vh, 60px); }
.disc.hard { background: var(--cobalt); }
.disc.hard svg { fill: #fff; stroke: #fff; }
.disc.down, .disc:active { transform: translateY(calc(var(--drop) - 1px)); box-shadow: inset 0 calc(var(--disc) * -0.04) 0 rgba(0,0,0,0.18), 0 1px 0 var(--ink); }
.disc:focus-visible, .pill:focus-visible { outline: 4px solid var(--sun); outline-offset: 4px; }

/* ---------- stage ---------- */
#stage {
  position: absolute; left: 50%; top: var(--stageY, 50%); transform: translate(-50%, -50%);
  display: grid; grid-template-columns: var(--side) var(--S) var(--side); column-gap: var(--gap); align-items: center;
}
#boardSlot { width: var(--S); height: var(--S); }
#left, #right { display: flex; flex-direction: column; gap: calc(var(--S) * 0.04); }
#left { align-items: flex-end; }
#right { align-items: flex-start; }

.card {
  position: relative; background: var(--card); border: var(--bw) solid var(--ink); border-radius: calc(var(--S) * 0.035);
  box-shadow: var(--shadow); padding: calc(var(--S) * 0.03) calc(var(--S) * 0.035) calc(var(--S) * 0.035);
}
.lab {
  display: inline-block; font-family: 'Bungee', sans-serif; font-weight: 400; text-transform: uppercase; letter-spacing: 0.06em;
  font-size: clamp(11px, calc(var(--S) * 0.028), 20px); line-height: 1; padding: 0.38em 0.6em 0.3em; border-radius: 0.4em;
  background: var(--raise); color: #fff; transform: rotate(-3deg);
}
#holdCard > .lab { background: var(--violet); }
#nextCard > .lab { background: var(--coral); }
.s-score .lab { background: var(--cobalt); }
.s-lines .lab { background: var(--teal); }
.s-level .lab { background: var(--sun); color: var(--ink); }

#holdCard, #nextCard { width: var(--cardW, 160px); }
#holdCv { display: block; width: 100%; aspect-ratio: 1.45; margin-top: 6px; }
.nexts { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.nexts .n { display: block; width: 100%; aspect-ratio: 1.9; }
.nexts .n.big { aspect-ratio: 1.45; }

#statCard { width: var(--cardW, 160px); padding: 0 18px; text-align: center; }
.stat { padding: calc(var(--S) * 0.03) 0; }
.stat + .stat { border-top: 3px dashed rgba(243, 239, 230, 0.14); }
.num {
  font-family: 'Bungee', sans-serif; font-weight: 400; font-size: clamp(20px, calc(var(--S) * 0.075), 62px);
  line-height: 1; margin-top: 8px; display: flex; justify-content: center; transition: color 600ms ease;
}
.num.big { font-family: 'Bungee', sans-serif; font-weight: 400; font-size: clamp(24px, calc(var(--S) * 0.11), 100px); letter-spacing: 0; margin-top: 6px; }
.num .slot { display: inline-block; height: 1em; overflow: hidden; }
.num .strip { display: flex; flex-direction: column; transition: transform 380ms cubic-bezier(.25,1.4,.45,1); }
.num .strip span { height: 1em; line-height: 1em; }
.num.flash { transition: none; }
.num.bounce { animation: bounce 520ms cubic-bezier(.3,1.7,.5,1); }
@keyframes bounce { 0% { transform: scale(1); } 30% { transform: scale(1.35) translateY(-6%); } 100% { transform: scale(1); } }

/* ---------- footer ---------- */
#hint {
  position: absolute; left: 0; right: 0; bottom: max(2.6vh, 12px); display: flex; justify-content: center; flex-wrap: wrap;
  gap: 10px 18px; font-size: clamp(13px, 1.9vh, 20px); color: var(--bone); padding: 0 16px;
}
#hint > span { display: inline-flex; align-items: center; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.04em; }
kbd {
  display: inline-block; min-width: 1.9em; padding: 0.2em 0.45em 0.12em; margin-right: 0.3em; border-radius: 6px; background: var(--raise);
  border: 2.5px solid var(--ink); box-shadow: 0 3px 0 var(--ink); font-family: 'Bungee', sans-serif;
  font-weight: 400; font-size: 0.8em; text-align: center; color: var(--bone);
}
#touch { display: none; position: absolute; left: 0; right: 0; bottom: max(2.2vh, 12px, env(safe-area-inset-bottom)); justify-content: center; gap: var(--tgap, 14px); }
.tg { display: flex; gap: var(--tgap, 14px); }
body.touch #touch { display: flex; }
body.touch #hint { display: none; }

/* wide screen with touch: two thumb clusters at the bottom corners */
body.wide.touch #touch { justify-content: space-between; padding: 0 max(2.4vw, 14px); }
body.wide.touch .tg { flex-wrap: wrap; width: calc(var(--disc) * 2 + var(--tgap, 14px)); justify-content: center; }
body.wide.touch .tg1 { flex-direction: row; }

/* ---------- tall (portrait) ---------- */
body.tall #top { padding: 12px 14px 0; align-items: center; }
body.tall .title { font-size: clamp(22px, 6.4vw, 34px); }
body.compact .title .tw { display: inline; }
body.tall .tbtns { gap: 10px; }
body.tall .disc.sm { width: 42px; height: 42px; }
body.tall #stage {
  grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "left right" "board board"; column-gap: 8px; row-gap: 12px;
  align-items: stretch; justify-content: space-between; width: var(--S);
}
body.tall #left { grid-area: left; flex-direction: row; gap: 8px; align-items: stretch; }
body.tall #right { grid-area: right; min-width: 0; }
body.tall #right #statCard { width: 100%; overflow: hidden; }
body.tall #boardSlot { grid-area: board; }
body.compact { --bw: 3px; --drop: 4px; }
body.compact .card { border-radius: 12px; padding: 7px 9px 8px; }
body.compact .lab { font-size: 9px; letter-spacing: 0.04em; }
body.compact #holdCard { width: auto; }
body.compact #holdCv { width: calc(var(--S) * 0.14); aspect-ratio: 1.3; }
body.compact #nextCard { width: auto; }
body.compact .nexts { flex-direction: row; align-items: center; gap: 4px; }
body.compact .nexts .n { width: calc(var(--S) * 0.1); aspect-ratio: 1.15; }
body.compact .nexts .n.big { width: calc(var(--S) * 0.13); aspect-ratio: 1.3; }
body.compact #statCard { width: auto; height: 100%; padding: 8px 6px; display: grid; grid-template-columns: auto auto; grid-template-areas: "s s" "l v"; column-gap: 5px; justify-content: center; align-content: center; }
body.compact .stat { padding: 0; border: 0 !important; }
body.compact .s-score { grid-area: s; }
body.compact .s-lines { grid-area: l; }
body.compact .s-level { grid-area: v; }
body.compact .stat .lab { font-size: 7.5px; letter-spacing: 0.02em; padding: 0.38em 0.45em 0.3em; }
body.compact .num { font-size: 14px; margin-top: 4px; }
body.compact .num.big { font-size: clamp(20px, calc(var(--S) * 0.075), 38px); margin-top: 4px; margin-bottom: 4px; }

/* ---------- overlay cards ---------- */
#overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; pointer-events: none; padding: 16px; }
#overlay { transition: background 300ms; }
#overlay.show { pointer-events: auto; background: rgba(5, 4, 12, 0.6); }
.sheet {
  background: var(--card); border: 5px solid var(--ink); border-radius: 22px; box-shadow: 0 10px 0 var(--ink);
  padding: 26px 28px 30px; width: min(430px, 100%); max-height: calc(100vh - 40px); overflow: auto; text-align: center;
  transform: translateY(120vh) rotate(-2deg); transition: transform 520ms cubic-bezier(.2,1.25,.4,1);
}
#overlay.show .sheet { transform: translateY(0) rotate(-1deg); }
.panel { display: none; }
.panel.on { display: block; }
.panel h2 {
  margin: 0 0 14px; font-family: 'Bungee', sans-serif; font-weight: 400; font-size: 40px; letter-spacing: 0.01em; line-height: 1;
  color: var(--sun); -webkit-text-stroke: 0.1em var(--ink); paint-order: stroke fill; text-shadow: 0 0.1em 0 var(--ink);
}
.panel p { margin: 0 0 12px; font-size: 17px; line-height: 1.3; color: var(--bone); }
.keys { list-style: none; padding: 0; margin: 10px 0 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; text-align: left; font-size: 16px; text-transform: uppercase; letter-spacing: 0.03em; }
.keys li { display: flex; align-items: center; }
.keys span { margin-left: 4px; }
.touchnote { display: none; }
body.touch .touchnote { display: block; font-size: 14px; }
.pill {
  background: var(--cobalt); color: #fff; font-family: 'Bungee', sans-serif; font-weight: 400; font-size: 24px; letter-spacing: 0.04em;
  padding: 14px 44px 12px; border-radius: 16px; border: 4px solid var(--ink);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,0.2), 0 7px 0 var(--ink); transition: transform 70ms ease-out, box-shadow 70ms ease-out;
  animation: throb 1.4s ease-in-out infinite;
}
.pill:active { transform: translateY(6px); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.2), 0 1px 0 var(--ink); animation: none; }
@keyframes throb { 0%, 100% { scale: 1; } 50% { scale: 1.05; } }
.bigscore { font-family: 'Bungee', sans-serif; font-weight: 400; font-size: 54px; line-height: 1.1; margin: 4px 0 8px; color: var(--cobalt); -webkit-text-stroke: 0.08em var(--ink); paint-order: stroke fill; text-shadow: 0 0.08em 0 var(--ink); }
.overstats { font-size: 17px; color: var(--bone); margin-bottom: 16px; text-transform: uppercase; letter-spacing: 0.03em; }
.board { list-style: none; padding: 0; margin: 0 auto 18px; max-width: 300px; text-align: left; font-size: 14px; }
.board:empty { display: none; }
.board li { display: flex; justify-content: space-between; padding: 5px 4px; border-top: 1px solid rgba(243, 239, 230, 0.1); }
.board li.mine { color: var(--sun); }
.board a { color: inherit; }
.board .v { font-family: 'Bungee', sans-serif; }
.board .cap { border: 0; text-transform: uppercase; letter-spacing: 0.08em; font-family: 'Bungee', sans-serif; font-size: 12px; justify-content: center; }
.goal { font-size: 16px; }

/* ---------- short wide touch screens (phone on its side) ---------- */
body.squat #top { padding: 10px 14px 0; align-items: center; }
body.squat .title { font-size: clamp(18px, 6vh, 28px); }
body.squat .disc.sm { width: 40px; height: 40px; }
body.squat #stage { top: 50%; column-gap: 8px; align-items: start; height: var(--S); }
body.squat #left, body.squat #right { align-items: center; gap: 8px; }
body.squat #left { padding-top: var(--padL, 56px); }
body.squat #right { padding-top: var(--padR, 56px); }
body.squat #statCard { height: auto; }
body.squat #touch { justify-content: space-between; padding: 0 max(10px, env(safe-area-inset-left)); bottom: 10px; }
body.squat .tg { width: auto; flex-wrap: nowrap; }
body.touch .keys { display: none; }
