/* Shared Beechhouse design system: time-of-day palette + base primitives.
   Linked (render-blocking) before /lib/tod.js so the theme is set with no flash. */

:root {
  /* time-of-day palette (defaults = morning; overridden by [data-tod]) */
  --paper:   #fdf6ea;
  --paper-2: #f6ead4;
  --surface: #fffdf9;
  --ink:     #2a251d;
  --muted:   #8a7d67;
  --line:    #ece0ca;
  --amber:   #e08a3c;
  --amber-d: #c26b3f;
  --green:   #5c7a5a;

  --placeholder:   #b6ab96;
  --grain-opacity: .35;
  --grain-blend:   multiply;
  --bg-layers:
    radial-gradient(125% 85% at 100% -5%, rgba(240,170,70,.20), transparent 55%),
    radial-gradient(90% 70% at 0% 100%, rgba(214,175,120,.16), transparent 52%);

  /* Tag hues. Tags are free text here, so these aren't named per tag — a tag
     is hashed to one of them by tagHue() in lib/tasks.js. Eight is enough to
     keep collisions rare on a personal list; all are mid-tone enough to stay
     legible against both the light papers and the night surface. */
  --tag-1: #4e7a4a;
  --tag-2: #c26b3f;
  --tag-3: #b4922e;
  --tag-4: #c25f8e;
  --tag-5: #3f6fb0;
  --tag-6: #4f8f8a;
  --tag-7: #8a6bbf;
  --tag-8: #a8553f;

  --r-lg: 20px;
  --r-md: 14px;
  --shadow: 0 1px 2px rgba(42,37,29,.05), 0 12px 30px -12px rgba(42,37,29,.18);
}

/* ── Midday: bright, clear, a hint of blue sky ─────────────────── */
:root[data-tod="midday"] {
  --paper:   #f5f4ef;
  --paper-2: #ecebe3;
  --surface: #ffffff;
  --ink:     #23211c;
  --muted:   #7c7768;
  --line:    #e6e3da;
  --amber:   #cf7538;
  --amber-d: #b05a28;
  --placeholder: #ada79a;
  --bg-layers:
    radial-gradient(130% 80% at 50% -15%, rgba(120,170,215,.20), transparent 55%),
    radial-gradient(90% 70% at 0% 100%, rgba(198,182,142,.14), transparent 50%);
}

/* ── Evening: golden-hour sunset, warm and dimming ─────────────── */
:root[data-tod="evening"] {
  --paper:   #f1e0cd;
  --paper-2: #ead2b6;
  --surface: #fbf0e2;
  --ink:     #38271c;
  --muted:   #9a7d63;
  --line:    #e3cdb1;
  --amber:   #c95f30;
  --amber-d: #a1441f;
  --green:   #6a8258;
  --placeholder: #b79a80;
  --shadow: 0 1px 2px rgba(58,39,28,.08), 0 14px 32px -12px rgba(160,68,31,.32);
  --bg-layers:
    radial-gradient(130% 95% at 100% -5%, rgba(230,110,55,.30), transparent 55%),
    radial-gradient(105% 85% at 0% 100%, rgba(118,84,138,.24), transparent 58%);
}

/* ── Night: dark, moonlit, cool and quiet ──────────────────────── */
:root[data-tod="night"] {
  --paper:   #13151d;
  --paper-2: #191c26;
  --surface: #1e2230;
  --ink:     #e9ecf4;
  --muted:   #8b93a8;
  --line:    #2c3242;
  --amber:   #e0a56d;
  --amber-d: #edb886;
  --green:   #86a883;
  --placeholder: #5b6376;
  --grain-opacity: .05;
  --grain-blend:   screen;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 16px 38px -16px rgba(0,0,0,.75);
  --bg-layers:
    radial-gradient(80% 65% at 85% 4%, rgba(188,205,245,.13), transparent 50%),
    radial-gradient(130% 95% at 8% 105%, rgba(46,64,120,.38), transparent 62%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  background-image: var(--bg-layers);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 1.1s ease, color 1.1s ease;
}
/* faint paper grain */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  opacity: var(--grain-opacity); mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%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)' opacity='.5'/%3E%3C/svg%3E");
}

.wrap {
  position: relative; z-index: 1;
  min-height: 100%;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 22px calc(22px + env(safe-area-inset-bottom));
}

/* wordmark + top nav */
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 500; letter-spacing: .14em; text-transform: uppercase;
  font-size: 12px; color: var(--muted);
  opacity: 0; animation: rise .6s .05s ease forwards;
}
.brand .leaf { width: 16px; height: 16px; color: var(--amber); }
.brand .nav {
  margin-left: auto; letter-spacing: .04em; text-transform: none;
  font-size: 13px; color: var(--amber-d); text-decoration: none;
  display: inline-flex; align-items: center; gap: 5px;
}
.brand .nav:active { opacity: .6; }

button { font: inherit; cursor: pointer; border: 0; }

.datechip { background: var(--surface); border: 1.5px solid var(--line); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font-size: .95rem; }
.datechip[aria-pressed="true"] { border-color: var(--amber); background: color-mix(in srgb, var(--amber) 12%, var(--surface)); font-weight: 600; }

/* Date field: a fully custom pill (icon + "Add date"/formatted date) with the
   real <input type=date> laid invisibly on top so tapping opens the native
   picker. Native date inputs can't be sized/labelled reliably on mobile, so we
   don't style the input itself — we style our own .datepill. */
.datefield { position: relative; display: inline-flex; }
.datefield input[type="date"] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.datepill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1.5px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 8px 14px; font-size: .95rem;
  pointer-events: none; /* taps fall through to the input above */
}
.datepill .ic { width: 15px; height: 15px; flex: 0 0 auto; }
/* Selected (a custom date is set): same treatment as an active .datechip. */
.datefield.selected .datepill {
  border-color: var(--amber); color: var(--ink); font-weight: 600;
  background: color-mix(in srgb, var(--amber) 12%, var(--surface));
}

footer { text-align: center; color: var(--muted); font-size: .78rem; padding-top: 18px; opacity: .8; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translate(-50%, 130%);
  background: var(--ink); color: var(--paper);
  padding: 13px 20px; border-radius: 999px; font-weight: 500; font-size: .95rem;
  display: flex; align-items: center; gap: 9px; z-index: 20;
  box-shadow: 0 14px 34px -10px rgba(42,37,29,.5);
  transition: transform .34s cubic-bezier(.2,.9,.3,1.2);
}
.toast.show { transform: translate(-50%, 0); }
.toast.err { background: #8a3b2e; }
.toast .tick {
  width: 20px; height: 20px; border-radius: 50%; background: var(--green);
  display: grid; place-items: center; color: #fff; font-size: 12px;
}

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ── Tags ───────────────────────────────────────────────────────────
   Free-text tag entry (lib/tagInput.js), used identically on the capture and
   edit pages, plus the read-only tag chips on a list row. Shared here rather
   than inlined per page because three pages render tags. */

.tagfield {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  position: relative;
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--r-md); padding: 9px 11px;
  transition: border-color .18s;
}
.tagfield:focus-within { border-color: var(--amber); }

.tagpills { display: contents; }

.tagpill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--hue, var(--line));
  background: color-mix(in srgb, var(--hue, var(--amber)) 12%, var(--surface));
  color: var(--ink); border-radius: 999px;
  padding: 5px 6px 5px 11px; font-size: .9rem; font-weight: 500;
}
.tagpill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--hue, var(--muted)); }
.tagpill-x {
  background: transparent; color: var(--muted); line-height: 1;
  width: 20px; height: 20px; border-radius: 999px; font-size: .72rem;
  display: grid; place-items: center; padding: 0;
}
.tagpill-x:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, transparent); }

.taginput {
  flex: 1; min-width: 8ch;
  border: 0; background: transparent; outline: none;
  font: inherit; font-size: 1rem; color: var(--ink); padding: 4px 2px;
}
.taginput::placeholder { color: var(--placeholder); }
.taginput:disabled { cursor: not-allowed; }

.tagsuggs {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 2px; min-width: 180px; max-width: 100%;
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow); padding: 6px;
}
.tagsuggs[hidden] { display: none; }
.tagsugg {
  display: flex; align-items: center; gap: 9px; text-align: left; white-space: nowrap;
  color: var(--ink); background: transparent; border-radius: 10px;
  padding: 8px 12px; font-size: .95rem;
}
.tagsugg .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--hue, var(--muted)); flex: 0 0 auto; }
.tagsugg:hover, .tagsugg.active { background: var(--paper-2); }

/* Read-only tag chip (list rows). */
.tagchip {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid color-mix(in srgb, var(--hue, var(--line)) 45%, transparent);
  background: color-mix(in srgb, var(--hue, var(--amber)) 10%, transparent);
  color: var(--muted); border-radius: 999px;
  padding: 2px 8px; font-size: .74rem; font-weight: 500;
}
.tagchip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--hue, var(--muted)); }

/* A refused tag (duplicate, or over the limit) has to be visible or it reads
   as the app silently swallowing input. */
.shake { animation: shake .3s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  30%, 70% { transform: translateX(2px); }
  50%      { transform: translateX(-3px); }
}
