/* Theme: "Sunny Lemon / 阳光柠檬" (adapted from the Superdesign draft).
   Every color, font, radius, shadow and animation lives here.
   game.js reads --piece-* / --board-* / --face variables for canvas drawing. */
:root {
  /* Fonts: system only. Display stack prefers hand-drawn-ish faces where the OS has them. */
  --font-ui: ui-rounded, "SF Pro Rounded", "Nunito", "Arial Rounded MT Bold", "PingFang SC", "HarmonyOS Sans SC",
             "Hiragino Maru Gothic ProN", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --font-display: "Chalkboard SE", "Chalkboard", "Comic Sans MS", "HanziPen SC", "Hannotate SC", "Yuanti SC",
             "Marker Felt", ui-rounded, "Arial Rounded MT Bold", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;

  /* Palette */
  --ink: #3b2a1a;
  --ink-soft: #7a6450;
  --ink-faint: rgba(59, 42, 26, .12);
  --bg-top: #fff6c9;
  --bg-bottom: #ffe680;
  --primary: #ffd23f;
  --primary-hover: #ffe066;
  --accent: #ff8a3d;
  --accent-ink: #e0661a;
  --grass: #7bc67b;
  --card: #fffdf4;
  --white: #ffffff;
  --blush: #ffb3c1;
  --well: rgba(59, 42, 26, .05);

  /* Shape */
  --outline: 3px solid var(--ink);
  --radius-card: 28px;
  --radius-board: 32px;
  --radius-md: 18px;
  --radius-sm: 10px;
  --shadow-sticker: 0 6px 0 rgba(59, 42, 26, .18);
  --shadow-hover: 0 10px 0 rgba(59, 42, 26, .15);
  --shadow-press: 0 2px 0 rgba(59, 42, 26, .25);
  --shadow-card: 0 8px 0 rgba(59, 42, 26, .10);
  --spring: cubic-bezier(.34, 1.56, .64, 1);

  /* Canvas (read by game.js) */
  --board-bg: #fffbea;
  --board-grid: #f3e5b8;
  --face: #3b2a1a;
  --piece-I: #5bc8f5;
  --piece-J: #5b8def;
  --piece-L: #ffa552;
  --piece-O: #ffd23f;
  --piece-S: #7bd67b;
  --piece-T: #b98cf5;
  --piece-Z: #ff7a7a;

  /* Pets */
  --cat-fur: #fffdf4;
  --cat-inner: #ffc2d1;
  --dog-fur: #ffd9a0;
  --dog-ear: #d9934f;
  --dog-belly: #fff6e6;

  /* Effects */
  --popup-ms: 1500ms;
  --confetti-ms: 1600ms;
}

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%) fixed;
}
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; }

/* ---------- Sky (soft clouds and bubbles drifting) ---------- */
.cloud { background: rgba(255, 255, 255, .65); border-radius: 999px; filter: blur(2px); }
.cloud::before, .cloud::after { content: ""; position: absolute; background: inherit; border-radius: 50%; }
.cloud::before { width: 46%; height: 150%; left: 16%; bottom: 20%; }
.cloud::after { width: 34%; height: 120%; right: 14%; bottom: 25%; }
.cloud-1 { width: 150px; height: 42px; top: 9%; left: -12%; animation: drift 46s linear infinite; }
.cloud-2 { width: 210px; height: 54px; top: 38%; left: -20%; opacity: .7; animation: drift 64s linear -22s infinite; }
.cloud-3 { width: 120px; height: 36px; top: 74%; left: -10%; opacity: .55; animation: drift 52s linear -38s infinite; }
.bubble-dot { border-radius: 50%; border: 3px solid rgba(255, 255, 255, .6); bottom: -40px; }
.dot-1 { width: 22px; height: 22px; left: 12%; animation: rise 26s ease-in 2s infinite; }
.dot-2 { width: 36px; height: 36px; left: 78%; animation: rise 32s ease-in 9s infinite; }
.dot-3 { width: 16px; height: 16px; left: 46%; background: rgba(255, 255, 255, .5); border: 0; animation: rise 22s ease-in 15s infinite; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(125vw); } }
@keyframes rise { 0% { transform: translateY(0) scale(.8); opacity: .9; } 100% { transform: translateY(-110vh) scale(1.2); opacity: 0; } }

/* ---------- Header ---------- */
.title { font-family: var(--font-display); font-size: clamp(22px, 3.6vw, 34px); font-weight: 800; letter-spacing: 1px; color: var(--ink); }
.title-badge { background: var(--white); border: var(--outline); border-radius: 50%; box-shadow: var(--shadow-sticker); }

/* ---------- Buttons ---------- */
.btn, .debug-panel button {
  border: var(--outline);
  background: var(--white);
  color: var(--ink);
  border-radius: 999px;
  font-weight: 800;
  box-shadow: var(--shadow-sticker);
  transition: transform .2s var(--spring), box-shadow .2s var(--spring), background .15s ease;
}
.btn:hover { background: #fff3e6; transform: translateY(-4px); box-shadow: var(--shadow-hover); }
.btn:active { transform: translateY(4px) scale(.94); box-shadow: var(--shadow-press); }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn:focus-visible, .tbtn:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }
.btn-small { padding: 8px 18px; font-size: 15px; }
.btn-big { padding: 12px 36px; font-size: 22px; font-family: var(--font-display); }

/* ---------- Cards ---------- */
.card { background: var(--card); border: var(--outline); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.card-title { font-family: var(--font-display); font-size: 18px; font-weight: 800; color: var(--accent-ink); }
.next-well { background: var(--well); border-radius: var(--radius-md); }
.stat-label { font-size: 14px; font-weight: 800; color: var(--ink-soft); }
.score-value { font-size: clamp(32px, 4.2vw, 46px); line-height: 1.1; font-weight: 800; color: var(--accent); text-shadow: 0 2px 0 rgba(59, 42, 26, .08); }
.score-value.is-pop { animation: pop-counter .24s var(--spring); }
.stat-row { border-bottom: 2px dashed var(--ink-faint); }
.stat-value { font-size: 24px; font-weight: 800; color: var(--ink); }
.stat-best { font-size: 20px; color: var(--ink-soft); }
.progress-label { font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.progress-label b { color: var(--accent-ink); font-size: 15px; }
.progress-track { background: #efe6cf; border: var(--outline); border-radius: 999px; }
.progress-fill { background: linear-gradient(180deg, #9ad89a 0 35%, var(--grass) 35%); border-radius: 999px; transition: width .4s var(--spring); }
@keyframes pop-counter { 0% { transform: scale(1); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }

.help .card-title { color: var(--ink-soft); font-size: 16px; }
.keys { font-size: 13px; font-weight: 800; color: var(--ink-soft); }
kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; padding: 0 5px;
  font: 800 12px var(--font-ui); color: var(--ink); background: var(--white); border: 2px solid var(--ink);
  border-radius: 8px; box-shadow: 0 3px 0 rgba(59, 42, 26, .2); }
.kbd-wide { min-width: 46px; }

/* ---------- Board frame: white sticker frame with double ink outline ---------- */
.board-wrap { border-radius: 22px; }
#board {
  border-radius: 22px;
  background: var(--board-bg);
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 13px var(--white), 0 0 0 16px var(--ink), 0 24px 0 rgba(59, 42, 26, .12);
}

/* ---------- Overlays: start / pause / game over ---------- */
.overlay { background: rgba(255, 246, 201, .62); border-radius: 22px; backdrop-filter: blur(3px); }
.overlay-card { background: var(--white); border: var(--outline); border-radius: var(--radius-card); box-shadow: var(--shadow-sticker);
  animation: spring-in .4s var(--spring) both; }
.pic-frame { background: var(--white); border: var(--outline); border-radius: var(--radius-md); }
.pic-round { border-radius: 50%; }
.screen-start .pic-frame, .screen-pause .pic-frame { animation: bob 3s ease-in-out infinite; }
.overlay-title { font-family: var(--font-display); font-size: clamp(20px, calc(var(--board-h) * .046), 30px); line-height: 1.2; font-weight: 800; color: var(--accent); }
.screen-start .overlay-title { animation: wobble 3.2s ease-in-out infinite; }
.overlay-text { font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.btn-pulse { animation: pulse-glow 1.8s ease-in-out infinite; }
.overlay .btn-big { color: #8a4300; padding-top: 12px; padding-bottom: 12px; }
.hint-box { background: #faf6ea; border: 2px solid var(--ink); border-radius: var(--radius-md); }
.hint-title { font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.hint-keys { font-size: 12px; font-weight: 800; color: var(--ink); }
.hint-touch span { background: var(--white); border: 2px solid var(--ink); border-radius: 8px; padding: 2px 8px; }
.hint-foot { font-size: 11px; color: var(--ink-soft); }
.ribbon { display: inline-block; padding: 4px 16px; border: var(--outline); border-radius: 999px; background: var(--primary);
  font-family: var(--font-display); font-size: 17px; font-weight: 800; color: var(--ink); transform: rotate(-2deg);
  box-shadow: var(--shadow-sticker); animation: ribbon-pop .5s .25s var(--spring) both, shimmer 2.4s .8s ease-in-out infinite; }
.go-stats { font-size: 14px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.go-best { font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.link-btn { font-size: 14px; font-weight: 800; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--accent-ink); }
.link-btn:focus-visible { outline: 3px solid var(--accent); border-radius: 8px; }
.go-heart { color: #ff8fa3; font-size: 22px; animation: heart-beat 1.4s ease-in-out infinite; }
.screen-gameover .overlay-img { animation: settle .6s ease-out both, breathe 3s .6s ease-in-out infinite; }
.peek { animation: peek .7s .2s var(--spring) both; filter: drop-shadow(0 4px 0 rgba(59, 42, 26, .12)); }
.peek-dog { animation-delay: .35s; }
.peek .blink { transform-box: fill-box; transform-origin: center; animation: blink 4s infinite; }
.peek-dog .blink { animation-delay: 1.6s; }
.peek-ear-l { transform-box: fill-box; transform-origin: 60% 90%; animation: twitch 3.4s infinite; }
.peek-ear-r { transform-box: fill-box; transform-origin: 40% 90%; animation: twitch 4.6s .8s infinite; }
@keyframes spring-in { 0% { transform: scale(.8) translateY(20px); opacity: 0; } 100% { transform: scale(1) translateY(0); opacity: 1; } }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
@keyframes pulse-glow { 0%, 100% { box-shadow: var(--shadow-sticker), 0 0 0 0 rgba(255, 210, 63, .7); }
  50% { box-shadow: var(--shadow-sticker), 0 0 0 10px rgba(255, 210, 63, 0); } }
@keyframes ribbon-pop { 0% { transform: rotate(-2deg) scale(0); } 100% { transform: rotate(-2deg) scale(1); } }
@keyframes shimmer { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.08); } }
@keyframes heart-beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.25); } 30% { transform: scale(1); } 45% { transform: scale(1.15); } }
@keyframes peek { 0% { transform: translateY(30px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }

/* ---------- Level-up card (no backdrop; play continues) ---------- */
.levelup-card { background: var(--white); border: var(--outline); border-radius: var(--radius-card); box-shadow: var(--shadow-sticker); }
.levelup.is-in .levelup-card { animation: drop-in .5s var(--spring) both; }
.levelup.is-leaving { animation: fade-out .3s ease-in forwards; }
.lu-frame { background: #fff8d6; border: var(--outline); border-radius: 50%; }
.lu-img { animation: sway .6s ease-in-out infinite alternate; transform-origin: 50% 100%; }
.lu-ribbon { padding: 4px 16px; border: var(--outline); border-radius: 999px; background: var(--primary); transform: rotate(-2deg);
  font-family: var(--font-display); font-size: clamp(16px, calc(var(--board-h) * .034), 22px); font-weight: 800; color: var(--ink);
  box-shadow: var(--shadow-sticker); white-space: nowrap; animation: ribbon-pop .45s .2s var(--spring) both; }
.lu-ribbon b { color: var(--accent-ink); }
.lu-sub { font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.lu-star { color: var(--accent); font-size: 16px; animation: twinkle 1s ease-in-out infinite alternate; }
.lu-star.s2, .lu-star.s4 { color: var(--primary); font-size: 20px; animation-delay: .3s; -webkit-text-stroke: 1px var(--ink); }
.lu-note { color: var(--ink-soft); font-size: 20px; font-weight: 900; animation: note-bob 1.2s ease-in-out infinite alternate; }
.lu-note.n2 { animation-delay: .4s; }
.lu-lemon { border-radius: 50%; border: 2px solid #e2a800;
  background: radial-gradient(circle, #fff7c2 18%, transparent 20%), repeating-conic-gradient(#ffe45c 0 36deg, #fff3a6 36deg 40deg);
  animation: tumble 2.4s linear infinite; }
@keyframes drop-in { 0% { transform: translateY(-60px) scale(.7); opacity: 0; } 100% { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes sway { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }
@keyframes twinkle { from { transform: scale(.8) rotate(0); opacity: .6; } to { transform: scale(1.2) rotate(20deg); opacity: 1; } }
@keyframes note-bob { from { transform: translateY(0) rotate(-8deg); } to { transform: translateY(-8px) rotate(8deg); } }
@keyframes tumble { to { transform: rotate(360deg); } }

/* ---------- Mascot corner ---------- */
.tip { background: var(--white); border: var(--outline); border-radius: 22px; box-shadow: var(--shadow-sticker);
  font-weight: 800; font-size: 15px; line-height: 1.45; color: var(--ink); }
.tip::after { content: ""; position: absolute; left: 50%; bottom: -10px; width: 16px; height: 16px; margin-left: -8px;
  background: var(--white); border-right: var(--outline); border-bottom: var(--outline); transform: rotate(45deg); }
.mascot-frame { background: var(--white); border: var(--outline); border-radius: 50%; box-shadow: var(--shadow-card);
  animation: bob 3s ease-in-out infinite; }
.mascot-img { transform-origin: 50% 100%; animation: breathe 3s ease-in-out infinite; }
.bubble { background: var(--white); border: var(--outline); border-radius: 18px; font-weight: 800; color: var(--accent-ink);
  box-shadow: var(--shadow-sticker); font-family: var(--font-display); }

/* ---------- Popup text ---------- */
.popup-text { margin-top: 4px; padding: 6px 16px; max-width: 96%; text-align: center;
  font-family: var(--font-display); font-size: clamp(14px, calc(var(--board-h) * .042), 26px); font-weight: 900;
  color: var(--accent-ink); background: var(--white); border: var(--outline); border-radius: 999px; box-shadow: var(--shadow-sticker); }
.popup-img { filter: drop-shadow(0 6px 0 rgba(59, 42, 26, .15)); }

/* ---------- Touch pad ---------- */
.touch-controls { background: var(--white); border: var(--outline); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.tbtn { border: var(--outline); border-radius: 999px; font-size: 26px; font-weight: 800; color: #2f63c9; background: #dce9ff;
  box-shadow: var(--shadow-sticker); transition: transform .12s var(--spring), box-shadow .12s ease; }
.tbtn[data-action="rotate"] { background: var(--primary); color: var(--accent-ink); }
.tbtn[data-action="down"] { background: #dff5e3; color: #2f8a3e; }
.tbtn[data-action="drop"] { background: #ffe6d1; color: var(--accent-ink); font-size: 20px; }
.tbtn:active, .tbtn.is-pressed { transform: translateY(4px) scale(.94); box-shadow: var(--shadow-press); }

.debug-panel { background: var(--white); border: 2px dashed var(--accent); border-radius: var(--radius-sm); font-size: 13px; }
.debug-panel button { padding: 4px 10px; font-size: 13px; box-shadow: none; border-width: 2px; }

/* ---------- Idle animations ---------- */
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.03, .97); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes wag { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(14deg); } }
@keyframes twitch { 0%, 86%, 100% { transform: rotate(0); } 90% { transform: rotate(-14deg); } 94% { transform: rotate(6deg); } }
@keyframes head-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

.pet svg .blink { transform-box: fill-box; transform-origin: center; animation: blink 4.2s infinite; }
.pet-dog svg .blink { animation-delay: 1.3s; animation-duration: 5s; }
.cat-tail { transform-box: fill-box; transform-origin: 0% 100%; animation: wag 1.6s ease-in-out infinite; }
.dog-tail { transform-box: fill-box; transform-origin: 0% 100%; animation: wag .45s ease-in-out infinite; }
.cat-ear-left, .dog-ear-left { transform-box: fill-box; transform-origin: 70% 90%; animation: twitch 3.7s infinite; }
.cat-ear-right { transform-box: fill-box; transform-origin: 30% 90%; animation: twitch 5.3s 1s infinite; }
.dog-ear-right { transform-box: fill-box; transform-origin: 50% 10%; animation: twitch 4.4s .6s infinite; }
.cat-head, .dog-head { animation: head-bob 2.6s ease-in-out infinite; }
.pet svg { filter: drop-shadow(0 5px 0 rgba(59, 42, 26, .12)); }

/* ---------- Milestone animations (classes toggled by effects.js) ---------- */
@keyframes cheer { 0%, 100% { transform: translateY(0) scale(1); } 25% { transform: translateY(-22px) scale(1.06, .95); }
  50% { transform: translateY(0) scale(1.05, .92); } 70% { transform: translateY(-10px); } }
.mascot.is-cheer .mascot-img { animation: cheer .8s ease-out 1; }
@keyframes bubble-pop { 0% { transform: scale(0); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.bubble { animation: bubble-pop .3s ease-out; transform-origin: 20% 100%; }

@keyframes pop-in { 0% { transform: scale(.2) rotate(-12deg); opacity: 0; } 55% { transform: scale(1.12) rotate(4deg); opacity: 1; }
  75% { transform: scale(.96) rotate(-2deg); } 85%, 100% { transform: scale(1); opacity: 1; } }
@keyframes spin-in { 0% { transform: scale(.1) rotate(-540deg); opacity: 0; } 60% { transform: scale(1.18) rotate(10deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }
@keyframes slide-in { 0% { transform: translateX(120%) rotate(12deg); opacity: 0; } 60% { transform: translateX(-8%) rotate(-6deg); opacity: 1; } 100% { transform: translateX(0) rotate(0); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-7deg); } 75% { transform: rotate(7deg); } }
@keyframes fade-out { to { opacity: 0; transform: translateY(-14px) scale(.9); } }
@keyframes settle { 0% { transform: translateY(-40px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }

.popup.is-celebrate .popup-img { animation: pop-in .55s ease-out both, wiggle .5s .6s ease-in-out 2; }
.popup.is-tetris .popup-img { animation: spin-in .7s ease-out both, wiggle .4s .75s ease-in-out 2; width: 92%; max-width: 300px; }
.popup.is-dance .popup-img { animation: slide-in .55s ease-out both, wiggle .35s .6s ease-in-out 3; }
.popup.is-leaving { animation: fade-out .3s ease-in forwards; }
.popup .popup-text { animation: bubble-pop .35s .15s var(--spring) both; }

/* Confetti + notes (board flash on cleared rows is drawn on canvas). */
.confetti { position: absolute; top: -4%; left: var(--x); width: var(--s); height: var(--s);
  animation: confetti-fall var(--confetti-ms) cubic-bezier(.25, .6, .4, 1) var(--d) forwards; opacity: 0; }
.confetti.lemon { border-radius: 50%; border: 3px solid #f4c542;
  background: radial-gradient(circle, #fff7c2 18%, transparent 20%), repeating-conic-gradient(#ffe45c 0 36deg, #fff3a6 36deg 40deg); }
.confetti.star { background: var(--primary); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.confetti.heart { background: #ff9fb0; clip-path: path("M10 17 L2 9 A4.5 4.5 0 0 1 10 3 A4.5 4.5 0 0 1 18 9 Z"); }
@keyframes confetti-fall { 0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--r)); } }
.note { position: absolute; bottom: 30%; left: var(--x); font-size: 30px; font-weight: 900; color: var(--accent);
  animation: note-float 1.3s ease-out var(--d) forwards; opacity: 0; }
@keyframes note-float { 0% { opacity: 0; transform: translateY(0) rotate(-10deg); } 20% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-160px) rotate(16deg); } }

@media (pointer: coarse), (max-width: 820px) { .score-value { font-size: 32px; } .stat-value { font-size: 20px; } .stat-best { font-size: 18px; } }

@media (max-width: 720px) and (max-height: 700px) { .score-value { font-size: 26px; } .stat-value { font-size: 17px; } .stat-best { font-size: 15px; } }

/* Respect reduced-motion: no loops, no confetti; effects just appear and disappear. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .confetti, .note, .sky { display: none !important; }
}

/* Game-over title stays on one line on every board size. */
.screen-gameover .overlay-title { white-space: nowrap; font-size: clamp(16px, calc(var(--board-h) * .037), 26px); }
@media (max-width: 720px) {
  .screen-gameover .overlay-title { white-space: normal; font-size: 18px; }
  .overlay .btn-big { font-size: 18px; }
  .ribbon { font-size: 14px; padding: 2px 10px; white-space: nowrap; }
  .go-stats { font-size: 12px; }
  .overlay-text { font-size: 12px; }
}
