:root {
  color-scheme: dark;
  --bg: #120f18;
  --surface: #17131d;
  --surface-2: #211b2a;
  --bubble: #25202d;
  --input: #2a2433;
  --line: #3a3146;
  --text: #f7f1fa;
  --muted: #aaa1b6;
  --weak: #776e82;
  --pink: #ff43d6;
  --purple: #a832ff;
  --mint: #43f0b5;
  --mint-bg: #183b32;
  --amber: #ffc56d;
  --amber-bg: #3c2e19;
  --danger: #ff6b7a;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
button { border: 0; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.app-shell {
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 14px) 18px calc(env(safe-area-inset-bottom) + 96px);
  background: var(--bg);
}

.topbar {
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand { font-size: 24px; font-weight: 800; letter-spacing: 0; }
.subtitle { margin-top: 4px; color: var(--muted); font-size: 13px; }
.home-title { margin: 12px 0 0; font-size: 26px; line-height: 1.15; letter-spacing: 0; }
.status-pill {
  min-width: 118px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 67, 214, .52);
  background: rgba(255, 67, 214, .1);
  color: var(--pink);
  font-size: 13px;
  font-weight: 800;
}

.pill, .wide {
  min-height: 46px;
  border-radius: 999px;
  padding: 0 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 800;
}
.primary, .send {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  border-color: transparent;
  color: white;
}
.danger { color: #ffd9df; background: #2a1520; border-color: #633044; }

.page-stack { position: relative; min-height: calc(100dvh - 204px); margin-top: 12px; }
.page { display: none; animation: fade .16s ease; }
.page.active { display: block; }
.chat-page { display: none; }
.chat-page.active {
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: fixed;
  inset: 0;
  padding: calc(env(safe-area-inset-top) + 0px) 0 0;
  background: var(--bg);
  z-index: 5;
}
@keyframes fade { from { opacity: .45; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.metrics {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.chip {
  min-width: 32px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 999px;
  font-weight: 800;
}
.chip.mint { color: var(--mint); background: var(--mint-bg); }
.chip.amber { color: var(--amber); background: var(--amber-bg); margin-left: 10px; }
.metric-spacer { flex: 1; }
.storage-label { color: var(--weak); }

.search-wrap { margin: 10px 0; }
.search, .field, .composer input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  outline: 0;
  background: var(--input);
  color: var(--text);
  border-radius: 18px;
  padding: 0 16px;
}
.search::placeholder, .field::placeholder, .composer input::placeholder { color: var(--weak); }
.field { margin: 7px 0 14px; border-radius: 18px; }
.area { min-height: 96px; padding-top: 14px; resize: vertical; }
label { color: var(--muted); font-size: 13px; }

.tabs {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}
.tabs button.active { color: white; background: rgba(255, 67, 214, .18); border-color: rgba(255, 67, 214, .5); }

.list { display: grid; gap: 0; }
.item {
  min-height: 86px;
  display: grid;
  grid-template-columns: 54px 1fr 42px;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  background: transparent;
  border-bottom: 1px solid rgba(58, 49, 70, .58);
}
.avatar, .profile-avatar, .chat-avatar {
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  font-weight: 800;
}
.avatar { width: 54px; height: 54px; }
.avatar img, .chat-avatar img, .profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.title-row { display: flex; align-items: center; min-width: 0; }
.item-title { min-width: 0; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 16px; font-weight: 800; }
.badge {
  height: 24px;
  display: inline-grid;
  place-items: center;
  padding: 0 9px;
  margin-left: 8px;
  border-radius: 12px;
  color: var(--mint);
  background: var(--mint-bg);
  font-size: 10px;
  font-weight: 800;
}
.item-desc { display: none; }
.item-meta { margin-top: 5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font-size: 13px; }
.more {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--pink);
  font-size: 22px;
  font-weight: 800;
}

.empty {
  padding: 26px 22px 24px;
  margin-top: 16px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
}
.empty strong { display: block; margin-top: 12px; font-size: 20px; color: var(--text); }
.empty span { display: block; margin-top: 8px; color: var(--muted); line-height: 1.5; }
.empty-icon {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: white;
  font-size: 28px;
}
.skeleton { margin-top: 18px; display: grid; gap: 12px; }
.skeleton i { display: block; height: 36px; border-radius: 18px; background: rgba(33, 27, 42, .9); }
.skeleton i:nth-child(2) { margin-right: 58px; }
.skeleton i:nth-child(3) { margin-right: 24px; }

.profile-card, .settings-card {
  padding: 18px;
  margin-bottom: 14px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.profile-card { display: grid; grid-template-columns: 72px 1fr; gap: 16px; align-items: center; }
.profile-avatar { width: 72px; height: 72px; }
.profile-title { font-size: 20px; font-weight: 800; }
.profile-note { margin-top: 5px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.section-title { margin-bottom: 14px; font-size: 18px; font-weight: 800; }
.switch-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin-bottom: 12px; }
.wide { width: 100%; margin-top: 10px; }
.entry-card {
  width: 100%;
  min-height: 84px;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 14px;
  align-items: center;
  margin: 14px 0 0;
  padding: 18px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
}
.entry-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: var(--pink);
  background: var(--surface-2);
}
.entry-card strong { display: block; font-size: 18px; }
.entry-card em { display: block; margin-top: 5px; color: var(--muted); font-size: 13px; font-style: normal; }
.entry-card b {
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 17px;
  color: var(--mint);
  background: var(--mint-bg);
  font-size: 12px;
}
.data-card, .model-panel { margin-top: 14px; }

.bottom-nav {
  position: fixed;
  left: 18px;
  right: 18px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  height: 66px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 14px;
  border-radius: 24px;
  background: rgba(30, 24, 38, .96);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px);
  z-index: 4;
}
.bottom-nav button {
  min-width: 0;
  border-radius: 18px;
  background: #1e1826;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
  gap: 1px;
}
.bottom-nav button span { display: block; font-size: 17px; line-height: 16px; }
.bottom-nav button.active { color: var(--pink); background: var(--surface-2); }
.bottom-nav .import-nav { color: white; background: linear-gradient(135deg, var(--pink), var(--purple)); }

.chat-head {
  min-height: 74px;
  display: grid;
  grid-template-columns: 44px 42px 1fr 42px;
  gap: 12px;
  align-items: center;
  padding: 0 12px;
  background: var(--surface);
}
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 24px;
}
.chat-avatar { width: 42px; height: 42px; }
.chat-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 16px; font-weight: 800; }
.chat-meta { margin-top: 3px; color: var(--mint); font-size: 12px; }
.messages { overflow-y: auto; padding: 12px 14px 18px; scroll-behavior: smooth; }
.msg {
  max-width: min(342px, 88%);
  margin: 8px 0;
  padding: 18px 20px;
  border-radius: 18px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 18px;
}
.msg.assistant { background: var(--bubble); border: 1px solid rgba(58, 49, 70, .7); }
.msg.user {
  max-width: min(300px, 80%);
  margin-left: auto;
  padding: 15px 20px;
  background: linear-gradient(135deg, #1978ff, #c13cff);
  color: white;
}
.msg.system {
  max-width: max-content;
  min-height: 28px;
  display: grid;
  place-items: center;
  margin: 14px auto;
  padding: 0 14px;
  color: var(--weak);
  background: rgba(36, 29, 45, .82);
  border-radius: 14px;
  font-size: 12px;
}
.reasoning {
  max-width: min(342px, 88%);
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 18px;
  color: #bdebdc;
  background: linear-gradient(180deg, rgba(67, 240, 181, .12), rgba(67, 240, 181, .04));
  border: 1px solid rgba(67, 240, 181, .28);
  font-size: 12px;
  line-height: 1.55;
}
.composer {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  gap: 8px;
  align-items: center;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--surface);
}
.composer input { min-height: 46px; }
.send { width: 46px; height: 46px; border-radius: 18px; font-size: 20px; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 10;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  padding: 20px 18px calc(env(safe-area-inset-bottom) + 18px);
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .35);
}
.sheet h3 { margin: 0 0 8px; }
.sheet p { margin: 0 0 14px; color: var(--muted); line-height: 1.5; }
.sheet button {
  width: 100%;
  min-height: 50px;
  border-radius: 18px;
  margin-top: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-weight: 800;
}

.notice {
  position: fixed;
  left: 22px;
  right: 22px;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  z-index: 20;
  padding: 12px 16px;
  text-align: center;
  border-radius: 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .3);
  color: var(--text);
  font-weight: 800;
  font-size: 13px;
}

@media (min-width: 760px) {
  .app-shell { max-width: 520px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .bottom-nav { left: 50%; right: auto; width: 484px; transform: translateX(-50%); }
  .chat-page.active { max-width: 520px; left: 50%; transform: translateX(-50%); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* Motion layer */
.app-shell {
  position: relative;
  overflow: hidden;
}
.app-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255,255,255,.034) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,.024) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.82), transparent 72%);
  opacity: .2;
  animation: gridDrift 18s linear infinite;
}
.app-shell::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  height: 120px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,67,214,.08), transparent);
  animation: headerGlow 6s ease-in-out infinite alternate;
}
.topbar,
.home-title,
.page-stack,
.bottom-nav {
  position: relative;
  z-index: 1;
}
.brand,
.home-title {
  animation: titleIn .46s cubic-bezier(.2,.8,.2,1);
}
.status-pill {
  box-shadow: 0 0 0 1px rgba(255,67,214,.02), 0 10px 24px rgba(255,67,214,.08);
  animation: chipBreath 3.8s ease-in-out infinite;
}
.page.active {
  animation: pageRise .24s cubic-bezier(.2,.8,.2,1);
}
.chip,
.tabs button,
.icon-btn,
.send,
.sheet button,
.entry-card,
.profile-card,
.settings-card,
.more {
  transition: transform .18s ease, background .18s ease, border-color .18s ease, box-shadow .18s ease, filter .18s ease;
}
.metrics:hover .chip {
  transform: translateY(-1px);
  filter: brightness(1.08);
}
.tabs button:active {
  transform: scale(.96);
}
.tabs button.active {
  box-shadow: 0 8px 24px rgba(255,67,214,.09);
}
.item {
  position: relative;
  animation: listRise .42s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: calc(min(var(--i), 12) * 34ms);
  transition: transform .18s ease, border-color .18s ease;
}
.item::before {
  content: "";
  position: absolute;
  inset: 6px -8px;
  z-index: -1;
  border-radius: 20px;
  background: linear-gradient(90deg, rgba(255,67,214,.08), rgba(67,240,181,.04));
  opacity: 0;
  transform: scale(.98);
  transition: opacity .18s ease, transform .18s ease;
}
.item:hover::before {
  opacity: 1;
  transform: scale(1);
}
.item:hover {
  transform: translateX(2px);
  border-color: rgba(255,67,214,.22);
}
.avatar,
.profile-avatar,
.chat-avatar {
  box-shadow: 0 12px 28px rgba(168,50,255,.18);
  transition: transform .22s ease, box-shadow .22s ease;
}
.item:hover .avatar,
.profile-card:hover .profile-avatar {
  transform: scale(1.04) rotate(-2deg);
  box-shadow: 0 16px 34px rgba(255,67,214,.22);
}
.more:hover {
  transform: rotate(90deg) scale(1.05);
  background: rgba(255,67,214,.14);
  color: white;
}
.empty,
.profile-card,
.settings-card,
.entry-card {
  animation: cardFloatIn .46s cubic-bezier(.2,.8,.2,1) both;
}
.profile-card:hover,
.settings-card:hover,
.entry-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,67,214,.28);
  box-shadow: 0 18px 44px rgba(0,0,0,.22);
}
.skeleton i {
  background: linear-gradient(90deg, rgba(33,27,42,.9), rgba(58,49,70,.78), rgba(33,27,42,.9));
  background-size: 220% 100%;
  animation: shimmer 1.7s ease-in-out infinite;
}
.bottom-nav {
  box-shadow: 0 18px 48px rgba(0,0,0,.34);
}
.bottom-nav button {
  position: relative;
  overflow: hidden;
}
.bottom-nav button::after {
  content: "";
  position: absolute;
  inset: auto 18px 5px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0;
  transform: scaleX(.35);
  transition: opacity .18s ease, transform .18s ease;
}
.bottom-nav button.active {
  transform: translateY(-1px);
}
.bottom-nav button.active::after {
  opacity: .78;
  transform: scaleX(1);
}
.bottom-nav .import-nav {
  box-shadow: 0 10px 28px rgba(168,50,255,.25);
}
.bottom-nav .import-nav::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 0%, rgba(255,255,255,.26) 45%, transparent 70%);
  transform: translateX(-120%);
  animation: buttonSheen 3.2s ease-in-out infinite;
}
.icon-btn:hover {
  transform: translateY(-1px);
  background: rgba(255,67,214,.12);
}
.msg {
  animation: bubbleIn .28s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: calc(min(var(--i), 8) * 18ms);
  transform-origin: left bottom;
}
.msg.user {
  transform-origin: right bottom;
  box-shadow: 0 14px 30px rgba(25,120,255,.16);
}
.reasoning {
  animation: reasoningIn .34s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: calc(min(var(--i), 8) * 18ms);
}
.reasoning strong {
  color: var(--mint);
}
.composer input {
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.composer input:focus {
  border-color: rgba(255,67,214,.5);
  box-shadow: 0 0 0 3px rgba(255,67,214,.1);
  background: #30283a;
}
.send:hover {
  transform: translateY(-1px) scale(1.03);
  filter: brightness(1.08);
}
.sheet-backdrop {
  opacity: 0;
  animation: backdropIn .18s ease forwards;
}
.sheet {
  transform: translateY(18px) scale(.98);
  opacity: 0;
  transition: transform .24s cubic-bezier(.2,.8,.2,1), opacity .2s ease;
}
.sheet.sheet-live {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.sheet button:hover {
  transform: translateY(-1px);
  border-color: rgba(255,67,214,.24);
  background: #2a2335;
}
.notice {
  transform: translateY(10px) scale(.98);
  opacity: 0;
  transition: transform .18s cubic-bezier(.2,.8,.2,1), opacity .18s ease;
}
.notice.notice-live {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.notice.danger {
  color: #ffd9df;
  background: #2a1520;
  border-color: #633044;
}
.tap-pop {
  animation: tapPop .24s cubic-bezier(.2,.8,.2,1);
}

@keyframes titleIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pageRise {
  from { opacity: .45; transform: translateY(8px) scale(.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes listRise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes reasoningIn {
  from { opacity: 0; filter: blur(4px); transform: translateY(8px); }
  to { opacity: 1; filter: blur(0); transform: translateY(0); }
}
@keyframes cardFloatIn {
  from { opacity: 0; transform: translateY(10px) scale(.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes shimmer {
  0% { background-position: 140% 0; }
  100% { background-position: -80% 0; }
}
@keyframes buttonSheen {
  0%, 64% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}
@keyframes chipBreath {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.12); }
}
@keyframes gridDrift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 34px 34px, 34px 34px; }
}
@keyframes headerGlow {
  from { opacity: .45; }
  to { opacity: .9; }
}
@keyframes backdropIn {
  to { opacity: 1; }
}
@keyframes tapPop {
  0% { transform: scale(1); }
  45% { transform: scale(.96); }
  100% { transform: scale(1); }
}

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