:root {
  --cream: #f4eee4;
  --paper: #fff9f1;
  --ink: #2a221c;
  --muted: #7a6e64;
  --line: rgba(42, 34, 28, 0.1);
  --mint: #6eb8a4;
  --mint-soft: #d8efe7;
  --lilac: #b8a4d8;
  --lilac-soft: #ece4f7;
  --apricot: #e8a87c;
  --apricot-soft: #f8e4d4;
  --lemon: #e8d06a;
  --lemon-soft: #f7efc4;
  --shadow: 0 18px 50px rgba(80, 50, 30, 0.1);
  --radius: 22px;
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --ui: "Outfit", "Avenir Next", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html[data-theme="dark"] {
  --cream: #171410;
  --paper: #231e1a;
  --ink: #f3ebe2;
  --muted: #b4a89c;
  --line: rgba(243, 235, 226, 0.12);
  --mint: #86cbb8;
  --mint-soft: #2a4039;
  --lilac: #c8b6e4;
  --lilac-soft: #3a3148;
  --apricot: #edb48c;
  --apricot-soft: #433126;
  --lemon: #ecd57a;
  --lemon-soft: #3d3720;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--cream);
  font-family: var(--ui);
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
img { max-width: 100%; display: block; }

.bloom {
  position: fixed;
  z-index: 0;
  pointer-events: none;
  filter: blur(60px);
  opacity: 0.55;
}
.bloom-a { width: 340px; height: 340px; background: var(--mint); top: -80px; left: -60px; }
.bloom-b { width: 280px; height: 280px; background: var(--lilac); top: 20%; right: -80px; }
.bloom-c { width: 300px; height: 300px; background: var(--apricot); bottom: -90px; left: 30%; opacity: 0.4; }

.hidden { display: none !important; }

.gate, .app { position: relative; z-index: 1; }
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(440px, 100%);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: 32px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
}
.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--muted);
}
h1, h2, h3 { font-family: var(--display); font-weight: 650; letter-spacing: -0.03em; }
.gate-card h1 { font-size: clamp(42px, 8vw, 58px); margin: 0 0 10px; }
.lede { margin: 0 0 28px; color: var(--muted); font-size: 17px; }

label { display: block; font-size: 13px; margin-bottom: 8px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="date"], input[type="time"], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
}
textarea { min-height: 220px; resize: vertical; font-family: var(--serif); font-size: 17px; line-height: 1.65; }
input:focus, textarea:focus, select:focus { border-color: var(--mint); box-shadow: 0 0 0 4px var(--mint-soft); }

.btn, .text-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.btn.primary { background: var(--ink); color: var(--cream); border-color: transparent; }
.btn.mint { background: var(--mint-soft); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: #9a3b2f; }
.form-error { color: #9a3b2f; font-size: 14px; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding-bottom: calc(76px + var(--safe-bottom));
}
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 22px 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background:
    radial-gradient(circle at 30% 30%, var(--lemon), transparent 46%),
    linear-gradient(135deg, var(--mint), var(--lilac) 60%, var(--apricot));
}
.brand strong { display: block; font-family: var(--display); font-size: 22px; line-height: 1; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: 0.04em; }
.desktop-nav { display: none; gap: 6px; margin-left: auto; }
.desktop-nav a, .dock a {
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--muted);
}
.desktop-nav a.active, .dock a.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 50%;
  cursor: pointer;
}
.text-btn { color: var(--muted); padding: 8px 10px; }

.main { padding: 8px 18px 28px; width: min(1120px, 100%); margin: 0 auto; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 22px;
}
.page-head h1 { margin: 0; font-size: clamp(34px, 6vw, 52px); }
.page-head p { margin: 6px 0 0; color: var(--muted); }

.dropzone {
  position: relative;
  border: 1.5px dashed color-mix(in srgb, var(--apricot) 70%, var(--line));
  background: color-mix(in srgb, var(--paper) 80%, var(--apricot-soft));
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 18px;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.dropzone.over {
  transform: scale(1.01);
  border-color: var(--mint);
  background: var(--mint-soft);
}
.dropzone strong { font-family: var(--display); font-size: 24px; display: block; }
.dropzone span { color: var(--muted); font-size: 14px; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.chip.active { background: var(--ink); color: var(--cream); border-color: transparent; }

.masonry {
  columns: 1;
  column-gap: 14px;
}
@media (min-width: 640px) { .masonry { columns: 2; } }
@media (min-width: 980px) { .masonry { columns: 3; } }

.card {
  break-inside: avoid;
  margin-bottom: 14px;
  background: var(--paper);
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(80, 50, 30, 0.05);
}
.card img {
  width: 100%;
  height: auto;
  cursor: zoom-in;
  background: var(--lemon-soft);
}
.card-body { padding: 12px 14px 14px; }
.card-body h3 { margin: 0 0 4px; font-size: 16px; }
.meta { color: var(--muted); font-size: 12px; }
.pdf-card {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(180deg, var(--lilac-soft), var(--paper) 55%);
  padding: 18px;
}
.pdf-card .badge {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--paper);
  font-family: var(--display);
  font-weight: 650;
}
.heic-fallback {
  aspect-ratio: 4/5;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, var(--lemon-soft), var(--apricot-soft));
  font-family: var(--display);
  text-align: center;
  padding: 20px;
}

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}
.empty h2 { margin: 0 0 8px; color: var(--ink); }
.empty-art {
  width: 88px;
  height: 88px;
  margin: 0 auto 16px;
  border-radius: 28px;
  background:
    radial-gradient(circle at 30% 30%, var(--lemon), transparent 50%),
    linear-gradient(135deg, var(--mint-soft), var(--lilac-soft));
}

.journal-layout {
  display: grid;
  gap: 18px;
}
@media (min-width: 860px) {
  .journal-layout { grid-template-columns: 300px 1fr; align-items: start; }
}
.entry-list { display: grid; gap: 10px; }
.entry-item {
  text-align: left;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  cursor: pointer;
}
.entry-item.active { border-color: var(--lilac); box-shadow: 0 0 0 4px var(--lilac-soft); }
.composer, .reader {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.reader .prose { font-family: var(--serif); font-size: 18px; }
.prose p { margin: 0 0 1em; }
.prose h1, .prose h2, .prose h3 { margin: 1.1em 0 0.4em; }
.prose ul { padding-left: 1.2em; }
.prose blockquote {
  margin: 0 0 1em;
  padding-left: 14px;
  border-left: 3px solid var(--apricot);
  color: var(--muted);
}
.file-picks { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.file-picks label {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink);
}
.form-row { display: grid; gap: 12px; margin-bottom: 12px; }
@media (min-width: 640px) {
  .form-row.two { grid-template-columns: 1fr 160px; }
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.cal-head h1 { margin: 0; font-size: clamp(28px, 5vw, 44px); }
.weekdays, .month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.weekdays span {
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 0 10px;
}
.day-cell {
  min-height: 72px;
  border: 0;
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  border-radius: 16px;
  padding: 8px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.day-cell.mute { opacity: 0.35; }
.day-cell.today { box-shadow: inset 0 0 0 2px var(--mint); }
.day-cell.selected { background: var(--ink); color: var(--cream); }
.dots { display: flex; gap: 4px; min-height: 8px; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.journal { background: var(--mint); }
.dot.events { background: var(--lilac); }
.dot.files { background: var(--apricot); }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.dock {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(10px + var(--safe-bottom));
  display: flex;
  justify-content: space-around;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 8px;
  z-index: 5;
}
.dock a { flex: 1; text-align: center; padding: 12px 8px; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(18, 14, 12, 0.88);
  color: #f6efe6;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 16px;
}
.lightbox figure { margin: 0; text-align: center; }
.lightbox img { max-height: 80dvh; margin: 0 auto; border-radius: 12px; }
.lightbox figcaption { margin-top: 12px; color: #d8cfc4; }
.lb-close, .lb-prev, .lb-next {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 28px;
  padding: 12px;
}
.lb-close { position: absolute; top: 12px; right: 12px; font-size: 16px; }

.sheet {
  width: min(720px, calc(100vw - 20px));
  max-height: calc(100dvh - 24px);
  border: 0;
  border-radius: 24px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(28, 22, 18, 0.45); }
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  padding: 18px 18px 8px;
}
.sheet-head h2 { margin: 4px 0 0; }
.row-gap { display: flex; align-items: center; gap: 10px; }
#pdf-frame { width: 100%; height: min(70dvh, 720px); border: 0; background: #111; }
.day-body { padding: 8px 18px 22px; display: grid; gap: 18px; }
.stack { display: grid; gap: 10px; }
.mini-file {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--cream);
  border-radius: 14px;
  padding: 8px;
}
.mini-file img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }

.toasts {
  position: fixed;
  right: 16px;
  bottom: calc(90px + var(--safe-bottom));
  display: grid;
  gap: 8px;
  z-index: 30;
}
.toast {
  background: var(--ink);
  color: var(--cream);
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  box-shadow: var(--shadow);
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.loading { color: var(--muted); padding: 28px 0; }

@media (min-width: 860px) {
  .app { padding-bottom: 24px; }
  .desktop-nav { display: flex; }
  .top-actions { margin-left: 0; }
  .dock { display: none; }
  .day-cell { min-height: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
