/* 甜筒 · ToTo 互动首页 — 9:16 竖屏优先（背景与全站白底方格一致） */
.toto-home {
  --th-ink: #333333;
  --th-muted: #666666;
  --th-chip: rgba(255, 255, 255, 0.96);
  --th-accent: #e87471;
  --th-soft: #f5f5f5;
  --th-bar: rgba(255, 255, 255, 0.94);
  --th-safe-top: env(safe-area-inset-top, 0px);
  --th-safe-bottom: env(safe-area-inset-bottom, 0px);
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--th-ink);
  background-color: var(--bg, #FFFFFF);
  background-image:
    linear-gradient(var(--grid-line, #EEF2F6) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line, #EEF2F6) 1px, transparent 1px);
  background-size: var(--grid-size, 40px) var(--grid-size, 40px);
}

.toto-home::before {
  display: none;
}
.toto-home > * { position: relative; z-index: 1; }

/* 顶部导航：避开灵动岛 / 状态栏 */
.th-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding:
    calc(10px + var(--th-safe-top))
    10px
    8px;
  background: var(--th-bar);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(61, 44, 36, 0.06);
  z-index: 20;
}
.th-logo {
  font-family: 'Quicksand', 'Noto Sans SC', sans-serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--th-ink);
  white-space: nowrap;
  text-decoration: none;
}
.th-nav-links {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.th-nav-links::-webkit-scrollbar { display: none; }
.th-nav-btn {
  flex-shrink: 0;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--th-muted);
  background: transparent;
  border: none;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.th-nav-btn:active { background: rgba(61, 44, 36, 0.06); color: var(--th-ink); }
.th-gear {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--th-muted); background: rgba(255,255,255,0.55);
  border: 1px solid rgba(61, 44, 36, 0.08); cursor: pointer; flex-shrink: 0;
}
.th-gear svg { width: 15px; height: 15px; }
.th-menu {
  position: absolute;
  top: calc(52px + var(--th-safe-top));
  right: 10px;
  min-width: 140px;
  background: #fffdf9;
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(61, 44, 36, 0.14);
  border: 1px solid rgba(61, 44, 36, 0.08);
  padding: 6px; z-index: 40; display: none;
}
.th-menu.open { display: block; }
.th-menu a, .th-menu button {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; border: none; background: none;
  border-radius: 10px; font-size: 13px; color: var(--th-ink);
  text-decoration: none; cursor: pointer;
}
.th-menu a:hover, .th-menu button:hover { background: var(--th-soft); }

/* 上半：9:16 小熊舞台 — 吃掉中间全部剩余高度 */
.th-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 12px 2px;
  gap: 6px;
}

/* 以舞台可用高度撑满 9:16，避免又扁又留白 */
.th-bear-wrap {
  position: relative;
  flex: 1 1 0;
  min-height: 140px;
  aspect-ratio: 9 / 16;
  width: auto;
  height: auto;
  max-height: 100%;
  max-width: min(92vw, 360px);
  align-self: center;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 14px 36px rgba(61, 44, 36, 0.2);
  background: #e8d8c8;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.th-bear-wrap video,
.th-bear-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
}
.th-bear-wrap img {
  z-index: 1;
  transition: opacity 0.35s;
  background: #e8d8c8;
}
.th-bear-wrap video { z-index: 2; }
.th-bear-wrap.is-loading video { opacity: 0; }
.th-bear-wrap.is-ready video { opacity: 1; transition: opacity 0.3s; }

.th-bear-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 3;
  font-size: 11px;
  color: rgba(255,255,255,0.95);
  background: rgba(61, 44, 36, 0.45);
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

.th-bubble {
  flex-shrink: 0;
  max-width: min(86vw, 340px);
  padding: 7px 12px;
  border-radius: 14px 14px 14px 5px;
  background: rgba(255, 252, 247, 0.94);
  border: 1px solid rgba(61, 44, 36, 0.08);
  box-shadow: 0 4px 14px rgba(61, 44, 36, 0.08);
  font-size: 12px;
  line-height: 1.4;
  color: var(--th-ink);
  text-align: center;
  min-height: 2.4em;
  transition: opacity 0.35s;
}

/* 下半：贴底，吃掉底部安全区 */
.th-panel {
  flex: 0 0 auto;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.92) 10px, rgba(255, 255, 255, 0.98));
  padding-top: 2px;
  padding-bottom: 0;
}

.th-mode-bar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 2px 12px 4px;
}
.th-mode-btn {
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid rgba(61, 44, 36, 0.1);
  background: rgba(255,255,255,0.7);
  font-size: 12px;
  font-weight: 600;
  color: var(--th-muted);
  cursor: pointer;
}
.th-mode-btn.active {
  background: #fff;
  color: var(--th-ink);
  border-color: rgba(232, 116, 113, 0.45);
  box-shadow: 0 2px 8px rgba(232, 116, 113, 0.18);
}

.th-chat {
  max-height: 14dvh;
  min-height: 0;
  overflow-y: auto;
  padding: 0 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}
.th-chat:empty { display: none; }
.th-chat:not(:empty) {
  display: flex;
  min-height: 48px;
}
.th-msg {
  max-width: 88%;
  padding: 8px 11px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}
.th-msg.user {
  align-self: flex-end;
  background: #f5f5f5;
  border-bottom-right-radius: 4px;
}
.th-msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid rgba(61, 44, 36, 0.06);
  border-bottom-left-radius: 4px;
}
.th-msg.typing { opacity: 0.7; font-style: italic; }

.th-voice-status {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--th-muted);
}
.th-voice-status.on { display: flex; }
.th-voice-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--th-accent);
  animation: th-pulse 1.2s ease-in-out infinite;
}
@keyframes th-pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* 情绪按钮：贴在输入框上方 */
.th-emotions {
  display: flex;
  flex-wrap: nowrap;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 12px 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.th-emotions::-webkit-scrollbar { display: none; }
.th-emotion {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(61, 44, 36, 0.1);
  background: var(--th-chip);
  color: var(--th-ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(61, 44, 36, 0.06);
  -webkit-tap-highlight-color: transparent;
}
.th-emotion:active { transform: scale(0.96); }
.th-emotion.active {
  background: #ffe8e4;
  border-color: rgba(232, 116, 113, 0.35);
  color: #b84f4c;
}

.th-emoji-panel {
  display: none;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 12px 0;
}
.th-emoji-panel.open { display: flex; }
.th-emoji-panel button {
  width: 34px; height: 34px; border: none; background: transparent;
  font-size: 20px; cursor: pointer; border-radius: 8px;
}

.th-composer {
  flex-shrink: 0;
  padding: 6px 10px calc(10px + var(--th-safe-bottom));
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.th-input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: #fff;
  border: 1px solid rgba(61, 44, 36, 0.12);
  border-radius: 22px;
  padding: 5px 6px 5px 12px;
  min-height: 42px;
}
.th-input {
  flex: 1;
  border: none; outline: none; resize: none;
  font-size: 15px; line-height: 1.4; max-height: 80px;
  background: transparent; color: var(--th-ink); font-family: inherit;
  padding: 6px 0;
}
.th-input::placeholder { color: #b0a098; }
.th-input-wrap.voice-mode .th-input { display: none; }
.th-voice-hint {
  display: none;
  flex: 1;
  font-size: 13px;
  color: var(--th-muted);
  padding: 8px 0;
  text-align: center;
}
.th-input-wrap.voice-mode .th-voice-hint { display: block; }

.th-icon-btn {
  width: 34px; height: 34px; border: none; border-radius: 50%;
  background: transparent; color: var(--th-muted);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.th-icon-btn svg { width: 18px; height: 18px; }
.th-icon-btn.active { color: var(--th-accent); background: #ffe8e4; }

.th-send {
  width: 42px; height: 42px; border: none; border-radius: 50%;
  background: var(--th-accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(232, 116, 113, 0.35);
}
.th-send:disabled { opacity: 0.45; }
.th-send svg { width: 17px; height: 17px; }
.th-send.is-voice-on {
  background: #3d2c24;
  box-shadow: 0 4px 12px rgba(61, 44, 36, 0.3);
}

/* 换装弹层 */
.th-wardrobe {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(40, 28, 22, 0.55);
  display: none; align-items: center; justify-content: center; padding: 20px;
  padding-top: calc(20px + var(--th-safe-top));
  padding-bottom: calc(20px + var(--th-safe-bottom));
}
.th-wardrobe.open { display: flex; }
.th-wardrobe-card {
  width: min(88vw, 360px);
  max-height: 88dvh;
  background: #fffaf4;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.28);
  display: flex; flex-direction: column;
}
.th-wardrobe-media {
  position: relative; width: 100%;
  aspect-ratio: 9 / 16;
  background: #efe4d8;
}
.th-wardrobe-media video,
.th-wardrobe-media img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.th-wardrobe-foot {
  padding: 12px 14px calc(12px + var(--th-safe-bottom));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.th-wardrobe-foot p { font-size: 13px; color: var(--th-muted); margin: 0; }
.th-wardrobe-close {
  padding: 8px 16px; border-radius: 999px; border: none;
  background: var(--th-ink); color: #fff; font-size: 13px; cursor: pointer;
}

body.toto-home-active #pet-root,
body.toto-home-active #bottom-nav {
  display: none !important;
}
body.toto-home-active {
  /* 保持全站 page-grid-bg，不再覆盖成米色 */
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  overscroll-behavior: none;
}
html:has(body.toto-home-active) {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}
body.toto-home-active #app,
body.toto-home-active .app-main,
body.toto-home-active #page-container {
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  background: transparent;
}
body.toto-home-active #page-container {
  display: flex;
  flex-direction: column;
}
body.toto-home-active #page-container > .toto-home {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

/* 手机端：隐藏侧栏，用页内顶部标签 */
@media (max-width: 959px) {
  body.toto-home-active #app { flex-direction: column; }
  body.toto-home-active #app-sidebar {
    display: none !important;
  }
}

@media (min-width: 768px) {
  /* 电脑端：取消手机框白底高亮，铺满主区域与全站方格一致 */
  .toto-home {
    max-width: none;
    width: 100%;
    margin: 0;
    box-shadow: none;
    border-radius: 0;
    background-color: transparent;
    background-image: none;
  }
  .th-nav {
    background: transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .th-panel {
    background: transparent;
  }
  .th-composer {
    background: transparent;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
  }
  .th-bear-wrap {
    max-width: min(360px, 42vh);
  }
  .th-chat { max-height: 140px; }
}

/* 电脑端：侧栏导航，隐藏页内顶部标签 */
@media (min-width: 960px) {
  body.toto-home-active #app {
    flex-direction: row;
    align-items: stretch;
  }
  body.toto-home-active #app-sidebar:not(.hidden) {
    display: flex !important;
  }
  body.toto-home-active .app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    justify-content: stretch;
    background: transparent;
  }
  body.toto-home-active #page-container > .toto-home {
    width: 100%;
    max-width: none;
  }
  body.toto-home-active .th-nav-links {
    display: none;
  }
  body.toto-home-active .th-nav {
    justify-content: space-between;
    padding-top: 12px;
    padding-left: 20px;
    padding-right: 20px;
  }
  .th-stage {
    padding-left: 20px;
    padding-right: 20px;
  }
  .th-panel {
    max-width: 520px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
  }
}
