/* 磚塊躲貓貓畫面樣式。
 *
 * 區塊：殼層／選單／選關／棋盤疊層與動物動畫／通關特效／HUD 網子／對話框。
 * 動物動畫掛在 critters.js 輸出的 class（.anim-puff 等）。
 * 網子折斷掛在 nets.js 的 .net-snap。
 * 通關光暈把 rotate 放在 .result-fx-spin，外層只做置中，避免轉一圈停住。
 */
:root {
  color-scheme: dark;
  --nori: #1c3a34;
  --nori-deep: #10241f;
  --porcelain: #eef4f3;
  --mist: #d5e4e0;
  --ink: #14221f;
  --salmon: #e5735c;
  --yolk: #f3c96b;
  --sea: #4e9c94;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --tray: #14302b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Noto Sans TC", "Noto Sans SC", "Noto Sans JP", "Noto Sans KR", "Noto Sans Arabic", "Noto Sans Hebrew", "Noto Sans Devanagari", "Noto Sans Bengali", "Noto Sans Thai", "Noto Sans Khmer", "Noto Sans Lao", "Noto Sans", "PingFang TC", "Hiragino Sans CNS", sans-serif;
  color: var(--porcelain);
  background:
    radial-gradient(1200px 600px at 80% -10%, #2f5d52 0%, transparent 55%),
    linear-gradient(180deg, #1a3832 0%, var(--nori-deep) 100%);
  min-height: 100dvh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

/* ---------- 殼層：左側暖簾、頂欄、按鈕 ---------- */
.noren {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(18vw, 140px);
  background: repeating-linear-gradient(
    90deg,
    #14342f 0 18px,
    #1a4039 18px 22px,
    #0f2a26 22px 40px
  );
  box-shadow: 18px 0 40px #0003;
  pointer-events: none;
  opacity: .55;
}

.app {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  position: relative;
  flex-shrink: 0;
  color: var(--porcelain);
}
.brand-mark svg {
  position: absolute;
  z-index: 0;
  left: 2px;
  top: -3px;
  width: 32px;
  height: 32px;
  display: block;
}
.brand-tile {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  bottom: 0;
  height: 23px;
  border-radius: 9px;
  background: #e5735c;
  box-shadow: inset 0 -8px 0 #d4634e;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong {
  font-family: "Noto Serif TC", "Noto Sans SC", "Noto Sans Arabic", "Noto Sans Hebrew", "Noto Sans Devanagari", "Noto Sans", "Songti TC", serif;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: .04em;
}
.brand-text small {
  font-size: 9px;
  letter-spacing: .28em;
  color: var(--mist);
  margin-top: 3px;
}
html[lang="en"] .brand-text small { display: none; }

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

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:focus-visible { outline: 2px solid var(--yolk); outline-offset: 3px; }

.text-btn {
  background: none;
  border: 0;
  padding: 8px 10px;
  letter-spacing: .12em;
  font-size: 13px;
  color: var(--mist);
}
.site-home { text-decoration: none; }

/* The viewport owns the shell; only menus and text panels may scroll. */
html, body { width:100%; height:100%; overflow:hidden; overscroll-behavior:none; }
body { min-height:0; }
.app {
  width:100%; height:100vh; height:100dvh; min-height:0;
  padding:max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display:flex; flex-direction:column; gap:8px; overflow:hidden;
}
.app .topbar { flex:0 0 auto; width:100%; max-width:1200px; margin:0 auto; gap:8px; }
.app .screen { min-width:0; min-height:0; flex:1; width:100%; max-width:1200px; margin:0 auto; }
.app #screen-menu, .app #screen-levels { overflow-y:auto; overflow-x:hidden; overscroll-behavior:contain; padding:8px; }
.app #screen-menu { max-width:760px; }
.app #screen-play {
  display:grid; gap:6px;
  grid-template-rows:auto auto auto minmax(0,1fr) auto auto;
  grid-template-areas:"hud" "stage" "coach" "board" "hint" "nav";
}
.app #screen-design {
  display:grid; gap:6px;
  grid-template-rows:auto minmax(0,1fr) auto auto auto;
}
.app .screen.hidden, .app .screen[hidden] { display:none !important; }
.app .hud { grid-area:hud; margin:0; }
.app .hud-item { padding:5px 10px; }
.app .hud-item strong { font-size:18px; }
.app .stage-bar { grid-area:stage; margin:0; }
.app .tutorial-coach {
  grid-area:coach; min-height:0; max-height:clamp(80px,22dvh,180px);
  overflow-y:auto; overflow-x:hidden; overscroll-behavior:contain;
  margin:0; padding:8px 12px;
}
.app .tutorial-coach[hidden] { display:none; }
.app .tutorial-title { font-size:18px; margin-bottom:4px; }
.app .tutorial-copy { margin-bottom:4px; }
.app #screen-play > .board-tray { grid-area:board; }
.app .board-tray {
  min-width:0; min-height:0; width:100%; height:100%; max-width:none;
  padding:10px; margin:0; display:flex; align-items:center; justify-content:center;
  background:transparent; box-shadow:none; overflow:hidden;
}
.app .board-stack { flex:0 0 auto; width:var(--board-size, 1px); height:var(--board-size, 1px); }
.app .board-tray canvas { width:100%; height:100%; max-width:100%; }
.app #screen-play > .hint { grid-area:hint; }
.app #screen-play > .play-nav { grid-area:nav; }
.app .hint { margin:0; min-width:0; max-height:3.5em; overflow-y:auto; overflow-x:hidden; }
.app .play-nav { margin:0; }
.app .design-toolbar { margin:0; max-height:22dvh; overflow-y:auto; overflow-x:hidden; }
.app .brand { min-width:0; gap:6px; }
.app .brand-text { min-width:0; overflow-wrap:anywhere; }
.app .utilities { gap:2px; flex-shrink:0; }
.app .text-btn { letter-spacing:normal; }
.app a:focus-visible, .app canvas:focus-visible { outline:2px solid var(--yolk); outline-offset:2px; }
dialog { max-width:calc(100vw - 24px); max-height:calc(100dvh - 24px); overflow-x:hidden; overflow-y:auto; }
#toast { max-width:calc(100vw - 24px); text-align:center; }
@media (min-width:850px), (orientation:landscape) and (max-height:600px) {
  .app #screen-play {
    grid-template-columns:minmax(180px, min(32%,340px)) minmax(0,1fr);
    grid-template-rows:auto auto minmax(0,1fr) auto auto;
    grid-template-areas:"hud board" "stage board" "coach board" "hint board" "nav board";
  }
  .app .tutorial-coach { max-height:none; align-self:stretch; }
  .app .hud { gap:4px; }
  .app .hud-item { padding:5px; }
}
@media (max-width:520px) {
  .app .topbar { flex-wrap:wrap; gap:2px; }
  .app .brand-text strong { font-size:15px; }
  .app .utilities { margin-inline-start:auto; }
  .app .icon-btn { width:34px; height:36px; }
  .app .text-btn { padding:6px; }
  .app .brand-mark { width:30px; }
}
@media (max-width:600px) and (max-height:650px) and (orientation:portrait) {
  .app #screen-play { gap:4px; }
  .app .tutorial-coach { max-height:90px; font-size:12px; padding:6px 10px; }
  .app .tutorial-title { font-size:15px; }
  .app .tutorial-play .stage-bar { display:none; }
  .app .tutorial-play .hud { grid-template-columns:1fr 1fr; }
  .app .tutorial-play .hud > .hud-item:first-child { display:none; }
  .app .hud-item { display:flex; align-items:center; justify-content:center; gap:5px; padding:4px; }
  .app .hud-item strong { margin:0; font-size:16px; }
  .app .hud-item > span { font-size:10px; letter-spacing:0; }
  .app .hint { font-size:11px; max-height:2.8em; }
}
.icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  background: transparent;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn .slash { display: none; }
body.muted #btn-mute .wave { display: none; }
body.muted #btn-mute .slash { display: block; }
/* 音樂關閉：音符變淡並畫上斜線；整體靜音時音樂鈕也一起變淡 */
body.music-off #btn-music .slash { display: block; }
body.music-off #btn-music,
body.muted #btn-music { opacity: .55; }

.lang-wrap { position: relative; }
html[dir="rtl"] .lang-menu {
  right: auto;
  left: 0;
}
html[dir="rtl"] .noren {
  inset: 0 0 0 auto;
  box-shadow: -18px 0 40px #0003;
}
.lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 176px;
  max-height: min(80vh, 560px);
  overflow: auto;
  padding: 6px;
  background: color-mix(in srgb, var(--tray) 88%, #000);
  backdrop-filter: blur(14px);
  border: 1px solid #ffffff22;
  border-radius: 14px;
  z-index: 50;
  box-shadow: 0 16px 40px #0006;
}
.lang-menu.hidden,
.lang-menu[hidden] { display: none; }
.lang-menu [role="option"] {
  display: block;
  width: 100%;
  text-align: start;
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  letter-spacing: 0;
  color: var(--porcelain);
}
.lang-menu [role="option"][aria-selected="true"] {
  background: #ffffff1c;
}
.lang-menu [role="option"]:hover,
.lang-menu [role="option"]:focus-visible {
  background: #ffffff14;
}

.screen.hidden { display: none; }
/* 畫面轉場：舊畫面往上淡出（game.js 等它結束才換 DOM），新畫面從下方滑入；
   兩段加起來與背景音樂的交叉淡化同長 */
.screen.leaving {
  animation: screen-leave .21s ease-in both;
  pointer-events: none;
}
.screen.entering {
  animation: screen-enter .42s var(--ease) both;
}
@keyframes screen-leave {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-12px); }
}
@keyframes screen-enter {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

.eyebrow {
  margin: 0 0 12px;
  letter-spacing: .22em;
  font-size: 12px;
  color: var(--yolk);
}

h1 {
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-weight: 900;
  font-size: clamp(36px, 8vw, 58px);
  line-height: 1.18;
  margin: 0 0 16px;
  letter-spacing: .02em;
}

.lede {
  margin: 0 0 32px;
  max-width: 28em;
  line-height: 1.75;
  color: var(--mist);
  font-size: 15px;
}

.size-block { margin-bottom: 28px; }
.size-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--mist);
}
.size-label strong { color: var(--porcelain); font-weight: 800; }

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pills button {
  min-width: 44px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid #ffffff22;
  background: #ffffff0d;
  padding: 0 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pills button[aria-pressed="true"] {
  background: var(--yolk);
  color: var(--ink);
  border-color: var(--yolk);
}

.menu-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.primary, .ghost {
  border-radius: 999px;
  min-height: 52px;
  padding: 0 26px;
  border: 1px solid transparent;
  font-weight: 800;
  letter-spacing: .06em;
}
.primary {
  background: var(--salmon);
  color: #2a120c;
  box-shadow: 0 10px 24px #e5735c33;
}
.primary:hover { filter: brightness(1.05); }
.ghost {
  background: transparent;
  border-color: #eef4f355;
}
.compact { min-height: 44px; padding: 0 18px; font-size: 14px; }

.best-line {
  margin: 22px 0 0;
  color: var(--mist);
  font-size: 13px;
  min-height: 1.2em;
}

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}
.stage-copy { min-width: 0; }
.stage-line {
  margin: 0;
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-weight: 900;
  font-size: 22px;
  letter-spacing: .04em;
  color: var(--yolk);
}
.stage-note {
  margin: 0;
  font-size: 12px;
  letter-spacing: .1em;
  color: var(--mist);
}

.hint-tools { display: flex; gap: 8px; flex-shrink: 0; }
.hint-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 14px;
  border: 1px solid #ffffff22;
  background: #0e2420cc;
  color: #c5d2ce;
  display: grid;
  place-items: center;
}
.hint-btn svg { width: 26px; height: 26px; display: block; }
.hint-btn:hover:not(:disabled) { background: #ffffff18; color: var(--porcelain); }
.hint-btn:disabled,
.hint-btn.spent {
  opacity: .38;
  cursor: default;
}

.tutorial-play .hint-tools { visibility: hidden; }
.tutorial-play .hud > .hud-item:first-child { visibility: hidden; }

.tutorial-coach {
  margin: 0 0 14px;
  padding: 14px 16px 10px;
  border-radius: 18px;
  background: #0e2420cc;
  border: 1px solid #ffffff22;
}
.tutorial-kicker {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: .14em;
  color: var(--yolk);
}
.tutorial-title {
  margin: 0 0 6px;
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-weight: 900;
  font-size: 20px;
  letter-spacing: .04em;
}
.tutorial-copy {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--mist);
}
.tutorial-coach .text-btn {
  width: auto;
  margin: 0 0 0 auto;
  display: block;
  color: var(--mist);
  letter-spacing: .08em;
}

.overlay-cell.tutorial-glow {
  overflow: visible;
  border-radius: 18%;
  pointer-events: none;
  box-shadow: inset 0 0 0 4px #ff0000, 0 0 0 2px #ff0000cc;
  background: #ff000028;
}
.tutorial-glow.tap:not(.is-on) {
  box-shadow: inset 0 0 0 3px #ff000099, 0 0 0 1px #ff000066;
  background: #ff000014;
}
.tutorial-glow.drag-path {
  box-shadow: inset 0 0 0 4px #ff0000, 0 0 0 2px #ff0000cc;
  background: #ff000028;
}
/* 雙擊：兩圈空心紅環緊接出現，第一圈散盡才落下第二圈 */
.tutorial-glow.dbl {
  animation: tutorial-dbl-press 1.35s ease-out infinite;
}
@keyframes tutorial-dbl-press {
  0%, 100% { transform: scale(1); }
  4% { transform: scale(.86); }
  10% { transform: scale(1.04); }
  16% { transform: scale(1); }
  28% { transform: scale(.86); }
  34% { transform: scale(1.04); }
  40%, 100% { transform: scale(1); }
}
.tutorial-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22%;
  height: 22%;
  margin: -11% 0 0 -11%;
  border-radius: 50%;
  border: 7px solid #ff0000;
  box-shadow: 0 0 14px #ff0000, inset 0 0 6px #ff000099;
  background: transparent;
  transform: scale(.2);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}
.tutorial-glow.dbl .tutorial-ring {
  animation: tutorial-ring-out 1.35s cubic-bezier(.12, .8, .3, 1) infinite;
}
.tutorial-glow.dbl .tutorial-ring.delay {
  animation-delay: .32s;
}
@keyframes tutorial-ring-out {
  0% { transform: scale(.2); opacity: 1; border-width: 9px; }
  14% { transform: scale(4.8); opacity: .9; border-width: 6px; }
  22% { transform: scale(7.4); opacity: 0; border-width: 3px; }
  23%, 100% { transform: scale(.2); opacity: 0; }
}
/* 單擊：格子只壓一次，實心紅塊鋪滿整格 */
.tutorial-glow.tap.is-on {
  overflow: hidden;
  animation: tutorial-tap-press 1.15s ease-out infinite;
}
@keyframes tutorial-tap-press {
  0%, 100% { transform: scale(1); }
  16% { transform: scale(.9); }
  32% { transform: scale(1.03); }
  48%, 100% { transform: scale(1); }
}
.tutorial-wash {
  position: absolute;
  inset: 9%;
  border-radius: 16%;
  background: #ff2a2ae8;
  box-shadow: inset 0 0 18px #ff0000cc;
  transform: scale(.08);
  opacity: 0;
  pointer-events: none;
}
.tutorial-glow.tap.is-on .tutorial-wash {
  animation: tutorial-wash-out 1.15s ease-out infinite;
}
@keyframes tutorial-wash-out {
  0% { transform: scale(.08); opacity: .95; }
  38% { transform: scale(1); opacity: .82; }
  100% { transform: scale(1); opacity: 0; }
}
/* 拖曳：實心圓在起點擴大並定住，再帶著後方箭頭往下走三格 */
.tutorial-glow.drag {
  overflow: visible;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  z-index: 5;
}
.tutorial-drag-dot {
  position: absolute;
  left: 50%;
  top: var(--drag-y0, 16%);
  width: 38%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ff2a2a;
  box-shadow: 0 0 16px #ff0000, inset 0 0 8px #ffffff55;
  transform: translate(-50%, -50%) scale(.12);
  opacity: 0;
  pointer-events: none;
  z-index: 2;
  animation: tutorial-drag-dot 2.4s ease-in-out infinite;
}
.tutorial-drag-arrow {
  position: absolute;
  left: 50%;
  top: var(--drag-y0, 16%);
  width: 24px;
  height: 0;
  transform: translateX(-50%);
  overflow: visible;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  animation: tutorial-drag-arrow 2.4s ease-in-out infinite;
}
.tutorial-drag-arrow .shaft {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 10px;
  width: 7px;
  margin-left: -3.5px;
  border-radius: 4px;
  background: #ff0000;
  box-shadow: 0 0 10px #ff0000;
}
.tutorial-drag-arrow .head {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 16px solid #ff0000;
  filter: drop-shadow(0 0 6px #ff0000);
}
@keyframes tutorial-drag-dot {
  0% { top: var(--drag-y0); transform: translate(-50%, -50%) scale(.12); opacity: 1; }
  12% { top: var(--drag-y0); transform: translate(-50%, -50%) scale(1); opacity: 1; }
  24% { top: var(--drag-y0); transform: translate(-50%, -50%) scale(1); opacity: 1; }
  72% { top: calc(var(--drag-y0) + var(--drag-travel)); transform: translate(-50%, -50%) scale(1); opacity: 1; }
  84% { top: calc(var(--drag-y0) + var(--drag-travel)); transform: translate(-50%, -50%) scale(1); opacity: 1; }
  92% { top: calc(var(--drag-y0) + var(--drag-travel)); transform: translate(-50%, -50%) scale(1); opacity: 0; }
  93%, 100% { top: var(--drag-y0); transform: translate(-50%, -50%) scale(.12); opacity: 0; }
}
@keyframes tutorial-drag-arrow {
  0%, 24% { height: 0; opacity: 0; }
  26% { height: 0; opacity: 1; }
  72% { height: var(--drag-travel); opacity: 1; }
  84% { height: var(--drag-travel); opacity: 1; }
  92% { height: var(--drag-travel); opacity: 0; }
  93%, 100% { height: 0; opacity: 0; }
}

.extras {
  margin-top: 30px;
  border-top: 1px solid #ffffff1f;
  padding-top: 14px;
}
.extras summary {
  cursor: pointer;
  font-size: 13px;
  letter-spacing: .1em;
  color: var(--mist);
  padding: 6px 0;
}
.extras[open] summary { margin-bottom: 18px; }

/* ---------- 選關卡片；.ocd 是無叉叉通關的光暈 ---------- */
.levels-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.levels-title {
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-weight: 900;
  font-size: clamp(28px, 6vw, 40px);
  margin: 0;
}
.levels-summary {
  margin: 0;
  font-size: 13px;
  color: var(--mist);
  white-space: nowrap;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(94px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.level-card {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 12px 8px 10px;
  border-radius: 18px;
  border: 1px solid #ffffff1f;
  background: #ffffff0f;
  color: inherit;
  text-align: center;
  transition: transform .18s var(--ease), background .18s var(--ease);
}
.level-card:hover:not(:disabled) { transform: translateY(-2px); background: #ffffff1c; }
.level-card.locked {
  opacity: .55;
  cursor: pointer;
}
.level-card.locked:hover {
  opacity: 1;
  background: #ffffff22;
}
.level-no {
  font-family: "Noto Serif TC", serif;
  font-weight: 900;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  position: relative;
}
.level-stars { display: flex; gap: 2px; }
.level-stars .star { width: 15px; height: 15px; }
.level-meta {
  font-size: 11px;
  color: var(--mist);
  font-variant-numeric: tabular-nums;
}
.level-card.ocd .level-no {
  color: #ffe7a3;
  text-shadow:
    0 0 8px #f3c96b88,
    0 0 18px #f3c96b66,
    0 0 28px #e7b55f44;
  animation: ocd-glow 2.4s ease-in-out infinite;
}
@keyframes ocd-glow {
  0%, 100% {
    text-shadow:
      0 0 6px #f3c96b66,
      0 0 14px #f3c96b44,
      0 0 22px #e7b55f33;
  }
  50% {
    text-shadow:
      0 0 10px #ffe7a3aa,
      0 0 22px #f3c96b88,
      0 0 34px #e7b55f66;
  }
}

.star { fill: #ffffff2e; }
.star.on { fill: var(--yolk); }

/* Found animals live in an SVG layer above the canvas so their keyframes run. */
.board-stack { position: relative; display: block; }
.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.overlay-cell {
  position: absolute;
  /* The puff handles its own explosive entrance */
}
.overlay-cell:not(.clip):not(.ghost):not(.net-cell):not(.cell-puff):not(.tutorial-glow) {
  animation: critter-pop .4s cubic-bezier(.15, .8, .3, 1) both;
}
.overlay-cell.clip { overflow: hidden; border-radius: 14%; }
.overlay-cell.ghost { opacity: .38; filter: grayscale(.55); animation: none; }
/* The net brings its own break animation, so skip the pop. */
.overlay-cell.net-cell { animation: none; }
.critter { display: block; width: 100%; height: 100%; overflow: visible; }
.critter-body { transform-origin: 50% 80%; animation: breathe 3.4s ease-in-out infinite; }
.critter-head { transform-origin: 50% 82%; }
.critter-fur { transform-origin: 50% 57%; transform: scale(.7); opacity: 0; }
.critter-paw { opacity: 0; transform-origin: 50% 90%; }
.critter-zzz { opacity: 0; }
.critter .lid { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); }

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015, .985); }
}

/* Still (Ghost) */
.anim-still .critter-body { transform: scale(1.02); animation: none; }
.anim-still .lid { transform: scaleY(0); }

@keyframes critter-pop {
  0% { transform: scale(.1); opacity: 0; }
  25% { transform: scale(1.15); opacity: 1; }
  55% { transform: scale(.95); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* 全員歡呼：最後一隻現身後，場上動物依 --wave（列+欄）錯開起跳，像波浪掃過去；
   耳朵跟著彈、眼睛瞇成笑。動畫掛在 .critter 根節點，不干擾各自的入場動畫。 */
.overlay-layer.cheer .overlay-cell:not(.net-cell) .critter {
  animation: cheer-hop .56s cubic-bezier(.3, .6, .4, 1) calc(var(--wave, 0) * 70ms) infinite;
}
.overlay-layer.cheer .overlay-cell:not(.net-cell) .ear {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: cheer-ear .56s ease-in-out calc(var(--wave, 0) * 70ms) infinite;
}
.overlay-layer.cheer .overlay-cell:not(.net-cell) .lid {
  animation: none;
  transform: scaleY(.5);
  transition: transform .25s ease-out;
}
@keyframes cheer-hop {
  0%, 100% { transform: translateY(0) scale(1) rotate(0); }
  18% { transform: translateY(3%) scale(1.08, .9) rotate(0); }
  48% { transform: translateY(-22%) scale(.95, 1.07) rotate(-5deg); }
  68% { transform: translateY(-14%) scale(.98, 1.03) rotate(4deg); }
  88% { transform: translateY(1%) scale(1.05, .95) rotate(0); }
}
@keyframes cheer-ear {
  0%, 100% { transform: scaleY(1); }
  18% { transform: scaleY(.9); }
  55% { transform: scaleY(1.18); }
}

/* 炸毛：三段式──瞬間受驚（0–0.5s）→ 警戒張望（0.5–2.2s）→ 放鬆回到呼吸。
   炸開的毛只閃現一下就完全淡掉，避免像刺蝟一樣永遠掛著一圈刺；
   「嚇到」主要靠豎耳、放大的瞳孔與左右張望的頭來表現。 */
.overlay-cell.cell-puff { animation: critter-startle .3s cubic-bezier(.15, .8, .3, 1) both; }
.anim-puff .critter-fur { animation: fur-puff .7s cubic-bezier(.15, .8, .3, 1) both; }
.anim-puff .critter-body {
  animation:
    puff-body 2.4s cubic-bezier(.2, .7, .3, 1) both,
    breathe 3.4s ease-in-out 2.4s infinite;
}
.anim-puff .critter-head { animation: puff-look 2.4s ease-in-out both; }
.anim-puff .ear { transform-box: fill-box; transform-origin: 50% 100%; animation: ear-perk 2.4s ease-out both; }
.anim-puff .pupil { animation: pupil-wide 2.4s ease-in-out both; }
.anim-puff .eye { animation: eye-bulge 2.4s ease-in-out both; }
@keyframes critter-startle {
  0% { transform: scale(.1); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes fur-puff {
  0% { transform: scale(.75) rotate(0deg); opacity: 0; }
  12% { transform: scale(1.16) rotate(5deg); opacity: .6; }
  35% { transform: scale(1.04) rotate(-2deg); opacity: .32; }
  60%, 100% { transform: scale(1.1) rotate(0deg); opacity: 0; }
}
/* 受驚後身體會先縮一下、往後彈開，再挺直保持緊繃，最後慢慢鬆下來 */
@keyframes puff-body {
  0% { transform: translate(0, 0) scale(1); }
  6% { transform: translate(0, 4%) scale(1.12, .84); }
  14% { transform: translate(-4%, -9%) scale(.92, 1.14) rotate(-6deg); }
  24% { transform: translate(4%, -3%) scale(1.04, .98) rotate(5deg); }
  32% { transform: translate(-2%, -4%) scale(.99, 1.06) rotate(-2deg); }
  40%, 82% { transform: translate(0, -3%) scale(.98, 1.05) rotate(0); }
  100% { transform: translate(0, 0) scale(1) rotate(0); }
}
/* 頭部：先後仰，再往兩側張望確認危險，最後回正 */
@keyframes puff-look {
  0% { transform: translateY(0) rotate(0); }
  14% { transform: translateY(-3%) rotate(-5deg); }
  30% { transform: translateY(-1%) rotate(0); }
  48% { transform: translateY(-1%) rotate(7deg); }
  68% { transform: translateY(-1%) rotate(-6deg); }
  84% { transform: translateY(0) rotate(0); }
  100% { transform: translateY(0) rotate(0); }
}
@keyframes ear-perk {
  0% { transform: scaleY(1); }
  12% { transform: scaleY(1.22); }
  22%, 80% { transform: scaleY(1.12); }
  100% { transform: scaleY(1); }
}
/* 瞳孔放大並跟著頭的方向瞄過去 */
@keyframes pupil-wide {
  0% { transform: scale(1) translateX(0); }
  12% { transform: scale(1.7) translateX(0); }
  30% { transform: scale(1.35) translateX(0); }
  48% { transform: scale(1.35) translateX(1.6px); }
  68% { transform: scale(1.35) translateX(-1.6px); }
  84% { transform: scale(1.15) translateX(0); }
  100% { transform: scale(1) translateX(0); }
}
@keyframes eye-bulge {
  0% { transform: scale(1); }
  12% { transform: scale(1.24); }
  30%, 80% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* 理毛 */
.anim-groom .critter-paw { animation: paw-wipe 1.9s ease-in-out .2s infinite; }
.anim-groom .critter-head { animation: head-tilt 1.9s ease-in-out .2s infinite; }
.anim-groom .critter-body { animation: body-rock 1.9s ease-in-out .2s infinite; }
.anim-groom .lid { animation: groom-lid 1.9s ease-in-out .2s infinite; }
.anim-groom .snout { animation: groom-snout 1.9s ease-in-out .2s infinite; }
@keyframes paw-wipe {
  0% { transform: translate(0, 18%) rotate(0); opacity: 0; }
  14% { opacity: 1; }
  32% { transform: translate(-14%, -6%) rotate(-24deg); opacity: 1; }
  58% { transform: translate(14%, -10%) rotate(20deg); opacity: 1; }
  80% { transform: translate(0, 14%) rotate(0); opacity: .9; }
  100% { transform: translate(0, 18%) rotate(0); opacity: 0; }
}
@keyframes head-tilt {
  0%, 100% { transform: rotate(0) translate(0, 0); }
  32% { transform: rotate(-8deg) translate(-2%, 2%); }
  62% { transform: rotate(6deg) translate(2%, 1%); }
}
@keyframes groom-snout {
  0%, 100% { transform: translate(0, 0); }
  32% { transform: translate(-2px, -1.5px); }
  62% { transform: translate(1.5px, -1px); }
}
@keyframes body-rock {
  0%, 100% { transform: rotate(0); }
  45% { transform: rotate(2deg) translate(1px, -1px); }
}
@keyframes groom-lid {
  0%, 15%, 85%, 100% { transform: scaleY(0); }
  35%, 65% { transform: scaleY(.85); }
}

/* 睜眼看一下，繼續閉眼睡 */
.anim-blink .lid { animation: lid-cycle 3.4s ease-in-out both infinite; }
.anim-blink .critter-zzz { animation: zzz-drift 3.4s ease-in-out both infinite; }
.anim-blink .critter-body { animation: doze 3.4s ease-in-out both infinite; }
@keyframes lid-cycle {
  0%, 12% { transform: scaleY(1); }
  22%, 46% { transform: scaleY(0); }
  58%, 100% { transform: scaleY(1); }
}
@keyframes zzz-drift {
  0%, 20% { opacity: 0; transform: translate(0, 4%); }
  34%, 56% { opacity: 0; }
  76% { opacity: .9; transform: translate(4%, -8%) scale(1.1); }
  100% { opacity: 0; transform: translate(8%, -16%) scale(1.2); }
}
@keyframes doze {
  0%, 100% { transform: translateY(0) scale(1); }
  38% { transform: translateY(1%) scale(.995, .99); }
  76% { transform: translateY(3.5%) scale(.985, .97); }
}

/* 探頭 */
.anim-peek .critter-body { animation: peek-up 1.25s cubic-bezier(.15, 1.45, .4, 1) both; }
.anim-peek .ear { animation: peek-ear 1.25s cubic-bezier(.15, 1.45, .4, 1) both; }
.anim-peek .snout, .anim-peek .beak { animation: peek-snout 1.25s cubic-bezier(.15, 1.45, .4, 1) both; }
@keyframes peek-up {
  0% { transform: translateY(62%) scale(.75, 1.25); }
  35% { transform: translateY(-11%) scale(1.1, .9); }
  55% { transform: translateY(5%) scale(.95, 1.05); }
  100% { transform: translateY(0) scale(1); }
}
@keyframes peek-ear {
  0%, 25% { transform: scaleY(1); }
  40% { transform: scaleY(.85); }
  65% { transform: scaleY(1.08); }
  100% { transform: scaleY(1); }
}
@keyframes peek-snout {
  0%, 25% { transform: translateY(0); }
  40% { transform: translateY(3px); }
  65% { transform: translateY(-1.5px); }
  100% { transform: translateY(0); }
}

/* ---------- 通關舞台：星砸入、彩帶、旋轉光暈 ---------- */
.result-stage {
  position: relative;
  height: 148px;
  margin: -8px 0 10px;
  border-radius: 18px;
  background: linear-gradient(180deg, #dceae6 0%, #cadfda 100%);
  overflow: hidden;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  isolation: isolate;
}
.result-stage[data-stars="3"] { background: linear-gradient(180deg, #fdf0d2 0%, #f6dfae 100%); }
.result-stage[data-stars="-1"] { background: linear-gradient(180deg, #dfe3e2 0%, #c9d1cf 100%); }
.result-stage[data-stars="0"] { background: linear-gradient(180deg, #d7e2df 0%, #c2cfcc 100%); }
.result-stage[data-stars="1"] { background: linear-gradient(180deg, #eef3e4 0%, #d5e4d6 100%); }

.result-fx {
  position: absolute;
  left: 50%;
  top: 50%;
  /* A square wider than the stage diagonal, so a 90° turn never leaves the sides bare. */
  width: 180%;
  aspect-ratio: 1;
  height: auto;
  pointer-events: none;
  z-index: 0;
  transform: translate(-50%, -50%);
  overflow: visible;
}
.result-fx-spin {
  display: none;
  position: absolute;
  inset: 0;
  background: conic-gradient(
    from 0deg,
    var(--fx-a, #f4a261),
    var(--fx-b, #e9c46a),
    var(--fx-c, #2a9d8f),
    var(--fx-d, #7b8cde),
    var(--fx-e, #f2c6d8),
    var(--fx-a, #f4a261)
  );
  mask-image: repeating-conic-gradient(from 0deg, #000 0deg 8deg, transparent 8deg 18deg);
  -webkit-mask-image: repeating-conic-gradient(from 0deg, #000 0deg 8deg, transparent 8deg 18deg);
  filter: saturate(1.15) brightness(1.05);
  mix-blend-mode: multiply;
  opacity: .55;
  animation: fx-spin 14s linear infinite;
  will-change: transform;
}
.result-stage[data-stars="0"] .result-fx-spin,
.result-stage[data-stars="1"] .result-fx-spin,
.result-stage[data-stars="2"] .result-fx-spin,
.result-stage[data-stars="3"] .result-fx-spin { display: block; }
.result-stage[data-stars="0"] .result-fx-spin,
.result-stage[data-stars="1"] .result-fx-spin {
  mask-image: none;
  -webkit-mask-image: none;
  mix-blend-mode: multiply;
  animation-duration: 18s;
}
.result-stage[data-stars="1"] .result-fx-spin {
  background: conic-gradient(
    from 0deg,
    #f4ecc0,
    #c5ead8,
    #e8d48a,
    #b7d8c8,
    #f7f1d2,
    #d3e8c8,
    #f4ecc0
  );
  filter: blur(26px) saturate(1.35);
  opacity: .95;
}
.result-stage[data-stars="0"] .result-fx-spin {
  background: conic-gradient(
    from 0deg,
    #d5e0dc,
    #c3d2ce,
    #e4ebe8,
    #b9c8c4,
    #d5e0dc
  );
  filter: blur(30px) saturate(.9);
  opacity: .7;
}
@keyframes fx-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.result-stage.hit { animation: stage-hit .22s cubic-bezier(.15, .8, .3, 1); }
@keyframes stage-hit {
  0% { transform: translate(0, 0) scale(1); }
  28% { transform: translate(var(--hit-x, 0px), var(--hit-y, 3px)) scale(1.028); }
  100% { transform: translate(0, 0) scale(1); }
}

.result-hero,
.result-stars { position: relative; z-index: 1; }
.result-hero { width: 92px; height: 92px; }
.result-hero .critter { width: 100%; height: 100%; }
.hero-cheer { animation: hero-jump .62s var(--ease) .15s 4 both; }
.hero-hop { animation: hero-jump .8s var(--ease) .2s 2 both; }
.hero-relief { animation: hero-wiggle 1.1s ease-in-out .2s 2 both; }
.hero-sad { animation: hero-droop 1.4s var(--ease) .1s both; }
@keyframes hero-jump {
  0%, 100% { transform: translateY(0) scale(1); }
  28% { transform: translateY(-26%) scale(1.04); }
  56% { transform: translateY(0) scale(.94); }
}
@keyframes hero-wiggle {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(-8deg); }
  70% { transform: rotate(8deg); }
}
@keyframes hero-droop {
  0% { transform: translateY(-8%) rotate(0); }
  100% { transform: translateY(6%) rotate(6deg); opacity: .8; }
}

.result-stars {
  display: flex;
  gap: 10px;
  align-items: center;
  perspective: 640px;
  perspective-origin: 50% 40%;
}
.star-hit {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  transform-style: preserve-3d;
}
.result-stars .star {
  width: 40px;
  height: 40px;
  overflow: visible;
  transform-origin: 50% 50%;
  filter: grayscale(.4) brightness(1.1);
  opacity: .38;
}
.result-stars .star.pending { opacity: 0; }
.result-stars .star.on {
  opacity: 1;
  filter:
    drop-shadow(0 1px 0 #fff6c8cc)
    drop-shadow(0 3px 0 #b56d12)
    drop-shadow(0 6px 8px #4a2e0888)
    drop-shadow(0 0 10px #ffd76acc);
}
/* Linear so 74% in the sheet is 74% of --star-fly on the clock. */
.result-stars .star.fly {
  animation: star-smash var(--star-fly, .72s) linear both;
}
.result-stars .star.on.fly {
  animation:
    star-smash var(--star-fly, .72s) linear both,
    star-glow 1.8s ease-in-out var(--star-fly, .72s) infinite;
}
.result-stars .star .star-shine { opacity: 0; transform-box: fill-box; }
.result-stars .star.on .star-shine {
  animation: star-gleam 2.2s ease-in-out .8s infinite;
}
@keyframes star-smash {
  0% {
    transform:
      translate3d(var(--from-x), var(--from-y), 160px)
      rotate(var(--from-rot))
      scale(2.9);
    opacity: 0;
  }
  12% { opacity: 1; }
  48% {
    transform:
      translate3d(calc(var(--from-x) * .55), calc(var(--from-y) * .55), 88px)
      rotate(calc(var(--from-rot) * .55))
      scale(2.05);
  }
  74% {
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1.24, .76);
    opacity: 1;
  }
  86% { transform: scale(.93, 1.07); }
  100% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
}
@keyframes star-glow {
  0%, 100% {
    filter:
      drop-shadow(0 1px 0 #fff6c8cc)
      drop-shadow(0 3px 0 #b56d12)
      drop-shadow(0 6px 8px #4a2e0888)
      drop-shadow(0 0 8px #ffd76a88);
  }
  50% {
    filter:
      drop-shadow(0 1px 0 #fffbe6)
      drop-shadow(0 3px 0 #c98416)
      drop-shadow(0 7px 10px #4a2e08aa)
      drop-shadow(0 0 16px #ffe9a8);
  }
}
@keyframes star-gleam {
  0%, 58% { transform: translateX(-28px); opacity: 0; }
  68% { opacity: .95; }
  86%, 100% { transform: translateX(28px); opacity: 0; }
}

.star-puffs {
  position: absolute;
  inset: -18px;
  pointer-events: none;
  z-index: 2;
}
.star-puffs i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--s, 8px);
  height: var(--s, 8px);
  margin: 0;
  border-radius: 50%;
  background: radial-gradient(circle, #fff6d8 0%, #e8c56a88 55%, transparent 70%);
  opacity: 0;
}
.star-hit.smash .star-puffs i {
  animation: star-puff .48s ease-out both;
}
@keyframes star-puff {
  0% { transform: translate(-50%, -50%) scale(.35); opacity: .8; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.7); opacity: 0; }
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.confetti i {
  position: absolute;
  top: -14px;
  left: var(--x);
  width: 7px;
  height: 12px;
  border-radius: 2px;
  background: var(--tint);
  opacity: 0;
}
.confetti.drop i {
  animation: confetti-fall 2.1s linear var(--delay) 2 both;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translateY(190px) rotate(var(--spin)); opacity: 0; }
}

.result-record {
  margin: 4px 0 0;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #b7812c;
  min-height: 1.2em;
}

/* ---------- HUD：時間、剩餘動物、三支網子 ---------- */
.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.hud-item {
  background: #0e2420cc;
  border: 1px solid #ffffff14;
  border-radius: 16px;
  padding: 10px 12px;
}
.hud-item > span {
  display: block;
  font-size: 11px;
  letter-spacing: .16em;
  color: var(--mist);
  margin-bottom: 4px;
}
.hud-item strong {
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 800;
  white-space: nowrap;
}
.hud-item em {
  font-style: normal;
  margin: 0 4px;
  color: var(--sea);
  font-weight: 600;
}

.nets { display: flex; gap: 4px; height: 28px; align-items: center; }
.nets i { display: block; width: 28px; height: 28px; }
.nets i.lost { opacity: .42; filter: grayscale(.7); }

.net { display: block; width: 100%; height: 100%; overflow: visible; }
.net-whole, .net-hoop-fly { transform-box: fill-box; transform-origin: 50% 50%; }
.net-stub-fly { transform-box: fill-box; transform-origin: 100% 100%; }

/* The whole net swipes in, jolts, and hands over to the two halves at 75%. */
.net-snap .net-whole { animation: net-swipe .4s var(--ease) both; }
@keyframes net-swipe {
  0% { transform: translate(26%, -30%) rotate(-26deg); opacity: 0; }
  45% { transform: translate(0, 0) rotate(0); opacity: 1; }
  74% { transform: translate(0, 0) rotate(5deg); opacity: 1; }
  75%, 100% { opacity: 0; }
}
.net-snap .net-shard { animation: net-shard-in .01s linear .3s both; }
@keyframes net-shard-in { from { opacity: 0; } to { opacity: 1; } }
.net-snap .net-hoop-fly { animation: net-hoop-drop .42s var(--ease) .3s both; }
@keyframes net-hoop-drop {
  0% { transform: translate(7%, -34%) rotate(-24deg); }
  62% { transform: translate(0, 4%) rotate(4deg); }
  100% { transform: translate(0, 0) rotate(0); }
}
.net-snap .net-stub-fly { animation: net-stub-tip .42s var(--ease) .3s both; }
@keyframes net-stub-tip {
  0% { transform: rotate(34deg); }
  70% { transform: rotate(-6deg); }
  100% { transform: rotate(0); }
}

.board-tray {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  background: var(--tray);
  border-radius: 28px;
  padding: 14px;
  box-shadow:
    inset 0 1px 0 #ffffff22,
    0 24px 50px #0005;
}
.board-tray canvas {
  display: block;
  width: min(calc(100vw - 64px), calc(100dvh - 260px), 640px);
  height: auto;
  aspect-ratio: 1;
  border-radius: 18px;
  background: var(--porcelain);
  cursor: pointer;
  touch-action: none;
}
.loading {
  position: absolute;
  inset: 14px;
  display: grid;
  place-items: center;
  background: #eef4f3f0;
  color: var(--ink);
  border-radius: 18px;
  font-weight: 700;
}
.loading.hidden { display: none; }

.hint {
  text-align: center;
  color: var(--mist);
  font-size: 13px;
  margin: 14px 0 12px;
}
.hint b { color: var(--yolk); font-weight: 800; }
.hint.warn { color: var(--salmon); font-weight: 700; }
.play-nav { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.design-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.tools { display: flex; gap: 6px; }
.tool {
  border: 1px solid #ffffff24;
  background: #ffffff10;
  border-radius: 999px;
  height: 40px;
  padding: 0 16px;
  font-weight: 700;
}
.tool[aria-pressed="true"] {
  background: var(--porcelain);
  color: var(--ink);
}
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #ffffff55;
  padding: 0;
}
.swatch[aria-pressed="true"] {
  outline: 2px solid var(--yolk);
  outline-offset: 2px;
}
.swatch:disabled { opacity: .28; }

#toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  background: var(--porcelain);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: .25s var(--ease);
  z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 對話框、玩法說明圖、成績數字 ---------- */
dialog {
  color-scheme: light;
  border: 0;
  border-radius: 24px;
  padding: 28px 24px 22px;
  width: min(440px, calc(100% - 32px));
  background: var(--porcelain);
  color: var(--ink);
  box-shadow: 0 24px 60px #0005;
}
#dialog-result[open] {
  animation: result-fade-in .5s var(--ease) both;
}
#dialog-result[open]::backdrop {
  animation: result-backdrop-in .5s var(--ease) both;
}
@keyframes result-fade-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes result-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
dialog .eyebrow { color: #b7812c; }
dialog::backdrop { background: #10241fcc; }
dialog h2 {
  font-family: "Noto Serif TC", serif;
  font-size: 28px;
  margin: 0 0 12px;
}
.rules-diagrams {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}
.rule-card {
  margin: 0;
  background: #dceae6;
  border-radius: 14px;
  padding: 8px 6px 6px;
  text-align: center;
}
.rule-svg { width: 100%; height: auto; display: block; max-height: 112px; }
.rule-card figcaption {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 800;
  color: #34524c;
  letter-spacing: .04em;
}
.rules-copy p { line-height: 1.65; margin: 0 0 8px; color: #34524c; font-size: 14px; }
#dialog-rules {
  max-height: min(92dvh, 720px);
  overflow: auto;
  padding-top: 22px;
}
dialog .primary { width: 100%; margin-top: 8px; }
dialog .text-btn { width: 100%; color: #34524c; }
.rules-actions {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.rules-actions .ghost { width: 100%; color: #34524c; border-color: #34524c33; }
.tutorial-result .result-stars,
.tutorial-result .stats { display: none; }
.result-links {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  margin-top: 4px;
}
#dialog-result {
  max-height: min(92dvh, 720px);
  overflow: auto;
}
.result-ocd {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: linear-gradient(135deg, #fff4d0, #f7e2a4);
  color: #7a5a18;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}
.result-ocd.hidden { display: none; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 18px 0 8px;
}
.stats.stats-two { grid-template-columns: 1fr 1fr; }
.stats div {
  background: #d7e6e2;
  border-radius: 14px;
  padding: 10px 8px;
  text-align: center;
}
.stats dt { font-size: 11px; letter-spacing: .12em; color: #4d6c66; }
.stats dd {
  margin: 6px 0 0;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

@media (max-height: 760px) {
  .topbar { margin-bottom: 12px; }
  .hud { margin-bottom: 10px; }
  .hud-item { padding: 8px 10px; }
  .hud-item strong { font-size: 18px; }
  .board-tray { padding: 10px; border-radius: 22px; }
  .hint { margin: 10px 0 8px; }
}

@media (max-width: 520px) {
  .noren { width: 18px; opacity: .35; }
  .hud-item strong { font-size: 18px; }
  .brand-text small { display: none; }
  .rules-diagrams { gap: 6px; }
  .rule-card { padding: 8px 4px 6px; }
  .rule-card figcaption { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .critter, .critter *, .net *, .confetti i, .result-hero *,
  .result-fx-spin, .result-stage, .level-card.ocd .level-no,
  .result-stars .star, .result-stars .star-shine, .star-puffs i,
  .tutorial-glow,
  .tutorial-ring,
  .tutorial-wash,
  .tutorial-drag-dot,
  .tutorial-drag-arrow,
  .screen.leaving, .screen.entering,
  #dialog-result[open], #dialog-result[open]::backdrop {
    animation: none !important;
  }
  /* No animation means both halves would sit on top of the intact net. */
  .net-snap .net-whole { display: none; }
  .result-stage[data-stars="0"] .result-fx-spin,
  .result-stage[data-stars="1"] .result-fx-spin,
  .result-stage[data-stars="2"] .result-fx-spin,
  .result-stage[data-stars="3"] .result-fx-spin { opacity: .28; }
  .result-stars .star.pending { opacity: 1; }
  .tutorial-drag-arrow {
    height: var(--drag-travel) !important;
    opacity: .85 !important;
  }
  .tutorial-drag-dot {
    top: calc(var(--drag-y0) + var(--drag-travel)) !important;
    transform: translate(-50%, -50%) scale(1) !important;
    opacity: .85 !important;
  }
}
