@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&display=swap');

/* Token reka bentuk Taman Main Adik — guna pemboleh ubah ini, jangan reka warna baru sesuka hati */
:root {
  --bg: #FFF8EC; --card: #FFFFFF; --ink: #33262B; --muted: #8A7A70; --line: #F0E2CF;
  --pink: #FF5C7A; --yellow: #FFD23F; --blue: #3B82F6; --green: #2EBD8C; --orange: #F7A440; --purple: #B07CFF;
  --radius: 28px; --outline: 5px solid var(--ink);
  --tap: 88px;                     /* saiz minimum sasaran sentuh */
  --safe-l: env(safe-area-inset-left, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: 'Baloo 2', ui-rounded, system-ui, sans-serif; overflow: hidden;
  touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
img, svg { -webkit-user-drag: none; }
button { font: inherit; color: inherit; }

/* animasi rig karakter */
.rig { transform-box: fill-box; transform-origin: 50% 100%; animation: tma-bob 1.8s ease-in-out infinite; }
.rig.jump { animation: tma-jump .7s cubic-bezier(.3,1.6,.5,1); }
.eyes-normal { transform-box: fill-box; transform-origin: center; animation: tma-blink 4.2s infinite; }
@keyframes tma-bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-4px) scale(1.01,.99) } }
@keyframes tma-blink { 0%,93%,100% { transform: scaleY(1) } 95% { transform: scaleY(.1) } }
@keyframes tma-jump { 0% { transform: translateY(0) scale(1.08,.9) } 35% { transform: translateY(-38px) scale(.94,1.08) }
  70% { transform: translateY(0) scale(1.1,.88) } 100% { transform: none } }
@keyframes tma-pop-in { from { transform: scale(.4); opacity: 0 } to { transform: scale(1); opacity: 1 } }
@keyframes tma-wiggle { 0%,100% { transform: rotate(0) } 25% { transform: rotate(-6deg) } 75% { transform: rotate(6deg) } }
.wiggle { animation: tma-wiggle .35s ease-in-out 2; }
svg { overflow: visible; }

/* butang rumah — sentiasa kiri atas, sama dalam semua game */
.home-btn { position: fixed; z-index: 50; top: calc(14px + var(--safe-t)); left: calc(14px + var(--safe-l));
  width: var(--tap); height: var(--tap); border-radius: 50%; background: var(--pink); border: var(--outline);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none;
  box-shadow: 0 6px 0 rgba(51,38,43,.25); }
.home-btn svg { width: 40px; height: 40px; }
.home-btn span { font-size: 13px; font-weight: 800; color: #fff; line-height: 1; margin-top: -2px; }
.home-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(51,38,43,.25); }

.home-btn.hold.holding { animation: tma-hold-fill .8s linear forwards; }
@keyframes tma-hold-fill { from { box-shadow: 0 0 0 0 var(--yellow) } to { box-shadow: 0 0 0 9px var(--yellow) } }

/* butang Langkau penerangan — muncul hanya semasa karakter bercakap panjang */
.voice-skip { position: fixed; z-index: 90; top: calc(14px + var(--safe-t)); right: calc(14px + env(safe-area-inset-right, 0px));
  display: flex; align-items: center; gap: 5px; min-height: 48px; padding: 6px 14px 6px 10px; border-radius: 999px;
  border: 3px solid rgba(255,255,255,.85); background: rgba(51,38,43,.55); color: #fff; font-size: 17px; font-weight: 800; cursor: pointer;
  box-shadow: none; opacity: .85; animation: tma-pop-in .3s both; }
/* lebih kecil & lut sinar (aduan "rimas") — muncul hanya untuk penerangan panjang yang dah pernah didengar */
.voice-skip svg { width: 24px; height: 24px; }

/* skrin mula (buka kunci audio) */
.start-gate { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; cursor: pointer; }
/* Audit UI Okt 2026: butang Rumah kekal boleh ditekan di skrin "Main!" (dulu tertutup → anak terperangkap; satu-satunya jalan keluar = mula main) */
body:has(> .start-gate) > .home-btn { z-index: 61; }
.start-kawan { width: min(260px, 50vw); }
.start-kawan svg { width: 100%; height: auto; display: block; }
.start-play { display: flex; align-items: center; gap: 10px; background: var(--green); color: #fff; border: var(--outline);
  border-radius: 999px; padding: 14px 40px; font-size: 38px; font-weight: 800; box-shadow: 0 8px 0 rgba(51,38,43,.25);
  animation: tma-wiggle 1.2s ease-in-out infinite; }
.start-play svg { width: 44px; height: 44px; }

/* butang besar umum */
.big-btn { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 10px 28px;
  border-radius: 999px; border: var(--outline); background: var(--blue); color: #fff; font-size: 26px; font-weight: 800;
  text-decoration: none; cursor: pointer; box-shadow: 0 6px 0 rgba(51,38,43,.25); }
.big-btn svg { width: 40px; height: 40px; }
.big-btn.go-home { background: var(--pink); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(51,38,43,.25); }

/* tamat pusingan */
.end-overlay { position: fixed; inset: 0; z-index: 70; background: rgba(255,248,236,.92); display: flex;
  align-items: center; justify-content: center; animation: tma-pop-in .35s ease-out; }
.end-card { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px; }
.end-kawan { width: min(220px, 40vw); }
.end-kawan svg, .sticker-art svg { width: 100%; height: auto; display: block; }
.end-sticker { display: flex; flex-direction: column; align-items: center; background: #fff; border: 4px dashed var(--pink);
  border-radius: 24px; padding: 10px 18px; animation: tma-pop-in .5s .6s both cubic-bezier(.3,1.6,.5,1); }
.sticker-art { width: 110px; }
.end-sticker-label { font-weight: 800; color: var(--pink); font-size: 20px; }
.end-actions { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }

.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 80; }

/* tangan petunjuk */
.hint-hand { position: fixed; z-index: 40; width: 72px; left: 0; top: 0; pointer-events: none;
  animation: tma-hint-tap 1.1s ease-in-out 3 both; }
.hint-hand.drag { animation: tma-hint-drag 1.6s ease-in-out 3 both; }
@keyframes tma-hint-tap { 0%,100% { transform: translate(calc(var(--x1) - 20px), calc(var(--y1) + 10px)) scale(1) }
  50% { transform: translate(calc(var(--x1) - 20px), calc(var(--y1) - 4px)) scale(.88) } }
@keyframes tma-hint-drag { 0% { transform: translate(calc(var(--x1) - 20px), calc(var(--y1) + 6px)); opacity: 0 }
  15% { opacity: 1 } 80% { transform: translate(calc(var(--x2) - 20px), calc(var(--y2) + 6px)); opacity: 1 }
  100% { transform: translate(calc(var(--x2) - 20px), calc(var(--y2) + 6px)); opacity: 0 } }

/* ---------- telefon (sisi pendek < 600px) ---------- */
/* Butang Rumah lebih kecil (64px) supaya ruang game cukup; Langkau jadi bulatan ikon 52px (aria-label kekal).
   Kedudukan Langkau dipilih oleh ui.js (tempat yang tidak menutup butang game). */
@media (max-width: 599px), (max-height: 599px) {
  .home-btn { width: 64px; height: 64px; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); border-width: 4px; }
  .home-btn svg { width: 30px; height: 30px; }
  .home-btn span { font-size: 10px; }
  .voice-skip { min-height: 44px; font-size: 15px; padding: 4px 12px 4px 8px; }
  .voice-skip svg { width: 22px; height: 22px; }
  .start-play { font-size: 30px; padding: 10px 30px; }
  .end-kawan { width: min(160px, 30vh); }
  .sticker-art { width: 80px; }
  .big-btn { min-height: 64px; font-size: 22px; padding: 8px 22px; }
  .big-btn svg { width: 32px; height: 32px; }
}

/* Audit UI Okt 2026 — telefon landskap: kawan + pelekat sebaris, butang di bawah (dulu Main lagi/Rumah terpotong di bawah skrin 390px) */
@media (orientation: landscape) and (max-height: 500px) {
  .end-card { display: grid; grid-template-columns: auto auto; grid-template-areas: "kawan sticker" "act act"; align-items: center; justify-items: center; gap: 8px 28px; padding: 8px; }
  .end-card:not(:has(.end-sticker)) { grid-template-columns: auto; grid-template-areas: "kawan" "act"; }
  .end-kawan { grid-area: kawan; width: min(150px, 40vh); }
  .end-sticker { grid-area: sticker; }
  .end-actions { grid-area: act; }
}

/* ---------- pusingkan telefon (initGame({ landskap: true })) ---------- */
.tma-pusing { position: fixed; inset: 0; z-index: 95; background: var(--bg); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; padding: calc(20px + var(--safe-t)) 20px calc(20px + env(safe-area-inset-bottom, 0px)); text-align: center;
  touch-action: none; animation: tma-pop-in .3s ease-out; }
.tma-pusing[hidden] { display: none; }
.tp-seni { display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.tp-kawan { width: 120px; }
.tp-kawan svg { width: 100%; height: auto; display: block; }
.tp-fon { width: 150px; }
.tp-fon svg { width: 100%; height: auto; display: block; overflow: visible; }
.tp-badan { transform-box: view-box; transform-origin: 75px 80px; animation: tma-pusing 2.6s ease-in-out infinite; }
.tp-anak { transform-box: view-box; transform-origin: 75px 80px; animation: tma-pusing-anak 2.6s ease-in-out infinite; }
@keyframes tma-pusing { 0%, 18% { transform: rotate(0) } 50%, 82% { transform: rotate(-90deg) } 100% { transform: rotate(0) } }
@keyframes tma-pusing-anak { 0%, 30% { opacity: 0 } 45%, 80% { opacity: 1 } 95%, 100% { opacity: 0 } }
.tma-pusing.goyang .tp-fon { animation: tma-wiggle .35s ease-in-out 3; }
.tp-tajuk { margin: 0; font-size: 30px; font-weight: 800; line-height: 1.1; }
.tp-teks { margin: 0; max-width: 30ch; font-size: 17px; font-weight: 600; color: var(--muted); line-height: 1.35; }
.tp-putar { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 64px; min-width: 180px; padding: 8px 30px;
  border-radius: 999px; border: var(--outline); background: var(--blue); color: #fff; font-size: 26px; font-weight: 800; cursor: pointer;
  box-shadow: 0 6px 0 rgba(51,38,43,.25); }
.tp-putar svg { width: 36px; height: 36px; }
.tp-putar:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(51,38,43,.25); }
.tp-ios { margin: 0; max-width: 32ch; font-size: 15px; font-weight: 700; color: var(--ink); background: #fff; border: 3px dashed var(--line);
  border-radius: 16px; padding: 8px 12px; line-height: 1.35; }
.tp-ios[hidden] { display: none; }
.tp-terus { min-height: 48px; padding: 8px 18px; border: 0; background: none; color: var(--muted); font-size: 16px; font-weight: 700;
  text-decoration: underline; cursor: pointer; }
/* butang Putar kecil di kepala hab (telefon sahaja — dipapar oleh hab) */
.putar-hub[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) { .rig, .eyes-normal, .start-play, .tp-badan, .tp-anak { animation: none } .tp-anak { opacity: 1 } }
