/*
  布局策略：默认就是手机。
  桌面那些三栏并排、悬停、滑入动画，全部收在 @media (min-width: 781px) 里。
  手机上左右两栏是抽屉，对话区永远占满整屏。
*/

:root {
  --bg: #faf9f5;
  --panel: #ffffff;
  --soft: #f0eee6;
  --hover: #e8e5da;
  --ink: #23211d;
  --muted: #7a756c;
  --line: #e7e3da;
  --accent: #d97757;
  --accent-dark: #c25e3f;
  --accent-light: #f0a184;
  --accent-soft: #f5e9e3;
  --warn: #9a5b2f;
  --touch: 44px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei UI",
          "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #262624;
  --panel: #30302d;
  --soft: #1f1e1c;
  --hover: #33322f;
  --ink: #f5f4f0;
  --muted: #a3a29b;
  --line: #3a3936;
  --accent: #d97757;
  --accent-dark: #e08b6e;
  --accent-soft: #3a2f2a;
  --warn: #d9a273;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  min-height: -webkit-fill-available;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.7 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.msg .body, .card .txt, input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

input, textarea {
  font: inherit;
  font-size: 16px; /* 小于 16px 时 iOS 会自动放大页面 */
  touch-action: manipulation;
}

/* ===== 动画 ===== */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@keyframes popIn {
  0%   { opacity: 0; transform: scale(.6); }
  60%  { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-7px) scale(1.035); }
}
@keyframes haloPulse {
  0%   { transform: scale(.75); opacity: .55; }
  70%  { transform: scale(1.7);  opacity: 0; }
  100% { transform: scale(1.7);  opacity: 0; }
}
@keyframes pulse {
  0%, 100% { opacity: .28; transform: translateY(0); }
  50%      { opacity: 1;   transform: translateY(-3px); }
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== 整体骨架：手机上是单栏 ===== */

.shell {
  display: flex;
  height: 100%;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  position: relative;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* 顶栏：左菜单、中标题、右能力 */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  padding-top: calc(6px + env(safe-area-inset-top));
  min-height: 52px;
  border-bottom: 1px solid transparent;
}

.topbar .title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.ghost {
  min-height: var(--touch);
  min-width: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: var(--ink);
  font-size: 15px;
  padding: 0 10px;
  border-radius: 10px;
}
.ghost:active { background: var(--hover); }

/* 对话区 */

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px calc(14px + env(safe-area-inset-right)) 12px calc(14px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.thread::-webkit-scrollbar { width: 8px; }
.thread::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.msg {
  display: flex;
  animation: fadeUp .28s ease both;
}
.msg.user { justify-content: flex-end; }
.msg .body {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 16px;
  line-height: 1.7;
}
.msg.user .body {
  background: var(--accent-soft);
  border-bottom-right-radius: 6px;
}
.msg.assistant .body {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.picture { display: block; max-width: 100%; border-radius: 12px; }

.typing { display: flex; gap: 5px; padding: 6px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  opacity: .35;
  animation: pulse 1.3s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }

.caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  background: var(--accent);
  vertical-align: -.18em;
  animation: blink .9s steps(2) infinite;
}

/* 输入区：贴着屏幕底部，跟随键盘 */

.composer {
  flex: 0 0 auto;
  padding: 8px calc(12px + env(safe-area-inset-right))
           calc(10px + env(safe-area-inset-bottom))
           calc(12px + env(safe-area-inset-left));
  background: var(--bg);
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 22px;
  padding: 6px 6px 6px 16px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer-inner:focus-within {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer textarea {
  flex: 1;
  min-height: 32px;
  max-height: 140px;
  resize: none;
  border: 0;
  outline: none;
  background: none;
  color: var(--ink);
  padding: 6px 0;
  line-height: 1.5;
}

.send {
  flex: 0 0 auto;
  width: var(--touch);
  height: var(--touch);
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.send:active { background: var(--accent-dark); }
.send:disabled { opacity: .45; }

.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 6px 0 0; min-height: 1em; }
.hint.error { color: var(--warn); }

/* ===== 首页 ===== */

.welcome {
  margin: auto 0;
  padding: 16px 0 20px;
  text-align: center;
}
.welcome.gone { display: none; }

.orb {
  width: clamp(46px, 13vw, 64px);
  height: clamp(46px, 13vw, 64px);
  margin: 0 auto 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #f7bda4, var(--accent) 55%, var(--accent-dark));
  box-shadow: 0 10px 28px rgba(217, 119, 87, .3);
  animation: popIn .6s cubic-bezier(.2, .8, .3, 1.15) both,
             float 5s ease-in-out .6s infinite;
}

.welcome h1 {
  margin: 0 0 6px;
  font-size: clamp(20px, 5.6vw, 27px);
  font-weight: 600;
  animation: fadeUp .5s ease .15s both;
}
.welcome p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14.5px;
  animation: fadeUp .5s ease .22s both;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.card {
  display: flex;
  align-items: center;
  min-height: 54px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  text-align: left;
  animation: fadeUp .45s ease both;
}
.card:active { background: var(--hover); }
.card .txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.card .txt b { font-size: 15.5px; font-weight: 600; }
.card .txt i { font-style: normal; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* ===== 抽屉（手机上默认收起） ===== */

.sidebar,
.rail {
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(86vw, 22rem);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  visibility: hidden;
  transition: transform .24s ease, visibility .24s ease;
  will-change: transform;
  z-index: 30;
}

.sidebar {
  left: 0;
  transform: translateX(-100%);
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  border-right: 1px solid var(--line);
  gap: 10px;
  overflow-y: auto;
}
.sidebar.open { transform: none; visibility: visible; }

.rail {
  right: 0;
  transform: translateX(100%);
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  border-left: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.rail.open { transform: none; visibility: visible; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .38);
  display: none;
  z-index: 25;
}
.scrim.show { display: block; animation: fadeIn .2s ease both; }

.brand { display: flex; align-items: center; gap: 9px; padding: 2px 8px 4px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.brand-name { font-weight: 600; }

.new-btn {
  min-height: var(--touch);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
}
.new-btn:active { background: var(--hover); }

.conv-list { display: flex; flex-direction: column; gap: 2px; }

.conv-item {
  display: flex;
  align-items: center;
  min-height: var(--touch);
  border-radius: 10px;
  padding: 0 4px 0 10px;
  color: var(--muted);
  cursor: pointer;
}
.conv-item:active { background: var(--hover); }
.conv-item.on { background: var(--hover); color: var(--ink); font-weight: 500; }
.conv-item .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 10px 0;
}
.conv-item .del {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 0;
  background: none;
  color: var(--muted);
  opacity: .5;
  border-radius: 8px;
  font-size: 16px;
}
.conv-item .del:active { background: var(--hover); opacity: 1; }

.side-foot {
  margin-top: auto;
  display: flex;
  gap: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.side-foot .ghost { flex: 1; color: var(--muted); }

.rail-title {
  margin: 0 0 8px;
  padding: 0 8px;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .04em;
}

.chips { display: flex; flex-direction: column; gap: 2px; }

.chip {
  min-height: var(--touch);
  border: 0;
  background: none;
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  text-align: left;
}
.chip:active { background: var(--hover); }
.chip b { font-weight: 500; font-size: 14.5px; }
.chip i { font-style: normal; color: var(--muted); font-size: 12.5px; line-height: 1.45; }

.drawer-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px;
}
.drawer-card .ability-title { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.drawer-card .label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 13.5px; }
.drawer-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
.drawer-card button {
  width: 100%;
  min-height: var(--touch);
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
}

/* ===== 登录 ===== */

html.plain { overflow: auto; height: auto; min-height: 100%; }

body.plain {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  height: auto;
  overflow-y: auto;
  padding: calc(24px + env(safe-area-inset-top)) 0 calc(24px + env(safe-area-inset-bottom));
}

.login-card {
  width: min(368px, 100% - 32px);
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 22px 24px;
  box-shadow: 0 14px 40px rgba(31, 30, 27, .06);
  animation: fadeUp .45s ease both;
}

.login-head { text-align: center; margin-bottom: 20px; }

.login-orb {
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #f7bda4, var(--accent) 55%, var(--accent-dark));
  animation: popIn .55s cubic-bezier(.2, .8, .3, 1.15) both;
}

.site-name { margin: 0 0 5px; font-size: 19px; font-weight: 600; }
.site-note { margin: 0; font-size: 13.5px; color: var(--muted); }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 13.5px; color: var(--muted); }
.field input {
  display: block;
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus {
  outline: none;
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 66px; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  min-height: 40px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 0 10px;
  border-radius: 8px;
}
.pw-toggle:active { background: var(--hover); }

.submit {
  width: 100%;
  min-height: 50px;
  margin-top: 6px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 500;
}
.submit:active { background: var(--accent-dark); }
.submit:disabled { opacity: .6; }

.err {
  min-height: 1.3em;
  margin: 12px 0 0;
  color: var(--warn);
  font-size: 13.5px;
  text-align: center;
}

/* ===== 家长端 ===== */

body.parent {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
}

body.parent .bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

body.parent .wrap { padding: 16px 14px calc(40px + env(safe-area-inset-bottom)); }

.link {
  min-height: var(--touch);
  border: 0;
  background: none;
  color: var(--muted);
  padding: 0 10px;
  border-radius: 8px;
}
.link:active { background: var(--hover); }

.lead { color: var(--muted); font-size: 14px; }
.insight {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.insight h3 { margin: 0 0 6px; font-size: 16px; }
.meta { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.tip { color: var(--warn); font-size: 14px; margin: 6px 0 0; }
.empty { color: var(--muted); }

.insight form .label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 13.5px; }
.insight form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
.insight form button {
  min-height: var(--touch);
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  padding: 0 18px;
}

/* ===== 桌面：恢复三栏 ===== */

@media (min-width: 48em) and (hover: hover) and (pointer: fine) {
  .sidebar,
  .rail {
    position: static;
    visibility: visible;
    transform: none;
    transition: none;
    z-index: auto;
    width: auto;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .sidebar {
    flex: 0 0 260px;
    background: var(--soft);
    border-right: 1px solid var(--line);
    overflow-y: auto;
  }

  .rail {
    flex: 0 0 236px;
    background: var(--soft);
    border-left: 1px solid var(--line);
    overflow-y: auto;
  }

  .scrim { display: none !important; }
  .topbar { padding: 10px 20px; min-height: 54px; border-bottom: 0; }
  .topbar .title { text-align: left; }
  .thread { padding: 4px 20px 12px; gap: 14px; }
  .msg .body { max-width: 80%; }
  .composer { padding: 8px 20px 16px; }
  .composer-inner { max-width: 720px; margin: 0 auto; }

  .welcome { margin: 6vh auto 0; max-width: 640px; text-align: center; }
  .welcome h1 { font-size: 27px; }
  .welcome p { font-size: 15px; }
  .orb { width: 64px; height: 64px; margin-bottom: 22px; }

  .cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 11px;
  }
  .card { min-height: 0; padding: 14px 15px; animation: fadeUp .45s ease both; }
}

/* 需要悬停才出现的控件只在真有鼠标时才有 */
@media (min-width: 48em) and (hover: hover) and (pointer: fine) {
  .card:hover { border-color: var(--accent-light); transform: translateY(-2px); }
  .ghost:hover { background: var(--hover); }
  .new-btn:hover { background: var(--hover); }
  .conv-item:hover { background: var(--hover); }
  .chip:hover { background: var(--hover); }
  .chip:hover b { color: var(--accent); }
  .submit:hover:not(:disabled) { background: var(--accent-dark); }
  .send:hover { background: var(--accent-dark); }
}

/* 触摸设备永远显示抽屉按钮，跟屏宽无关 */
.only-narrow { display: inline-flex; }

@media (min-width: 48em) and (hover: hover) and (pointer: fine) {
  .only-narrow { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
