:root {
  color-scheme: light;
  --canvas: #e9e8e0;
  --paper: #f8f6ef;
  --surface: #fffefa;
  --ink: #20271f;
  --muted: #62695f;
  --green: #294a36;
  --green-2: #48634e;
  --green-soft: #e0e8da;
  --danger: #963b30;
  --line: rgba(32, 39, 31, .13);
  --serif: "Songti SC", "Noto Serif CJK SC", "Noto Serif SC", STSong, SimSun, serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: var(--sans); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
a { color: inherit; text-decoration: none; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid #a75531; outline-offset: 3px; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.icon { display: block; width: 21px; height: 21px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.app { display: flex; flex-direction: column; width: min(100%, 510px); height: 100vh; height: 100dvh; margin: 0 auto; padding-top: var(--safe-top); background: var(--paper); }
.main { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; }
.main.full-screen { display: flex; flex-direction: column; overflow: hidden; }
.screen-content { padding: 23px 22px 30px; }
.page-head, .home-top, .sub-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.page-head { margin: 0 0 19px; }
.page-head h1 { margin: 0; font: 600 34px/1.3 var(--serif); }
.sub-head { flex: 0 0 auto; min-height: 65px; padding: 9px 15px; border-bottom: 1px solid var(--line); background: var(--paper); }
.sub-head h1 { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; font: 600 21px/1.3 var(--serif); }
.sub-head > .icon-button { border-color: transparent; }
.icon-button { display: inline-grid; width: 44px; height: 44px; flex: 0 0 44px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 13px; background: transparent; color: var(--green); }
.primary, .secondary, .danger-button { min-height: 44px; padding: 10px 16px; border: 1px solid transparent; border-radius: 12px; font-size: 14px; font-weight: 650; }
.primary { background: var(--green); color: #fff; }
.secondary { border-color: var(--line); background: var(--surface); color: var(--green); }
.danger-button { background: var(--danger); color: #fff; }
.text-button { display: inline-flex; min-height: 40px; align-items: center; padding: 6px 7px; border: 0; background: transparent; color: var(--green); font-size: 14px; font-weight: 650; }
.danger, .error { color: var(--danger); }
.empty { margin: 0; padding: 32px 15px; color: var(--muted); text-align: center; font-size: 14px; }
.empty.error { color: var(--danger); }
.avatar { position: relative; display: inline-grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; overflow: hidden; border-radius: 50%; background: var(--green-soft); color: var(--green); font: 600 17px/1 var(--serif); }
.avatar-photo { position: absolute; inset: 0; width: 100%; height: 100%; background: inherit; object-fit: cover; }
.avatar.friend { background: #eee0d2; color: #704b37; }
.avatar.unbound { border: 1px dashed var(--green-2); background: transparent; }
.pair-avatars { display: inline-flex; padding-left: 7px; }
.pair-avatars .avatar { margin-left: -7px; border: 2px solid var(--paper); }
.ai-avatar { background: var(--green); color: #fff; }

.bottom-nav { z-index: 1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); flex: 0 0 auto; min-height: calc(63px + var(--safe-bottom)); padding: 5px 12px calc(6px + var(--safe-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.nav-item { display: grid; justify-items: center; align-content: center; gap: 4px; border-radius: 13px; color: var(--muted); font-size: 12px; }
.nav-item.active { color: var(--green); font-weight: 700; }
.nav-item .icon { box-sizing: content-box; padding: 3px 12px; border-radius: 18px; }
.nav-item.active .icon { background: var(--green-soft); }

.home-top h1 { margin: 0; font: 650 32px/1.25 var(--serif); letter-spacing: .03em; }
.account-button { display: inline-flex; min-height: 44px; align-items: center; }
.home-intro { margin: 29px 0 20px; }
.home-intro h2 { margin: 0; font: 600 33px/1.3 var(--serif); letter-spacing: -.02em; }
.home-intro p { margin: 8px 0 0; color: var(--green-2); font-size: 13px; }
.home-cover { display: block; overflow: hidden; border-radius: 23px; background: var(--surface); }
.home-cover:empty { min-height: 220px; background: var(--green-soft); }
.cover-photo { width: 100%; height: clamp(230px, 62vw, 335px); object-fit: cover; }
.text-cover { display: flex; min-height: 235px; align-items: center; padding: 27px 23px; background: var(--green-soft); color: var(--green); font: 600 25px/1.65 var(--serif); }
.text-cover span, .cover-copy h3 { display: -webkit-box; overflow: hidden; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 4; }
.cover-copy { padding: 17px 20px; }
.cover-copy h3 { margin: 0 0 8px; font: 600 21px/1.4 var(--serif); -webkit-line-clamp: 2; }
.cover-copy p { margin: 0 0 14px; color: var(--muted); font-size: 12px; }
.cover-link { display: flex; justify-content: space-between; align-items: center; color: var(--green); font-size: 14px; font-weight: 700; }
.cover-copy p + .cover-link, .cover-copy h3 + .cover-link { padding-top: 13px; border-top: 1px solid var(--line); }

.field { display: block; margin: 14px 0 0; font-size: 14px; font-weight: 650; }
.field input, .field textarea, .ingredient-row input, .input-row textarea { display: block; width: 100%; min-width: 0; margin: 7px 0 0; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px; font-weight: 400; }
.field input, .ingredient-row input { min-height: 45px; }
.field textarea { min-height: 80px; resize: vertical; line-height: 1.6; }
.form-error, .form-status, .consequence { margin: 13px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.form-error, .form-status.error, .consequence { color: var(--danger); }
.form-actions { display: flex; gap: 9px; margin-top: 17px; }
.form-actions > * { flex: 1; }

.login-screen { display: flex; min-height: 100%; flex-direction: column; justify-content: center; align-items: center; padding: 28px 22px calc(34px + var(--safe-bottom)); }
.login-icon { width: 58px; height: 58px; margin-bottom: 13px; }
.login-screen h1 { margin: 0 0 16px; font: 650 36px/1.3 var(--serif); letter-spacing: .09em; }
.login-form { width: min(100%, 330px); }
.login-form .primary { width: 100%; margin-top: 23px; }

.search { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.search .icon { width: 18px; height: 18px; color: var(--muted); }
.search input { width: 100%; min-width: 0; padding: 0; border: 0; background: transparent; font-size: 16px; }
.recipe-list { margin-top: 16px; }
.recipe-row, .conversation-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 13px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.recipe-row > .icon, .conversation-row > .icon { width: 17px; height: 17px; color: var(--muted); }
.recipe-row strong, .conversation-row strong { overflow-wrap: anywhere; font-size: 16px; }
.recipe-initial { display: grid; width: 52px; height: 50px; place-items: center; border-radius: 12px; background: var(--green-soft); color: var(--green); font: 600 24px var(--serif); }
.detail-title { margin: 0 0 12px; overflow-wrap: anywhere; font: 600 33px/1.35 var(--serif); }
.detail-section { padding: 17px 0; border-bottom: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 10px; font-size: 16px; }
.detail-section p, .detail-section li { margin: 0; overflow-wrap: anywhere; color: var(--muted); font-size: 15px; line-height: 1.7; }
.detail-section ol { margin: 0; padding-left: 23px; }
.detail-section ol li + li { margin-top: 7px; }
.ingredients { margin: 0; padding: 0; list-style: none; }
.ingredients li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .6fr); gap: 10px; }
.ingredients li span:last-child { text-align: right; }
.ingredients li + li { margin-top: 5px; }
.source-link { display: inline-flex; min-height: 44px; align-items: center; gap: 5px; margin-top: 7px; color: var(--green); font-size: 14px; font-weight: 650; }
.source-link .icon { width: 15px; height: 15px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 13px; background: #eaece3; }
.segmented button { min-height: 43px; padding: 6px 9px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 14px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--green); font-weight: 700; }
.read-link { width: 100%; margin: 10px 0 0; }
.ingredient-fields { min-width: 0; margin: 15px 0 0; padding: 0; border: 0; }
.ingredient-fields legend { padding: 0; font-size: 14px; font-weight: 650; }
.ingredient-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .75fr) 44px; align-items: end; gap: 7px; }
.ingredient-row .remove-row { font-size: 22px; }
.add-ingredient { padding-left: 0; }

.binding-card { margin-top: 20px; padding: 23px 20px; border-radius: 21px; background: var(--green-soft); text-align: center; }
.binding-avatars .avatar { border-color: var(--green-soft); }
.binding-avatars .unbound { border-color: var(--green-2); }
.binding-card h2 { margin: 11px 0 0; font: 600 26px/1.35 var(--serif); }
.binding-card p { margin: 10px 0 0; font-size: 13px; }
.binding-actions { display: grid; gap: 8px; margin-top: 18px; }
.invite-code { display: block; margin: 16px 0 2px; padding: 13px; overflow-wrap: anywhere; border: 1px dashed var(--green-2); border-radius: 12px; color: var(--green); font-size: 23px; font-weight: 700; letter-spacing: .13em; user-select: all; }
#bind-form { text-align: left; }
#bind-form button { width: 100%; margin-top: 10px; }
.write-moment { display: flex; width: 100%; align-items: center; gap: 12px; padding: 10px 13px; border: 0; border-radius: 15px; background: var(--green-soft); color: var(--green); text-align: left; font-size: 15px; font-weight: 650; }
.write-moment .avatar { width: 34px; height: 34px; border-color: var(--green-soft); background: var(--surface); font-size: 14px; }
.write-moment .avatar.friend { background: #eee0d2; }
.write-plus { display: grid; width: 31px; height: 31px; place-items: center; margin-left: auto; border-radius: 50%; background: var(--green); color: #fff; }
.write-plus .icon { width: 17px; height: 17px; }
.journal-date { display: flex; align-items: center; gap: 11px; margin: 23px 0 13px; color: var(--muted); font-size: 12px; font-weight: 500; }
.journal-date::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.moment { margin-bottom: 22px; }
.moment header { display: flex; align-items: center; gap: 10px; }
.moment .avatar { width: 37px; height: 37px; font-size: 15px; }
.moment strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.moment time { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.moment-delete { flex: none; margin-inline-start: auto; }
.moment p { margin: 10px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; font-size: 15px; line-height: 1.7; }
.moment-photo { display: block; width: 100%; margin-top: 10px; padding: 0; overflow: hidden; border: 0; border-radius: 16px; background: var(--green-soft); }
.moment-photo img { width: 100%; max-height: 320px; object-fit: cover; }

dialog { color: var(--ink); }
dialog::backdrop { background: rgba(25, 31, 24, .4); }
.confirm-dialog, .moment-dialog { max-width: calc(100% - 32px); max-height: calc(100% - 22px); padding: 20px; border: 0; border-radius: 20px; background: var(--surface); }
.confirm-dialog { width: 360px; }
.confirm-dialog h2, .moment-dialog h2 { margin: 0; overflow-wrap: anywhere; font: 600 24px/1.35 var(--serif); }
.confirm-dialog p { margin: 10px 0 0; overflow-wrap: anywhere; color: var(--muted); font-size: 14px; line-height: 1.6; }
.confirm-dialog p.form-error { color: var(--danger); }

.settings-profile { display: flex; align-items: center; gap: 10px; padding: 15px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.settings-profile .avatar { width: 52px; height: 52px; border: 2px solid var(--paper); background: var(--surface); font-size: 21px; }
.settings-profile strong { flex: 1; min-width: 0; overflow-wrap: anywhere; font: 600 21px/1.35 var(--serif); }
.settings-profile > span:not(.avatar) { flex: 0 0 auto; color: var(--green); font-size: 13px; font-weight: 650; }
.settings-profile > .icon, .settings-row > .icon { width: 16px; height: 16px; color: var(--muted); }
.settings-list { margin-top: 12px; padding: 0 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.settings-row { display: flex; min-height: 57px; align-items: center; gap: 8px; padding: 8px 3px; border-bottom: 1px solid var(--line); font-size: 15px; }
.settings-row > span:first-child { flex: 0 0 auto; }
.settings-row:last-child { border-bottom: 0; }
.setting-label { display: inline-flex; align-items: center; gap: 9px; }
.setting-label .icon { width: 19px; height: 19px; color: var(--green); }
.settings-row > .icon { margin-left: auto; }
.settings-value { display: flex; flex: 1; min-width: 0; align-items: center; justify-content: flex-end; gap: 7px; color: var(--muted); text-align: right; overflow-wrap: anywhere; font-size: 13px; }
.settings-value .avatar { width: 30px; height: 30px; font-size: 13px; }
.settings-value > span:last-child { min-width: 0; }
.logout-button { width: 100%; margin-top: 22px; color: var(--danger); }
.settings-form > .field:first-child { margin-top: 0; }
.profile-picture { display: flex; align-items: center; gap: 14px; }
.profile-picture .avatar { width: 76px; height: 76px; font-size: 27px; }
.profile-picture-actions { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.memory-section + .memory-section { margin-top: 22px; }
.memory-section header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.memory-section h2 { margin: 0; font: 600 23px/1.4 var(--serif); }
.memory-section .empty { padding-block: 17px; text-align: left; }
.memory-list { margin: 4px 0 0; padding: 0; list-style: none; }
.memory-list li { padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.memory-list strong { display: block; white-space: pre-wrap; font-size: 15px; line-height: 1.6; }
.memory-list small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.memory-list details { margin-top: 7px; color: var(--muted); font-size: 13px; }
.memory-list summary { width: fit-content; cursor: pointer; }
.memory-list details p { margin: 6px 0 0; white-space: pre-wrap; line-height: 1.6; }

.moment-dialog { inset: auto 0 0; width: min(100%, 510px); max-width: none; margin: 0 auto; padding: 18px 22px calc(18px + var(--safe-bottom)); border-radius: 23px 23px 0 0; background: var(--paper); }
.moment-dialog[open] { animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(22px); opacity: .6; } }
.sheet-handle { width: 34px; height: 4px; margin: -7px auto 15px; border-radius: 4px; background: #c8c9c1; }
.photo-picker { display: inline-flex; align-items: center; gap: 7px; margin-top: 11px; }
.photo-picker .icon { width: 17px; height: 17px; }
.moment-preview { position: relative; width: 80px; margin-top: 10px; }
.moment-preview img { width: 80px; height: 80px; border-radius: 11px; object-fit: cover; }
.moment-preview .attachment-remove { position: absolute; top: -5px; right: -5px; }

.conversation-row small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.conversation-row .avatar { width: 48px; height: 48px; font-size: 20px; }
.chat-screen { display: flex; flex: 1; min-height: 0; flex-direction: column; background: #f5f3eb; }
.chat-members { max-width: 50%; color: var(--muted); text-align: right; overflow-wrap: anywhere; font-size: 12px; }
.chat-history { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 12px 14px 2px; }
.history-tools { text-align: center; }
.history-status, .chat-date { margin: 7px 0 15px; color: var(--muted); text-align: center; font-size: 12px; }
.message { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
.message.mine { justify-content: flex-end; }
.message .avatar { width: 30px; height: 30px; font-size: 13px; }
.message-content { min-width: 0; max-width: 79%; }
.message-author { display: block; margin-bottom: 4px; overflow-wrap: anywhere; color: var(--muted); font-size: 12px; }
.bubble { width: fit-content; max-width: 100%; padding: 9px 12px; border-radius: 5px 15px 15px 15px; background: var(--surface); box-shadow: 0 1px 2px rgba(32, 39, 31, .05); font-size: 15px; line-height: 1.55; }
.message.mine .bubble { background: var(--green); color: #fff; border-radius: 15px 5px 15px 15px; }
.message-text { overflow-wrap: anywhere; white-space: pre-wrap; }
.message-meta { display: flex; min-height: 14px; align-items: center; gap: 8px; margin-top: 4px; color: var(--muted); font-size: 11px; }
.message.mine .message-meta { color: #e0e8da; }
.message-retry { min-height: 29px; padding: 0 4px; border: 0; background: transparent; color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.send-error { margin: -7px 0 11px; color: var(--danger); text-align: right; font-size: 12px; }
.bubble.media-bubble { padding: 5px; }
.bubble.media-bubble .message-text, .bubble.media-bubble .message-meta { margin-right: 6px; margin-left: 6px; }
.bubble.media-bubble .message-text { margin-top: 5px; }
.bubble.image-bubble, .message.mine .bubble.image-bubble { padding: 0; background: transparent; color: var(--ink); box-shadow: none; }
.message.mine .image-bubble .message-meta { color: var(--muted); }
.image-message { display: block; max-width: 100%; padding: 0; border: 0; border-radius: 11px; background: transparent; cursor: zoom-in; }
.chat-image { width: auto; max-width: 100%; min-height: 45px; max-height: 230px; object-fit: contain; border-radius: 11px; }
.chat-video { display: block; width: 240px; max-width: 100%; max-height: 235px; border-radius: 11px; background: #161a16; }
.file-message { display: flex; align-items: center; gap: 9px; padding: 6px; }
.file-message > span:last-child { min-width: 0; }
.file-message strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.file-message small { display: block; opacity: .85; font-size: 11px; }
.file-icon .icon { width: 24px; height: 24px; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.chat-composer { padding: 8px 12px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.mention-row { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.mention-button { min-height: 34px; padding: 4px 10px; border: 0; border-radius: 9px; background: var(--green-soft); color: var(--green); font-size: 13px; font-weight: 650; }
.input-row { display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px; align-items: end; gap: 7px; }
.input-row textarea { min-height: 44px; max-height: 108px; margin: 0; padding: 10px 11px; resize: none; line-height: 22px; }
.send-button, .attach-button { display: grid; height: 44px; place-items: center; padding: 0; border: 1px solid transparent; border-radius: 12px; }
.send-button { background: var(--green); color: #fff; }
.attach-button { border-color: var(--line); background: var(--surface); color: var(--green); }
.attach-button[aria-expanded="true"] { background: var(--green-soft); }
.attachment-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 13px; padding: 0 12px 3px; }
.attachment-option { display: grid; justify-items: center; gap: 6px; padding: 0; border: 0; background: transparent; color: var(--green); font-size: 13px; }
.attachment-option span { display: grid; width: 48px; height: 45px; place-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.attachment-draft { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; padding: 6px 8px; border-radius: 11px; background: var(--green-soft); }
.attachment-thumb { display: grid; width: 52px; height: 45px; flex: 0 0 auto; place-items: center; overflow: hidden; border-radius: 8px; }
.attachment-thumb img, .attachment-thumb video { width: 100%; height: 100%; object-fit: cover; }
.attachment-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.attachment-remove { display: grid; width: 31px; height: 31px; flex: 0 0 31px; place-items: center; padding: 0; border: 1px solid var(--paper); border-radius: 50%; background: var(--ink); color: #fff; font-size: 20px; line-height: 1; }
.image-viewer { inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 62px 16px 25px; border: 0; background: rgba(15, 18, 15, .94); }
.image-viewer[open] { display: grid; place-items: center; }
.image-viewer img { max-width: 100%; max-height: calc(100dvh - 90px); object-fit: contain; }
.image-viewer .icon-button { position: absolute; top: calc(10px + var(--safe-top)); right: 13px; border-color: rgba(255,255,255,.24); background: rgba(255,255,255,.12); color: #fff; font-size: 25px; }
.toast { position: fixed; z-index: 3; left: 50%; bottom: calc(72px + var(--safe-bottom)); max-width: calc(100% - 35px); padding: 10px 15px; transform: translateX(-50%); border-radius: 12px; background: var(--ink); color: #fff; text-align: center; font-size: 13px; }

@media (min-width: 540px) {
  .app { border-inline: 1px solid var(--line); }
  .screen-content { padding-inline: 27px; }
}

@media (prefers-reduced-motion: reduce) {
  .moment-dialog[open] { animation: none; }
}
