:root {
  --bg: #fbf6ee; --bg2: #f3eadb; --card: #fffdf9; --ink: #2b2420; --muted: #7b6f66; --line: #e6dccd;
  --accent: #d9822b; --accent-ink: #fff; --accent-soft: #fbe6cf; --ok: #2f9e6b; --warn: #c2410c; --bubble: #fff;
  --shadow: 0 6px 24px rgba(80, 50, 20, .08);
  --radius: 16px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1b1916; --bg2: #24211d; --card: #2a2622; --ink: #f2ebe2; --muted: #a99d91; --line: #3a352f;
  --accent: #f0a050; --accent-ink: #231a10; --accent-soft: #3d2f20; --ok: #5cc994; --warn: #ff9b6b; --bubble: #35302a;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; }
.tagline { margin: 0; color: var(--muted); flex: 1; min-width: 200px; font-size: 14px; }
.top-actions { display: flex; gap: 8px; }

.btn, .chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; cursor: pointer;
  padding: 8px 16px; transition: background .15s, border-color .15s;
}
.chip { padding: 4px 12px; font-size: 13px; }
.btn:hover:not(:disabled), .chip:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.layout { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 20px; padding: 20px; max-width: 1200px; margin: 0 auto; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; padding: 12px 16px; } }

/* ---- stage ---- */
.stage-wrap { position: sticky; top: 12px; align-self: start; }
@media (max-width: 860px) { .stage-wrap { position: static; } }
.stage {
  background: linear-gradient(180deg, var(--card), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 460px;
}
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-height: 20px; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.stage[data-state="working"] .status .dot { background: var(--accent); animation: pulse 1.2s infinite; }
.stage[data-state="waiting"] .status .dot { background: var(--warn); animation: pulse .6s infinite; }
.stage[data-state="done"] .status .dot { background: var(--ok); }
#statusText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bubble {
  position: relative; background: var(--bubble); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px;
  box-shadow: var(--shadow); max-height: 220px; overflow-y: auto; animation: pop .25s ease-out;
}
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.facts-mini { margin-top: 6px !important; font-size: 12px; color: var(--muted); }
.thought { margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.thought summary { cursor: pointer; }
.thought p { font-style: italic; }

.pet-area { position: relative; display: flex; justify-content: center; align-items: flex-end; height: 230px; margin-top: auto; }
.pet { width: 190px; height: 190px; color: var(--ink); transform-origin: 50% 100%; }
.pet svg, .pet img { width: 100%; height: 100%; display: block; object-fit: contain; }
.pet img { filter: drop-shadow(0 6px 6px rgba(0,0,0,.12)); }

.prop { position: absolute; pointer-events: none; opacity: 0; transition: opacity .25s; }
.prop-laptop { width: 120px; bottom: 0; left: 50%; transform: translateX(-50%); }
.prop-bell { width: 46px; top: 4px; right: 18%; transform-origin: 50% 10%; }
.prop-zzz { top: 10px; right: 22%; font-weight: 700; color: var(--muted); }
.prop-zzz span { display: inline-block; animation: zzz 2.4s infinite; opacity: 0; }
.prop-zzz span:nth-child(2) { animation-delay: .6s; font-size: 18px; }
.prop-zzz span:nth-child(3) { animation-delay: 1.2s; font-size: 24px; }
.prop-spark { top: 0; left: 0; right: 0; text-align: center; color: var(--accent); font-size: 22px; letter-spacing: 40px; }
.prop-spark span { display: inline-block; animation: twinkle 1s infinite alternate; }
.prop-spark span:nth-child(2) { animation-delay: .3s; }

/* part animations */
.pet .pt-body { transform-box: fill-box; transform-origin: 50% 100%; animation: breathe 3.2s ease-in-out infinite; }
.pet .pt-eyes { transform-box: fill-box; transform-origin: 50% 50%; animation: blink 4.5s infinite; }
.pet .pt-sleep, .pet .pt-talk { display: none; }
.pet .pt-pawl, .pet .pt-pawr { transform-box: fill-box; transform-origin: 50% 50%; }
.pet .pt-tail { transform-box: fill-box; transform-origin: 0% 100%; animation: tail 2.6s ease-in-out infinite; }
.pet img { animation: breathe 3.2s ease-in-out infinite; transform-origin: 50% 100%; }

.stage[data-state="working"] .prop-laptop { opacity: 1; }
.stage[data-state="working"] .pet { transform: translateY(-34px) scale(.86); transition: transform .3s; }
.stage[data-state="working"] .pt-pawl { animation: tap .32s infinite alternate; }
.stage[data-state="working"] .pt-pawr { animation: tap .32s .16s infinite alternate; }
.stage[data-state="working"] .code-lines rect { animation: type 1.4s infinite; }
.stage[data-state="working"] .pet img { animation: bob .5s ease-in-out infinite alternate; }

.stage[data-state="waiting"] .prop-bell { opacity: 1; animation: ring .5s ease-in-out infinite; }
.stage[data-state="waiting"] .pet { animation: shake .5s ease-in-out infinite; }

.stage[data-state="done"] .prop-spark { opacity: 1; }
.stage[data-state="done"] .pet { animation: hop .6s ease-out 3; }

.stage[data-state="sleep"] .prop-zzz { opacity: 1; }
.stage[data-state="sleep"] .pt-eyes { display: none; }
.stage[data-state="sleep"] .pt-sleep { display: inline; }
.stage[data-state="sleep"] .pt-body, .stage[data-state="sleep"] .pet img { animation-duration: 5s; }

.stage.talking .pt-mouth { animation: mouthA .28s steps(1) infinite; }
.stage.talking .pt-talk { display: inline; animation: mouthB .28s steps(1) infinite; }

@keyframes breathe { 0%,100% { transform: scale(1, 1); } 50% { transform: scale(1.025, .975); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes tap { from { transform: translateY(0); } to { transform: translateY(5px); } }
@keyframes tail { 0%,100% { transform: rotate(0deg); } 50% { transform: rotate(-8deg); } }
@keyframes ring { 0%,100% { transform: rotate(-14deg); } 50% { transform: rotate(14deg); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@keyframes hop { 0% { transform: translateY(0); } 40% { transform: translateY(-22px) scale(1.03, .97); } 100% { transform: translateY(0); } }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-4px); } }
@keyframes zzz { 0% { opacity: 0; transform: translate(0, 6px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(12px, -16px); } }
@keyframes twinkle { from { opacity: .3; transform: scale(.8); } to { opacity: 1; transform: scale(1.15); } }
@keyframes type { 0% { opacity: .25; } 50% { opacity: 1; } 100% { opacity: .25; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes mouthA { 0% { opacity: 1; } 50% { opacity: 0; } }
@keyframes mouthB { 0% { opacity: 0; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .pet, .pet *, .prop, .prop * { animation: none !important; transition: none !important; }
}

.talk { display: flex; gap: 8px; }
.talk input { flex: 1; min-width: 0; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); }
.talk input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.stage-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---- panels ---- */
.panels { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 6px; font-size: 17px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.lead { margin: 0 0 12px; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.settings { margin-top: 12px; gap: 16px; font-size: 14px; }
.settings select { margin-left: 6px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.note.warn { color: var(--warn); }
.muted { color: var(--muted); font-size: 13px; }

.drop {
  display: block; margin-top: 12px; border: 2px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center;
  color: var(--muted); cursor: pointer; font-size: 14px; transition: border-color .15s, background .15s;
}
.drop input { display: none; }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.where { margin-top: 10px; font-size: 14px; }
.where summary { cursor: pointer; color: var(--accent); }
.where dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.where dt { font-weight: 600; }
.where dd { margin: 0; min-width: 0; }
.where code { font-size: 12.5px; overflow-wrap: anywhere; background: var(--bg2); padding: 1px 6px; border-radius: 6px; }

.facts { margin: 6px 0 0; padding-left: 18px; }
.facts li { margin: 3px 0; overflow-wrap: anywhere; }
.facts li.empty { list-style: none; margin-left: -18px; color: var(--muted); }
.facts li.partial { list-style: none; margin-left: -18px; color: var(--warn); font-size: 13px; }
.past { margin-top: 10px; font-size: 13px; }
.past summary { cursor: pointer; color: var(--muted); }
.past-list { margin: 6px 0 0; padding-left: 20px; }
.past-list li { margin: 3px 0; overflow-wrap: anywhere; }

.brain-state { margin: 0 0 8px; font-size: 14px; }
.brain-state.err { color: var(--warn); }
.brain-state.ok { color: var(--ok); }
.bar { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; margin-bottom: 10px; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.pet-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 480px) { .pet-pick { grid-template-columns: repeat(2, 1fr); } }
.pet-card {
  border: 2px solid var(--line); border-radius: 14px; background: var(--bg); padding: 8px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px;
}
.pet-card .thumb { width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--muted); }
.pet-card .thumb svg, .pet-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.pet-card small { color: var(--muted); }
.pet-card[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.persona { display: grid; gap: 8px; margin-top: 12px; }
.persona label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.persona input, .persona textarea { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); resize: vertical; }
.persona .chip { justify-self: start; }

.foot { max-width: 1200px; margin: 10px auto 30px; padding: 0 20px; font-size: 14px; }
.foot p { margin: 6px 0; }

/* ---- picture-in-picture window ---- */
body.in-pip { background: var(--bg); }
body.in-pip .stage { min-height: 100vh; border: 0; border-radius: 0; box-shadow: none; padding: 8px; }
body.in-pip .stage-tools #thinkWrap { display: none; }
body.in-pip .pet-area { height: 200px; }
body.in-pip .pet { width: 160px; height: 160px; }
