:root {
  color-scheme: light;
  --ink: #34325e;
  --muted: #747391;
  --paper: #fffaf0;
  --card: #ffffff;
  --line: #e7e3f4;
  --accent: #7668df;
  --green: #28a995;
  --pink: #ff789b;
  --yellow: #ffd85a;
  --sky: #bce8ff;
  --shadow: 0 16px 48px rgba(91, 82, 150, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: #dff3ef; color: var(--ink); }
button, input, textarea { font: inherit; }
button { cursor: pointer; transition: transform .16s ease, background-color .16s ease, color .16s ease, border-color .16s ease, box-shadow .16s ease; }
button:not(:disabled):active { transform: translateY(1px) scale(.99); }
button:focus-visible { outline: 3px solid rgba(118, 104, 223, .2); outline-offset: 2px; }
.phone {
  width: min(100%, 430px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--paper);
  padding: max(18px, env(safe-area-inset-top)) 18px 110px;
  overflow: hidden;
}
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.brand { font: 800 23px/1 Georgia, serif; letter-spacing: -1px; }
.brand i { color: var(--accent); font-style: normal; }
.main-nav { display: flex; gap: 4px; max-width: 310px; padding: 4px; overflow-x: auto; border-radius: 99px; background: #efebff; scrollbar-width: none; }
.main-nav button { border: 0; border-radius: 99px; padding: 7px 10px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.main-nav button:hover { color: var(--accent); }
.main-nav button.active { background: var(--card); color: var(--accent); box-shadow: 0 3px 10px rgba(91, 82, 150, .1); }
.main-nav i { display: inline-grid; min-width: 17px; height: 17px; padding: 0 4px; place-items: center; border-radius: 99px; background: #ddd8ff; color: #5e53bd; font-size: 10px; font-style: normal; }
.nav-user { display: flex; align-items: center; gap: 6px; }
.nav-user-btn { display: flex; align-items: center; gap: 6px; border: 0; background: transparent; cursor: pointer; padding: 4px 8px; border-radius: 10px; }
.nav-user-btn:hover { background: #f5f2ff; }
.nav-user-btn.active { background: #f5f2ff; }
.nav-avatar { width: 28px; height: 28px; border-radius: 8px; background: var(--yellow); color: #62582f; font-weight: 900; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-name { font-size: 12px; font-weight: 600; color: var(--ink); max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-arrow { font-size: 10px; color: var(--muted); transition: transform 0.2s; }
.nav-arrow.open { transform: rotate(180deg); }
.nav-user-static { display: flex; align-items: center; gap: 6px; }
.page-header { margin-bottom: 16px; }
.page-header .eyebrow { display: block; font-size: 10px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--accent); }
.page-header h1 { font: 700 20px/1.3 Georgia, "Songti SC", serif; margin: 2px 0 4px; }
.page-header .lead { color: var(--muted); font-size: 12px; margin: 0; }
.account-bar {
  display: flex; align-items: center; gap: 10px; margin: -10px 0 22px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.72);
}
.user-avatar { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; border-radius: 12px; background: var(--yellow); color: #62582f; font-weight: 900; }
.user-copy { min-width: 0; flex: 1; }
.user-copy b, .user-copy small { display: block; }
.user-copy b { color: var(--ink); font-size: 13px; }
.user-copy small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.account-required { color: var(--muted); font-size: 13px; }
.account-logout { margin-left: auto; }
.admin-badge { display: inline-block; margin-left: 5px; padding: 2px 6px; border-radius: 99px; background: #fff0b8; color: #7c6521; font-size: 9px; font-style: normal; vertical-align: middle; }
.admin-dropdown { position: relative; }
.admin-dropdown-menu { position: absolute; top: 100%; right: 0; margin-top: 6px; padding: 6px 0; border: 1px solid var(--line); border-radius: 12px; background: white; box-shadow: 0 8px 24px rgba(0,0,0,.1); z-index: 100; min-width: 120px; }
.admin-dropdown-menu button { display: block; width: 100%; padding: 8px 16px; border: 0; background: transparent; color: var(--ink); font-size: 12px; text-align: left; cursor: pointer; }
.admin-dropdown-menu button:hover { background: #f5f2ff; }
.admin-dropdown-menu button.active { color: var(--accent); font-weight: 600; }
.auth-empty { margin-top: 70px; padding: 34px 24px; border: 1px dashed #aaa1df; border-radius: 22px; text-align: center; }
.auth-empty h1 { font-size: 25px; }
.auth-empty p { color: var(--muted); line-height: 1.6; }
.auth-card { margin-top: 36px; padding: 30px 24px; border: 1px solid #ddd7ff; border-radius: 24px; background: rgba(255,255,255,.9); box-shadow: 0 18px 50px rgba(78,65,145,.1); }
.auth-card h1 { margin: 8px 0; font-size: 29px; }
.auth-card > p { color: var(--muted); line-height: 1.6; }
.auth-form { display: grid; gap: 14px; margin-top: 22px; }
.auth-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 800; }
.auth-form input { width: 100%; box-sizing: border-box; padding: 13px 14px; border: 1px solid #d9d4ee; border-radius: 13px; outline: none; background: white; color: var(--ink); }
.auth-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(118,104,223,.12); }
.auth-switch { display: block; margin: 16px auto 0; }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; }
h1 { font: 700 34px/1.16 Georgia, "Songti SC", serif; margin: 8px 0 12px; }
.lead { color: var(--muted); margin: 0 0 24px; line-height: 1.6; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.section { margin: 18px 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-head h2 { font-size: 16px; margin: 0; }
.counter { color: var(--muted); font-size: 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.photo-wrap { position: relative; aspect-ratio: 1; }
.photo {
  aspect-ratio: 1;
  border-radius: 15px;
  object-fit: cover;
  width: 100%;
  background: #e9e1d3;
}
.photo-remove {
  position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border: 0; border-radius: 50%;
  background: rgba(52, 50, 94, .78); color: white; line-height: 1; font-size: 17px;
}
.photo-add {
  aspect-ratio: 1; border: 1.5px dashed #aaa1df; border-radius: 15px;
  background: #f5f2ff; color: var(--muted); display: grid; place-items: center;
}
.photo-add b { display: block; color: var(--ink); font-size: 28px; font-weight: 400; line-height: 1; }
.photo-add small { font-size: 11px; }
.voice {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 16px;
  border: 0; border-radius: 18px; background: #dff8f1; color: #168a78; text-align: left;
}
.voice:disabled { cursor: not-allowed; opacity: .72; }
.voice-dot { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--green); color: white; font-size: 20px; }
.voice.recording .voice-dot { animation: pulse 1s infinite; background: var(--accent); }
@keyframes pulse { 50% { transform: scale(.88); opacity: .72; } }
.voice span { display: block; font-weight: 700; }
.voice small { color: #57968b; }
.story-editor {
  margin-bottom: 10px; padding: 14px 14px 8px; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card);
}
.story-editor textarea {
  display: block; width: 100%; min-height: 118px; padding: 0; resize: vertical; border: 0; outline: 0;
  background: transparent; color: var(--ink); line-height: 1.65;
}
.story-editor textarea::placeholder { color: #aaa6c1; }
.story-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.audio-draft { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.audio-draft audio, .source-details audio, .saved-detail audio { width: 100%; height: 42px; }
.text-button { flex: 0 0 auto; border: 0; background: transparent; color: var(--accent); font-size: 12px; }
.transcript-tip {
  margin: 10px 2px 0; padding: 10px 12px; border-radius: 12px; background: #eef9ff;
  color: #516b91; font-size: 12px; line-height: 1.55;
}
.styles { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 3px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 9px 14px; white-space: nowrap; color: var(--muted); }
.chip:hover { border-color: #bdb5ee; color: var(--accent); }
.chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.primary {
  width: 100%; border: 0; border-radius: 17px; padding: 16px; background: var(--accent);
  color: white; font-weight: 800; box-shadow: 0 10px 25px rgba(118, 104, 223, .28);
}
.primary:hover:not(:disabled) { background: #685bd0; box-shadow: 0 12px 28px rgba(118, 104, 223, .34); }
.primary:disabled { cursor: not-allowed; opacity: .48; box-shadow: none; }
.note { padding: 21px; margin-top: 20px; }
.note h3 { font: 700 24px/1.3 Georgia, "Songti SC", serif; margin: 0 0 12px; }
.note p { white-space: pre-wrap; line-height: 1.75; font-size: 15px; }
.source-details { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 15px; color: var(--muted); }
.source-details summary { color: var(--green); cursor: pointer; font-weight: 700; }
.source-details h4 { color: var(--ink); font-size: 13px; margin: 16px 0 5px; }
.source-details p, .source-details li { font-size: 13px; line-height: 1.6; }
.source-details ol { padding-left: 20px; }
.note-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 18px; }
.secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid #d8d2f1; background: white; border-radius: 13px; padding: 12px;
  color: var(--accent); font-weight: 700;
}
.secondary:hover { border-color: #aaa1df; background: #f7f5ff; box-shadow: 0 6px 16px rgba(91, 82, 150, .1); }
.secondary:disabled { cursor: not-allowed; opacity: .5; }
.compact-button { flex: 0 0 auto; padding: 10px 13px; font-size: 12px; }
.button-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.notes-page h1 { margin-bottom: 4px; }
.notes-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.notes-title p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.notes-status { display: flex; justify-content: space-between; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.saved { margin-top: 0; }
.saved-card {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px; padding: 12px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--card);
  cursor: pointer;
}
.saved-card:hover { background: #f9f7ff; }
.saved-card:active { background: #f0edff; }
.saved-thumb { width: 54px; height: 54px; border-radius: 12px; object-fit: cover; background: #efebff; flex-shrink: 0; }
.saved-info { flex: 1; min-width: 0; }
.saved-info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.saved-info small { display: block; color: var(--muted); margin-top: 4px; font-size: 12px; }
.saved-arrow { width: 20px; height: 20px; flex-shrink: 0; color: var(--muted); }
.saved-detail { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.saved-detail > p { white-space: pre-wrap; line-height: 1.7; font-size: 14px; }
.saved-detail h4 { margin: 15px 0 5px; font-size: 12px; color: var(--green); }
.saved-photos { display: flex; gap: 7px; overflow-x: auto; padding: 3px 0; }
.saved-photos img { width: 78px; height: 78px; flex: 0 0 78px; border-radius: 11px; object-fit: cover; }
.saved-actions { display: flex; align-items: center; justify-content: flex-end; margin-top: 18px; }
.danger-button { flex: 0 0 auto; border: 0; background: transparent; color: #a85577; padding: 10px 4px; font-size: 12px; }
.danger-button:hover { color: #873d5c; background: #fff2f6; border-radius: 10px; padding-left: 10px; padding-right: 10px; }
.empty { color: var(--muted); font-size: 14px; padding: 14px 0; }
.notes-empty { margin-top: 40px; padding: 36px 24px; border: 1px dashed #bdb5ee; border-radius: 22px; background: rgba(255,255,255,.45); text-align: center; }
.notes-empty span { display: block; font: 700 21px Georgia, "Songti SC", serif; }
.notes-empty p { margin: 10px 0 20px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.notes-empty .primary { width: auto; padding-left: 24px; padding-right: 24px; }
.load-more-trigger { padding: 20px; text-align: center; cursor: pointer; }
.load-more-trigger span { display: inline-block; padding: 10px 20px; border-radius: 99px; background: #f5f2ff; color: var(--accent); font-size: 13px; font-weight: 600; }
.load-more-trigger:active span { background: #e8e4ff; }
.notes-end { padding: 20px; text-align: center; color: var(--muted); font-size: 12px; }

/* Note detail page */
.note-detail { padding: 0 0 40px; }
.note-detail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.back-btn { display: flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--accent); font-size: 14px; font-weight: 600; padding: 8px 0; cursor: pointer; }
.back-btn:hover { opacity: 0.7; }
.note-date { color: var(--muted); font-size: 12px; }
.note-detail h1 { font: 700 26px/1.3 Georgia, "Songti SC", serif; margin: 0 0 16px; }
.note-body { white-space: pre-wrap; line-height: 1.8; font-size: 15px; color: #4d5371; margin: 0 0 20px; }
.note-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 20px 0; }
.note-photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; }
.note-source { margin: 16px 0; padding: 14px; background: #f9f7ff; border-radius: 14px; }
.note-source h4 { margin: 0 0 8px; font-size: 12px; color: var(--green); }
.note-source p { margin: 0; white-space: pre-wrap; font-size: 13px; line-height: 1.6; }
.note-source ol { margin: 8px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.7; }
.note-source audio { width: 100%; height: 44px; margin-top: 8px; border-radius: 10px; }
.note-actions { display: flex; gap: 10px; margin-top: 24px; }
.note-actions .secondary { flex: 1; }
.note-actions .danger-button { flex: 0 0 auto; }
.note-empty { text-align: center; padding: 60px 20px; }
.note-empty p { color: var(--muted); margin-bottom: 20px; }
.admin-page h1 { margin: 4px 0 0; }
.admin-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.admin-summary { margin: 0 0 15px; color: var(--muted); font-size: 12px; }
.admin-list, .login-event-list { display: grid; gap: 10px; }
.admin-card, .login-event { padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.admin-card-head, .login-event-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.admin-card-head b, .login-event-head b { font-size: 14px; }
.provider-tag { padding: 4px 8px; border-radius: 99px; background: #efebff; color: var(--accent); font-size: 10px; font-weight: 800; }
.admin-account { margin-top: 5px; overflow: hidden; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.admin-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 13px; }
.admin-metrics span { padding: 10px 6px; border-radius: 12px; background: #f7f5ff; text-align: center; }
.admin-metrics b, .admin-metrics small { display: block; }
.admin-metrics b { font-size: 14px; }
.admin-metrics small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.admin-meta, .login-event-meta { display: grid; gap: 3px; margin-top: 11px; color: var(--muted); font-size: 10px; }
.login-event { border-left-width: 4px; }
.login-event.success { border-left-color: var(--green); }
.login-event.failure { border-left-color: var(--pink); }
.login-event-head span { padding: 3px 7px; border-radius: 99px; font-size: 10px; font-weight: 800; }
.login-event.success .login-event-head span { background: #dff8f1; color: #168a78; }
.login-event.failure .login-event-head span { background: #fff0f4; color: #a85577; }
.login-event-copy { margin-top: 6px; color: var(--muted); font-size: 11px; }
.login-failure { margin-top: 9px; padding: 8px 10px; border-radius: 10px; background: #fff2f6; color: #9b4969; font-size: 11px; }
.login-event details { margin-top: 8px; color: var(--muted); font-size: 10px; }
.login-event details p { overflow-wrap: anywhere; line-height: 1.5; }
.toast {
  position: fixed; z-index: 30; left: 50%; top: 18px; transform: translateX(-50%);
  background: #4d4788; color: white; border-radius: 99px; padding: 10px 16px; font-size: 13px;
}
@media (max-width: 380px) {
  .phone { padding-left: 14px; padding-right: 14px; }
  .brand { font-size: 21px; }
  .main-nav button { padding-left: 8px; padding-right: 8px; font-size: 11px; }
  .account-bar { display: none; }
  .nav-name { display: none; }
  .nav-user-btn { padding: 4px; }
  .notes-title { align-items: center; }
}
@media (min-width: 700px) { .phone { min-height: 920px; box-shadow: 0 0 80px rgba(0,0,0,.15); } }
