/* =========================================================
   Squeaky Pipeline — Yandex Games friendly UI
   - No scroll, no selection, no drag
   - Responsive portrait/landscape
   ========================================================= */

:root{
  --vh: 100vh;
  --vvb: 0px; /* visualViewport bottom inset (browser UI) */
  --banner: 0px; /* reserved space for sticky banner (safety) */
  --cell: 54px;
  --gap: 7px;

  --radius: 18px;
  --radius-sm: 14px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body{
  width:100%;
  height:100%;
  margin:0;
  padding:0;
  overflow:hidden;
  background:#0b0d10;
  font-family: var(--font);
}

body{
  overscroll-behavior:none;
}

#app{
  position:relative;
  width:100%;
  height: var(--vh);
  overflow:hidden;
  touch-action:none; /* no page pan/zoom */
  color: var(--text);
  user-select:none;
  -webkit-user-select:none;
  -webkit-touch-callout:none;
}

#bg{
  position:absolute;
  inset:0;
  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(255,168,91,0.10), transparent 60%),
    radial-gradient(900px 600px at 80% 60%, rgba(91,180,255,0.08), transparent 65%),
    linear-gradient(180deg, rgba(255,255,255,0.03), transparent 45%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  filter: saturate(1.05);
}

/* subtle "film grain" (pure CSS, no images)
   Keep static (no animation) to avoid expensive repaints on mobile. */
#bg::after{
  content:'';
  position:absolute;
  inset:0;
  pointer-events:none;
  opacity: 0.18;
  background:
    repeating-linear-gradient( 45deg,
      rgba(255,255,255,0.02) 0px,
      rgba(255,255,255,0.02) 1px,
      rgba(0,0,0,0.00) 2px,
      rgba(0,0,0,0.00) 6px
    );
  mix-blend-mode: overlay;
}

#root{
  position:relative;
  width:100%;
  height:100%;
  padding-bottom: 0;
}

/* Boot gating: keep UI hidden until SDK ready() + language are applied */
#app.booting #root{
  opacity: 0;
  pointer-events:none;
}
#app:not(.booting) #root{
  opacity: 1;
  pointer-events:auto;
}

/* ======================= THEMES ======================= */
.theme-dark{
  --bg0: #07090c;
  --bg1: #0b0f14;
  --text: rgba(245,248,255,0.92);
  --muted: rgba(245,248,255,0.62);
  --faint: rgba(245,248,255,0.42);

  --card: rgba(20,25,34,0.72);
  --cardBorder: rgba(255,255,255,0.09);

  --btn: rgba(255,255,255,0.06);
  --btnBorder: rgba(255,255,255,0.12);

  --tile: rgba(255,255,255,0.05);
  --tileBorder: rgba(255,255,255,0.11);

  --accent: #ffb06a;      /* warm copper */
  --accent2:#76c3ff;      /* cold steel */
  --danger: #ff6f6f;
  --ok: #7ef0b8;

  --pipeEdge: rgba(0,0,0,0.55);
  --pipeBody: rgba(222,182,140,0.90);
  --pipeHi: rgba(255,255,255,0.22);
  --water: rgba(126, 230, 255, 0.92);
  --waterGlow: rgba(126, 230, 255, 0.32);

  --starOn: rgba(255, 208, 106, 0.98);
  --starOff: rgba(245,248,255,0.32);
  --starGlow: rgba(255, 208, 106, 0.30);
}

.theme-light{
  --bg0:#f6f7fb;
  --bg1:#eef1f7;
  --text: rgba(10,14,18,0.92);
  --muted: rgba(10,14,18,0.62);
  --faint: rgba(10,14,18,0.42);

  --card: rgba(255,255,255,0.78);
  --cardBorder: rgba(10,14,18,0.08);

  --btn: rgba(10,14,18,0.05);
  --btnBorder: rgba(10,14,18,0.12);

  --tile: rgba(10,14,18,0.04);
  --tileBorder: rgba(10,14,18,0.12);

  --accent:#b85b27;
  --accent2:#1f6fb0;
  --danger:#c73737;
  --ok:#147a48;

  --pipeEdge: rgba(0,0,0,0.18);
  --pipeBody: rgba(184, 120, 70, 0.92);
  --pipeHi: rgba(255,255,255,0.34);
  --water: rgba(0, 126, 190, 0.92);
  --waterGlow: rgba(0, 126, 190, 0.26);

  --starOn: rgba(255, 186, 74, 0.96);
  --starOff: rgba(10,14,18,0.26);
  --starGlow: rgba(255, 186, 74, 0.22);
}

/* ======================= SCREENS ======================= */
.screen{
  position:absolute;
  inset:0;
  display:none;
  flex-direction:column;
  gap: 12px;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-bottom: calc(16px + env(safe-area-inset-bottom) + var(--vvb) + var(--banner));
  overflow:hidden;
}

.screen.active{ display:flex; }

.screen-inner{
  width: min(560px, 100%);
  margin: 0 auto;
  display:flex;
  flex-direction:column;
  gap: 12px;
}

.menu-header{ padding: 2px 2px 0; }
.logo{ display:flex; align-items:center; gap: 12px; }
.logo-mark{
  width: 44px; height:44px;
  border-radius: 14px;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow: 0 14px 28px rgba(0,0,0,0.25);
  overflow:hidden;
}
.brand-icon{ width:100%; height:100%; display:block; }
.logo-mark .brand-icon{ width:44px; height:44px; }
.logo-text h1{
  margin:0;
  font-size: 22px;
  letter-spacing: 0.2px;
  color: var(--text);
}
.tagline{
  margin-top: 3px;
  font-size: 13.5px;
  color: var(--muted);
}

/* ======================= SPLASH ======================= */
.boot{
  position:absolute;
  inset:0;
  z-index: 1000;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 18px;
  padding-top: calc(18px + env(safe-area-inset-top));
  padding-bottom: calc(18px + env(safe-area-inset-bottom) + var(--vvb) + var(--banner));
  background:
    radial-gradient(900px 500px at 30% 20%, rgba(255,176,106,0.10), transparent 60%),
    radial-gradient(700px 520px at 75% 65%, rgba(118,195,255,0.10), transparent 60%),
    rgba(0,0,0,0.82);
  opacity: 0;
  pointer-events:none;
  transition: opacity 240ms ease;
}
.boot.active{ opacity: 1; pointer-events:auto; }
.boot.hide{ opacity: 0; pointer-events:none; }

.boot-inner{
  width: 92px;
  height: 92px;
  border-radius: 28px;
  background: var(--card);
  border: 1px solid var(--cardBorder);
  box-shadow: 0 18px 56px rgba(0,0,0,0.35);
  display:flex;
  align-items:center;
  justify-content:center;
  position:relative;
  overflow:hidden;
}
.boot-inner::after{
  content:'';
  position:absolute;
  inset:-30%;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.14) 40%, rgba(255,255,255,0.04) 60%, transparent 100%);
  transform: translateX(-65%) rotate(18deg);
  animation: bootShine 1.1s ease-in-out infinite;
  opacity: 0.75;
  pointer-events:none;
}
.boot-icon{
  width: 60px;
  height: 60px;
  display:block;
  filter: drop-shadow(0 18px 28px rgba(0,0,0,0.28));
}

@keyframes bootShine{
  0%{ transform: translateX(-65%) rotate(18deg); }
  55%{ transform: translateX(70%) rotate(18deg); }
  100%{ transform: translateX(70%) rotate(18deg); }
}

@media (prefers-reduced-motion: reduce){
  .boot-inner::after{ animation:none; display:none; }
}

.splash{
  position:absolute;
  inset:0;
  z-index: 999;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 18px;
  padding-top: calc(18px + env(safe-area-inset-top));
  padding-bottom: calc(18px + env(safe-area-inset-bottom) + var(--vvb) + var(--banner));
  background:
    radial-gradient(900px 500px at 30% 20%, rgba(255,176,106,0.10), transparent 60%),
    radial-gradient(700px 520px at 75% 65%, rgba(118,195,255,0.10), transparent 60%),
    rgba(0,0,0,0.58);
  opacity: 0;
  pointer-events:none;
  transition: opacity 260ms ease;
}
.splash.active{ opacity: 1; pointer-events:auto; }
.splash.hide{ opacity: 0; pointer-events:none; }

.splash-inner{
  width: min(520px, 100%);
  text-align:center;
  padding: 22px 18px;
  border-radius: 26px;
  background: var(--card);
  border: 1px solid var(--cardBorder);
  box-shadow: 0 18px 56px rgba(0,0,0,0.35);
  backdrop-filter: blur(14px);
  transform: translateY(0);
  animation: splashPop 520ms cubic-bezier(.2,.9,.2,1) both;
}

.splash-logo{
  width: 96px;
  height: 96px;
  margin: 0 auto 12px;
  border-radius: 28px;
  box-shadow: 0 18px 56px rgba(0,0,0,0.30);
  position: relative;
  overflow:hidden;
}
.splash-logo::after{
  content:'';
  position:absolute;
  inset:-30%;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.16) 40%, rgba(255,255,255,0.05) 60%, transparent 100%);
  transform: translateX(-60%) rotate(18deg);
  animation: splashShine 1.25s ease-in-out infinite;
  opacity: 0.75;
  pointer-events:none;
}
.splash-logo .brand-icon{ width:100%; height:100%; }

.splash-title{
  font-size: 22px;
  font-weight: 860;
  letter-spacing: 0.2px;
  color: var(--text);
}
.splash-studio{
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: 0.25px;
  color: var(--muted);
}

@keyframes splashPop{
  0%{ opacity: 0; transform: translateY(8px) scale(0.985); }
  100%{ opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes splashShine{
  0%{ transform: translateX(-60%) rotate(18deg); }
  55%{ transform: translateX(65%) rotate(18deg); }
  100%{ transform: translateX(65%) rotate(18deg); }
}

@media (prefers-reduced-motion: reduce){
  .splash-inner{ animation: none; }
  .splash-logo::after{ animation: none; display:none; }
}

.card{
  background: var(--card);
  border: 1px solid var(--cardBorder);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.22);
  backdrop-filter: blur(10px);
}

.stats-row{
  display:flex;
  gap: 12px;
  align-items:stretch;
}
.stats-row.small{ margin-top: 10px; }

.stat{
  flex:1;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.07);
  padding: 10px 12px;
  background: rgba(255,255,255,0.04);
}
.theme-light .stat{ border-color: rgba(10,14,18,0.06); background: rgba(10,14,18,0.03); }
.stat.wide{ flex: 1; }
.stat-label{
  font-size: 12px;
  color: var(--muted);
}
.stat-value{
  margin-top: 2px;
  font-size: 18px;
  font-weight: 720;
  letter-spacing: 0.2px;
  color: var(--text);
}

.menu-actions{ display:flex; flex-direction:column; gap: 10px; }
.menu-footer .row{ justify-content:space-between; }

.row{
  display:flex;
  gap: 10px;
  align-items:center;
  justify-content:center;
  flex-wrap:wrap;
}

.fineprint{
  margin-top: 10px;
  text-align:center;
  color: var(--faint);
  font-size: 12px;
}
.dot{ margin: 0 6px; opacity:0.7; }

/* ======================= BUTTONS ======================= */
.btn{
  appearance:none;
  border: 1px solid var(--btnBorder);
  background: var(--btn);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 14px 14px;
  width:100%;
  font-size: 16px;
  font-weight: 720;
  letter-spacing: 0.2px;
  cursor:pointer;
  user-select:none;
  transition: transform 120ms ease, filter 120ms ease, background 120ms ease;
}
.btn:hover{ filter: brightness(1.05); }
.btn:active{ transform: translateY(1px); }
.btn:disabled{ opacity:0.55; cursor:default; transform:none; }

.btn:focus-visible,
.tile:focus-visible,
.iconbtn:focus-visible{
  outline: 2px solid rgba(118,195,255,0.55);
  outline-offset: 2px;
}

.btn.primary{
  background:
    radial-gradient(18px 18px at 25% 25%, rgba(255,255,255,0.22), transparent 60%),
    linear-gradient(135deg, rgba(255,176,106,0.92), rgba(118,195,255,0.74));
  border-color: rgba(255,255,255,0.14);
  color: rgba(10,12,16,0.92);
  text-shadow: 0 1px 0 rgba(255,255,255,0.25);
}
.btn.primary:hover{ filter: brightness(1.03) saturate(1.05); }

.btn.small{
  width:auto;
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 12px;
  font-weight: 700;
}
.btn.danger{
  border-color: rgba(255,111,111,0.32);
  background: rgba(255,111,111,0.10);
  color: var(--danger);
}

/* ======================= TOP/BOTTOM BARS ======================= */
.topbar{
  height: 50px;
  min-height: 50px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 0 8px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--cardBorder);
  box-shadow: 0 10px 24px rgba(0,0,0,0.18);
}

.topbar-title{
  font-size: 15px;
  font-weight: 760;
  color: var(--text);
  letter-spacing: 0.2px;
  display:flex;
  align-items:center;
  gap: 8px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.sep{
  opacity:0.6;
  padding: 0 4px;
}

.topbar-right{
  display:flex;
  gap: 8px;
  align-items:center;
}

.pill{
  min-width: 44px;
  height: 30px;
  padding: 0 9px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  font-size: 13.5px;
  font-weight: 760;
  color: var(--text);
}

/* keep pills compact when we have 3 of them on mobile */
@media (max-width: 420px){
  .pill{ min-width: 42px; padding: 0 8px; font-size: 13px; }
}

/* Mobile portrait: keep the header on ONE line (more space for the board).
   Reduce noise and shrink metrics. */
@media (max-width: 420px){
  #pillMoves{ display:none; }
  .topbar-title{ font-size: 14px; }
  .topbar-title #labelMode,
  .topbar-title .sep{ display:none; }
}
.theme-light .pill{ background: rgba(10,14,18,0.05); border-color: rgba(10,14,18,0.10); }

.iconbtn{
  width: 38px;
  height: 38px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius: 13px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 18px;
  font-weight: 850;
  cursor:pointer;
  transition: transform 120ms ease, filter 120ms ease;
}
.theme-light .iconbtn{ border-color: rgba(10,14,18,0.12); background: rgba(10,14,18,0.05); }
.iconbtn:hover{ filter: brightness(1.05); }
.iconbtn:active{ transform: translateY(1px); }

.topbar-spacer{
  width: 38px;
  height: 38px;
}

.bottombar{
  display:flex;
  gap: 10px;
  padding-top: 10px;
}
.bottombar .btn{ padding: 14px 12px; }

/* ======================= HOW SCREEN ======================= */
.content-wrap{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.content{
  width: min(560px, 100%);
}
.content h2{
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--text);
}
.content p{
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}
.bullets{
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}
.bullets li{ margin: 8px 0; }

/* ======================= RATINGS SCREEN ======================= */
.ratings-card{
  display:flex;
  flex-direction:column;
  gap: 10px;
}

.tabs{
  display:flex;
  gap: 8px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--btnBorder);
  background: rgba(255,255,255,0.04);
}
.theme-light .tabs{ background: rgba(10,14,18,0.04); }

.seg{
  flex: 1;
  padding: 10px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 750;
  cursor:pointer;
  transition: filter 120ms ease, transform 120ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.seg:hover{ filter: brightness(1.05); }
.seg:active{ transform: translateY(1px); }
.seg.active{
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
  color: var(--text);
}
.theme-light .seg.active{
  background: rgba(10,14,18,0.07);
  border-color: rgba(10,14,18,0.12);
}

.ratings-status{
  font-size: 13.5px;
  color: var(--muted);
  padding: 6px 4px 0;
  min-height: 20px;
}

.ratings-list{
  display:flex;
  flex-direction:column;
  gap: 6px;
  padding: 4px 0;
}

.ratings-empty{
  padding: 10px 8px;
  text-align:center;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--muted);
}

.ratings-card .fineprint{
  color: var(--muted);
}

.rating-row{
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.04);
}
.theme-light .rating-row{
  border-color: rgba(10,14,18,0.10);
  background: rgba(10,14,18,0.04);
}

.rating-row.me{
  border-color: rgba(126,230,255,0.22);
  background: rgba(126,230,255,0.06);
}
.rating-rank{
  min-width: 34px;
  text-align:right;
  font-variant-numeric: tabular-nums;
  color: var(--faint);
  font-weight: 800;
}
.rating-player{
  flex:1;
  display:flex;
  align-items:center;
  gap: 10px;
  min-width: 0;
}
.rating-avatar{
  width: 26px;
  height: 26px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  object-fit: cover;
  background: rgba(0,0,0,0.10);
}
.theme-light .rating-avatar{ border-color: rgba(10,14,18,0.10); }
.rating-name{
  color: var(--text);
  font-size: 13.5px;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rating-score{
  min-width: 56px;
  text-align:right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 850;
}

.rating-divider{
  height: 14px;
  display:flex;
  align-items:center;
  justify-content:center;
  color: var(--faint);
  font-weight: 900;
  letter-spacing: 2px;
  opacity: 0.65;
}

.ratings-actions{
  justify-content: space-between;
  gap: 10px;
  padding-top: 6px;
}
.ratings-actions .btn{ flex: 1; }

@media (max-width: 420px){
  .seg{ font-size: 13px; padding: 9px 8px; }
  .rating-row{ padding: 8px 9px; }
  .rating-score{ min-width: 52px; }
}

/* ======================= LEVELS SCREEN ======================= */
.levels-card{
  display:flex;
  flex-direction:column;
  gap: 10px;
}

.levels-meta{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}

.levels-progress,
.levels-page{
  font-size: 13.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.levels-grid{
  display:grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding: 6px 2px;
}

@media (max-width: 520px){
  .levels-grid{ grid-template-columns: repeat(5, 1fr); gap: 7px; }
}
@media (max-width: 380px){
  .levels-grid{ grid-template-columns: repeat(4, 1fr); gap: 7px; }
}

.levelbtn{
  appearance:none;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05);
  border-radius: 16px;
  padding: 10px 6px;
  color: var(--text);
  cursor:pointer;
  user-select:none;
  box-shadow: 0 10px 22px rgba(0,0,0,0.18);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap: 6px;
  aspect-ratio: 1 / 1;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease;
}
.theme-light .levelbtn{
  border-color: rgba(10,14,18,0.12);
  background: rgba(10,14,18,0.04);
  box-shadow: 0 12px 26px rgba(0,0,0,0.10);
}
.levelbtn:hover{ filter: brightness(1.05); }
.levelbtn:active{ transform: translateY(1px); }

.levelnum{
  font-size: 15px;
  font-weight: 860;
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
}

.levelstars{
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--starOn);
  text-shadow: 0 0 10px var(--starGlow);
}
.levelstars.dim{ color: var(--starOff); text-shadow:none; }

.mini-star{
  display: inline-block;
  margin: 0 1px;
  color: var(--starOn);
  text-shadow: 0 0 10px var(--starGlow);
}
.mini-star.dim{
  color: var(--starOff);
  text-shadow: none;
  opacity: 0.62;
}

.levelbtn.s2{ border-color: rgba(255,176,106,0.22); }
.levelbtn.s3{ border-color: rgba(255,176,106,0.30); box-shadow: 0 12px 26px rgba(0,0,0,0.22), 0 0 0 1px rgba(255,176,106,0.10); }

.levels-actions{
  justify-content: space-between;
  gap: 10px;
  padding-top: 2px;
}
.levels-actions .btn{ flex: 1; }

/* ======================= BOARD ======================= */
.board-wrap{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  position: relative;
}

.board{
  display:grid;
  gap: var(--gap);
  align-content:center;
  justify-content:center;
  touch-action:none;
}

/* ======================= WIN FX ======================= */
.winfx{
  position:absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events:none;
  border-radius: 18px;
  overflow:hidden;
  z-index: 3;
  opacity: 1;
  mix-blend-mode: screen;
}

.winfx::before{
  content:"";
  position:absolute;
  inset: -60% -60%;
  background:
    linear-gradient(90deg,
      transparent 0%,
      rgba(255,255,255,0.00) 35%,
      rgba(255,255,255,0.16) 50%,
      rgba(255,255,255,0.06) 58%,
      transparent 100%);
  transform: translateX(-70%) rotate(18deg);
  opacity: 0;
}

.winfx::after{
  content:"";
  position:absolute;
  inset: 0;
  background: radial-gradient(120px 120px at 50% 50%, rgba(126,230,255,0.14), transparent 62%);
  opacity: 0;
}

.board-wrap.celebrate .winfx::before{
  animation: winSweep 1.25s cubic-bezier(.18,.85,.2,1) 1 both;
}
.board-wrap.celebrate .winfx::after{
  animation: winGlow 3.0s ease-out 1 both;
}

@keyframes winSweep{
  0%{ transform: translateX(-75%) rotate(18deg); opacity: 0; }
  10%{ opacity: 0.95; }
  65%{ opacity: 0.65; }
  100%{ transform: translateX(75%) rotate(18deg); opacity: 0; }
}

@keyframes winGlow{
  0%{ opacity: 0; }
  16%{ opacity: 1; }
  100%{ opacity: 0; }
}

.tile{
  width: var(--cell);
  height: var(--cell);
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--tileBorder);
  background:
    radial-gradient(18px 18px at 28% 22%, rgba(255,255,255,0.08), transparent 60%),
    linear-gradient(180deg, rgba(255,255,255,0.06), transparent 60%),
    var(--tile);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 10px 22px rgba(0,0,0,0.22);
  padding: 0;
  cursor:pointer;
  /* Avoid animating box-shadow: it's paint-heavy on mobile and
     can introduce input lag when many tiles change state. */
  transition: transform 90ms ease, filter 120ms ease, border-color 120ms ease;
}
.theme-light .tile{
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.45),
    0 12px 26px rgba(0,0,0,0.10);
}

.tile:hover{ filter: brightness(1.04); }
.tile:active{ transform: translateY(1px); }
.tile:disabled{ opacity: 0.78; cursor:default; }
.tile.locked{
  cursor:default;
  border-color: rgba(255,255,255,0.18);
}

/* IMPORTANT (mobile performance)
   Do NOT animate large overlays for each wet tile.
   Keep the scene calm: only water animation remains. */

.tile svg{
  width:100%;
  height:100%;
  display:block;
}

.pipe-edge{
  stroke: var(--pipeEdge);
  stroke-width: 36;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.pipe-shadow{
  stroke: rgba(0,0,0,0.40);
  stroke-width: 34;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  opacity: 0.55;
}
.pipe-body{
  stroke: var(--pipeBody);
  stroke-width: 28;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.pipe-hi{
  stroke: var(--pipeHi);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  opacity: 0.75;
}
.pipe-water{
  stroke: var(--water);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  opacity: 0;
  stroke-opacity: 1;
  /* No SVG filters on mobile: keep it smooth. */
  filter: none;
  stroke-dasharray: 10 12;
  stroke-dashoffset: 0;
  /* IMPORTANT (performance):
     Do NOT animate all tiles all the time.
     We enable animation only when the tile is "wet". */
  animation: none;
}

/* Extra highlight path removed for performance (keep only one moving water path). */
.pipe-water-hi{ display:none; }
@keyframes flow{
  0%{ stroke-dashoffset: 0; }
  100%{ stroke-dashoffset: -44; }
}

/* center joints were removed (cleaner look) */

.tile.wet{
  border-color: rgba(126,230,255,0.22);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 12px 26px rgba(0,0,0,0.26),
    0 0 0 1px rgba(126,230,255,0.12);
}
.tile.wet .pipe-water{
  opacity: 1;
  /* Steps-based animation reduces continuous repaints on mobile
     while still looking like flowing water. */
  animation: flow 1.4s steps(12) infinite;
}

/* Low-power mode: avoid animating stroke-dashoffset in many SVGs.
   Use a very cheap opacity pulse instead (still gives a sense of life). */
#app.lowpower .tile.wet .pipe-water{
  stroke-dasharray: none;
  animation: waterPulse 1.9s ease-in-out infinite;
}

@keyframes waterPulse{
  0%, 100%{ stroke-opacity: 0.62; }
  50%{ stroke-opacity: 1; }
}

@media (prefers-reduced-motion: reduce){
  .tile.wet .pipe-water{
    animation: none !important;
    stroke-dasharray: none;
  }
}
.tile.wet .pipe-water-hi{ opacity: 0; }

/* Couplings at tile edges help read stubs/joins */
.coupling{
  fill: rgba(0,0,0,0.12);
  stroke: rgba(255,255,255,0.22);
  stroke-width: 3;
  opacity: 0.82;
}
.tile.wet .coupling{
  stroke: rgba(126,230,255,0.42);
  opacity: 0.92;
}
.theme-light .coupling{
  fill: rgba(10,14,18,0.06);
  stroke: rgba(10,14,18,0.20);
}
.theme-light .tile.wet .coupling{
  stroke: rgba(0,126,190,0.32);
}

/* Leak droplets (only when a specific side is leaking) */
.leak-drop{
  fill: rgba(255,111,111,0.92);
  opacity: 0;
  filter: none;
}
.tile.leakN .dropN,
.tile.leakE .dropE,
.tile.leakS .dropS,
.tile.leakW .dropW{
  opacity: 1;
}

.tile.end,
.tile.goal{
  border-color: rgba(255,176,106,0.30);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 12px 26px rgba(0,0,0,0.26),
    0 0 0 1px rgba(255,176,106,0.12);
}

.tile.start{
  border-color: rgba(126,230,255,0.28);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 12px 26px rgba(0,0,0,0.26),
    0 0 0 1px rgba(126,230,255,0.10);
}

.tile.leak{
  border-color: rgba(255,111,111,0.55);
  /* No pulsing borders (performance + less flicker). */
}

.marker{
  fill: rgba(255,255,255,0.08);
  stroke: rgba(255,255,255,0.30);
  stroke-width: 3;
}
.marker.start{
  fill: rgba(126,230,255,0.10);
  stroke: rgba(126,230,255,0.62);
}
.marker.end{
  fill: rgba(255,176,106,0.10);
  stroke: rgba(255,176,106,0.70);
}

/* ========= Endpoint ornaments (Source & Boiler) ========= */
.endpoint-shadow{
  fill: rgba(0,0,0,0.22);
  opacity: 0.9;
}

.source-nozzle{
  fill: rgba(255,255,255,0.06);
  stroke: rgba(255,255,255,0.22);
  stroke-width: 3;
}

.source-handle{
  fill: rgba(255,255,255,0.06);
  stroke: rgba(255,255,255,0.22);
  stroke-width: 3;
}
.source-handleknob{
  fill: rgba(255,255,255,0.08);
  stroke: rgba(255,255,255,0.22);
  stroke-width: 3;
}
.source-ring{
  fill: rgba(126,230,255,0.10);
  stroke: rgba(126,230,255,0.72);
  stroke-width: 3;
}
.source-arrow{
  fill: rgba(126,230,255,0.92);
  filter: none;
}
.bubble{ display:none; }

.boiler-body{
  fill: rgba(255,176,106,0.12);
  stroke: rgba(255,176,106,0.62);
  stroke-width: 3;
}
.boiler-base{
  fill: rgba(255,176,106,0.10);
  stroke: rgba(255,176,106,0.50);
  stroke-width: 3;
}
.boiler-window{
  fill: rgba(126,230,255,0.80);
  opacity: 0;
  filter: none;
}
.tile.end.wet .boiler-window{
  opacity: 0.92;
}
.boiler-rivet{
  fill: rgba(255,255,255,0.28);
  opacity: 0.80;
}
.boiler-detail{
  stroke: rgba(255,255,255,0.22);
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
  opacity: 0.9;
}
.boiler-gauge{
  fill: rgba(0,0,0,0.16);
  stroke: rgba(255,255,255,0.22);
  stroke-width: 3;
}
.boiler-needle{
  stroke: rgba(255,176,106,0.88);
  stroke-width: 3.5;
  stroke-linecap: round;
}

/* Steam removed (keep only water motion). */
.steam{ display:none; }

/* Warm glow removed (less flicker, better FPS). */

/* ======================= OVERLAY ======================= */
.overlay{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 18px;
  background: rgba(0,0,0,0.55);
}
.overlay.hidden{ display:none; }

.modal{
  width: min(520px, 100%);
  text-align:center;
}
.modal h2{
  margin: 0 0 8px;
  font-size: 20px;
  color: var(--text);
}
.modal p{
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-line; /* allow \n in modal text (star goals / reasons) */
}

.stars{
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 6px;
  font-size: 26px;
  margin-bottom: 14px;
  color: var(--starOn);
}
.star{
  color: var(--starOn);
  text-shadow:
    0 0 18px var(--starGlow),
    0 0 8px rgba(255,255,255,0.08),
    0 10px 20px rgba(0,0,0,0.35);
  filter: none;
}
.star.dim{
  color: var(--starOff);
  text-shadow: none;
  opacity: 0.62;
}

/* ======================= TOAST ======================= */
.toast{
  position:absolute;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom) + var(--vvb) + var(--banner));
  transform: translateX(-50%);
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.62);
  color: rgba(245,248,255,0.92);
  border: 1px solid rgba(255,255,255,0.12);
  font-size: 13px;
  box-shadow: 0 10px 22px rgba(0,0,0,0.25);
  pointer-events:none;
  opacity: 0;
  transition: opacity 140ms ease, transform 140ms ease;
}
.theme-light .toast{
  background: rgba(10,14,18,0.72);
  color: rgba(245,248,255,0.92);
}
.toast.show{
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

.hidden{ display:none !important; }

/* ======================= SMALL HEIGHT SAFETY ======================= */
@media (max-height: 520px){
  .screen{ padding: 12px; padding-top: calc(12px + env(safe-area-inset-top)); padding-bottom: calc(12px + env(safe-area-inset-bottom) + var(--vvb) + var(--banner)); }
  .card{ padding: 12px; border-radius: 16px; }
  .btn{ padding: 12px; }
  .topbar{ height: 46px; min-height: 46px; }
  .bottombar .btn{ padding: 12px; }
}

/* =========================================================
   v1.5.3 — Legendary Plumber (no logo) + full-screen boot loader
   ========================================================= */

/* Menu: title only (no logo mark) */
.menu-title{
  margin: 0;
  font-size: 22px;
  font-weight: 860;
  letter-spacing: 0.2px;
  color: var(--text);
}

/* Boot overlay should hide the UI completely (opaque base layer) */
.boot{
  background:
    radial-gradient(900px 500px at 30% 20%, rgba(255,176,106,0.12), transparent 60%),
    radial-gradient(700px 520px at 75% 65%, rgba(118,195,255,0.12), transparent 60%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

/* Simple indeterminate progress bar (no text, no logo) */
.boot-bar{
  width: min(340px, 72vw);
  height: 12px;
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 18px 56px rgba(0,0,0,0.35);
}

.theme-light .boot-bar{
  background: rgba(10,14,18,0.06);
  border-color: rgba(10,14,18,0.12);
  box-shadow: 0 18px 56px rgba(0,0,0,0.18);
}

.boot-bar::before{
  content:'';
  position:absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 44%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255,176,106,0.92), rgba(118,195,255,0.74));
  transform: translateX(-130%);
  will-change: transform;
  animation: bootSlide 1.05s ease-in-out infinite;
}

@keyframes bootSlide{
  0%{ transform: translateX(-130%); }
  55%{ transform: translateX(260%); }
  100%{ transform: translateX(260%); }
}

@media (prefers-reduced-motion: reduce){
  .boot-bar::before{ animation:none; opacity: 0.85; transform:none; width: 100%; }
}
