:root {
  color-scheme: light;
  --ink: #16324a;
  --ink-soft: #5e7284;
  --paper: #f5fbff;
  --panel: #ffffff;
  --line: #dceaf2;
  --sky: #dff3ff;
  --mint: #bcebdc;
  --orange: #f28a3c;
  --orange-deep: #d86122;
  --berry: #d84f79;
  --shadow: 0 24px 70px rgba(22, 50, 74, .16);
  font-family: Inter, ui-rounded, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #cfeaf6; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; color: var(--ink); background: linear-gradient(135deg, #cbeefa, #dbf5e9); }
button, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid rgba(242, 138, 60, .5); outline-offset: 3px; }

.app-shell { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(420px, 1.3fr) minmax(360px, .7fr); gap: 18px; padding: 18px; }
.playground, .control-panel { background: rgba(255, 255, 255, .86); border: 1px solid rgba(255, 255, 255, .9); box-shadow: var(--shadow); border-radius: 32px; overflow: hidden; backdrop-filter: blur(18px); }
.playground { min-height: calc(100vh - 36px); display: grid; grid-template-rows: auto 1fr auto; }
.topbar, .panel-heading, .section-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar { padding: 22px 24px 8px; position: relative; z-index: 5; }
.eyebrow { margin: 0 0 2px; color: var(--orange-deep); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.7rem, 4vw, 2.5rem); letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 1.45rem; letter-spacing: -.025em; }
h3 { margin-bottom: 0; font-size: 1rem; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.status-dot { display: inline-flex; align-items: center; gap: 7px; color: #31586b; font-size: .9rem; font-weight: 700; }
.status-dot::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #29b57b; box-shadow: 0 0 0 5px rgba(41, 181, 123, .13); }
.icon-button, .install-button, .stop-button, .text-button { border: 0; cursor: pointer; color: var(--ink); }
.icon-button { width: 42px; height: 42px; border-radius: 50%; background: #edf7fb; font-size: 1.05rem; }
.install-button { min-height: 42px; padding: 0 14px; border-radius: 13px; background: var(--ink); color: #fff; font-weight: 800; }

.scene { position: relative; min-height: 490px; display: grid; place-items: center; overflow: hidden; touch-action: none; isolation: isolate; }
.ambient { position: absolute; border-radius: 50%; filter: blur(2px); opacity: .68; }
.ambient-one { width: 340px; height: 340px; left: -110px; top: 6%; background: radial-gradient(circle at 65% 50%, #b1e8fc, transparent 70%); }
.ambient-two { width: 360px; height: 360px; right: -120px; bottom: -60px; background: radial-gradient(circle at 35% 40%, #beeeda, transparent 70%); }
.floor-glow { position: absolute; width: min(72%, 540px); height: 90px; bottom: 42px; border-radius: 50%; background: radial-gradient(ellipse, rgba(58, 123, 140, .2), transparent 69%); z-index: -1; }
.cat-shell { position: relative; width: min(56%, 410px); min-width: 270px; aspect-ratio: 1; display: grid; place-items: center; user-select: none; cursor: grab; z-index: 2; }
.cat-shell:active { cursor: grabbing; }
.rig-root { position: absolute; inset: 0; transform-origin: 50% 88%; filter: drop-shadow(0 18px 16px rgba(45, 74, 86, .14)); will-change: transform; }
.rig-root::after { content: ""; position: absolute; left: 35%; top: 48%; width: 30%; height: 27%; border-radius: 50%; background: radial-gradient(ellipse, rgba(255,255,255,.13), transparent 68%); pointer-events: none; z-index: 7; }
.bone { position: absolute; transform-box: border-box; will-change: transform; }
.art { position: absolute; inset: 0; background-repeat: no-repeat; pointer-events: none; }
.parts-sprite { background-image: url("./assets/rig/cat-parts.png"); background-size: 400% 400%; }
.face-sprite { background-image: url("./assets/rig/cat-face.png"); background-size: 400% 400%; background-repeat: no-repeat; }
.p-r1-c1 { background-position: 0 0; } .p-r1-c2 { background-position: 33.333% 0; } .p-r1-c3 { background-position: 66.667% 0; } .p-r1-c4 { background-position: 100% 0; }
.p-r2-c1 { background-position: 0 33.333%; } .p-r2-c2 { background-position: 33.333% 33.333%; } .p-r2-c3 { background-position: 66.667% 33.333%; } .p-r2-c4 { background-position: 100% 33.333%; }
.p-r3-c1 { background-position: 0 66.667%; } .p-r3-c2 { background-position: 33.333% 66.667%; } .p-r3-c3 { background-position: 66.667% 66.667%; } .p-r3-c4 { background-position: 100% 66.667%; }
.p-r4-c1 { background-position: 0 100%; }
.torso { left: 26%; top: 35%; width: 48%; aspect-ratio: 1; z-index: 3; transform-origin: 50% 72%; }
.head { left: 14%; top: 1%; width: 72%; aspect-ratio: 1; z-index: 8; transform-origin: 50% 79%; }
.arm { top: 34%; width: 28%; aspect-ratio: 1; z-index: 9; transform-origin: 50% 25%; }
.arm-left { left: 18%; transform: rotate(10deg); }
.arm-right { right: 18%; transform: rotate(-10deg); }
.forearm { left: 0; top: 54%; width: 100%; aspect-ratio: 1; transform-origin: 50% 25%; }
.arm-left .forearm { transform: rotate(-12deg); }
.arm-right .forearm { transform: rotate(12deg); }
.leg { top: 61%; width: 27%; aspect-ratio: 1; z-index: 2; transform-origin: 50% 24%; }
.leg-left { left: 25%; }
.leg-right { right: 25%; }
.shin { left: 0; top: 52%; width: 100%; aspect-ratio: 1; transform-origin: 50% 23%; }
.tail { aspect-ratio: 1; transform-origin: 19% 50%; }
.tail-one { left: 61%; top: 51%; width: 36%; z-index: 1; transform: rotate(18deg); }
.tail-two { left: 50%; top: 1%; width: 100%; transform: rotate(20deg); }
.tail-three { left: 54%; top: -1%; width: 100%; transform: rotate(-8deg); }
.face-overlay { position: absolute; z-index: 3; opacity: 0; pointer-events: none; }
.face-overlay.show { opacity: 1; }
.face-eyes { left: 25%; top: 37%; width: 50%; aspect-ratio: 1; }
.face-mouth { left: 17.5%; top: 55%; width: 65%; aspect-ratio: 1; }
.eyes-closed { background-position: 33.333% 0; }
.eyes-unimpressed { background-position: 66.667% 0; }
.eyes-roll { background-position: 100% 0; }
.mouth-smile { background-position: 0 66.667%; }
.mouth-kiss { background-position: 33.333% 66.667%; }
.mouth-laugh { background-position: 66.667% 66.667%; }
.mouth-surprise { background-position: 0 100%; }
.mouth-annoyed { background-position: 33.333% 100%; }
.rig-prop { position: absolute; z-index: 12; opacity: 0; pointer-events: none; transform: scale(.5); transition: opacity .15s, transform .2s; filter: drop-shadow(0 7px 6px rgba(22,50,74,.18)); }
.rig-prop.show { opacity: 1; transform: scale(1); }
.prop-hat { left: 34%; top: -5%; font-size: clamp(2.3rem, 6vw, 4rem); }
.prop-phone { left: 53%; top: 35%; font-size: clamp(1.8rem, 4.2vw, 3rem); }
.prop-bag { left: 48%; top: 58%; font-size: clamp(2.2rem, 5.2vw, 3.6rem); }
.prop-shoes { left: 40%; bottom: -2%; font-size: clamp(2.2rem, 5vw, 3.4rem); }
.cat-shadow { position: absolute; width: 58%; height: 10%; left: 21%; bottom: 4%; background: rgba(39, 81, 95, .18); filter: blur(12px); border-radius: 50%; z-index: -1; }
.touch-glow { position: absolute; width: 64px; height: 64px; margin: -32px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .9); background: radial-gradient(circle, rgba(242, 138, 60, .32), transparent 70%); opacity: 0; pointer-events: none; }
.touch-glow.show { animation: touch-pop .55s ease-out; }
.speech-bubble { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); z-index: 5; max-width: min(82%, 520px); padding: 12px 18px; border-radius: 18px 18px 18px 5px; background: var(--ink); color: #fff; text-align: center; font-weight: 700; box-shadow: 0 12px 30px rgba(22, 50, 74, .18); }
.gesture-hint { position: absolute; bottom: 15px; left: 50%; transform: translateX(-50%); width: 90%; margin: 0; text-align: center; color: var(--ink-soft); font-size: .85rem; }
.effect-layer { position: absolute; inset: 0; z-index: 6; pointer-events: none; display: grid; place-items: center; font-size: clamp(3rem, 9vw, 6rem); }
.effect-layer.pop { animation: effect-pop 1.1s ease both; }

.vitals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 0 24px 22px; }
.vitals > div { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: baseline; }
.vitals span { color: var(--ink-soft); font-size: .78rem; font-weight: 700; }
.vitals strong { font-size: .9rem; }
.meter { grid-column: 1 / -1; height: 7px; overflow: hidden; border-radius: 20px; background: #e7f0f4; }
.meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #39b58a, #6ad2a8); transition: width .45s ease; }
.meter.mood i { background: linear-gradient(90deg, var(--orange), #ffbd68); }

.control-panel { padding: 24px; overflow: auto; max-height: calc(100vh - 36px); }
.panel-heading { margin-bottom: 18px; }
.stop-button { background: #fff1f2; color: #a43649; border-radius: 12px; padding: 10px 14px; font-weight: 800; }
.command-box { border: 2px solid #dbeaf1; background: #f7fbfd; border-radius: 22px; padding: 13px; transition: border-color .2s, box-shadow .2s; }
.command-box:focus-within { border-color: var(--orange); box-shadow: 0 0 0 4px rgba(242, 138, 60, .12); }
.command-box textarea { width: 100%; resize: none; min-height: 70px; padding: 4px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 1rem; line-height: 1.55; }
.command-box textarea::placeholder { color: #8296a5; }
.command-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; }
.voice-button, .send-button { min-height: 46px; border: 0; border-radius: 14px; cursor: pointer; font-weight: 850; }
.voice-button { display: inline-flex; align-items: center; gap: 8px; padding: 0 14px; background: #e8f5fa; color: var(--ink); }
.voice-button.listening { background: #ffe8ed; color: #a43649; animation: pulse 1.1s infinite; }
.send-button { padding: 0 24px; color: #fff; background: linear-gradient(135deg, var(--orange), var(--orange-deep)); box-shadow: 0 8px 18px rgba(216, 97, 34, .25); }
.quick-section, .history-section { margin-top: 24px; }
.section-title { margin-bottom: 12px; }
.section-title > span { color: var(--ink-soft); font-size: .78rem; }
.text-button { padding: 4px 0; background: transparent; color: var(--orange-deep); font-weight: 800; }
.action-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.action-grid button { min-height: 70px; padding: 8px 4px; display: grid; place-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 16px; background: #fff; color: var(--ink); font-size: .78rem; font-weight: 750; cursor: pointer; transition: transform .15s, border-color .15s, background .15s; }
.action-grid button span { font-size: 1.45rem; }
.action-grid button:hover { transform: translateY(-2px); border-color: #f7b27d; background: #fff9f4; }
.history-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.history-list li { display: flex; gap: 11px; padding: 10px 12px; border-radius: 15px; background: #f4f9fb; }
.history-list strong, .history-list small { display: block; }
.history-list strong { font-size: .88rem; }
.history-list small { margin-top: 2px; color: var(--ink-soft); font-size: .76rem; line-height: 1.35; }
.history-icon { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border-radius: 10px; background: #fff; }
.help-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--ink-soft); }
.help-box summary { color: var(--ink); font-weight: 800; cursor: pointer; }
.help-box p { margin: 10px 0 0; font-size: .86rem; line-height: 1.55; }
.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translate(-50%, 30px); z-index: 20; max-width: calc(100vw - 36px); padding: 12px 18px; border-radius: 14px; background: var(--ink); color: #fff; opacity: 0; pointer-events: none; transition: .25s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes touch-pop { 0% { opacity: 0; transform: scale(.4); } 35% { opacity: 1; } 100% { opacity: 0; transform: scale(1.45); } }
@keyframes effect-pop { 0% { opacity: 0; transform: scale(.4) translateY(25px); } 25% { opacity: 1; transform: scale(1.12) translateY(0); } 75% { opacity: 1; } 100% { opacity: 0; transform: scale(.9) translateY(-30px); } }
@keyframes pulse { 50% { transform: scale(1.035); } }
@keyframes chest-breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.018,.99) translateY(1%); } }
@keyframes tail-tip-idle { 0%,100% { transform: rotate(-2deg); } 50% { transform: rotate(6deg); } }
.torso > .art { animation: chest-breathe 3.2s ease-in-out infinite; transform-origin: 50% 58%; }
.tail-three > .art { animation: tail-tip-idle 2.8s ease-in-out infinite; transform-origin: 24% 50%; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .playground, .control-panel { border-radius: 0; border: 0; box-shadow: none; }
  .playground { min-height: 68dvh; }
  .control-panel { max-height: none; }
  .scene { min-height: 430px; }
  .cat-shell { width: min(56%, 390px); }
}

@media (max-width: 560px) {
  .topbar { padding: max(16px, env(safe-area-inset-top)) 16px 4px; }
  .status-dot { display: none; }
  .scene { min-height: 390px; }
  .cat-shell { width: min(79%, 350px); min-width: 240px; }
  .speech-bubble { top: 9px; font-size: .9rem; padding: 10px 14px; }
  .gesture-hint { font-size: .75rem; }
  .vitals { padding: 0 16px 16px; gap: 9px; }
  .vitals span { font-size: .72rem; }
  .control-panel { padding: 20px 16px max(28px, env(safe-area-inset-bottom)); }
  .action-grid { grid-template-columns: repeat(3, 1fr); }
  .action-grid button { min-height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
