/* Joyful Cats: phong cách "giấy ô li + bút dạ" theo bản vẽ của bé */
:root {
  --ink: #2b2b2b;
  --paper: #f4f6ef;
  --grid: #d8e0d9;
  --blue: #4fb3e8;
  --blue-d: #2f86c4;
  --pink: #ff9fb8;
  --red: #d9534f;
  --yellow: #ffd34d;
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.screen { display: none; max-width: 1100px; margin: 0 auto; padding: 18px 16px 40px; }
body[data-mode="title"] #title,
body[data-mode="test"] #test,
body[data-mode="play"] #play { display: block; }

h1, h2 { margin: 0; }
.center { text-align: center; }
.note { color: #6b6b6b; font-size: 14px; }

/* ---------- Nút ---------- */
.btn {
  font: inherit; font-weight: 800; font-size: 17px;
  color: var(--ink); background: #fff;
  border: 3px solid var(--ink); border-radius: 18px;
  padding: 10px 18px; cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.big { font-size: 24px; padding: 14px 28px; border-radius: 24px; }
.btn.small { font-size: 15px; padding: 6px 12px; border-radius: 14px; box-shadow: 0 3px 0 var(--ink); }
.btn.primary { background: var(--blue); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.18); }

.card {
  background: #fff; border: 3px solid var(--ink); border-radius: 22px;
  padding: 18px 22px; box-shadow: 6px 6px 0 rgba(43,43,43,.12);
}

/* ---------- Logo ---------- */
.logo { text-align: center; margin-top: 10px; }
.logo-meo { display: inline-flex; align-items: center; gap: 4px; font-size: 64px; font-weight: 900; line-height: 1; }
.logo-meo span { display: inline-block; animation: wob 2.6s ease-in-out infinite; }
.logo-meo span:nth-child(2) { animation-delay: .15s; }
.logo-meo span:nth-child(3) { animation-delay: .3s; }
.logo-meo span:nth-child(4) { animation-delay: .45s; }
.logo-meo .ring {
  width: 54px; height: 54px; border-radius: 50%;
  border: 9px solid var(--ink);
  background: repeating-linear-gradient(90deg, #fff 0 6px, #cfd6d0 6px 8px);
}
.logo-meo .bang {
  background: repeating-linear-gradient(0deg, var(--ink) 0 5px, #fff 5px 8px);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-text-stroke: 2px var(--ink);
}
.logo h1 {
  font-size: clamp(40px, 8vw, 72px); font-weight: 900; letter-spacing: 1px;
  color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 4px 5px 0 var(--blue);
}
.tag { margin: 4px 0 0; font-size: 20px; font-weight: 700; color: var(--blue-d); }

@keyframes wob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-6px) rotate(3deg); } }

.hero-cats { display: flex; justify-content: center; gap: clamp(4px, 2vw, 22px); margin: 18px 0 6px; flex-wrap: wrap; }
.hero-cat { width: clamp(90px, 19vw, 170px); animation: bob 1.8s ease-in-out infinite; animation-delay: var(--d); }
.hero-cat svg { width: 100%; height: auto; overflow: visible; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px) rotate(2deg); } }

.menu { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 14px 0 26px; }

.story { max-width: 760px; margin: 0 auto 22px; font-size: 18px; line-height: 1.5; }
.story h2 { font-size: 24px; margin-bottom: 6px; }
.words { display: flex; flex-wrap: wrap; gap: 10px; padding: 0; list-style: none; margin: 8px 0 12px; }
.words li { background: #eaf6fd; border: 2px solid var(--ink); border-radius: 14px; padding: 4px 12px; font-size: 20px; }

.sketch { max-width: 420px; margin: 0 auto 20px; padding: 12px; transform: rotate(-1.5deg); }
.sketch img { width: 100%; display: block; border-radius: 12px; }
.sketch figcaption { text-align: center; padding-top: 8px; font-weight: 700; }

.foot { text-align: center; color: #777; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.paw { width: 34px; display: inline-block; }
.paw svg { width: 100%; display: block; }

/* ---------- Thanh trên cùng ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.topbar-r { display: flex; gap: 8px; }
body[data-mic="on"] .mic-btn { background: #c8f2c2; animation: pulse 1.4s infinite; }
body[data-mic="denied"] .mic-btn { background: #ffd6d6; }
@keyframes pulse { 0%, 100% { box-shadow: 0 3px 0 var(--ink), 0 0 0 0 rgba(80,190,80,.5); } 50% { box-shadow: 0 3px 0 var(--ink), 0 0 0 8px rgba(80,190,80,0); } }

.hud-items { display: flex; gap: 6px; align-items: center; }
.hud-ic { width: 46px; height: 30px; opacity: .25; filter: grayscale(1); transition: .3s; }
.hud-ic.got { opacity: 1; filter: none; transform: scale(1.12); }
.hud-ic svg { width: 100%; height: 100%; }

/* ---------- Sân khấu ---------- */
.stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden;
  border: 4px solid var(--ink); border-radius: 26px;
  background: linear-gradient(#dff1ff 0 55%, #f7f3e6 55% 100%);
  box-shadow: 6px 8px 0 rgba(43,43,43,.15);
  user-select: none;
}
.fence {
  position: absolute; left: 0; right: 0; bottom: 12%; height: 34%;
  background:
    repeating-linear-gradient(90deg, transparent 0 4.2%, rgba(43,43,43,.55) 4.2% 4.5%),
    linear-gradient(#e9c896, #d8b07a);
  border-top: 3px solid rgba(43,43,43,.55);
  opacity: .55;
}
.ground { position: absolute; left: 0; bottom: 0; width: 100%; height: 14%; }
.stop-dot { position: absolute; bottom: 9%; width: 1.2%; aspect-ratio: 1; margin-left: -.6%; border-radius: 50%; background: rgba(43,43,43,.25); }

.obj { position: absolute; bottom: 12%; transform: translateX(-50%); }
.obj svg { display: block; width: 100%; height: auto; overflow: visible; }
.box { width: 7%; }
.crates { width: 11%; z-index: 1; }
.dog { width: 10%; bottom: 31%; z-index: 2; transform: translateX(-50%) scaleX(-1); }
.dog.twitch { animation: twitch .25s infinite; }
@keyframes twitch { 50% { transform: translateX(-50%) scaleX(-1) rotate(4deg); } }
.door { width: 7.5%; }

.item { width: 6%; bottom: 30%; animation: float 1.6s ease-in-out infinite; transition: opacity .3s, transform .3s; }
.item-key { width: 6.5%; }
.item.taken { opacity: 0; transform: translateX(-50%) translateY(-60px) scale(1.6); animation: none; }
@keyframes float { 0%, 100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-8px); } }

/* Chó: vùng nhìn + Zzz + tiếng sủa */
.cone {
  position: absolute; left: 54%; bottom: 12%; width: 13.5%; height: 30%;
  clip-path: polygon(100% 0, 0 100%, 95% 100%);
  background: linear-gradient(200deg, rgba(255,90,90,.55), rgba(255,90,90,.12));
  opacity: 0; transition: opacity .25s;
}
.cone.on { opacity: 1; }
.zzz { position: absolute; bottom: 48%; font-weight: 900; font-size: clamp(16px, 2.6vw, 30px); color: var(--blue-d); opacity: 0; transition: opacity .3s; }
.zzz.on { opacity: 1; animation: zz 1.6s ease-in-out infinite; }
.zzz small { font-size: .7em; margin-left: 2px; }
@keyframes zz { 50% { transform: translate(6px, -8px); } }
.dog-bubble {
  position: absolute; bottom: 52%; transform: translateX(-50%) scale(0);
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 4px 12px;
  font-weight: 900; font-size: clamp(14px, 2.4vw, 26px); color: var(--red); transition: transform .15s; z-index: 4;
}
.dog-bubble.on { transform: translateX(-50%) scale(1); }

/* Laser */
.laser-post { position: absolute; bottom: 12%; width: 1.4%; height: 13%; margin-left: -.7%; background: #8a8f98; border: 3px solid var(--ink); border-radius: 6px 6px 2px 2px; }
.laser { position: absolute; bottom: 19%; height: 5px; background: #ff2a2a; box-shadow: 0 0 10px 3px rgba(255,40,40,.75); opacity: 0; transition: opacity .3s; }
.laser.revealed { opacity: 1; }
.laser.alarm { animation: alarm .14s 5 alternate; }
@keyframes alarm { from { opacity: .1; } to { opacity: 1; } }
.laser-q { position: absolute; bottom: 30%; transform: translateX(-50%); font-weight: 900; font-size: clamp(18px, 3vw, 34px); color: #b9b9b9; animation: blink 1.4s infinite; }
.laser-q.gone { display: none; }
@keyframes blink { 50% { opacity: .2; } }

.mist-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.puff {
  position: absolute; width: 5%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.95), rgba(200,230,255,.5) 60%, transparent 70%);
  transform: scale(.2); opacity: 0; animation: puff 1.9s ease-out forwards;
}
@keyframes puff { 15% { opacity: 1; } 100% { transform: scale(2.4) translateY(-20%); opacity: 0; } }

/* Mèo */
.cat { position: absolute; bottom: 11%; width: 9.5%; transform: translateX(-50%); transition: left .7s ease-in-out; z-index: 6; }
.cat-body svg { width: 100%; height: auto; display: block; overflow: visible; }
.cat.walking .cat-body { animation: waddle .35s ease-in-out infinite; }
.cat.jumping .cat-body { animation: hop .7s ease-in-out; }
.pose-shake { animation: shake .3s 2; }
.pose-sit { transform: scaleY(.88) translateY(6%); transition: transform .15s; }
.pose-spray { transform: rotate(-8deg); transition: transform .1s; }
@keyframes waddle { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg) translateY(-4%); } }
@keyframes hop { 0% { transform: translateY(0); } 45% { transform: translateY(-120%) rotate(-10deg); } 100% { transform: translateY(0); } }
@keyframes shake { 25% { transform: translateX(-8%); } 75% { transform: translateX(8%); } }

.hint {
  position: absolute; bottom: 104%; left: 50%; transform: translateX(-50%) scale(0);
  width: max-content; max-width: 32vw;
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 6px 12px;
  font-weight: 800; font-size: clamp(12px, 1.7vw, 19px); text-align: center;
  transition: transform .2s; transform-origin: bottom center;
}
.hint::after { content: ""; position: absolute; left: 50%; top: 100%; margin-left: -8px; border: 8px solid transparent; border-top-color: var(--ink); }
.hint.on { transform: translateX(-50%) scale(1); }

/* Thắng */
.win { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(244,246,239,.7); opacity: 0; pointer-events: none; transition: opacity .4s; z-index: 10; }
.win.show { opacity: 1; pointer-events: auto; }
.win-card { background: #fff; border: 4px solid var(--ink); border-radius: 26px; padding: 18px 30px; text-align: center; transform: scale(.7); transition: transform .4s cubic-bezier(.3,1.6,.5,1); }
.win.show .win-card { transform: scale(1); }
.win-cat { width: 120px; margin: 0 auto; animation: bob 1s infinite; }
.win-cat svg { width: 100%; height: auto; overflow: visible; }
.win-card h2 { font-size: clamp(22px, 3.4vw, 36px); }
.win-card p { font-size: 19px; }

/* Lời máy nghe được */
.heard { min-height: 30px; text-align: center; margin: 10px 0 4px; font-size: 18px; color: #555; }
.heard b { color: var(--blue-d); text-transform: uppercase; }
.heard.miss i { color: #b25; }
body.no-voice .heard::before { content: "Trình duyệt này chưa nghe được giọng nói. Hãy dùng nút bấm bên dưới nhé!"; }

/* Nút lệnh */
.controls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 8px; }
.cmd {
  font: inherit; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 10px 4px;
  box-shadow: 0 5px 0 var(--ink); cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.cmd:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.cmd .ic { font-size: clamp(26px, 4vw, 40px); }
.cmd .w { font-weight: 900; font-size: clamp(16px, 2.4vw, 24px); text-transform: uppercase; }
.cmd.flash { animation: flash .5s; }
@keyframes flash { 0% { background: var(--yellow); transform: scale(1.08); } 100% { background: #fff; transform: scale(1); } }

/* Thử micro */
.tcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 18px 0; }
.tcard { background: #fff; border: 3px solid var(--ink); border-radius: 22px; padding: 16px 8px; text-align: center; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 5px 0 var(--ink); }
.tcard .ic { font-size: 44px; }
.tcard b { font-size: 30px; text-transform: uppercase; }
.tcard small { font-size: 22px; font-weight: 900; color: var(--blue-d); }
.tcard.hit { animation: hit .5s; }
@keyframes hit { 0% { transform: scale(1.18) rotate(-3deg); background: #c8f2c2; } 100% { transform: none; background: #fff; } }
.test-heard { text-align: center; font-size: 22px; min-height: 34px; }
.test-heard b { color: var(--blue-d); text-transform: uppercase; }

/* Pháo hoa */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti span { position: absolute; top: -40px; animation: fall 2.8s ease-in forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (max-width: 640px) {
  .logo-meo { font-size: 46px; }
  .logo-meo .ring { width: 40px; height: 40px; border-width: 7px; }
  .controls { gap: 6px; }
  .cmd { border-radius: 14px; padding: 8px 2px; }
  .story { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
