/* 颜色取自白大理石和暖金。字用深褐色，保证看得清。 */

:root {
  --bg: #f3efe6;
  --paper: rgba(255, 252, 247, 0.92);
  --card: #fffdf8;
  --ink: #3a332b;
  --muted: #6f655b;
  --line: rgba(176, 144, 96, 0.4);
  --gold: #b08968;
  --gold-deep: #8c6239;
  --blush: #f6e7c4;
  --danger: #8d4b43;
  --shadow: 0 18px 50px rgba(90, 70, 40, 0.12);
  --serif: "Noto Serif SC", "Songti SC", "PMingLiU", serif;
  --sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(255, 255, 255, 0.9), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(212, 175, 120, 0.28), transparent 50%),
    linear-gradient(180deg, #f7f3ea, #ebe2d2);
}

/* 宽屏两侧的柱子，只是装饰。窄屏藏起来，免得挡住内容。 */
body::before,
body::after {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  width: 56px;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 252, 245, 0.2), rgba(196, 176, 148, 0.28)),
    repeating-linear-gradient(180deg, rgba(176, 144, 96, 0.18) 0 16px, transparent 16px 34px);
  box-shadow: inset 0 0 0 1px rgba(176, 144, 96, 0.28);
}

body::before { left: 0; }
body::after { right: 0; }

@media (max-width: 839px) {
  body::before,
  body::after { display: none; }
}

button, input, textarea, select { font: inherit; color: inherit; }

button { cursor: pointer; }

.app {
  width: min(440px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  position: relative;
}

@media (min-width: 840px) {
  body { min-height: 100vh; }
  .app {
    height: min(920px, calc(100vh - 48px));
    height: min(920px, calc(100dvh - 48px));
    margin: 24px auto;
    border-radius: 28px;
    overflow: hidden;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
  }
}

/* 电脑版专用的东西，手机上先藏起来。 */
.cg-stage,
.plan-widget,
.gear,
.journal-btn,
.desktop-records-entry,
.close-btn { display: none; }

.app-header {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px 8px;
}

.avatar,
.avatar-sm {
  object-fit: cover;
  object-position: center 28%;
  border-radius: 50%;
  background: #efe6d8;
}

.avatar {
  width: 64px;
  height: 64px;
  border: 2px solid #d4b483;
  box-shadow: 0 6px 16px rgba(120, 90, 40, 0.18);
}

.who h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.who p { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }

.status {
  margin: 0;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--gold-deep);
  font-size: 0.75rem;
  white-space: nowrap;
}

.meander {
  display: block;
  width: calc(100% - 32px);
  height: 12px;
  margin: 0 16px 4px;
  color: var(--gold);
}

main { flex: 1; min-height: 0; display: flex; }

.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.page[hidden] { display: none; }

.messages,
.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 14px 12px;
}

.msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 10px 0;
}

.msg.user { flex-direction: row-reverse; }

.avatar-sm { width: 28px; height: 28px; flex: none; }

.msg-col { max-width: 82%; }

.bubble {
  padding: 10px 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  word-break: break-word;
}

.msg.user .bubble {
  background: linear-gradient(180deg, #f8e7c4, #f3d7a4);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 5px;
}

.bubble.pending::after {
  content: "▍";
  margin-left: 2px;
  color: var(--gold-deep);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.time {
  margin: 4px 4px 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.msg.user .time { text-align: right; }

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.78rem;
}

.sources span { color: var(--muted); }

.sources a,
.card a {
  color: var(--gold-deep);
}

.composer,
.page-foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.96);
}

.composer textarea {
  flex: 1;
  width: auto;
  min-width: 0;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
}

textarea { resize: none; max-height: 120px; }

textarea:focus,
input:focus,
select:focus,
button:focus-visible {
  border-color: var(--gold-deep);
  box-shadow: 0 0 0 3px rgba(176, 144, 96, 0.25);
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--gold-deep);
  color: #fffaf3;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.55; cursor: default; }

.btn.ghost {
  background: transparent;
  color: var(--gold-deep);
  border: 1px solid var(--line);
}

.btn.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(141, 75, 67, 0.45);
}

.page-foot .btn { width: 100%; }

nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.98);
  padding-bottom: env(safe-area-inset-bottom);
}

nav button {
  border: 0;
  background: transparent;
  padding: 12px 0 14px;
  color: var(--muted);
}

nav button.active {
  color: var(--gold-deep);
  font-weight: 700;
  box-shadow: inset 0 2px 0 var(--gold);
}

.page-intro { padding: 4px 16px 0; }

.page-intro h2,
.stack h3,
.settings-block h3 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
}

.page-intro p,
.hint { color: var(--muted); margin: 4px 0 0; font-size: 0.92rem; }

.inset { padding: 12px 16px; }

.stack { display: flex; flex-direction: column; gap: 10px; }

/* 比 .stack 更具体，避免手机上把电脑专用入口露出来。 */
.stack.desktop-records-entry { display: none; }

.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.row > input,
.row > select { width: auto; }

.row > input { flex: 1; }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 16px;
}

.seg button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 6px 0;
  color: var(--muted);
}

.seg button.active {
  background: var(--blush);
  color: var(--ink);
  border-color: transparent;
}

.list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
}

.card p { margin: 0; }

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.tag {
  flex: none;
  font-size: 0.75rem;
  color: var(--gold-deep);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

.card.done p { color: var(--muted); text-decoration: line-through; }

.actions { display: flex; gap: 8px; margin-top: 8px; }

.actions button,
.linkish {
  border: 0;
  background: transparent;
  color: var(--gold-deep);
  padding: 0;
  font-size: 0.88rem;
}

.checkline { flex-direction: row !important; align-items: flex-start; gap: 8px !important; }

.checkline input { width: auto; margin-top: 4px; }

.plan-line { display: flex; gap: 8px; align-items: flex-start; }

.plan-line input { width: auto; margin-top: 4px; }

.empty {
  margin: 12px 0;
  color: var(--muted);
  text-align: center;
}

.settings-block {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.card-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #d4b483;
  background: #f4ead8;
}

.file-btn input { display: none; }

.file-btn { display: inline-flex; align-items: center; }

code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.82em;
  word-break: break-all;
}

.toast {
  position: absolute;
  left: 50%;
  top: 92px;
  transform: translateX(-50%) translateY(8px);
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(58, 51, 43, 0.92);
  color: #fffaf3;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ================= 电脑版（窗口宽度 900px 以上） =================
   立绘铺满整个窗口，聊天框、计划表、设置都是浮在上面的玻璃。
   手机版不受这一段影响。 */
@media (min-width: 900px) {
  :root {
    --glass: rgba(255, 252, 247, 0.34);
    --glass-strong: rgba(255, 252, 247, 0.72);
    --glass-line: rgba(255, 255, 255, 0.55);
    --glass-shadow: 0 12px 40px rgba(60, 40, 20, 0.22);
  }

  body {
    overflow: hidden;
    background: linear-gradient(160deg, #f7f3ea, #e6d9c3);
  }
  body::before,
  body::after { display: none; }

  .app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    overflow: hidden;
  }

  /* 立绘：先铺一张模糊放大的同图当底，再把原图按比例放在下沿，站在地上一样。 */
  .cg-stage {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
  }
  .cg-bg {
    position: absolute;
    inset: -40px;
    width: calc(100% + 80px);
    height: calc(100% + 80px);
    object-fit: cover;
    filter: blur(36px) saturate(1.1);
    opacity: 0.55;
  }
  .cg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: 34% bottom;
    filter: drop-shadow(0 0 28px rgba(60, 40, 20, 0.18));
  }
  /* 没有角色卡时用的占位图是一个小图标，别放大成一大块。 */
  .cg-stage.is-placeholder .cg {
    inset: auto;
    left: 18%;
    bottom: 8%;
    width: min(340px, 30vw);
    height: auto;
    opacity: 0.8;
  }
  .cg-stage.is-placeholder .cg-bg { opacity: 0.25; }

  /* 左上角：名字、状态、齿轮。 */
  .app-header {
    position: absolute;
    top: 20px;
    left: 24px;
    z-index: 5;
    grid-template-columns: 1fr auto auto auto;
    gap: 12px;
    padding: 10px 12px 10px 18px;
    border-radius: 999px;
    background: var(--glass);
    border: 1px solid var(--glass-line);
    box-shadow: var(--glass-shadow);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
    backdrop-filter: blur(16px) saturate(1.3);
  }
  .app-header .avatar,
  .app-header .who p,
  .meander,
  nav,
  #page-study,
  #page-memory,
  .avatar-sm { display: none !important; }
  .who h1 { font-size: 1.25rem; text-shadow: 0 1px 8px rgba(255, 255, 255, 0.7); }

  .gear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--glass-line);
    background: rgba(255, 255, 255, 0.5);
    color: var(--gold-deep);
    font-size: 1.15rem;
    line-height: 1;
    padding: 0;
  }
  .gear:hover,
  .gear[aria-expanded="true"] { background: rgba(255, 255, 255, 0.85); }
  .journal-btn {
    display: inline-flex;
    font-family: var(--serif);
    font-size: 0.95rem;
    font-weight: 600;
  }

  /* 右下角：玻璃聊天框。 */
  main {
    position: absolute;
    z-index: 5;
    right: 28px;
    bottom: 24px;
    width: min(460px, 36vw);
    min-width: 360px;
    height: min(640px, calc(100vh - 300px));
    height: min(640px, calc(100dvh - 300px));
    min-height: 320px;
    display: block;
  }
  #page-chat {
    height: 100%;
    border-radius: 24px;
    overflow: hidden;
    background: var(--glass);
    border: 1px solid var(--glass-line);
    box-shadow: var(--glass-shadow);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    backdrop-filter: blur(20px) saturate(1.4);
  }
  #page-chat .messages { padding: 14px 16px 8px; }
  #page-chat .msg-col { max-width: 88%; }
  #page-chat .bubble {
    background: rgba(255, 255, 255, 0.66);
    border: 1px solid rgba(255, 255, 255, 0.7);
  }
  #page-chat .msg.user .bubble {
    background: rgba(246, 223, 170, 0.78);
  }
  #page-chat .time { color: #5b5147; }
  #page-chat .empty { color: #4d443b; }
  #page-chat .composer {
    border-top: 1px solid var(--glass-line);
    background: rgba(255, 255, 255, 0.28);
  }
  #page-chat .composer textarea { background: rgba(255, 255, 255, 0.7); }
  .messages::-webkit-scrollbar { width: 8px; }
  .messages::-webkit-scrollbar-thumb { background: rgba(120, 90, 50, 0.3); border-radius: 8px; }

  /* 右上角：计划表。 */
  .plan-widget {
    display: block;
    position: absolute;
    z-index: 5;
    top: 20px;
    right: 28px;
    width: min(460px, 36vw);
    min-width: 360px;
    border-radius: 20px;
    background: var(--glass);
    border: 1px solid var(--glass-line);
    box-shadow: var(--glass-shadow);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    backdrop-filter: blur(20px) saturate(1.4);
    overflow: hidden;
  }
  .plan-head {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 10px 16px;
    border: 0;
    background: transparent;
    font-family: var(--serif);
    font-weight: 600;
    font-size: 1.02rem;
    text-align: left;
  }
  .plan-count { font-family: var(--sans); font-weight: 400; font-size: 0.8rem; color: #5b5147; }
  .plan-body { padding: 0 12px 12px; }
  .plan-widget.folded .plan-body { display: none; }
  .plan-mini {
    list-style: none;
    margin: 0 0 8px;
    padding: 0 2px 0 0;
    max-height: 150px;
    overflow-y: auto;
  }
  .plan-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 10px;
  }
  .plan-item:hover { background: rgba(255, 255, 255, 0.4); }
  .plan-item label { flex: 1; display: flex; gap: 8px; align-items: flex-start; cursor: pointer; min-width: 0; }
  .plan-item input { width: auto; margin-top: 4px; flex: none; }
  .plan-text { font-size: 0.92rem; word-break: break-word; }
  .plan-text em {
    font-style: normal;
    font-size: 0.7rem;
    color: var(--gold-deep);
    border: 1px solid rgba(140, 98, 57, 0.4);
    border-radius: 999px;
    padding: 0 6px;
    margin-right: 6px;
  }
  .plan-item.done .plan-text { color: #5b5147; text-decoration: line-through; opacity: 0.8; }
  .plan-del {
    flex: none;
    border: 0;
    background: transparent;
    color: #5b5147;
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px 6px;
    opacity: 0;
  }
  .plan-item:hover .plan-del,
  .plan-del:focus-visible { opacity: 1; }
  .plan-empty,
  .plan-clear { padding: 4px 6px; font-size: 0.85rem; color: #4d443b; }
  .plan-mini-form { display: flex; gap: 6px; }
  .plan-mini-form select { width: auto; padding: 6px 8px; border-radius: 12px; background: rgba(255, 255, 255, 0.7); }
  .plan-mini-form input { flex: 1; min-width: 0; padding: 6px 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.7); }
  .plan-mini-form .btn { padding: 4px 14px; }

  /* 设置：默认收起。点齿轮从左边滑出一块玻璃面板，里面的表单和手机版是同一份。 */
  #page-settings {
    position: fixed;
    z-index: 20;
    top: 84px;
    left: 24px;
    bottom: 24px;
    width: min(480px, 40vw);
    min-width: 380px;
    border-radius: 24px;
    overflow: hidden;
    background: var(--glass-strong);
    border: 1px solid var(--glass-line);
    box-shadow: var(--glass-shadow);
    -webkit-backdrop-filter: blur(26px) saturate(1.4);
    backdrop-filter: blur(26px) saturate(1.4);
  }
  #page-settings .page-intro { position: relative; padding: 14px 52px 4px 20px; }
  #page-settings .inset { padding: 12px 20px 20px; }
  .stack.desktop-records-entry { display: flex; }

  /* 记忆与笔记：和设置一样，从左边滑出一块玻璃面板，复用手机版的表单和列表。 */
  #page-records {
    position: fixed;
    z-index: 20;
    top: 84px;
    left: 24px;
    bottom: 24px;
    width: min(480px, 40vw);
    min-width: 380px;
    border-radius: 24px;
    overflow: hidden;
    background: var(--glass-strong);
    border: 1px solid var(--glass-line);
    box-shadow: var(--glass-shadow);
    -webkit-backdrop-filter: blur(26px) saturate(1.4);
    backdrop-filter: blur(26px) saturate(1.4);
  }
  #page-records[hidden] { display: none; }
  #page-records .page-intro { position: relative; padding: 14px 52px 8px 20px; }
  #page-records .records-seg { margin: 12px 0 0; }
  #page-records .inset { padding: 12px 20px 20px; }
  #page-records #memory-form { padding: 0 0 12px; }
  #page-records .scroll.list,
  #page-records #memory-list,
  #page-records #note-list { overflow: visible; flex: none; padding: 0; }
  .close-btn {
    display: block;
    position: absolute;
    top: 10px;
    right: 14px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    color: var(--gold-deep);
    font-size: 1.3rem;
    line-height: 1;
    padding: 0;
  }

  .toast { position: fixed; top: 90px; z-index: 30; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble.pending::after,
  .toast { animation: none; transition: none; }
}

/* ================= iPhone：避开刘海和底部横条 =================
   「添加到主屏幕」后状态栏是透明的，页面会延伸到刘海下面，
   所以头部要让出 env(safe-area-inset-top)。只改间距，不改手机版的样子。 */
@media (max-width: 899px) {
  .app {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .app-header {
    padding-top: max(14px, calc(env(safe-area-inset-top) + 6px));
  }
  /* 禁止输入框聚焦时 iOS 自动放大页面 */
  input, textarea, select { font-size: 16px; }
}
