:root {
  --paper: #fffaf7;
  --cream: #f7eee8;
  --ink: #3d3332;
  --muted: #978985;
  --line: #ebded8;
  --rose: #c96f78;
  --rose-dark: #a7535f;
  --rose-soft: #f6dfe1;
  --blue: #69869c;
  --blue-soft: #e1ebf1;
  --shadow: 0 30px 80px rgba(94, 64, 61, .14);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #f3eeea;
}
button, textarea { font: inherit; }
button { color: inherit; }
.app { min-height: 100vh; }
.view { display: none; min-height: 100vh; }
.view.active { display: flex; }

.welcome { align-items: center; justify-content: center; padding: 28px 18px; }
.welcome-card {
  width: min(700px, 100%);
  padding: 70px 70px 58px;
  text-align: center;
  background: rgba(255, 252, 249, .88);
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 36px;
  box-shadow: 0 24px 70px rgba(72, 55, 52, .1);
  backdrop-filter: blur(18px);
}
.eyebrow { margin: 0 0 9px; color: var(--rose); font: 700 10px/1.2 Georgia, serif; letter-spacing: .3em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 14px; font: 500 clamp(30px, 5vw, 46px)/1.25 "Noto Serif SC", "Songti SC", serif; letter-spacing: .05em; }
.lead { margin-bottom: 48px; color: var(--muted); font-size: 14px; letter-spacing: .08em; }
.identity-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.identity {
  position: relative; min-height: 178px; padding: 24px 16px; border: 1px solid var(--line); border-radius: 26px;
  background: white; cursor: pointer; transition: transform .22s, box-shadow .22s, border-color .22s;
  display: grid; place-items: center; overflow: hidden;
}
.identity::before {
  content: ""; position: absolute; inset: 12px; border: 1px solid rgba(255,255,255,.76);
  border-radius: 19px; pointer-events: none;
}
.identity.boy { background: #e8f1f5; }
.identity.girl { background: #f7e7e8; }
.identity:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(91, 68, 64, .08); }
.identity.boy:hover { border-color: #aabdc9; }
.identity.girl:hover { border-color: #dfadb3; }
.identity-icon {
  position: relative; z-index: 1; width: 76px; height: 76px; display: grid; place-items: center;
  border-radius: 50%; font: 500 27px/1 "Noto Serif SC", serif;
  box-shadow: 0 8px 22px rgba(81,67,64,.07);
}
.boy .identity-icon { background: rgba(255,255,255,.7); color: var(--blue); }
.girl .identity-icon { background: rgba(255,255,255,.7); color: var(--rose-dark); }
.identity-arrow {
  position: absolute; right: 25px; bottom: 21px; color: rgba(91,77,73,.42);
  font-size: 16px; transition: transform .2s;
}
.identity:hover .identity-arrow { transform: translate(3px, -3px); }

.chat {
  flex-direction: column; width: min(900px, 100%); height: 100vh; height: 100dvh;
  min-height: 0; margin: 0 auto; overflow: hidden;
  background: #fffaf7; box-shadow: 0 0 55px rgba(83,60,56,.08);
}
.chat[data-role="boy"] {
  background: #eaf2f6;
}
.chat[data-role="girl"] {
  background: #f8e9ea;
}
.topbar {
  height: 82px; padding: 0 26px; display: grid; grid-template-columns: 48px 1fr auto;
  align-items: center; text-align: center; border-bottom: 1px solid var(--line); background: rgba(255,252,250,.9);
  position: sticky; top: 0; z-index: 5; backdrop-filter: blur(14px);
}
.topbar { flex: 0 0 auto; }
.chat[data-role="boy"] .topbar { background: rgba(244,250,252,.9); border-bottom-color: #d9e6eb; }
.chat[data-role="girl"] .topbar { background: rgba(255,248,247,.9); border-bottom-color: #eddcdd; }
.topbar h2 { margin: 2px 0 0; font: 600 18px/1.2 "Noto Serif SC", serif; letter-spacing: .08em; }
.tiny-date { margin: 0; color: var(--muted); font-size: 9px; letter-spacing: .15em; text-transform: uppercase; }
.icon-button, .role-pill, .delete-button { border: 0; background: transparent; cursor: pointer; }
.icon-button { width: 40px; height: 40px; font: 300 36px/1 sans-serif; color: #968783; }
.role-pill {
  width: 40px; height: 40px; border-radius: 50%;
  font: 600 13px/1 "Noto Serif SC", serif;
}
.top-actions { display: flex; align-items: center; justify-self: end; gap: 5px; }
.delete-button {
  width: 38px; height: 38px; border-radius: 50%; color: #9b8b87;
  font-size: 17px; line-height: 1;
  transition: background .2s, color .2s;
}
.delete-button:hover { background: #f8e4e3; color: #b84e59; }
.delete-button:disabled { opacity: .35; cursor: not-allowed; }
.role-pill.boy { background: var(--blue-soft); color: var(--blue); }
.role-pill.girl { background: var(--rose-soft); color: var(--rose-dark); }

.messages {
  flex: 1 1 auto; min-height: 0; max-height: none; overflow-y: auto;
  padding: 34px clamp(18px, 6vw, 54px);
  scrollbar-color: #cbb9b3 transparent; scrollbar-width: thin;
  -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
}
.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: #cbb9b3; border-radius: 99px; }
.date-divider {
  display: flex; align-items: center; gap: 14px; margin: 7px 0 28px;
  color: #9e918d; font-size: 10px; letter-spacing: .1em;
}
.date-divider::before, .date-divider::after {
  content: ""; height: 1px; flex: 1; background: rgba(123,105,100,.18);
}
.date-divider span { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 55px 20px; }
.empty-heart { color: #d3aaa9; font: 40px/1 Georgia, serif; margin-bottom: 16px; }
.empty h3 { margin-bottom: 8px; color: #716361; font: 500 16px/1.4 "Noto Serif SC", serif; }
.empty p { font-size: 12px; }
.message-row { display: flex; margin-bottom: 22px; gap: 9px; align-items: flex-end; animation: appear .35s ease both; }
.message-row.theirs { justify-content: flex-start; }
.message-row.mine { justify-content: flex-end; }
.message-avatar {
  width: 31px; height: 31px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%;
  font: 600 11px/1 "Noto Serif SC", serif;
}
.boy .message-avatar { background: var(--blue-soft); color: var(--blue); }
.girl .message-avatar { background: var(--rose-soft); color: var(--rose-dark); }
.mine .message-avatar { order: 2; }
.message-card { max-width: min(72%, 520px); }
.bubble {
  padding: 13px 16px; border-radius: 5px 18px 18px; line-height: 1.7; font-size: 14px;
  box-shadow: 0 4px 14px rgba(82,64,61,.04); white-space: pre-wrap; overflow-wrap: anywhere;
}
.mine .bubble { border-radius: 18px 5px 18px 18px; }
.message-title {
  display: inline-flex; align-items: center; gap: 5px; margin: 0 4px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
}
.mine .message-title { display: flex; justify-content: flex-end; }
.mood-happy .message-title { color: #538060; }
.mood-happy .bubble { background: #e7f3e9; color: #3f684a; }
.mood-sad .message-title { color: #aa4d57; }
.mood-sad .bubble { background: #fae4e5; color: #81434a; }
.mood-thought .message-title { color: #8a7559; }
.mood-thought .bubble { background: #fff6e6; color: #705f4a; border: 1px solid #eee0c9; }
.meta { display: flex; gap: 7px; margin-top: 5px; color: #aa9c98; font-size: 9px; }
.mine .meta { justify-content: flex-end; }
.mood-tag::before { content: "·"; margin-right: 7px; }
@keyframes appear { from { opacity: 0; transform: translateY(8px); } }

.write-panel {
  position: relative; flex: 0 0 auto; padding: 26px clamp(18px, 6vw, 54px) 22px;
  background: #fffdfb; border-top: 1px solid var(--line);
}
.composer-toggle, .compact-preview { display: none; }
.prompt-line { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.prompt-line h3 { margin: 0; font: 600 20px/1.3 "Noto Serif SC", serif; }
#dailyStatus { color: var(--muted); font-size: 10px; white-space: nowrap; }
.moods { display: flex; gap: 9px; margin: 18px 0 14px; }
.moods button {
  flex: 1; padding: 10px 8px; border: 1px solid var(--line); border-radius: 12px;
  background: #fffdfa; color: #7d706d; cursor: pointer; font-size: 12px; transition: .2s;
}
.moods button span { margin-right: 5px; color: #c58b8d; }
.moods button.selected { border-color: #d38f96; background: #fff1f1; color: #94515a; box-shadow: 0 0 0 2px rgba(201,111,120,.08); }
.moods button:disabled { opacity: .38; cursor: not-allowed; text-decoration: line-through; }
.moods button[data-mood="开心的"].selected {
  border-color: #8eae94; background: #edf6ee; color: #4e7558;
  box-shadow: 0 0 0 2px rgba(93,137,103,.08);
}
.moods button[data-mood="不开心的"].selected {
  border-color: #d38f96; background: #fff0f0; color: #a14e58;
}
.moods button[data-mood="随想"].selected {
  border-color: #d8c9b7; background: #fffaf0; color: #7d6c57;
  box-shadow: 0 0 0 2px rgba(174,148,113,.08);
}
.composer {
  display: block; position: relative; border: 1px solid var(--line); border-radius: 15px; background: #fffdfb;
  transition: border-color .22s, background .22s, box-shadow .22s;
}
textarea {
  display: block; width: 100%; min-height: 88px; padding: 15px 48px 15px 16px; border: 0; resize: vertical;
  outline: 0; background: transparent; color: var(--ink); line-height: 1.6;
}
textarea:focus { box-shadow: 0 0 0 2px rgba(201,111,120,.12); border-radius: 15px; }
textarea::placeholder { color: #b5aaa7; }
.counter { position: absolute; right: 13px; bottom: 10px; color: #b6aaa6; font-size: 9px; }
.counter b { font-weight: 400; }
.submit {
  width: 100%; margin-top: 12px; padding: 13px 18px; border: 0; border-radius: 13px;
  background: var(--rose); color: white; cursor: pointer; font-size: 13px; letter-spacing: .03em; transition: .2s;
}
.submit span { float: right; font-size: 18px; line-height: 15px; }
.submit:not(:disabled):hover { background: var(--rose-dark); transform: translateY(-1px); }
.submit:disabled { opacity: .35; cursor: default; }
.write-panel .prompt-line h3, .write-panel .submit { transition: color .22s, background .22s; }
.write-panel[data-mood="开心的"] .prompt-line h3 { color: #4e7558; }
.write-panel[data-mood="开心的"] .composer {
  border-color: #a9c3ae; background: #f3faf3; box-shadow: 0 0 0 3px rgba(101,145,110,.07);
}
.write-panel[data-mood="开心的"] .submit { background: #678f70; }
.write-panel[data-mood="开心的"] .submit:not(:disabled):hover { background: #4f7558; }
.write-panel[data-mood="不开心的"] .prompt-line h3 { color: #a14e58; }
.write-panel[data-mood="不开心的"] .composer {
  border-color: #e0a6aa; background: #fff3f3; box-shadow: 0 0 0 3px rgba(190,83,94,.06);
}
.write-panel[data-mood="不开心的"] .submit { background: #bf626b; }
.write-panel[data-mood="不开心的"] .submit:not(:disabled):hover { background: #a84d57; }
.write-panel[data-mood="随想"] .prompt-line h3 { color: #78664f; }
.write-panel[data-mood="随想"] .composer {
  border-color: #deceb9; background: #fffaf0; box-shadow: 0 0 0 3px rgba(179,151,111,.06);
}
.write-panel[data-mood="随想"] .submit { background: #a68c6b; }
.write-panel[data-mood="随想"] .submit:not(:disabled):hover { background: #8b7357; }
.once-note { margin: 10px 0 0; text-align: center; color: #b0a5a1; font-size: 9px; }
.write-panel.locked { text-align: center; padding-top: 31px; padding-bottom: 31px; }
.locked-card h3 { margin-bottom: 8px; font: 600 18px/1.4 "Noto Serif SC", serif; }
.locked-card p { margin: 0; color: var(--muted); font-size: 12px; }
.locked-icon { display: inline-grid; place-items: center; width: 38px; height: 38px; margin-bottom: 10px; border-radius: 50%; background: var(--rose-soft); color: var(--rose-dark); }
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 20; transform: translate(-50%, 20px);
  padding: 11px 18px; border-radius: 99px; background: #443a38; color: white;
  opacity: 0; pointer-events: none; transition: .25s; font-size: 12px; box-shadow: 0 10px 28px rgba(48,37,35,.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 600px) {
  .welcome-card { padding: 44px 18px 28px; border-radius: 28px; }
  .identity-grid { gap: 10px; }
  .identity { min-height: 158px; padding: 21px 8px; }
  .chat { height: 100vh; height: 100dvh; min-height: 0; }
  .messages { min-height: 0; padding-top: 24px; padding-bottom: 20px; }
  .topbar { height: 72px; padding: 0 14px; }
  .top-actions { gap: 1px; }
  .delete-button { width: 34px; height: 34px; }
  .role-pill { width: 36px; height: 36px; }
  .write-panel { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  .write-panel:not(.locked) .composer-toggle {
    position: absolute; right: 14px; top: 13px; z-index: 2;
    display: grid; place-items: center; width: 32px; height: 32px;
    border: 1px solid #ded3ce; border-radius: 10px; background: #fffaf7;
    color: #887a76; font-size: 20px; line-height: 1; cursor: pointer;
  }
  .write-panel:not(.locked) .prompt-line { padding-right: 38px; }
  .write-panel.compact {
    padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  }
  .write-panel.compact > :not(.composer-toggle):not(.compact-preview) { display: none; }
  .write-panel.compact .composer-toggle { top: 16px; right: 20px; }
  .write-panel.compact .compact-preview {
    display: flex; align-items: center; width: 100%; min-height: 44px;
    padding: 0 54px 0 15px; border: 1px solid #e3d9d4; border-radius: 13px;
    background: #fbf7f4; color: #aa9d98; font-size: 12px; text-align: left;
    cursor: pointer;
  }
  .moods button { font-size: 11px; padding-inline: 4px; }
}
