:root {
  --bg: #f6f1ea;
  --paper: #fffdf9;
  --ink: #221d17;
  --muted: #847a6e;
  --line: #e6ddd1;
  --accent: #c2562b;
  --accent-ink: #fff;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --paper: #211d18;
    --ink: #f1ebe3;
    --muted: #9c9284;
    --line: #342e27;
    --accent: #e0774a;
    --accent-ink: #1a120c;
    --danger: #ff8a80;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--sans); }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }
.primary { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 12px 22px; font-weight: 600; }
.danger-text { color: var(--danger); }
.code { font: 600 40px/1 ui-monospace, "SF Mono", monospace; letter-spacing: .2em; margin: 8px 0; }

#app {
  position: fixed; left: 0; right: 0; top: 0;
  height: 100%; /* set to the visual viewport height by app.js while the keyboard is up */
  display: flex; flex-direction: column;
}

/* ---------- sign in ---------- */
#signin { flex: 1; display: grid; place-items: center; padding: 24px; text-align: center; }
.signin-inner { max-width: 320px; }
.signin-icon { width: 84px; height: 84px; border-radius: 20px; box-shadow: var(--shadow); }
#signin h1 { font: 600 34px/1.1 var(--serif); margin: 18px 0 6px; }
#signin .primary { margin-top: 20px; width: 100%; }

/* ---------- header ---------- */
#bar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 999px; color: var(--ink); flex: none; }
.icon-btn:active { background: var(--line); }
.icon-btn:disabled { opacity: .25; }
#title { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; padding: 2px 0; }
#title-main { font: 600 20px/1.2 var(--serif); }
#title-sub { font-size: 13px; color: var(--muted); }

/* ---------- days ---------- */
#viewport { flex: 1; position: relative; overflow: hidden; touch-action: pan-y; }
#track { position: absolute; inset: 0; display: flex; width: 300%; left: -100%; will-change: transform; }
#track.anim { transition: transform .26s cubic-bezier(.2, .8, .2, 1); }
.day {
  width: 33.3334%; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px 24px; overscroll-behavior-y: contain;
}
.day-inner { max-width: 640px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding: 22vh 20px 0; }
.empty b { display: block; font: 600 20px/1.3 var(--serif); color: var(--ink); margin-bottom: 4px; }
.loading { text-align: center; color: var(--muted); padding-top: 30vh; }

.entry {
  background: var(--paper); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden;
}
.entry-photos { display: grid; gap: 2px; grid-template-columns: 1fr 1fr; }
.entry-photos.n1 { grid-template-columns: 1fr; }
.entry-photos img { width: 100%; height: 100%; object-fit: cover; display: block; aspect-ratio: 1; background: var(--line); }
.entry-photos.n1 img { aspect-ratio: auto; max-height: 70vh; }
.entry-photos.n3 img:first-child { grid-column: span 2; aspect-ratio: 2 / 1; }
.entry-body { padding: 12px 14px 10px; }
.entry-text { white-space: pre-wrap; overflow-wrap: anywhere; font: 17px/1.5 var(--serif); margin: 0 0 6px; }
.entry-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
.entry-more { padding: 4px 6px; margin: -4px -6px; color: var(--muted); }
.entry-more svg { width: 20px; height: 20px; }

/* ---------- composer ---------- */
#composer {
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px);
}
body.kb #composer { padding-bottom: 8px; }
.compose-row { display: flex; align-items: flex-end; gap: 2px; max-width: 680px; margin: 0 auto; }
#text {
  flex: 1; min-width: 0; resize: none; max-height: 40vh;
  font: 17px/1.35 var(--sans); color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: 22px;
  padding: 10px 14px; margin: 0 4px; outline: none;
}
#text:focus { border-color: var(--muted); }
.send { width: 44px; height: 44px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .3; }
#tray { display: flex; gap: 8px; overflow-x: auto; max-width: 680px; margin: 0 auto; padding: 0 4px; }
#tray:not(:empty) { padding-bottom: 8px; }
.chip { position: relative; flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: var(--line); }
.chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chip.busy img { opacity: .45; }
.chip.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px;
  border: 2px solid var(--paper); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite;
}
.chip.failed { outline: 2px solid var(--danger); }
.chip .x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0, 0, 0, .6); color: #fff; display: grid; place-items: center;
}
.chip .x svg { width: 14px; height: 14px; stroke-width: 2.4; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- sheets ---------- */
.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-card {
  width: 100%; max-width: 520px; background: var(--paper); border-radius: 20px 20px 0 0;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 14px);
}
.sheet-actions { display: flex; align-items: center; gap: 16px; margin-top: 14px; }
.sheet-actions .primary { padding: 10px 20px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-head b { font: 600 18px var(--serif); }
#cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 2px; }
#cal-grid .dow { font-size: 12px; color: var(--muted); padding: 4px 0; }
#cal-grid button { aspect-ratio: 1; border-radius: 12px; position: relative; font-size: 15px; }
#cal-grid button.has::after { content: ""; position: absolute; left: 50%; bottom: 14%; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--accent); }
#cal-grid button.photo { background-size: cover; background-position: center; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .7); font-weight: 600; }
#cal-grid button.photo::after { display: none; }
#cal-grid button.today { outline: 1.5px solid var(--muted); }
#cal-grid button.sel { outline: 2.5px solid var(--accent); }
#cal-grid button:disabled { opacity: .3; }
#edit-text {
  width: 100%; font: 17px/1.5 var(--serif); color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; resize: vertical; outline: none;
}
#edit-photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- photo viewer ---------- */
#viewer { position: fixed; inset: 0; background: #000; z-index: 20; overflow: hidden; touch-action: none; }
#viewer-track { position: absolute; inset: 0; display: flex; will-change: transform; }
#viewer-track.anim { transition: transform .25s ease-out; }
#viewer-track > div { flex: none; width: 100vw; height: 100%; display: grid; place-items: center; }
#viewer-track img { max-width: 100%; max-height: 100%; object-fit: contain; }
#viewer-close { position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 10px; color: #fff; background: rgba(255, 255, 255, .12); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 64px);
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 14px; z-index: 30;
}

/* plain server pages (sign-in confirm) */
body.plain { overflow: auto; display: grid; place-items: center; min-height: 100%; padding: 24px; text-align: center; }
.card { max-width: 360px; }
.card h1 { font: 600 26px/1.2 var(--serif); }
.card .primary { width: 100%; margin-top: 12px; }
