:root {
  --ink: #4a3a35; --bg: #fff6ea; --card: #fff; --accent: #ff8a5b; --accent2: #6cc4a1; --sky: #ffe2c2;
  --coin: #ffb400; --shadow: 0 4px 0 rgba(74, 58, 53, .18); --r: 22px;
  font-family: 'Leelawadee UI', 'Noto Sans Thai', 'Sarabun', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; background: none; }
input { font: inherit; }
#app { height: 100%; display: flex; flex-direction: column; }
.loading { margin: auto; font-size: 28px; }
.screen { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 16px; overflow-y: auto; min-height: 0;
  background: radial-gradient(circle at 20% 10%, #ffe9cf 0, transparent 40%), radial-gradient(circle at 90% 90%, #ffe0ea 0, transparent 40%), var(--bg); }
h1 { font-size: clamp(26px, 5vw, 40px); margin: 8px 0 4px; text-align: center; }
h2 { font-size: clamp(20px, 4vw, 28px); margin: 6px 0 12px; text-align: center; }
.sub { opacity: .75; margin: 0 0 12px; text-align: center; font-size: 18px; }

.btn { background: var(--accent); color: #fff; font-size: 22px; font-weight: 700; padding: 12px 26px; border-radius: 999px; box-shadow: var(--shadow); transition: transform .1s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(74, 58, 53, .18); }
.btn.green { background: var(--accent2); } .btn.grey { background: #b8aca6; } .btn.small { font-size: 17px; padding: 8px 16px; }
.btn:disabled { opacity: .45; }
.iconbtn { width: 52px; height: 52px; border-radius: 16px; background: #fff; box-shadow: var(--shadow); font-size: 26px; display: grid; place-items: center; }
.back { position: absolute; left: 12px; top: 12px; }

/* ----- เข้าเกม ----- */
.logo { width: 120px; height: 120px; margin-top: 10px; }
.code-dots { display: flex; gap: 12px; margin: 10px 0 18px; }
.code-dots span { width: 54px; height: 64px; border-radius: 16px; background: #fff; box-shadow: var(--shadow); font-size: 36px; font-weight: 700; display: grid; place-items: center; }
.keypad { display: grid; grid-template-columns: repeat(3, 84px); gap: 12px; }
.keypad button { height: 72px; border-radius: 20px; background: #fff; box-shadow: var(--shadow); font-size: 32px; font-weight: 700; }
.keypad button:active, .pinpad button:active { transform: translateY(3px); }
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; width: min(900px, 100%); }
.roster button { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 10px 6px 12px; font-size: 20px; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.roster .face { width: 80px; height: 80px; display: grid; place-items: center; font-size: 50px; }
.roster .face svg { width: 100%; height: 100%; }
.pin-slots { display: flex; gap: 14px; margin: 6px 0 18px; }
.pin-slots span { width: 70px; height: 70px; border-radius: 50%; background: #fff; box-shadow: inset 0 3px 0 rgba(0,0,0,.08); font-size: 40px; display: grid; place-items: center; }
.pinpad { display: grid; grid-template-columns: repeat(3, 92px); gap: 14px; }
.pinpad button { height: 92px; border-radius: 24px; background: #fff; box-shadow: var(--shadow); font-size: 50px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

/* ----- สร้างแมว ----- */
.create { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(280px, 1.2fr); gap: 18px; width: min(980px, 100%); align-items: start; }
.preview { background: #fff; border-radius: 32px; box-shadow: var(--shadow); aspect-ratio: 1; display: grid; place-items: center; padding: 10px; position: sticky; top: 0; }
.preview svg { width: 100%; height: 100%; }
.opts { display: flex; flex-direction: column; gap: 14px; }
.opt-row { background: #fff; border-radius: var(--r); padding: 10px 14px 14px; box-shadow: var(--shadow); }
.opt-row h3 { margin: 0 0 8px; font-size: 19px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 48px; height: 48px; border-radius: 50%; border: 3px solid var(--ink); }
.chip { padding: 8px 14px; border-radius: 999px; background: #f4ece6; font-size: 18px; font-weight: 600; }
.on { outline: 4px solid var(--accent); outline-offset: 3px; }
.chip.on { background: #ffe1d3; }
.name-in { width: 100%; font-size: 24px; padding: 10px 14px; border-radius: 16px; border: 3px solid #e8dcd3; margin-top: 8px; text-align: center; }

/* ----- บ้าน ----- */
.home { flex: 1; display: flex; flex-direction: column; min-height: 0; background: #f7e6d4; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.catname { font-size: 22px; font-weight: 800; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { background: #fff; border-radius: 999px; padding: 6px 14px; box-shadow: var(--shadow); font-size: 22px; font-weight: 800; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.heart-bar { width: 110px; height: 14px; border-radius: 9px; background: #f2dede; overflow: hidden; }
.heart-bar i { display: block; height: 100%; background: linear-gradient(90deg, #ff8fb6, #ff5a7a); border-radius: 9px; transition: width .6s; }
.badge { position: absolute; top: -6px; right: -6px; background: #ff5a5a; color: #fff; font-size: 14px; font-weight: 800; min-width: 24px; height: 24px; border-radius: 12px; display: grid; place-items: center; }
.stage-wrap { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 8px; }
.stage { position: relative; aspect-ratio: 1000 / 620; width: min(100%, calc((100vh - 200px) * 1000 / 620)); border-radius: 26px; overflow: hidden; box-shadow: 0 6px 0 rgba(74,58,53,.15); background: #fff4dc; touch-action: none; }
.stage .room-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.catbox { position: absolute; width: 24%; aspect-ratio: 260 / 232; transform: translate(-50%, -100%); transition: left 2.2s ease-in-out, top 2.2s ease-in-out; cursor: pointer; z-index: 5; }
.catbox > svg { width: 100%; height: 100%; display: block; overflow: visible; }
.catbox.walking > svg { animation: walk .45s ease-in-out infinite; }
@keyframes walk { 50% { transform: translateY(-4%) rotate(2deg); } }
.thought { position: absolute; left: 66%; top: -8%; background: #fff; border-radius: 50%; width: 30%; aspect-ratio: 1; display: grid; place-items: center; font-size: clamp(18px, 3vw, 34px); box-shadow: var(--shadow); animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }

.toolbar { display: flex; gap: 8px; padding: 8px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); overflow-x: auto; justify-content: center; flex-wrap: wrap; }
.tool { position: relative; background: #fff; border-radius: 18px; box-shadow: var(--shadow); width: 84px; height: 76px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 30px; line-height: 1; flex: none; }
.tool small { font-size: 14px; font-weight: 700; margin-top: 5px; }
.tool:active { transform: translateY(3px); }
.tool.need { animation: glow 1.2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 5px #ffd23f, var(--shadow); } }

/* แอนิเมชันแมว */
.cat-anim .cat-tail { transform-box: view-box; transform-origin: 136px 170px; animation: tail 2.4s ease-in-out infinite; }
@keyframes tail { 50% { transform: rotate(-12deg); } }
.cat-anim .cat-body { transform-box: view-box; transform-origin: 100px 186px; animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.02, .985); } }
.cat-anim .cat-eye { transform-box: fill-box; transform-origin: center; animation: blink 4.5s infinite; }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
.cat-anim .cat-head { transform-box: view-box; transform-origin: 100px 120px; animation: tilt 6s ease-in-out infinite; }
@keyframes tilt { 0%, 60%, 100% { transform: rotate(0); } 75% { transform: rotate(-5deg); } 88% { transform: rotate(3deg); } }
.eating .cat-head { animation: eat .44s ease-in-out infinite !important; }
@keyframes eat { 50% { transform: rotate(0) translateY(10px); } }
.jump > svg { animation: jump .5s ease-out !important; }
@keyframes jump { 40% { transform: translateY(-22%) scale(1.04, .96); } 100% { transform: none; } }
.petted > svg { animation: squish .35s; }
@keyframes squish { 40% { transform: scale(1.06, .94); } }

.bowl { position: absolute; width: 11%; transform: translate(-50%, -100%); z-index: 6; animation: pop-in .3s; }
.bubble { position: absolute; width: 8%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 30% 30%, #fff, rgba(190, 230, 255, .75) 45%, rgba(150, 210, 255, .5)); border: 2px solid rgba(255,255,255,.9); transform: translate(-50%, -50%); z-index: 7; animation: pop-in .3s; }
.bubble.gone { transform: translate(-50%, -50%) scale(1.6); opacity: 0; transition: .2s; pointer-events: none; }
.toy { position: absolute; width: 10%; aspect-ratio: 1; transform: translate(-50%, -50%); z-index: 8; transition: left .7s cubic-bezier(.3, 1.4, .6, 1), top .7s cubic-bezier(.3, 1.4, .6, 1); font-size: clamp(28px, 5vw, 56px); display: grid; place-items: center; animation: wiggle .5s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: translate(-50%, -50%) rotate(18deg); } }
@keyframes pop-in { from { transform: translate(-50%, -50%) scale(0); } }
.hint-banner { position: absolute; left: 50%; top: 4%; transform: translateX(-50%); background: rgba(255,255,255,.95); padding: 6px 16px; border-radius: 999px; font-size: clamp(16px, 2.4vw, 22px); font-weight: 700; z-index: 9; box-shadow: var(--shadow); white-space: nowrap; }

/* เอฟเฟกต์ */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.float { position: absolute; font-size: 34px; animation: floatup 1.2s ease-out forwards; }
@keyframes floatup { to { transform: translateY(-120px) scale(1.3); opacity: 0; } }
.toast { position: fixed; left: 50%; top: 14%; transform: translateX(-50%); background: #fff; padding: 14px 26px; border-radius: 999px; box-shadow: 0 6px 20px rgba(0,0,0,.15); font-size: 24px; font-weight: 800; z-index: 120; animation: toast 2.4s forwards; white-space: nowrap; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -20px); } 10%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
.flash { position: fixed; inset: 0; background: #fff; z-index: 130; animation: flash .5s forwards; pointer-events: none; }
@keyframes flash { to { opacity: 0; } }

/* ----- แผ่นหน้าต่าง (แต่งตัว ร้านค้า ภารกิจ) ----- */
.sheet-bg { position: fixed; inset: 0; background: rgba(74, 58, 53, .35); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--bg); width: min(1000px, 100%); max-height: 92vh; border-radius: 30px 30px 0 0; padding: 14px 16px max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sheet-head h2 { flex: 1; margin: 0; text-align: left; }
.sheet-body { overflow-y: auto; min-height: 0; flex: 1; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; flex: none; }
.tab { background: #fff; border-radius: 999px; padding: 8px 16px; font-size: 19px; font-weight: 700; box-shadow: var(--shadow); white-space: nowrap; }
.tab.on { background: var(--accent); color: #fff; outline: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; padding: 4px 2px 8px; }
.card { background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; font-size: 15px; font-weight: 700; text-align: center; }
.card .pic { width: 100%; aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; border-radius: 14px; background: #fbf4ee; }
.card .pic svg { width: 100%; height: 100%; }
.card .price { font-size: 17px; color: #c47f00; }
.card.owned .price { color: var(--accent2); }
.card.on { outline: 4px solid var(--accent); }
.card.locked { opacity: .55; }
.wardrobe { display: grid; grid-template-columns: minmax(180px, 34%) 1fr; gap: 14px; min-height: 0; flex: 1; }
.wardrobe .preview { position: relative; }
.msn { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 20px; padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.msn .ic { font-size: 38px; }
.msn .tx { flex: 1; font-size: 20px; font-weight: 700; }
.bar { height: 14px; background: #f1e6dd; border-radius: 8px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent2); border-radius: 8px; }
.speak { font-size: 24px; width: 46px; height: 46px; border-radius: 50%; background: #fff3c4; flex: none; }
.dialog { background: #fff; border-radius: 30px; padding: 20px; width: min(420px, 92vw); margin: auto; text-align: center; animation: up .2s; }
.dialog .pic { width: 200px; height: 200px; margin: 0 auto 8px; }
.dialog .pic svg { width: 100%; height: 100%; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.album { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.photo { background: #fff; padding: 10px 10px 30px; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,.12); transform: rotate(var(--rot)); }
.photo .pic { aspect-ratio: 1; border-radius: 4px; display: grid; place-items: center; }
.photo svg { width: 100%; height: 100%; }
.empty { text-align: center; padding: 30px; font-size: 20px; opacity: .7; }

/* ----- แต่งบ้าน ----- */
.deco .stage { outline: 4px dashed var(--accent); outline-offset: -4px; }
.deco .fur { cursor: grab; }
.fur.sel { filter: drop-shadow(0 0 6px #ff8a5b) drop-shadow(0 0 2px #ff8a5b); }
.deco-tools { position: absolute; z-index: 20; display: flex; gap: 6px; transform: translate(-50%, -130%); }
.deco-tools button { width: 46px; height: 46px; border-radius: 14px; background: #fff; box-shadow: var(--shadow); font-size: 24px; }
.tray { display: flex; gap: 10px; overflow-x: auto; padding: 8px 10px; }
.tray .card { flex: none; width: 104px; }
.deco-bar { display: flex; gap: 10px; align-items: center; padding: 4px 10px 0; flex-wrap: wrap; justify-content: center; }

@media (max-width: 700px) {
  .create, .wardrobe { grid-template-columns: 1fr; }
  .preview { position: static; max-width: 260px; justify-self: center; width: 100%; }
  .wardrobe .preview { max-width: 180px; }
  .tool { width: 70px; height: 66px; font-size: 26px; }
  .tool small { font-size: 12px; }
  .heart-bar { width: 70px; }
  .stage { width: min(100%, calc((100vh - 240px) * 1000 / 620)); }
  .keypad { grid-template-columns: repeat(3, 76px); } .pinpad { grid-template-columns: repeat(3, 84px); } .pinpad button { height: 84px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
