/* Block Toilet Rush — UI chrome. Canvas draws the board; DOM draws HUD & menus. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #2a2622; color: #333; overflow: hidden;
  user-select: none; -webkit-user-select: none;
  --topH: clamp(84px, 13vh, 118px);
  --botH: clamp(92px, 14vh, 132px);
  --accent: #c07f3f; --accent2: #9a6026;
  --page1: #f4e8d0; --page2: #e6cfa4; --ink: #5a3d1e; --card: #fff8ec;
}
/* per-theme page chrome */
body[data-theme="wood"]    { --accent:#c07f3f; --accent2:#9a6026; --page1:#f4e8d0; --page2:#e6cfa4; --ink:#5a3d1e; --card:#fdf3e0; }
body[data-theme="plastic"] { --accent:#f2903a; --accent2:#c96e1c; --page1:#f0e2df; --page2:#e2cfcb; --ink:#5b4a47; --card:#fbf1e8; }
body[data-theme="flat"]    { --accent:#25b6c8; --accent2:#1690a0; --page1:#c1e2f3; --page2:#a6d3ee; --ink:#33506a; --card:#eef6fb; }
body[data-theme="iso"]     { --accent:#7cc251; --accent2:#5a9b36; --page1:#d9e7b2; --page2:#bfd68b; --ink:#4f5b30; --card:#f2f7e6; }
body[data-theme="potty"]   { --accent:#ff8fab; --accent2:#e46b8a; --page1:#ffe6ef; --page2:#d6f4ec; --ink:#8a4a63; --card:#fff2f6; }

#app {
  position: relative; width: 100%; max-width: 480px; height: 100vh; height: 100dvh;
  margin: 0 auto; overflow: hidden;
  background: linear-gradient(180deg, var(--page1), var(--page2));
  box-shadow: 0 0 40px rgba(0,0,0,.35);
}
.screen { position: absolute; inset: 0; }
[hidden] { display: none !important; }

/* ---------- canvas ---------- */
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tut-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 15; pointer-events: none; }
.skip-tut {
  position: absolute; top: calc(48px + 40px); left: 10px; z-index: 16;
  border: none; border-radius: 999px; padding: 7px 12px; font-size: 12px; font-weight: 700;
  background: rgba(255,255,255,.85); color: #333; box-shadow: 0 2px 6px rgba(0,0,0,.2); cursor: pointer;
}
.skip-tut:active { transform: scale(.95); }

/* ---------- top HUD ---------- */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; height: 48px;
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 0;
  z-index: 5;
}
.icon-btn {
  width: 38px; height: 38px; border: none; border-radius: 12px;
  background: rgba(255,255,255,.55); color: var(--ink); font-size: 18px;
  box-shadow: 0 2px 6px rgba(0,0,0,.14); cursor: pointer; flex: none;
}
.icon-btn:active { transform: scale(.94); }
.level-name { font-weight: 800; color: var(--ink); font-size: 15px; }
.coinbox {
  margin-left: auto; background: rgba(255,255,255,.6); color: var(--ink);
  font-weight: 800; padding: 6px 12px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}

/* ---------- status strip ---------- */
.hud-status {
  position: absolute; top: 48px; left: 10px; right: 10px; height: 36px;
  display: flex; align-items: center; gap: 8px; z-index: 5;
}
.route-light {
  flex: 1; height: 30px; border-radius: 999px; display: flex; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 700; color: #fff;
  box-shadow: inset 0 2px 5px rgba(0,0,0,.12);
}
.route-light.idle  { background: #9aa3ab; }
.route-light.ready { background: #46b95e; animation: pulseG 1.1s ease-in-out infinite; }
.route-light.fail  { background: #e05a4a; }
@keyframes pulseG { 0%,100%{ box-shadow: inset 0 2px 5px rgba(0,0,0,.12), 0 0 0 0 rgba(70,185,94,.5);} 50%{ box-shadow: inset 0 2px 5px rgba(0,0,0,.12), 0 0 0 7px rgba(70,185,94,0);} }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.05; color: var(--ink); font-size: 10px; min-width: 40px; }
.stat b { font-size: 14px; }
.dots { display: flex; gap: 3px; margin-top: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: rgba(0,0,0,.16); }
.dot.on { background: #e05a4a; box-shadow: 0 0 5px rgba(224,90,74,.8); }
.piece-info {
  position: absolute; top: var(--topH); left: 0; right: 0; text-align: center;
  font-size: 11px; color: var(--ink); opacity: .6; z-index: 4; pointer-events: none;
  margin-top: -14px;
}

/* in-game theme picker popup */
.theme-pop {
  position: absolute; top: 92px; right: 10px; z-index: 14;
  background: var(--card); border-radius: 16px; padding: 12px; width: 200px;
  box-shadow: 0 12px 30px rgba(0,0,0,.35); animation: pop .18s ease;
}
.theme-pop-title { font-size: 12px; font-weight: 800; color: var(--ink); margin-bottom: 8px; }
.theme-pop-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.theme-pop .theme-chip { padding: 8px 11px; font-size: 12px; }

/* ---------- bottom controls ---------- */
.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--botH);
  display: flex; align-items: center; gap: 10px; padding: 0 12px calc(6px + env(safe-area-inset-bottom));
  z-index: 5;
}
.booster-bar { display: flex; gap: 8px; }
.booster {
  width: 46px; height: 46px; border: none; border-radius: 14px; font-size: 20px;
  background: rgba(255,255,255,.7); color: var(--ink); cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,.15);
}
.booster:active { transform: scale(.93); }
.booster.active { background: var(--accent); color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.5), 0 3px 8px rgba(0,0,0,.2); }
.run-btn {
  flex: 1; height: 58px; border: none; border-radius: 18px; cursor: pointer;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  color: #fff; font-size: 20px; font-weight: 900; letter-spacing: .5px;
  box-shadow: 0 5px 0 var(--accent2), 0 8px 14px rgba(0,0,0,.22);
  text-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.run-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent2), 0 4px 10px rgba(0,0,0,.22); }

/* ---------- toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: calc(var(--botH) + 8px); transform: translateX(-50%) translateY(10px);
  background: rgba(20,20,20,.86); color: #fff; padding: 9px 16px; border-radius: 12px;
  font-size: 13px; max-width: 90%; text-align: center; opacity: 0; transition: .25s; z-index: 8; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- home ---------- */
.home-inner { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; }
.brand { text-align: center; }
.brand-badge { font-size: 44px; }
.brand h1 { margin: 2px 0 4px; font-size: 30px; color: var(--ink); letter-spacing: .5px; }
.tagline { margin: 0; font-size: 13px; color: var(--ink); opacity: .8; }
.panel { background: rgba(255,255,255,.45); border-radius: 18px; padding: 12px 12px 14px; }
.panel.grow { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
.panel-title { font-weight: 800; color: var(--ink); font-size: 14px; margin-bottom: 10px; }
.hint-sm { font-weight: 500; opacity: .6; font-size: 11px; }
.theme-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-chip {
  border: none; border-radius: 999px; padding: 9px 14px; font-size: 13px; font-weight: 700;
  cursor: pointer; opacity: .55; box-shadow: 0 2px 6px rgba(0,0,0,.15); transition: .15s;
}
.theme-chip.active { opacity: 1; box-shadow: 0 0 0 3px rgba(255,255,255,.7), 0 3px 8px rgba(0,0,0,.2); transform: translateY(-1px); }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; overflow-y: auto; }
.level-btn {
  aspect-ratio: 1; border: none; border-radius: 14px; cursor: pointer;
  background: linear-gradient(180deg, #fff, #f0e9dd); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 3px 6px rgba(0,0,0,.14); font-size: 16px;
}
.level-btn b { font-size: 18px; font-weight: 900; }
.level-btn small { font-size: 9px; color: #d9a02a; letter-spacing: -1px; }
.level-btn.locked { opacity: .4; filter: grayscale(.6); cursor: not-allowed; }
.level-btn:not(.locked):active { transform: scale(.95); }
.big-btn {
  border: none; border-radius: 16px; height: 54px; cursor: pointer;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  color: #fff; font-size: 18px; font-weight: 900; letter-spacing: .5px;
  box-shadow: 0 5px 0 var(--accent2), 0 8px 14px rgba(0,0,0,.22);
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent2); }
.text-btn {
  border: none; background: transparent; color: var(--ink); opacity: .6;
  font-size: 12px; padding: 8px; cursor: pointer; text-decoration: underline;
}
.text-btn:active { opacity: 1; }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 20; }
.card {
  width: 84%; max-width: 340px; background: var(--card); border-radius: 24px; padding: 24px 20px;
  text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.4); animation: pop .3s ease;
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.card-emoji { font-size: 52px; }
.card h2 { margin: 6px 0 10px; color: var(--ink); font-size: 24px; }
.card-row { color: var(--ink); font-size: 15px; margin: 6px 0; }
.card-row.sub { opacity: .75; font-size: 14px; }
.stars-big { font-size: 40px; letter-spacing: 4px; margin: 6px 0 12px; }
.stars-big .star { color: rgba(0,0,0,.15); }
.stars-big .star.on { color: #ffce4b; text-shadow: 0 2px 6px rgba(255,180,0,.5); animation: starPop .4s ease backwards; }
.stars-big .star.on:nth-child(2){ animation-delay: .12s; } .stars-big .star.on:nth-child(3){ animation-delay: .24s; }
@keyframes starPop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1); } }
.card-actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.ghost-btn { border: none; background: rgba(0,0,0,.08); color: var(--ink); border-radius: 14px; padding: 12px 16px; font-weight: 700; cursor: pointer; font-size: 14px; }
.ghost-btn:active { transform: scale(.95); }
.card-actions .big-btn { height: auto; padding: 12px 18px; }
