:root {
  color-scheme: light;
  --bg: #eeebdf;
  --paper: #eeebdf;
  --ink: #29271f;
  --muted: #5c5547;
  --muted-strong: #4d4639;
  --line: #cfc7b4;
  --accent: #274195;
  --accent-deep: #263d70;
  --accent-soft: #e4eaf0;
  --surface: #f6f3e9;
  --warm: #efe4ce;
  --clay: #754a24;
  --danger: #9c354c;
  --shadow: 0 11px 34px #39281c12;
  --frame: 650px;
  --viewport-height: 100dvh;
  --viewport-top: 0px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; background: var(--bg); color: var(--ink); font-size: 1rem; }
body:has(dialog[open]) { overflow: hidden; }
button, input, textarea { font: inherit; }
button, a, label[for] { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: wait; opacity: .64; }
a { color: inherit; }
:focus-visible { outline: 3px solid #274195; outline-offset: 3px; }
button, summary, a { touch-action: manipulation; }
input, textarea { min-width: 0; color: var(--ink); }
input::placeholder, textarea::placeholder { color: #665e50; }
svg { width: 21px; height: 21px; flex: none; }
h1, h2, p { margin: 0; }
.frame {
  width: 100%;
  max-width: var(--frame);
  margin-inline: auto;
  padding-inline: max(20px, env(safe-area-inset-left)) max(20px, env(safe-area-inset-right));
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.primary, .secondary, .icon-button, .profile-button, .text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 14px;
  font-weight: 650;
  line-height: 1.25;
  text-decoration: none;
}
.primary { padding: 12px 19px; background: var(--accent); color: #fff; }
.secondary { padding: 10px 14px; background: var(--surface); color: var(--accent-deep); }
.icon-button { width: 44px; padding: 0; background: var(--paper); color: var(--accent-deep); border-color: var(--line); }
.text-button { padding: 0 10px; background: transparent; }
.danger { color: var(--danger); }
.destructive { background: var(--danger); }
@media (hover: hover) {
  .primary:hover { filter: brightness(.93); }
  .secondary:hover, .icon-button:hover, .text-button:hover { background: var(--accent-soft); }
}

.gate {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}
.gate-card {
  width: min(100%, 410px);
  padding: clamp(25px, 7vw, 40px);
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.brand-mark { display: block; border-radius: 26%; flex: none; }
.gate-mark { margin-bottom: 21px; }
.wordmark { color: var(--accent); font-weight: 750; font-size: .82rem; letter-spacing: .06em; }
.gate h1 { margin: 4px 0 23px; font-size: 2.2rem; letter-spacing: -.06em; }
.gate-status { color: var(--muted); line-height: 1.6; }
.gate form { display: grid; gap: 9px; }
.gate label, .sheet label { color: var(--muted-strong); font-weight: 650; font-size: .9rem; }
.gate input, .sheet input:not([type="file"]), textarea, .search-field select {
  appearance: none;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #cfc7b4;
  border-radius: 12px;
  background: #fffdf7;
  color: var(--ink);
}
.gate input { margin-bottom: 7px; }
.gate .primary { margin-top: 5px; }
.gate #retry-session { margin-top: 12px; }
.demo-login { margin-top: 25px; padding-top: 17px; border-top: 1px solid var(--line); }
.demo-login p { margin-bottom: 9px; color: var(--muted); font-size: .875rem; }
.demo-login div { display: flex; gap: 8px; }
.error { color: var(--danger); font-size: .9rem; line-height: 1.45; }

.journal { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: 100dvh; }
.journal-main { min-height: 0; overflow: auto; overscroll-behavior: contain; scroll-padding-block: 12px; }
.journal-page { max-width: 438px; margin-inline: auto; padding: 16px 12px; }
.journal .screen { min-height: calc(100dvh - 86px - env(safe-area-inset-bottom)); }
.journal :is(.book-back, .year-link, .date-row) { border: 0; background: transparent; }
.journal :is(.year-link, .date-row) { width: 100%; font: inherit; text-align: start; }
.journal .date-row { padding: 0; }
#dates [data-gap="8"] { --gap: 8px; }
#dates [data-gap="16"] { --gap: 16px; }
#dates [data-gap="23"] { --gap: 23px; }
.book-empty { margin: 12px 20px; color: var(--muted); font-size: .875rem; text-align: center; }
.book-entry-header { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.book-entry-header .author { min-width: 0; overflow-wrap: anywhere; }
.book-entries .content { white-space: pre-wrap; }
.entry-edit {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -10px -7px -10px 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--entry-accent);
}
.entry-edit svg { width: 14px; height: 14px; }
.book-search { padding: 20px 18px; }
.book-stickers { color: var(--cobalt); font-size: .9rem; }
.avatar {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: .75rem;
  font-weight: 750;
}
.avatar.member-2 { color: var(--clay); background: var(--warm); }
.profile-button { width: 44px; height: 44px; padding: 0; border: 1px solid #c7d0e5; font-size: 1.05rem; }
.profile-button.member-2 { border-color: #d9c8a6; }
.section-heading { margin-bottom: 18px; }
.section-heading h2 { font-size: 1.75rem; letter-spacing: -.035em; }
.search-field { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; align-items: center; gap: 9px; }
.search-field select { appearance: auto; min-width: 0; font: inherit; }
.search-note { margin-top: 12px; color: var(--muted); font-size: .9rem; }
.connection {
  margin-bottom: 13px;
  padding: 9px 12px;
  border: 1px solid #eed9d0;
  border-radius: 10px;
  background: #fff2eb;
  color: #764b3e;
  font-size: .875rem;
}

.action-bar {
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid #cfc7b4;
  background: #f6f3e9;
  backdrop-filter: blur(12px);
}
.bar-frame { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: 12px; max-width: 438px; min-height: 53px; }
#profile-button { grid-column: 3; }
.members-caption { grid-column: 2; justify-self: center; display: flex; align-items: center; min-width: 0; max-width: 100%; gap: 7px; color: var(--muted); font-size: .875rem; }
.members-caption .avatar + .avatar { margin-left: -13px; border: 2px solid #f6f3e9; }
.members-caption .caption-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dialog {
  padding: 0;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 20px 70px #211e1846;
}
dialog::backdrop { background: #211e1870; }
.sheet { width: min(560px, calc(100vw - 32px)); max-height: calc(var(--viewport-height) - 30px); border-radius: 24px; }
#editor { width: min(430px, calc(100vw - 24px)); }
#editor, #editor .sheet-header, #editor .sheet-footer { background: var(--detail-paper); }
.sheet-layout {
  display: flex;
  flex-direction: column;
  max-height: calc(var(--viewport-height) - 32px);
  padding-bottom: 1px;
}
.sheet-header, .sheet-footer { flex: none; padding: 13px 20px; background: var(--paper); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); }
.sheet-header h2 { font-size: 1.37rem; }
.sheet-context { margin-bottom: 3px; color: var(--muted); font-size: .875rem; }
.close-button { background: var(--surface); border-color: transparent; }
.sheet-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 16px 20px 20px; }
.date-inputs { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 10px; margin-bottom: 14px; }
.date-inputs label, #details label { display: grid; gap: 6px; }
.date-inputs input { margin-top: 5px; }
.editor-label { display: block; margin-bottom: 7px; }
textarea { display: block; resize: vertical; line-height: 1.55; }
#details { margin-top: 13px; }
#details summary {
  min-height: 44px;
  padding-block: 10px;
  color: var(--accent-deep);
  font-size: .9rem;
  font-weight: 650;
  cursor: pointer;
}
#details label { margin: 7px 0 4px; }
#details input { margin-bottom: 7px; }
.photo-picker, .photo-previews { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.photo-picker { margin-top: 10px; }
.photo-picker .secondary { cursor: pointer; }
.photo-picker:has(#entry-photos:focus-visible) #photo-label,
.photo-picker:has(#entry-camera:focus-visible) #camera-label { outline: 3px solid #274195; outline-offset: 3px; }
.photo-picker .secondary[aria-disabled="true"] { opacity: .65; cursor: default; }
.photo-picker svg { width: 18px; height: 18px; }
.photo-picker span { color: var(--muted); font-size: .875rem; }
.photo-preview { position: relative; margin: 7px 0 0; }
.photo-preview img { display: block; width: 72px; height: 72px; object-fit: cover; border-radius: 9px; background: var(--surface); }
.photo-preview .remove-preview {
  position: absolute;
  top: -4px;
  right: -4px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--accent-deep);
  color: white;
}
.photo-preview svg { width: 16px; height: 16px; }
.make-sticker { display: block; min-width: 72px; min-height: 44px; margin-top: 4px; padding: 0 4px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--accent-deep); font-size: .75rem; }
.make-sticker[aria-pressed="true"] { background: var(--accent-deep); color: white; }
.sheet-footer { border-top: 1px solid var(--line); }
.sheet-footer .error { margin-bottom: 7px; }
#sticker-library, #sticker-library :is(.sheet-header, .sheet-footer) { background: var(--detail-paper); }
#sticker-library { --sticker-gutter: 20px; }
#sticker-library :is(.sheet-header, .sheet-footer) { border: 0; }
#sticker-library .sheet-scroll { padding-block-start: 6px; padding-inline: var(--sticker-gutter); }
#close-sticker-library { background: transparent; }
.sticker-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 6px;
  margin-block: 8px;
}
.sticker-picker:empty { display: none; }
.sticker-choice, .sticker-source {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 5px;
  border: 0;
  background: transparent;
}
.sticker-choice[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: 3px;
  right: 4px;
  color: var(--cobalt);
  font-weight: 750;
}
.sticker-picker img { display: block; width: 100%; height: 100%; object-fit: contain; }
.sticker-source img { object-fit: cover; border-radius: 4px; }
.sticker-source[data-generated="true"]::after {
  content: "已生成";
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 2px 3px;
  background: var(--detail-paper);
  font-size: .7rem;
}
.sticker-status { color: var(--muted); font-size: .85rem; line-height: 1.45; }
.sticker-section-heading, .sticker-library-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sticker-section-heading h3 { margin: 0; font-size: 1rem; }
.sticker-section-heading .text-button { color: var(--cobalt); font-size: .82rem; }
.sticker-layout-preview {
  position: relative;
  min-height: 220px;
  max-width: 414px;
  margin: 8px auto;
  padding: 0;
  list-style: none;
  touch-action: none;
}
.sticker-layout-preview::before {
  content: "";
  position: absolute;
  inset: 7px auto 18px 50%;
  width: 5px;
  border-radius: 2.5px;
  background: var(--timeline-ink);
  transform: translateX(-50%);
}
.sticker-layout-preview :is(.branches, .counts) { visibility: hidden; }
.sticker-choice, .sticker-layout-preview .sticker {
  cursor: grab;
  touch-action: none;
  pointer-events: auto;
  user-select: none;
  -webkit-touch-callout: none;
}
.sticker-library-dragging { opacity: .35; }
.sticker-layout-preview .sticker.is-transforming { z-index: 3; }
#sticker-drag-image {
  position: absolute;
  z-index: 3;
  width: 74px;
  height: 74px;
  object-fit: contain;
  translate: -50% -50%;
  filter: drop-shadow(0 2px 2px #39281c45);
  pointer-events: none;
}
#sticker-sources { margin-bottom: 8px; }
#sticker-sources summary { min-height: 44px; padding-block: 9px; color: var(--cobalt); font-size: .9rem; cursor: pointer; }
.sticker-library-footer { position: relative; flex-wrap: wrap; }
.sticker-library-footer #sticker-count { margin-right: auto; }
#sticker-remove-zone {
  position: absolute;
  inset: 8px 16px;
  z-index: 2;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #f5e3de;
  color: var(--danger);
  font-size: .9rem;
  font-weight: 650;
  pointer-events: none;
}
#sticker-remove-zone.is-over { z-index: 4; background: #9c354cec; color: white; }
.sheet-actions, .confirm-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.sheet-actions .danger { margin-right: auto; }
.settings .sheet-scroll { padding-bottom: 18px; }
.settings-member { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; color: var(--accent-deep); font-weight: 650; }
.settings-member .avatar { width: 35px; height: 35px; font-size: .9rem; }
.settings-link {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-height: 49px;
  padding: 9px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--accent-deep);
  font-weight: 650;
  text-align: left;
  text-decoration: none;
}
.settings-link span { color: var(--muted); font-size: .875rem; font-weight: 500; }
.settings .error { margin-top: 9px; }
.confirmation { width: min(400px, calc(100vw - 32px)); padding: 20px; border-radius: 19px; }
.confirmation h2 { font-size: 1.23rem; }
.confirmation p { margin: 9px 0 16px; color: var(--muted); line-height: 1.5; }
.lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: calc(60px + env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
  border: 0;
  background: transparent;
  box-shadow: none;
}
.lightbox[open] { display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; }
.lightbox::backdrop { background: #151310f0; }
.lightbox img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .close-button { position: absolute; right: max(10px, env(safe-area-inset-right)); top: max(8px, env(safe-area-inset-top)); }
.toast {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: calc(64px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100vw - 36px);
  transform: translateX(-50%);
  padding: 10px 15px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: .9rem;
  pointer-events: none;
}
.toast:empty { display: none; }

@media (max-width: 600px) {
  .sheet, #editor {
    position: fixed;
    inset: auto 0 auto;
    top: calc(var(--viewport-top) + var(--viewport-height));
    transform: translateY(-100%);
    width: 100%;
    max-width: none;
    max-height: calc(var(--viewport-height) - 8px);
    margin: 0;
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: 23px 23px 0 0;
  }
  .sheet-layout { max-height: calc(var(--viewport-height) - 9px - env(safe-area-inset-bottom)); }
}
@media (max-width: 500px) {
  .journal-page { padding: 0; }
  .journal .screen { min-height: calc(100dvh - 54px - env(safe-area-inset-bottom)); border: 0; border-radius: 0; }
}
@media (max-width: 438px) {
  .sticker-layout-preview {
    width: calc(100% + var(--sticker-gutter) * 2);
    max-width: none;
    margin-inline: calc(-1 * var(--sticker-gutter));
  }
}
@media (max-width: 350px) {
  #sticker-library { --sticker-gutter: 13px; }
  .frame { padding-inline: max(13px, env(safe-area-inset-left)) max(13px, env(safe-area-inset-right)); }
  .sheet-header, .sheet-footer, .sheet-scroll { padding-inline: 13px; }
}
