:root {
  --paper: #f5ebe6;
  --paper-deep: #eadfd8;
  --fig: #3d1e38;
  --ochre: #d97443;
  --slate: #2c3e50;
  --ice: #e2e8f0;
  --ink-soft: rgba(61, 30, 56, .58);
  --line: rgba(61, 30, 56, .15);
  --serif: "Playfair Display", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;
  --page: min(100%, 680px);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); scroll-behavior: smooth; }
body { min-width: 320px; min-height: 100%; margin: 0; overflow-x: hidden; background: var(--paper); color: var(--fig); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
.eyebrow { margin: 0 0 9px; font: 700 9px/1 var(--sans); letter-spacing: 1.7px; opacity: .54; }

.notebook-shell { width: var(--page); min-height: 100dvh; margin: 0 auto; transition: filter .5s ease, transform .5s ease; }
body[data-auth="checking"] .notebook-shell,
body[data-auth="locked"] .notebook-shell { pointer-events: none; user-select: none; }

.notebook-topbar { position: sticky; z-index: 6; top: 0; display: flex; align-items: center; justify-content: space-between; width: 100%; padding: max(16px, env(safe-area-inset-top)) 20px 12px; background: linear-gradient(to bottom, rgba(245,235,230,.98) 72%, rgba(245,235,230,0)); }
.brand-lockup { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark, .auth-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--fig); color: var(--paper); font: italic 21px var(--serif); }
.brand-lockup strong { display: block; font: 600 19px var(--serif); letter-spacing: -.35px; }
.brand-lockup small { display: block; margin-top: 1px; font-size: 8px; letter-spacing: 1.35px; text-transform: uppercase; opacity: .52; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.sync-whisper { max-width: 110px; overflow: hidden; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; opacity: .48; }
.icon-button, .back-button, .tray-close, .dialog-close { display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 50%; background: transparent; color: var(--fig); font-size: 22px; text-decoration: none; }
.icon-button:active, .back-button:active, .tray-close:active, .dialog-close:active { transform: scale(.92); background: rgba(61,30,56,.08); }

.notebook-main { min-height: calc(100dvh - 72px); }
.route-view { display: none; animation: page-enter .32s cubic-bezier(.2,.8,.2,1); }
body[data-route="/"] .timeline-view { display: block; }
body[data-route="/write"] .writing-view,
body[data-route="/write/share"] .writing-view { display: block; }

.timeline-view { padding: 24px 22px max(140px, calc(env(safe-area-inset-bottom) + 112px)); }
.welcome-row { display: flex; align-items: end; justify-content: space-between; padding: 10px 4px 30px; }
.welcome-row h1 { margin: 0; font: 500 clamp(36px, 10vw, 48px)/1.01 var(--serif); letter-spacing: -1.8px; }
.welcome-row h1 em { color: var(--ochre); font-weight: 500; }
.presence-stack { position: relative; display: flex; padding: 0 7px 6px 0; }
.avatar, .tiny-avatar { display: grid; place-items: center; border-radius: 50%; color: white; font-family: var(--serif); }
.avatar { width: 38px; height: 38px; border: 2px solid var(--paper); font-size: 14px; }
.avatar-one { background: var(--ochre); }
.avatar-two { margin-left: -10px; background: var(--slate); }
.presence-dot { position: absolute; right: 0; bottom: 1px; width: 10px; height: 10px; border: 2px solid var(--paper); border-radius: 50%; background: #b59378; }
.presence-dot.connected { background: #6da17f; }

.memory-strip { display: flex; align-items: center; gap: 13px; margin: 0 0 38px; padding: 17px; background: var(--paper-deep); box-shadow: 0 12px 25px rgba(61,30,56,.06); transform: rotate(-.55deg); }
.memory-pin { display: grid; place-items: center; flex: 0 0 30px; height: 30px; border: 1px solid var(--ochre); border-radius: 50%; color: var(--ochre); }
.memory-strip p:last-child { margin: 0; font: italic 14px/1.35 var(--serif); }
.memory-date { align-self: flex-start; margin-left: auto; font-size: 9px; opacity: .45; }
.feed-heading { display: flex; align-items: end; justify-content: space-between; margin: 0 4px 20px; }
.feed-heading h2 { margin: 0; font: 500 21px var(--serif); }
.quiet-link { padding: 8px 0; color: var(--ochre); font-size: 9px; font-weight: 700; text-decoration: none; }
.feed { display: flex; flex-direction: column; gap: 30px; }
.day-group { display: grid; gap: 13px; }
.day-label { margin: 0 0 0 7px; font-size: 8px; font-weight: 700; letter-spacing: 1.5px; opacity: .42; }
.fragment { position: relative; isolation: isolate; padding: 21px 20px 20px; background: #fbf6f2; box-shadow: 0 15px 32px rgba(61,30,56,.09); animation: fragment-enter .46s both cubic-bezier(.2,.8,.2,1); }
.fragment:nth-of-type(even) { margin-left: 13px; transform: rotate(.42deg); }
.fragment:nth-of-type(odd) { margin-right: 13px; transform: rotate(-.36deg); }
.fragment::before { position: absolute; z-index: -1; top: -6px; left: 22%; width: 48px; height: 12px; background: rgba(217,116,67,.24); content: ""; transform: rotate(-3deg); pointer-events: none; }
.fragment[data-person="collins"]::before { right: 22%; left: auto; background: rgba(44,62,80,.22); transform: rotate(4deg); }
.fragment-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.tiny-avatar { width: 25px; height: 25px; margin: 0; font-size: 10px; }
.fragment-author { font-size: 10px; font-weight: 700; }
.fragment-time { margin-left: auto; font-size: 9px; opacity: .45; }
.fragment-content { display: grid; gap: 13px; }
.fragment-content p { margin: 0; font: 500 18px/1.48 var(--serif); }
.fragment-content h2, .fragment-content h3, .fragment-content h4 { margin: 1px 0; font-family: var(--serif); font-weight: 500; line-height: 1.1; }
.fragment-content h2 { font-size: 29px; }
.fragment-content h3 { font-size: 24px; }
.fragment-content h4 { font-size: 21px; }
.fragment-content em { color: var(--ochre); }
.fragment-media { margin: 4px 0; }
.fragment-media img { display: block; width: 100%; max-height: 440px; object-fit: cover; opacity: 0; transition: opacity .35s ease; }
.fragment-media img.loaded { opacity: 1; }
.fragment[data-person="nina"] .fragment-media img { clip-path: polygon(2% 5%,95% 0,100% 83%,84% 100%,5% 92%); }
.fragment[data-person="collins"] .fragment-media img { clip-path: polygon(0 6%,91% 0,100% 18%,95% 100%,5% 92%); }
.media-placeholder { min-height: 180px; background: linear-gradient(110deg, var(--paper-deep), #f7f0ec, var(--paper-deep)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.image-caption { display: block; margin: 7px 5px 0; font: italic 10px var(--serif); opacity: .55; }
.sticker { display: inline-flex; align-items: center; gap: 8px; width: fit-content; max-width: 100%; min-height: 38px; padding: 7px 10px; overflow: hidden; border: 1px dashed currentColor; border-radius: 5px; background: #fffdfb; color: var(--slate); font: 700 10px var(--sans); text-decoration: none; }
.sticker::before { display: grid; place-items: center; width: 20px; height: 20px; flex: 0 0 20px; border: 1px solid var(--ochre); content: "↗"; }
.sticker span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { display: none; padding: 68px 20px; text-align: center; }
.empty-state.visible { display: block; }
.empty-state > span { color: var(--ochre); font-size: 25px; }
.empty-state h2 { margin: 13px 0 6px; font: italic 23px var(--serif); }
.empty-state p { margin: 0; font-size: 11px; opacity: .55; }
.compose-dock { position: fixed; z-index: 5; right: max(22px, calc((100vw - 680px) / 2 + 22px)); bottom: max(18px, env(safe-area-inset-bottom)); display: grid; grid-template: 20px 16px / 42px auto; column-gap: 11px; width: min(280px, calc(100% - 44px)); padding: 10px 17px 10px 10px; border-radius: 24px 12px 24px 12px; background: var(--fig); color: var(--paper); box-shadow: 0 16px 38px rgba(61,30,56,.28); text-decoration: none; }
.compose-dock:active { transform: scale(.97) rotate(-.5deg); }
.compose-dock > span { grid-row: 1 / 3; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--ochre); font-size: 26px; }
.compose-dock strong { align-self: end; font-size: 11px; }
.compose-dock small { align-self: start; font-size: 8px; opacity: .62; }

.writing-view { min-height: calc(100dvh - 72px); padding-bottom: max(42px, env(safe-area-inset-bottom)); }
.writing-header { display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 10px; padding: 18px 20px 16px; border-bottom: 1px solid var(--line); }
.writing-header .eyebrow { margin-bottom: 4px; }
.writing-header h1 { margin: 0; font: 500 21px var(--serif); }
.publish-button { min-height: 42px; padding: 0 4px; border: 0; background: transparent; color: var(--ochre); font-size: 10px; font-weight: 700; }
.publish-button[disabled] { opacity: .4; }
.writing-paper { padding: 22px 24px 60px; }
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.author-switch, .tool-actions { display: flex; align-items: center; gap: 6px; }
.author-choice, .tool-button { display: inline-flex; align-items: center; min-height: 42px; border: 1px solid transparent; background: transparent; color: var(--fig); font-size: 10px; font-weight: 700; text-decoration: none; }
.author-choice { gap: 6px; padding: 5px 9px 5px 5px; border-radius: 22px; opacity: .48; }
.author-choice.selected { border-color: var(--line); background: rgba(255,255,255,.42); opacity: 1; }
.tool-button { gap: 5px; padding: 8px; border-radius: 5px; }
.tool-button:active, .tool-button[aria-current="page"] { background: var(--paper-deep); }
.echo-button { color: var(--ochre); }
.editor-wrap { position: relative; min-height: 54dvh; }
.editor { min-height: 54dvh; outline: 0; caret-color: var(--ochre); font: 500 21px/1.55 var(--serif); overflow-wrap: anywhere; }
.editor[data-empty="true"]::before { color: rgba(61,30,56,.28); content: attr(data-placeholder); font-style: italic; pointer-events: none; }
.editor p, .editor div { margin: 0 0 16px; }
.editor h2, .editor h3, .editor h4 { margin: 24px 0 14px; font-family: var(--serif); font-weight: 500; line-height: 1.06; letter-spacing: -1px; }
.editor h2 { font-size: 38px; }
.editor h3 { font-size: 30px; }
.editor h4 { font-size: 24px; }
.editor em { color: var(--ochre); }
.editor figure { position: relative; margin: 26px 0; }
.editor figure img { display: block; width: 100%; max-height: 440px; object-fit: cover; clip-path: polygon(1% 5%,95% 0,100% 87%,84% 100%,4% 93%); }
.editor figure button { position: absolute; top: 9px; right: 9px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(61,30,56,.8); color: white; }
.editor .sticker { margin: 3px 2px; vertical-align: middle; }
.drop-hint { position: absolute; inset: 0; display: none; place-items: center; border: 1px dashed var(--ochre); background: rgba(245,235,230,.93); color: var(--ochre); font: italic 17px var(--serif); pointer-events: none; }
.drop-hint.visible { display: grid; }
.drop-hint span { display: block; margin-bottom: 5px; font: 24px var(--sans); text-align: center; }
.editor-footer { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 9px; line-height: 1.5; }
.editor-footer kbd { padding: 1px 4px; border: 1px solid var(--line); border-radius: 3px; background: white; font: 10px var(--sans); }

.echo-tray { display: none; margin: 0 0 28px; padding: 22px; border: 1px solid rgba(61,30,56,.15); background: var(--paper-deep); box-shadow: 0 16px 34px rgba(61,30,56,.08); animation: tray-open .32s cubic-bezier(.2,.8,.2,1); }
body[data-route="/write/share"] .echo-tray { display: block; }
.echo-heading { display: flex; align-items: start; justify-content: space-between; }
.echo-heading h2 { margin: 0; font: 500 28px/1.05 var(--serif); letter-spacing: -1px; }
.tray-close { margin: -8px -8px 0 0; }
.echo-copy { max-width: 470px; margin: 14px 0 22px; font: 14px/1.45 var(--serif); }
.field-label { display: block; margin: 0 0 7px; font-size: 8px; font-weight: 700; letter-spacing: 1.4px; opacity: .55; }
.code-field { display: flex; background: rgba(255,255,255,.48); }
.code-field input { min-width: 0; flex: 1; padding: 13px 12px; border: 0; outline: 0; background: transparent; color: var(--fig); font: 600 21px var(--sans); letter-spacing: 3px; text-transform: uppercase; }
.code-field button { width: 48px; border: 0; background: transparent; color: var(--fig); font-size: 18px; }
.echo-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; margin-top: 10px; }
.primary-button, .secondary-button, .text-button { min-height: 42px; border-radius: 5px; font-size: 10px; font-weight: 700; }
.primary-button { padding: 12px 14px; border: 0; background: var(--fig); color: var(--paper); }
.secondary-button { padding: 11px 13px; border: 1px solid rgba(61,30,56,.28); background: transparent; color: var(--fig); }
.text-button { padding: 8px 9px; border: 0; background: transparent; color: var(--ochre); }
.previous-label { margin-top: 22px; }
#previousEchoes { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 5px; outline: 0; background: rgba(255,255,255,.48); color: var(--fig); }
.echo-status { display: grid; grid-template-columns: 9px auto 1fr; align-items: center; gap: 8px; margin-top: 16px; font-size: 9px; }
.echo-status span:last-child { overflow: hidden; opacity: .58; text-overflow: ellipsis; white-space: nowrap; }
.status-light { width: 8px; height: 8px; border-radius: 50%; background: #c89e56; box-shadow: 0 0 0 3px rgba(200,158,86,.14); }
.status-light.connected { background: #6da17f; }
.echo-sync-actions { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 10px; }
#manualPayload { width: 100%; margin-top: 4px; padding: 12px; resize: vertical; border: 1px solid var(--line); border-radius: 5px; outline: 0; background: rgba(255,255,255,.42); color: var(--fig); font: 9px/1.45 ui-monospace, SFMono-Regular, monospace; }
.import-payload { display: block; margin-left: auto; }

.auth-veil { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: max(22px, env(safe-area-inset-top)) 22px max(22px, env(safe-area-inset-bottom)); overflow: auto; background: rgba(61,30,56,.08); backdrop-filter: blur(20px) saturate(.72); -webkit-backdrop-filter: blur(20px) saturate(.72); transition: opacity .48s ease, backdrop-filter .48s ease, visibility .48s; }
body[data-auth="verified"] .auth-veil { visibility: hidden; opacity: 0; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); pointer-events: none; }
.auth-card { width: min(100%, 390px); padding: 28px 25px 25px; border: 1px solid rgba(245,235,230,.2); border-radius: 6px; background: rgba(61,30,56,.94); color: var(--paper); box-shadow: 0 30px 80px rgba(35,14,32,.34); }
.auth-mark { margin-bottom: 28px; background: var(--paper); color: var(--fig); }
.auth-card h2 { margin: 0; font: 500 35px/1.04 var(--serif); letter-spacing: -1.3px; }
.auth-card h2 em { color: var(--ochre); font-weight: 500; }
.auth-status { min-height: 40px; margin: 18px 0; font: italic 13px/1.45 var(--serif); opacity: .7; }
.pin-fields { display: grid; gap: 8px; }
.pin-fields label { font-size: 8px; font-weight: 700; letter-spacing: 1.4px; opacity: .62; }
.pin-fields input { width: 100%; height: 54px; padding: 0 14px; border: 1px solid rgba(245,235,230,.28); border-radius: 5px; outline: 0; background: rgba(245,235,230,.08); color: var(--paper); font-size: 24px; letter-spacing: 10px; text-align: center; }
.pin-fields input:focus { border-color: var(--ochre); box-shadow: 0 0 0 3px rgba(217,116,67,.16); }
.pin-fields small { margin-bottom: 5px; font-size: 8px; opacity: .5; }
.auth-card .primary-button { background: var(--ochre); }
.biometric-button { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 11px; width: 100%; min-height: 58px; margin-top: 11px; padding: 8px; border: 1px solid rgba(245,235,230,.22); border-radius: 5px; background: transparent; color: var(--paper); text-align: left; }
.biometric-button > span:first-child { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: rgba(245,235,230,.1); font-size: 23px; }
.biometric-button strong, .biometric-button small { display: block; }
.biometric-button strong { font-size: 10px; }
.biometric-button small { margin-top: 3px; font-size: 8px; opacity: .52; }

.link-dialog { width: min(calc(100% - 28px), 580px); margin: auto auto 0; padding: 25px 23px max(28px, env(safe-area-inset-bottom)); border: 0; border-radius: 24px 24px 0 0; background: var(--paper); color: var(--fig); box-shadow: 0 -18px 55px rgba(61,30,56,.22); }
.link-dialog[open] { animation: tray-open .28s cubic-bezier(.2,.8,.2,1); }
.link-dialog::backdrop { background: rgba(61,30,56,.4); backdrop-filter: blur(4px); }
.dialog-close { position: absolute; top: 10px; right: 12px; }
.preview-card { padding: 10px 0; }
.preview-site { font-size: 9px; letter-spacing: 1.5px; opacity: .5; }
.preview-card h2 { margin: 12px 0; font: 500 31px/1.08 var(--serif); overflow-wrap: anywhere; }
.preview-card p { font: 15px/1.5 var(--serif); }
.preview-card a { color: var(--ochre); font-size: 11px; font-weight: 700; }
.toast { position: fixed; z-index: 120; left: 50%; bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px)); max-width: calc(100% - 40px); padding: 11px 15px; border-radius: 5px; background: var(--fig); color: var(--paper); font-size: 10px; opacity: 0; pointer-events: none; transform: translate(-50%,10px); transition: .24s; box-shadow: 0 10px 30px rgba(61,30,56,.2); }
.toast.show { opacity: 1; transform: translate(-50%,0); }

@keyframes page-enter { from { opacity: 0; transform: translateY(10px); } }
@keyframes fragment-enter { from { opacity: 0; transform: translateY(12px); } }
@keyframes tray-open { from { opacity: 0; transform: translateY(18px); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (max-width: 470px) {
  .sync-whisper { display: none; }
  .timeline-view { padding-right: 20px; padding-left: 20px; }
  .writing-paper { padding-right: 20px; padding-left: 20px; }
  .editor-toolbar { align-items: flex-start; flex-direction: column; }
  .tool-actions { width: 100%; justify-content: flex-end; }
  .writing-header { grid-template-columns: 42px 1fr auto; padding-right: 16px; padding-left: 16px; }
  .writing-header h1 { font-size: 18px; }
  .echo-tray { margin-right: -4px; margin-left: -4px; padding: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
