/* ---------- Themes ---------- */
:root {
  --font-head: "Fraunces", Georgia, serif;
  --font-body: "Figtree", system-ui, sans-serif;
  --font-hand: "Caveat", "Comic Sans MS", cursive;
  --radius-s: 6px;
  --radius-m: 14px;
  --radius-l: 22px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* Dusk: an evening room lit by one lamp */
[data-theme="dusk"] {
  --bg: #2a1e2c; --bg-deep: #1f1621; --surface: #382839; --surface-2: #433045;
  --ink: #f6e9e2; --muted: #bfa7b3; --line: #57405a;
  --accent: #f2b36b; --accent-ink: #2a1e2c; --rose: #e39aa8;
  --paper: #f8f0e6; --paper-ink: #3a2a34; --glow: rgba(242, 179, 107, .16);
  --board: #33253a; --board-thread: rgba(255, 255, 255, .035);
  color-scheme: dark;
}
/* Linen: a bright morning, blush sheets */
[data-theme="linen"] {
  --bg: #f4ecee; --bg-deep: #ebdfe2; --surface: #fffafa; --surface-2: #f7eef0;
  --ink: #3b2a33; --muted: #7c6872; --line: #e2d2d7;
  --accent: #b5546e; --accent-ink: #fff8f9; --rose: #e9a2b3;
  --paper: #fffdfb; --paper-ink: #3b2a33; --glow: rgba(233, 162, 179, .28);
  --board: #ece0e3; --board-thread: rgba(59, 42, 51, .04);
  color-scheme: light;
}
/* Sage: a garden, mint tea */
[data-theme="sage"] {
  --bg: #e6ebe1; --bg-deep: #dbe2d4; --surface: #f6f8f2; --surface-2: #edf1e8;
  --ink: #26332b; --muted: #66756a; --line: #cfd8c8;
  --accent: #4f7a5e; --accent-ink: #f6f8f2; --rose: #d9a066;
  --paper: #fffef9; --paper-ink: #26332b; --glow: rgba(217, 160, 102, .22);
  --board: #d9e0d1; --board-thread: rgba(38, 51, 43, .045);
  color-scheme: light;
}
/* Midnight: navy and old gold */
[data-theme="midnight"] {
  --bg: #172033; --bg-deep: #111827; --surface: #22304a; --surface-2: #2a3a57;
  --ink: #eef0f6; --muted: #a9b3c7; --line: #34466a;
  --accent: #e8c27a; --accent-ink: #172033; --rose: #9db7e8;
  --paper: #f4f1ea; --paper-ink: #1d2638; --glow: rgba(232, 194, 122, .14);
  --board: #1d2a42; --board-thread: rgba(255, 255, 255, .03);
  color-scheme: dark;
}
/* Rosewater: dusky pink, warm and soft */
[data-theme="rosewater"] {
  --bg: #4a2f38; --bg-deep: #3c252d; --surface: #5a3a45; --surface-2: #664451;
  --ink: #fbeef0; --muted: #d8b6bf; --line: #77525f;
  --accent: #f5c6a5; --accent-ink: #3c252d; --rose: #f0a3b4;
  --paper: #fff6f1; --paper-ink: #4a2f38; --glow: rgba(245, 198, 165, .16);
  --board: #43303a; --board-thread: rgba(255, 255, 255, .04);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  font: 400 1.0625rem/1.6 var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1100px 700px at 12% -10%, var(--glow), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, var(--glow), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  transition: background-color .4s var(--ease), color .4s var(--ease);
}
body::after { /* faint paper grain */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: .06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 500; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-underline-offset: 3px; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.hand { font-family: var(--font-hand); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Buttons & fields ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: 500 .95rem/1 var(--font-body);
  padding: .8em 1.15em; border-radius: 999px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: .5em; text-decoration: none;
  transition: transform .15s var(--ease), background .2s, border-color .2s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: #d9534f; color: #d9534f; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 1.1em; height: 1.1em; }

.field { display: grid; gap: .4rem; font-size: .9rem; color: var(--muted); }
input[type="text"], input[type="password"], input[type="date"], textarea, select {
  width: 100%; font: 400 1rem/1.4 var(--font-body); color: var(--ink);
  background: var(--bg-deep); border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: .75em .9em;
}
textarea { resize: vertical; min-height: 6em; line-height: 1.55; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-l); padding: 40px 32px 32px; position: relative;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .55);
}
.login-card .door { width: 54px; height: 54px; margin-bottom: 18px; }
.login-card h1 { font-size: 2.1rem; margin-bottom: .3rem; }
.login-card p { color: var(--muted); }
.login-card form { display: grid; gap: 14px; margin-top: 22px; }
.login-card .error { color: var(--rose); font-size: .92rem; min-height: 1.4em; margin: 0; }

/* ---------- Shell ---------- */
.shell { max-width: 1120px; margin: 0 auto; padding: 0 20px 80px; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 22px 0; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); margin-right: auto; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand span { font-family: var(--font-head); font-size: 1.3rem; }
.nav { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.nav a {
  color: var(--muted); text-decoration: none; padding: .5em 1em; border-radius: 999px; font-size: .95rem; white-space: nowrap;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); }
.bell {
  position: relative; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  display: grid; place-items: center; cursor: pointer;
}
.bell svg { width: 20px; height: 20px; }
.bell .dot {
  position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--rose); color: var(--bg-deep); border-radius: 9px; font: 600 .7rem/18px var(--font-body); text-align: center;
}

@media (max-width: 720px) {
  .topbar { padding: 16px 0; }
  .nav { order: 3; width: 100%; justify-content: space-between; overflow-x: auto; }
  .nav a { padding: .55em .8em; font-size: .9rem; }
}

/* ---------- Home ---------- */
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: center;
  padding: 48px 0 40px;
}
.hero h1 { font-size: clamp(2.6rem, 6.5vw, 4.8rem); font-weight: 400; max-width: 12ch; }
.hero .sub { color: var(--muted); font-size: 1.15rem; margin-top: 14px; max-width: 40ch; }
.countdown {
  width: 230px; aspect-ratio: 1; background: var(--paper); color: var(--paper-ink);
  border-radius: 4px; padding: 26px 22px; transform: rotate(3deg);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .05), 0 22px 40px -18px rgba(0, 0, 0, .55);
  display: grid; align-content: center; text-align: center; position: relative;
}
.countdown::before { /* pin */
  content: ""; position: absolute; top: 12px; left: 50%; width: 14px; height: 14px; margin-left: -7px;
  border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff8, transparent 40%), var(--rose);
  box-shadow: 0 2px 3px rgba(0, 0, 0, .35);
}
.countdown .big { font-family: var(--font-head); font-size: 4rem; line-height: 1; }
.countdown .hand { font-size: 1.6rem; line-height: 1.1; margin-top: 6px; }
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; padding-top: 24px; gap: 28px; }
  .countdown { width: 190px; justify-self: center; }
}

.grid-2 { display: grid; grid-template-columns: 1.15fr .85fr; gap: 24px; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 28px;
}
.panel h2 { font-size: 1.5rem; margin-bottom: 14px; }
.letter {
  font-family: var(--font-hand); font-size: 1.65rem; line-height: 1.35; white-space: pre-wrap;
  background-image: repeating-linear-gradient(transparent 0 calc(1.35em - 1px), var(--line) calc(1.35em - 1px) 1.35em);
  background-position: 0 .3em; padding-bottom: 4px; margin: 0;
}
.letter-sign { text-align: right; font-family: var(--font-hand); font-size: 1.4rem; color: var(--muted); margin-top: 10px; }

.status-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.status-row:first-of-type { border-top: 0; padding-top: 4px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font: 600 1rem/1 var(--font-head); color: var(--bg-deep); background: var(--c, var(--rose));
}
.status-row .what { flex: 1; }
.status-row .what strong { display: block; font-weight: 500; }
.status-row .what span { color: var(--muted); font-size: .92rem; }
.tick { color: var(--accent); }

.strip { display: flex; gap: 18px; overflow-x: auto; padding: 18px 4px 22px; scroll-snap-type: x mandatory; }
.strip .polaroid { width: 170px; flex: none; scroll-snap-align: start; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 44px 0 6px; }
.section-head h2 { font-size: 2rem; }

/* ---------- Memory board ---------- */
.board {
  border-radius: var(--radius-l); padding: 48px 32px 56px; min-height: 420px;
  background-color: var(--board); border: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 44px 34px;
  box-shadow: inset 0 2px 30px rgba(0, 0, 0, .18);
}
[data-board="linen"] .board {
  background-image:
    repeating-linear-gradient(0deg, var(--board-thread) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, var(--board-thread) 0 1px, transparent 1px 4px);
}
[data-board="cork"] .board {
  --board: #b58a5e;
  background-image:
    radial-gradient(rgba(70, 40, 15, .35) 1px, transparent 1.6px),
    radial-gradient(rgba(255, 230, 190, .25) 1px, transparent 1.6px);
  background-size: 9px 9px, 13px 13px; background-position: 0 0, 4px 6px;
}
@media (max-width: 600px) {
  .board { padding: 32px 18px 40px; grid-template-columns: repeat(2, 1fr); gap: 30px 16px; }
}

.polaroid {
  --tilt: 0deg;
  position: relative; background: var(--paper); color: var(--paper-ink);
  padding: 11px 11px 0; border-radius: 2px; cursor: pointer; border: 0; text-align: left; font: inherit;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .1), 0 18px 30px -16px rgba(0, 0, 0, .55);
  transform: rotate(var(--tilt));
  transition: transform .35s var(--ease), box-shadow .35s var(--ease);
}
[data-tilt="false"] .polaroid { --tilt: 0deg !important; }
.polaroid:hover, .polaroid:focus-visible { transform: rotate(0deg) translateY(-6px) scale(1.03); z-index: 2; box-shadow: 0 2px 2px rgba(0, 0, 0, .1), 0 30px 46px -18px rgba(0, 0, 0, .6); }
.polaroid::before { /* washi tape */
  content: ""; position: absolute; top: -12px; left: 50%; width: 84px; height: 24px; margin-left: -42px;
  background: color-mix(in srgb, var(--rose) 62%, transparent);
  transform: rotate(var(--tape, -4deg));
  clip-path: polygon(0 8%, 3% 0, 6% 10%, 9% 0, 91% 0, 94% 12%, 97% 0, 100% 9%, 100% 92%, 97% 100%, 94% 88%, 91% 100%, 9% 100%, 6% 90%, 3% 100%, 0 91%);
}
.polaroid .photo { aspect-ratio: 1; background: #d8cfc7; overflow: hidden; }
.polaroid .photo img { width: 100%; height: 100%; object-fit: cover; }
.polaroid .cap {
  font-family: var(--font-hand); font-size: 1.35rem; line-height: 1.15; padding: 10px 4px 0; min-height: 2.5em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.polaroid .meta { display: flex; gap: 6px; align-items: center; justify-content: flex-end; font-size: .75rem; opacity: .65; padding: 4px 2px 10px; }
.polaroid .meta i { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--rose)); }

.empty {
  grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--muted);
}
.empty .hand { font-size: 2rem; color: var(--ink); display: block; margin-bottom: 8px; }

/* ---------- Agreement ---------- */
.contract {
  max-width: 780px; margin: 24px auto 0; background: var(--paper); color: var(--paper-ink);
  border-radius: 4px; padding: clamp(28px, 6vw, 64px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .06), 0 40px 70px -40px rgba(0, 0, 0, .6);
  font-family: var(--font-head); font-size: 1.04rem; line-height: 1.7;
}
.contract header { text-align: center; padding-bottom: 26px; margin-bottom: 30px; border-bottom: 1px solid color-mix(in srgb, var(--paper-ink) 18%, transparent); }
.contract h1 { font-size: clamp(2rem, 5vw, 2.8rem); font-weight: 400; }
.contract .subtitle { font-style: italic; opacity: .7; margin: .4rem 0 0; }
.contract .parties { margin-top: 18px; font-size: 1.15rem; }
.contract h2 { font-size: 1.3rem; font-weight: 600; margin: 34px 0 14px; display: flex; gap: .6em; }
.contract h2 .n { color: color-mix(in srgb, var(--accent) 70%, var(--paper-ink)); }
.clause { display: grid; grid-template-columns: 2.8em 1fr; gap: 0 .4em; margin-bottom: 12px; }
.clause .n { opacity: .55; font-variant-numeric: tabular-nums; }
.clause strong { font-weight: 600; }
.contract [contenteditable="true"] { outline: 1px dashed color-mix(in srgb, var(--paper-ink) 30%, transparent); outline-offset: 3px; border-radius: 3px; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.contract [contenteditable="true"]:focus { outline-style: solid; }

.sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-top: 44px; }
@media (max-width: 600px) { .sigs { grid-template-columns: 1fr; } }
.sig { border-top: 1px solid color-mix(in srgb, var(--paper-ink) 25%, transparent); padding-top: 12px; }
.sig .who { font-size: .85rem; opacity: .65; font-family: var(--font-body); }
.sig .ink { font-family: var(--font-hand); font-size: 2.3rem; line-height: 1.1; min-height: 1.2em; color: color-mix(in srgb, #1d3a8a 75%, var(--paper-ink)); }
.sig .when { font-size: .85rem; opacity: .65; font-family: var(--font-body); }
.sig .btn { margin-top: 8px; }
.contract-tools { max-width: 780px; margin: 20px auto 0; display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.notice {
  max-width: 780px; margin: 22px auto 0; padding: 14px 18px; border-radius: var(--radius-m);
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: .95rem;
}
.notice strong { color: var(--ink); font-weight: 500; }

/* ---------- Settings ---------- */
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 12px; }
@media (max-width: 860px) { .settings { grid-template-columns: 1fr; } }
.settings .panel { display: grid; gap: 18px; align-content: start; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.swatch {
  border: 2px solid var(--line); border-radius: var(--radius-m); padding: 10px; cursor: pointer;
  background: var(--sw-bg); color: var(--sw-ink); text-align: left; font: 500 .9rem/1.2 var(--font-body);
}
.swatch .chips { display: flex; gap: 4px; margin-bottom: 10px; }
.swatch .chips i { width: 18px; height: 18px; border-radius: 50%; }
.swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.colour-pick { display: flex; align-items: center; gap: 10px; }
.colour-pick input[type="color"] { width: 46px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }
.toggle { display: flex; align-items: center; gap: 10px; color: var(--ink); cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.savebar {
  position: sticky; bottom: 16px; margin-top: 24px; display: flex; justify-content: flex-end; gap: 10px; align-items: center;
  background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 8px 8px 20px;
}
.savebar .muted { margin-right: auto; font-size: .92rem; }

/* ---------- Dialogs & drawer ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius-l); padding: 0; color: var(--ink);
  background: var(--surface); width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  box-shadow: 0 40px 120px -20px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(10, 6, 12, .6); backdrop-filter: blur(3px); }
dialog[open] { animation: rise .32s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.dlg-close { position: absolute; top: 12px; right: 12px; z-index: 2; }
.memory-view { display: grid; grid-template-columns: 1.2fr 1fr; }
.memory-view .pic { background: var(--bg-deep); display: grid; place-items: center; min-height: 300px; }
.memory-view .pic img { max-height: 78vh; width: 100%; object-fit: contain; }
.memory-view .side { padding: 28px 24px 22px; display: flex; flex-direction: column; gap: 14px; max-height: 82vh; overflow: auto; }
.memory-view .caption { font-family: var(--font-hand); font-size: 2rem; line-height: 1.15; }
.memory-view .by { color: var(--muted); font-size: .9rem; }
@media (max-width: 720px) { .memory-view { grid-template-columns: 1fr; } .memory-view .pic img { max-height: 50vh; } }
.comments { display: grid; gap: 12px; margin: 4px 0; }
.comment { display: flex; gap: 10px; }
.comment .avatar { width: 30px; height: 30px; font-size: .8rem; }
.comment .body { background: var(--surface-2); border-radius: 4px 14px 14px 14px; padding: 8px 12px; flex: 1; }
.comment .body small { color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.comment .body small button { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.comment-form { display: flex; gap: 8px; margin-top: auto; }
.comment-form input { flex: 1; }

.form-dlg { padding: 30px; display: grid; gap: 16px; }
.form-dlg h2 { font-size: 1.7rem; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius-m); padding: 28px; text-align: center; cursor: pointer;
  color: var(--muted); display: grid; place-items: center; gap: 8px; min-height: 180px;
}
.drop.over { border-color: var(--accent); background: var(--glow); }
.drop img { max-height: 280px; border-radius: 4px; }

.drawer { width: min(420px, calc(100vw - 24px)); margin: 0 0 0 auto; height: 100vh; max-height: 100vh; border-radius: var(--radius-l) 0 0 var(--radius-l); }
.drawer[open] { animation: slide .3s var(--ease); }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer .inner { padding: 26px 22px; display: grid; gap: 4px; }
.drawer h2 { font-size: 1.6rem; margin-bottom: 10px; }
.notif { display: flex; gap: 12px; padding: 12px 8px; border-radius: var(--radius-m); text-decoration: none; color: var(--ink); }
.notif:hover { background: var(--surface-2); }
.notif.unread .text::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--rose); margin-right: 8px; vertical-align: middle; }
.notif .when { color: var(--muted); font-size: .85rem; display: block; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 999px; font-weight: 500;
  transition: all .3s var(--ease); z-index: 200; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media print {
  body { background: #fff; }
  body::after, .topbar, .contract-tools, .notice, .sig .btn, #toast { display: none !important; }
  .shell { padding: 0; }
  .contract { box-shadow: none; margin: 0; max-width: none; padding: 0; background: #fff; }
}

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