:root {
  --bg: #fdf6ec; --ink: #3b2f27; --soft: #8a7a6c; --card: #fffaf3; --line: #4a3b30;
  --accent: #e8743b; --accent-ink: #fff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; touch-action: manipulation; }
body { padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px); }
[hidden] { display: none !important; }
.screen { max-width: 560px; margin: 0 auto; padding-block: 12px 20px; min-height: 100%;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

.title { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 14px 0 16px; }
.title h1 { font-size: 30px; margin: 0; letter-spacing: -.5px; }
.hero { width: 54px; height: 54px; flex: none; display: inline-block; }
.hero svg { width: 100%; height: 100%; }
.card { background: var(--card); border: 2px solid #eadfce; border-radius: 18px; padding: 14px 16px; margin-bottom: 14px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--soft); margin: 6px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { flex: 1 0 auto; min-width: 48px; padding: 10px 8px; border-radius: 12px; border: 2px solid #e0d2bd; background: #fff;
  font: inherit; font-weight: 600; color: var(--ink); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.note { margin: 0 0 6px; color: var(--soft); font-size: 14px; min-height: 1.4em; }
.stats { margin: 4px 0 12px; font-weight: 600; }
.big { display: block; width: 100%; padding: 15px; margin-top: 10px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-size: 19px; font-weight: 700; }
.big:active { transform: scale(.98); }
.big small { display: block; font-size: 13px; font-weight: 600; opacity: .85; margin-top: 2px; }
.big.ghost { background: transparent; color: var(--ink); border: 2px solid #e0d2bd; font-size: 17px; }
details summary { font-weight: 700; }
details ul { padding-left: 20px; margin: 10px 0 2px; }
details li { margin-bottom: 6px; }
.foot { text-align: center; color: var(--soft); font-size: 13px; }

.bar { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; font-weight: 700; }
.bar #sound { width: 40px; height: 40px; border-radius: 12px; border: 2px solid #e0d2bd; background: #fff; font-size: 20px; line-height: 1; color: var(--ink); padding: 0; }
.bar #sound.off { color: #cfc2b0; text-decoration: line-through; }
.bar #back { width: 44px; height: 44px; border-radius: 12px; border: 2px solid #e0d2bd; background: #fff; font-size: 26px; line-height: 1; color: var(--ink); padding: 0 0 4px; }
#levelName { flex: 1; }
#clock { font-variant-numeric: tabular-nums; font-size: 22px; }
#lives { font-size: 24px; letter-spacing: 2px; color: #e2445c; }
#lives .gone { color: #d9cdbd; }
#lives .hit { display: inline-block; animation: shake .45s; }

.grid { --n: 6; display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 1px;
  width: min(100%, calc(100dvh - 270px)); aspect-ratio: 1; margin: 0 auto;
  background: rgba(74, 59, 48, .35); border: 3px solid var(--line); border-radius: 6px;
  touch-action: none; }
.cell { position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.cell svg { width: 86%; height: 86%; pointer-events: none; }
.cell svg.x { width: 46%; height: 46%; stroke: rgba(59, 47, 39, .62); stroke-width: 1.6; stroke-linecap: round; }
.cell svg.x.bad { width: 56%; height: 56%; stroke: #d81e3f; stroke-width: 2.3; }
.cell.pressing::after { content: ""; position: absolute; inset: 12%; border-radius: 50%;
  background: rgba(255, 255, 255, .75); animation: grow .35s linear forwards; }
.cell.xin svg { animation: xin .22s cubic-bezier(.3, 1.8, .5, 1); }
.cell.found { z-index: 2; }
.cell.found svg { animation: dogin .7s cubic-bezier(.3, 1.5, .5, 1); }
.cell.found::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 4px solid #fff; pointer-events: none; animation: ring .6s ease-out forwards; }
.spark { position: absolute; left: 50%; top: 50%; width: 14%; height: 14%; margin: -7% 0 0 -7%; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px #f7b733; pointer-events: none; animation: spark .65s ease-out forwards; }
.cell.shake { animation: shake .45s; z-index: 1; }
.cell.shake::before { content: ""; position: absolute; inset: 0; background: rgba(226, 68, 92, .55); animation: fade .45s forwards; }
.cell.ghost svg { opacity: .45; }
.cell.party svg { animation: bounce .7s ease-in-out; animation-delay: calc(var(--d) * 80ms); }
.cell svg.sil, .tray svg.sil, .zoogrid svg.sil { filter: brightness(0); opacity: .42; }
.tray { display: flex; justify-content: center; gap: 6px; margin: 12px auto 0; max-width: 100%; }
.slot { position: relative; flex: 1 1 0; max-width: 54px; aspect-ratio: 1; border-radius: 12px; background: #fff; border: 2px solid #e0d2bd; display: flex; align-items: center; justify-content: center; }
.slot svg { width: 84%; height: 84%; }
.slot.todo svg:not(.sil) { opacity: .5; }
.slot.got { background: #dff3d6; border-color: #7cc36a; }
.slot.got::after { content: "✓"; position: absolute; right: -5px; top: -7px; width: 18px; height: 18px; border-radius: 50%; background: #4caf50; color: #fff; font-size: 12px; font-weight: 800; line-height: 18px; text-align: center; }
.slot.dog { border-color: #f0b429; box-shadow: 0 0 0 2px rgba(240, 180, 41, .35); }
.slot.pop svg { animation: dogin .7s cubic-bezier(.3, 1.5, .5, 1); }
.toast { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 700; white-space: nowrap; z-index: 6; animation: pop .3s cubic-bezier(.3, 1.4, .5, 1); }
.intro { z-index: 20; }
.introIcon { width: 130px; height: 130px; margin: 4px auto 0; }
.introIcon svg { width: 100%; height: 100%; animation: unmask 1.1s ease-out both, bounce .8s ease-in-out 1.1s 2; }
.bubble { position: relative; background: #fff; border: 2px solid #e0d2bd; border-radius: 18px; padding: 12px 14px; margin: 16px 0 6px !important; font-size: 16px; text-align: left; }
.bubble::before { content: ""; position: absolute; left: 50%; top: -9px; width: 14px; height: 14px; margin-left: -8px; background: #fff; border-left: 2px solid #e0d2bd; border-top: 2px solid #e0d2bd; transform: rotate(45deg); }
.rankrow { display: flex; justify-content: space-between; align-items: baseline; font-size: 18px; }
.rankrow span { color: var(--soft); font-weight: 600; font-size: 15px; }
.xpbar { height: 14px; border-radius: 999px; background: #eadfce; overflow: hidden; margin: 8px 0 6px; }
.xpbar i { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #f0b429, #e8743b); transition: width .9s cubic-bezier(.2, .8, .3, 1); }
.lines { text-align: left; margin: 8px 0 12px; }
.lines div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 15px; }
.lines div b { font-variant-numeric: tabular-nums; }
.up { font-weight: 800; color: var(--accent); font-size: 19px; }
.newrow { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 10px 0; }
.newrow figure { margin: 0; width: 72px; font-size: 12px; font-weight: 700; }
.newrow svg { width: 60px; height: 60px; animation: bounce .8s ease-in-out 2; }
.newrow figcaption em { display: block; font-style: normal; color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.zoogrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 10px; }
.zoogrid figure { margin: 0; padding: 8px 4px; background: var(--card); border: 2px solid #eadfce; border-radius: 14px; text-align: center; font-size: 12px; font-weight: 700; }
.zoogrid figure.dog { border-color: #f0b429; background: #fff8e1; }
.zoogrid svg { width: 56px; height: 56px; }
.zoogrid figcaption span { display: block; color: var(--soft); font-weight: 600; }
.hint { text-align: center; color: var(--soft); font-size: 14px; margin: 12px 0 0; }

.overlay { position: fixed; inset: 0; background: rgba(59, 47, 39, .45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; }
.panel { background: var(--card); border-radius: 22px; padding: 22px 20px; width: 100%; max-width: 380px; max-height: 100%; overflow-y: auto; text-align: center; animation: pop .35s cubic-bezier(.3, 1.4, .5, 1); }
.panel h2 { margin: 0 0 4px; font-size: 24px; }
.panel .time { font-size: 44px; font-weight: 800; margin: 4px 0; font-variant-numeric: tabular-nums; }
.panel p { margin: 6px 0; }
.floating { position: fixed; left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(14px + env(safe-area-inset-bottom)); width: auto; z-index: 5; }
.spin { animation: bounce .8s ease-in-out infinite; }

@keyframes grow { from { transform: scale(0); opacity: .3; } to { transform: scale(1); opacity: 1; } }
@keyframes xin { from { transform: scale(0) rotate(-45deg); } 70% { transform: scale(1.3) rotate(8deg); } to { transform: scale(1) rotate(0); } }
@keyframes dogin { 0% { transform: scale(0) rotate(-25deg); } 35% { transform: scale(1.45) rotate(10deg); } 55% { transform: scale(.9) rotate(-8deg); } 75% { transform: scale(1.1) rotate(5deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes ring { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.9); opacity: 0; } }
@keyframes spark { from { transform: translate(0, 0) scale(1); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
@keyframes unmask { 0%, 35% { filter: brightness(0); opacity: .45; transform: scale(.8); } 100% { filter: brightness(1); opacity: 1; transform: scale(1); } }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes fade { to { opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-22%) rotate(-6deg); } 70% { transform: translateY(0) rotate(4deg); } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01s !important; } }
