* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0d1233;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-weight: 800; letter-spacing: .06em; color: #eef0ff;
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-tap-highlight-color: transparent;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
/* While the host has the game paused, every animation holds still. */
body.paused *, body.paused *::before, body.paused *::after { animation-play-state: paused !important; }
/* On YouTube the player uses YouTube's own mute button, so the game's are hidden. */
body.playables #btnSound, body.playables #btnMenuSound { display: none; }
button { font: inherit; letter-spacing: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- The bars around the board ---------- */
#play {
  position: fixed; inset: 0; display: flex; flex-direction: column; pointer-events: none;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
#top, #bottom { pointer-events: auto; flex: none; display: flex; align-items: center; gap: 8px; }
#top { justify-content: space-between; padding: 2px 6px; }
#stage { flex: 1; min-width: 0; min-height: 0; position: relative; }
#levelName { font-size: clamp(17px, 5.4vw, 28px); line-height: 1; white-space: nowrap; }
#levelName.low { color: #ff8080; }
/* Blitz has no hints: there is no time to think. */
body.blitz #btnHint { display: none; }
#levelSize { font-size: 12px; color: #9aa6e8; margin-top: 4px; }
#meters { display: grid; grid-template-columns: auto auto; gap: 3px 12px; font-size: 11px; text-align: right; justify-content: end; color: #b9c2f5; }
.meter { white-space: nowrap; }
.meter b { font-size: 15px; color: #ffe08a; }
#fillBar { grid-column: 1 / -1; height: 7px; background: rgba(255,255,255,.14); border-radius: 4px; overflow: hidden; }
#fillFill { display: block; height: 100%; background: linear-gradient(90deg, #6fb6ff, #ffe08a); transform: scaleX(0); transform-origin: left; transition: transform .2s; }

#bottom { justify-content: center; flex-wrap: wrap; padding: 2px 0; }
#bottom button, button.small {
  background: rgba(150,170,255,.14); border: 1.5px solid rgba(170,190,255,.5); border-radius: 12px;
  padding: 10px 13px; font-size: 12px; white-space: nowrap;
}
#bottom button:active, button.small:active { background: rgba(150,170,255,.32); }
#btnHint { border-color: #ffe08a !important; color: #ffe08a; }
#btnHint b { background: #ffe08a; color: #141a45; border-radius: 8px; padding: 1px 6px; margin-left: 3px; letter-spacing: 0; }
#btnMenu.sure { background: #ff5d8f; border-color: #fff; }

/* How-to-play line, over the top of the stage. */
#tip {
  position: absolute; left: 0; right: 0; top: 0; text-align: center; pointer-events: none;
  font-size: clamp(13px, 3.6vw, 18px); letter-spacing: .02em; color: #ffe08a; padding: 0 6px; text-shadow: 0 1px 6px #070a22;
}

/* A wide screen: the bars stand to the left and right of the board. */
body.wide #play { flex-direction: row; align-items: stretch; }
body.wide #top { flex-direction: column; justify-content: center; align-items: flex-start; gap: 14px; width: clamp(120px, 20vw, 240px); }
body.wide #meters { text-align: left; justify-content: start; width: 100%; }
body.wide #bottom { flex-direction: column; flex-wrap: nowrap; justify-content: center; align-items: stretch; width: clamp(110px, 16vw, 200px); }
body.wide #levelName { font-size: clamp(17px, 3vw, 32px); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; top: 20%; transform: translate(-50%, -8px); max-width: 92vw; text-align: center;
  background: rgba(13,18,51,.94); border: 1.5px solid #ffe08a; border-radius: 14px; padding: 10px 16px;
  font-size: clamp(13px, 3.8vw, 18px); letter-spacing: .02em; color: #ffe08a; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 5;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  gap: 14px; padding: 16px; background: rgba(7,10,34,.55); text-align: center; overflow-y: auto; z-index: 10;
}
#loading { background: #0d1233; }
#menu { background: rgba(7,10,34,.2); }
.logo {
  margin: 0; font-weight: 900; letter-spacing: .14em; margin-right: -.14em; line-height: 1;
  font-size: clamp(30px, min(12.5vw, 16vh), 88px);
  background: linear-gradient(180deg, #ffffff 20%, #ffe08a 60%, #ff9ad5); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(140,160,255,.75));
}
h2 { margin: 0; font-weight: 900; font-size: clamp(22px, 6.5vw, 40px); color: #ffe08a; }
.sub { margin: 0; font-weight: 600; font-size: clamp(14px, 3.8vw, 18px); letter-spacing: .01em; color: #c9d0fa; max-width: 520px; text-shadow: 0 1px 6px #070a22; }
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
button.big {
  background: linear-gradient(180deg, #7d8bff, #5a5fe0); border: 2px solid #c7ceff; border-radius: 16px; padding: 13px 26px;
  min-width: 190px; font-size: clamp(16px, 4.6vw, 22px); color: #fff; box-shadow: 0 0 22px rgba(120,130,255,.55);
}
button.big.alt { background: rgba(150,170,255,.14); border-color: rgba(170,190,255,.6); box-shadow: none; }
button.big:active { transform: scale(.97); }
/* The rewarded ad on the results screen: clearly marked as an ad, in its own colour. */
button.big.ad { background: linear-gradient(180deg, #ffe08a, #f2b84b); border-color: #fff4cf; color: #2a1f05; box-shadow: 0 0 18px rgba(255,214,120,.45); font-size: clamp(14px, 4vw, 18px); padding: 10px 22px; }
button.big:disabled { opacity: .55; cursor: default; }
button.big span { display: block; }
button.big small { display: block; font-weight: 600; font-size: 12px; letter-spacing: .01em; opacity: .9; margin-top: 3px; }
button.big small:empty { display: none; }

#loadBar { width: min(70vw, 360px); height: 10px; background: rgba(255,255,255,.14); border-radius: 6px; overflow: hidden; }
#loadFill { display: block; height: 100%; background: #ffe08a; transform: scaleX(0); transform-origin: left; transition: transform .2s; }
#loadText { margin: 0; font-weight: 600; font-size: 14px; letter-spacing: .01em; color: #9aa6e8; }

#rankLine, #winXp {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 5px 10px;
  background: rgba(13,18,51,.72); border: 1px solid rgba(170,190,255,.3); border-radius: 14px; padding: 8px 14px; font-size: 14px; max-width: min(92vw, 460px);
}
#rankBar, #xpBar { width: min(40vw, 160px); height: 8px; background: rgba(255,255,255,.14); border-radius: 5px; overflow: hidden; }
#rankFill, #xpFill { display: block; height: 100%; background: linear-gradient(90deg, #6fb6ff, #ffe08a); transform-origin: left; transition: transform .8s ease-out; }
#rankNext, #xpGain { font-weight: 600; font-size: 12px; letter-spacing: .01em; color: #c9d0fa; }
#rankName, #xpRank { color: #ffe08a; }
#xpNews { flex-basis: 100%; font-size: 14px; color: #ffe08a; }
#xpNews:empty { display: none; }

#winStats { display: flex; gap: 10px; }
#winStats div { background: rgba(13,18,51,.72); border: 1px solid rgba(170,190,255,.3); border-radius: 12px; padding: 6px 16px; min-width: 96px; }
#winStats span { display: block; font-size: 10px; color: #b9c2f5; }
#winStats b { font-size: 22px; color: #ffe08a; letter-spacing: 0; }
/* The top of the leaderboard, where the platform lets the game show it. */
#winBoard { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; font-size: 12px; text-align: left; background: rgba(13,18,51,.72); border: 1px solid rgba(170,190,255,.3); border-radius: 12px; padding: 6px 14px; min-width: 200px; }
#winBoard b { color: #ffe08a; text-align: right; }
#winBoard span { letter-spacing: .01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* After a win: a heading and a footer around the board, in place of the bars. */
#winHead, #winFoot { pointer-events: auto; flex: none; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 4px 0; animation: rise .35s ease-out; }
#winHead .logo { font-size: clamp(24px, min(9.5vw, 8vh), 56px); letter-spacing: .08em; margin-right: -.08em; }
#winFoot .row { gap: 10px; }
body.wide #winHead { justify-content: center; width: clamp(150px, 27vw, 380px); }
body.wide #winHead .logo { font-size: clamp(18px, min(4.2vw, 15vh), 50px); }
body.wide #winFoot { justify-content: center; width: clamp(180px, 27vw, 380px); }
body.wide #winFoot button.big { min-width: 0; width: 100%; }
body.wide #btnDouble { align-self: stretch; }
body.wide #winFoot .row { flex-direction: column; align-self: stretch; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

#hintBox { z-index: 15; background: rgba(7,10,34,.86); }
#adStandIn { background: #05060c; z-index: 20; gap: 14px; }
#adStandIn h2 { color: #9aa3b8; }
#adStandInBar { width: min(70vw, 420px); height: 12px; background: #1b2036; border-radius: 7px; overflow: hidden; }
#adStandInFill { display: block; height: 100%; background: #6f7aa0; transform: scaleX(0); transform-origin: left; }

/* Short screens (a phone on its side, or a very wide strip): everything tightens up. */
@media (max-height: 430px) {
  .overlay { gap: 7px; padding: 8px 14px; }
  .sub { font-size: 13px; }
  button.big { padding: 9px 20px; font-size: 16px; min-width: 160px; }
  #rankLine, #winXp { padding: 5px 12px; font-size: 12px; }
  #winStats div { padding: 4px 14px; }
  #winStats b { font-size: 17px; }
  #bottom button { padding: 8px 10px; font-size: 11px; }
  #menu { flex-direction: row; flex-wrap: wrap; align-content: safe center; column-gap: 16px; }
  #menu .logo, #menu .sub { flex-basis: 100%; }
  #menu .sub { max-width: none; }
  #winHead, #winFoot { gap: 5px; }
  button.big.ad { padding: 7px 16px; font-size: 14px; }
}
/* Narrow screens. */
@media (max-width: 340px) {
  #bottom { gap: 5px; }
  #bottom button { padding: 9px 7px; font-size: 10px; letter-spacing: .02em; }
  #meters { font-size: 9px; gap: 2px 8px; }
  .meter b { font-size: 12px; }
  button.big { min-width: 0; width: 100%; }
}
