:root {
  --pink: #f7b6d2;
  --pink-deep: #e66fa5;
  --pink-soft: #fde4ef;
  --blue: #007ba7;          /* Cerulean */
  --blue-soft: #e3f2f8;
  --salt: #ffffff;
  --ink: #3c3346;
  --muted: #8d8098;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #fff5fa 0%, #fde4ef 45%, #e3f2f8 100%);
  position: fixed; inset: 0;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- 页面容器：所有页叠在一起，只切可见性，不卸载 ---------- */
#views { position: absolute; left: 0; right: 0; top: 0; bottom: calc(var(--tab-h) + var(--safe-b)); }
.view {
  position: absolute; inset: 0; overflow: hidden;
  visibility: hidden; opacity: 0; pointer-events: none;
  transition: opacity .18s ease, visibility 0s linear .18s;
}
.view.active { visibility: visible; opacity: 1; pointer-events: auto; transition: opacity .18s ease; }

/* ---------- 底部按钮 ---------- */
.tabs {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(230, 111, 165, .18);
  z-index: 20;
}
.tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--muted); transition: color .15s;
}
.tabs svg { width: 25px; height: 25px; }
.tabs button.active { color: var(--pink-deep); }
.tabs button[data-tab="chat"].active { color: var(--blue); }
#tab-salt { transition: y .6s ease, height .6s ease; }

/* ---------- 占位页 ---------- */
.placeholder { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px; text-align: center; }
.ph-icon svg { width: 96px; height: 96px; }
.placeholder h2 { margin: 12px 0 6px; color: var(--pink-deep); font-weight: 600; }
.placeholder p { margin: 4px 0; color: var(--muted); line-height: 1.6; }
.placeholder .soon { margin-top: 14px; font-size: 12px; color: var(--blue); letter-spacing: 2px; }

/* ---------- 温室 ---------- */
.view[data-view="home"] { background: #e9dff0; }
.scene { position: absolute; left: 50%; top: 50%; transform-origin: 50% 50%; width: 941px; height: 1672px; }
.scene-bg { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.hot { position: absolute; border-radius: 18px; }
.hot:active { background: rgba(255, 255, 255, .12); }
.pill { color: #b0457c; font-size: 34px; letter-spacing: 6px; border-radius: 60px; text-shadow: 0 1px 0 #fff; }
.tree-glow {
  left: 15%; top: 2%; width: 55%; height: 55%; pointer-events: none; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 236, 190, .55), rgba(255, 220, 240, 0));
  opacity: 0; transition: opacity 1s;
}
.tree-glow.awake { opacity: 1; animation: breathe 2.4s ease-in-out infinite; }
.scene.asleep .scene-bg { filter: brightness(.82) saturate(.9); transition: filter 1.2s; }
@keyframes breathe { 50% { opacity: .45; } }
/* 盐罐：用掉的部分盖一层玻璃色，盐像是少下去 */
.jar-hot { overflow: hidden; }
.jar-used {
  position: absolute; left: 11%; right: 10%; top: 43%; height: 0;
  background: linear-gradient(180deg, rgba(232, 222, 240, .92), rgba(236, 226, 244, .82));
  border-radius: 6px 6px 2px 2px; transition: height 1s ease;
}
.cat-hot.purr { animation: purr .5s ease 2; }
@keyframes purr { 25% { transform: translateX(6px) rotate(1deg); } 75% { transform: translateX(-6px) rotate(-1deg); } }
.heart { position: absolute; font-size: 44px; color: var(--pink-deep); pointer-events: none; animation: rise 1.2s ease-out forwards; }
@keyframes rise { to { transform: translateY(-120px) scale(1.4); opacity: 0; } }

.quota-cards { position: absolute; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; display: flex; gap: 10px; pointer-events: none; }
.qcard {
  flex: 1; padding: 8px 12px; border-radius: 14px;
  background: rgba(255, 255, 255, .55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 12px rgba(160, 80, 130, .12);
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px;
}
.qlabel { font-size: 12px; color: var(--muted); align-self: center; }
.qval { font-size: 18px; font-weight: 600; color: var(--pink-deep); text-align: right; }
.qcard:nth-child(2) .qval { color: var(--blue); }
.qreset { grid-column: 1 / 3; font-size: 11px; color: var(--muted); }

/* ---------- 聊天 ---------- */
.chat { position: absolute; inset: 0; display: flex; flex-direction: column; }
.quota-line {
  position: absolute; top: var(--safe-t); left: 0; right: 0; height: 4px; padding: 0; z-index: 3;
  background: rgba(0, 123, 167, .12);
}
.quota-line::after { content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 24px; } /* 好点 */
#quota-fill {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, #fff, #f3f8fb); box-shadow: 0 0 4px rgba(0, 123, 167, .45);
  border-radius: 0 3px 3px 0; transition: width .8s ease;
}
#quota-fill.low { background: var(--pink-deep); }
.chat-head {
  padding: calc(10px + var(--safe-t)) 16px 8px; display: flex; align-items: center; justify-content: space-between;
  background: rgba(255, 255, 255, .6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(0, 123, 167, .08);
}
.who { font-weight: 600; color: var(--blue); display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c8c0d0; }
.dot.awake { background: #5fd18b; box-shadow: 0 0 6px #5fd18b; animation: breathe 1.6s infinite; }
.head-btn { font-size: 20px; color: var(--muted); padding: 0 6px; letter-spacing: 1px; }

.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 14px 12px 8px; }
.msg { display: flex; margin: 6px 0; }
.msg.user { justify-content: flex-end; }
.msg .ava { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; align-self: flex-end; margin-right: 8px; border: 1.5px solid rgba(0, 123, 167, .25); }
.msg .ava.me { margin-right: 0; margin-left: 8px; border-color: rgba(244, 163, 199, .7); }
.bubble {
  max-width: 82%; padding: 9px 13px; border-radius: 18px; line-height: 1.55; font-size: 15.5px;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: normal;
}
.msg.user .bubble { background: linear-gradient(135deg, #f9c4dc, #f4a3c7); color: #4a2238; border-bottom-right-radius: 6px; }
.msg.assistant .bubble { background: #fff; border: 1px solid rgba(0, 123, 167, .16); border-bottom-left-radius: 6px; box-shadow: 0 1px 4px rgba(0, 123, 167, .06); }
.msg.system { justify-content: center; }
.msg.system .bubble { background: none; color: var(--muted); font-size: 12px; padding: 2px; }
.msg.error .bubble { border-color: #f0a0a0; }
.err { color: #c04a5a; font-size: 13px; margin-top: 6px; }
.bubble p { margin: 0 0 .5em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: #f4f7fa; border-radius: 8px; padding: 8px; overflow-x: auto; font-size: 13px; white-space: pre; }
.bubble code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; background: rgba(0, 123, 167, .08); padding: 1px 4px; border-radius: 4px; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--blue); }
.bubble img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin: 6px 0; cursor: zoom-in; background: var(--blue-soft); }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 1.3em; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05em; margin: .4em 0; }
.bubble blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--pink); color: #6a5f74; }
.cursor::after { content: "▍"; color: var(--blue); animation: blink 1s steps(1) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
.think { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.think summary { cursor: pointer; list-style: none; user-select: none; }
.think summary::before { content: "▸ "; }
.think[open] summary::before { content: "▾ "; }
.think .think-body { white-space: pre-wrap; padding: 6px 8px; margin-top: 4px; background: #f7f4fa; border-radius: 8px; max-height: 260px; overflow-y: auto; }
.tools { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tool { font-size: 11px; color: var(--blue); background: var(--blue-soft); border-radius: 10px; padding: 1px 8px; }
.time { font-size: 10px; color: var(--muted); margin: 0 6px; align-self: flex-end; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
  background: rgba(255, 255, 255, .75); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(230, 111, 165, .12);
}
#input {
  flex: 1; resize: none; border: 1px solid rgba(0, 123, 167, .2); border-radius: 20px; padding: 9px 14px;
  font: inherit; font-size: 16px; line-height: 1.35; max-height: 140px; outline: none; background: #fff; color: var(--ink);
}
#input:focus { border-color: var(--blue); }
#send, #stop { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; }
#send { background: var(--blue); color: #fff; }
#send:disabled { opacity: .45; }
#stop { background: var(--pink-deep); color: #fff; }
#send svg, #stop svg { width: 20px; height: 20px; }

/* ---------- 弹层 ---------- */
.pop { position: fixed; inset: 0; z-index: 50; background: rgba(60, 40, 70, .28); display: flex; align-items: flex-end; justify-content: center; }
.pop-card {
  width: 100%; max-width: 480px; background: #fff; border-radius: 22px 22px 0 0;
  padding: 18px 20px calc(18px + var(--safe-b)); box-shadow: 0 -6px 30px rgba(0, 0, 0, .12);
  animation: up .2s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.pop-card h3 { margin: 0 0 12px; color: var(--pink-deep); }
.pop-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.pop-row span { width: 48px; font-size: 14px; }
.pop-row b { width: 64px; text-align: right; font-size: 14px; }
.bar { flex: 1; height: 10px; border-radius: 6px; background: #f1edf4; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #fff, var(--pink)); border: 1px solid var(--pink); border-radius: 6px; transition: width .6s; }
.bar.moon i { background: linear-gradient(90deg, #fff7d6, #f3d27a); border-color: #e6c25c; }
.bar.snow i { background: linear-gradient(90deg, #fff, #bfe3f2); border-color: #7fc3dd; }
.pop-sub { margin: 2px 0 0 58px; font-size: 12px; color: var(--muted); }
#pop-close, .menu-item { display: block; width: 100%; margin-top: 14px; padding: 11px; border-radius: 14px; background: var(--blue); color: #fff; font-size: 15px; }
.menu-item { background: var(--pink-soft); color: var(--ink); margin-top: 8px; }
.menu-item.ghost { background: none; color: var(--muted); }

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(20, 10, 25, .92); display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; touch-action: pinch-zoom; }

/* ---------- 门锁 ---------- */
.login { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #fde4ef, #f7b6d2 50%, #9fd2e6); }
.login-card { width: min(320px, 86vw); padding: 28px 24px; border-radius: 24px; background: rgba(255, 255, 255, .8);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); text-align: center; box-shadow: 0 10px 40px rgba(160, 60, 110, .2); }
.login-jar { width: 56px; height: 56px; margin: 0 auto; background: url(/icons/icon-192.png) center/cover; border-radius: 14px; }
.login h1 { font-size: 20px; color: var(--pink-deep); margin: 12px 0 16px; letter-spacing: 4px; }
.login input { width: 100%; padding: 11px 14px; border-radius: 14px; border: 1px solid rgba(0, 123, 167, .25); font-size: 16px; outline: none; }
.login button { width: 100%; margin-top: 12px; padding: 11px; border-radius: 14px; background: var(--blue); color: #fff; font-size: 16px; }
.login-err { min-height: 1.2em; color: #c04a5a; font-size: 13px; margin: 10px 0 0; }
