/* Nemo — warm, calm, thumb-sized targets. Mobile first; centred on a desktop.
   No build step: plain CSS custom properties. */

:root {
  --bg: #F6F1E8;
  --surface: #FFFDF9;
  --surface-2: #F0E8DA;
  --ink: #23201C;
  --ink-2: #6B615A;
  --ink-3: #948A80;
  --line: #E5DACA;
  --accent: #C4633F;
  --accent-soft: #F6E2D7;
  --accent-ink: #FFFFFF;
  --sage: #4A7A6C;
  --sage-soft: #DEEAE4;
  --amber: #9A6C15;
  --amber-soft: #F7E8C8;
  --danger: #A8412F;
  --danger-soft: #F7DFD9;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 24px -12px rgba(60, 40, 20, .18);
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120F;
    --surface: #1F1C18;
    --surface-2: #2A2621;
    --ink: #F2EDE4;
    --ink-2: #AEA396;
    --ink-3: #8A8075;
    --line: #332E27;
    --accent: #E08359;
    --accent-soft: #3A2820;
    --accent-ink: #1A1512;
    --sage: #86BBA8;
    --sage-soft: #22302B;
    --amber: #DCAC53;
    --amber-soft: #332A18;
    --danger: #E58A72;
    --danger-soft: #3A211B;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 26px -14px rgba(0,0,0,.7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

body {
  padding-bottom: calc(64px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

.view {
  max-width: 620px;
  margin: 0 auto;
  padding: 14px 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------------------------------------------------------------- header --- */

.page-head { display: flex; align-items: center; gap: 12px; padding: 6px 2px 0; }
.page-head .avatar { width: 52px; height: 52px; border-radius: 50%; overflow: hidden; flex: none;
  background: var(--surface-2); box-shadow: var(--shadow); }
.page-head .avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page-head .avatar svg { width: 100%; height: 100%; display: block; }
.page-head .titles { flex: 1; min-width: 0; }
.page-head .sub { color: var(--ink-2); font-size: .85rem; }

/* ----------------------------------------------------------------- cards --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card.tight { padding: 12px; gap: 8px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h2 { flex: 1 1 auto; }
.card-head .hint { color: var(--ink-3); font-size: .78rem; }

.section-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-3); font-weight: 700;
}

/* -------------------------------------------------------------- medicine --- */

.dose-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.dose {
  position: relative;
  display: flex; flex-direction: column; gap: 3px;
  min-height: 92px; padding: 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  text-align: left; cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.dose:active { transform: scale(.985); }
.dose .when { font-size: .74rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.dose .state { font-size: 1.02rem; font-weight: 650; }
.dose .detail { font-size: .8rem; color: var(--ink-2); }
.dose.done { background: var(--sage-soft); border-color: var(--sage); }
.dose.done .state { color: var(--sage); }
.dose.pending { border-style: dashed; }
.dose .check { position: absolute; top: 10px; right: 10px; font-size: 1.1rem; }
.dose.busy { opacity: .6; pointer-events: none; }

/* -------------------------------------------------------------- quick log -- */

.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.quick {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 74px; padding: 8px 6px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.quick:active { transform: scale(.96); background: var(--accent-soft); }
.quick .icon { font-size: 1.45rem; line-height: 1; }
.quick .label { font-size: .78rem; font-weight: 600; text-align: center; }
.quick .count { font-size: .68rem; color: var(--ink-3); }
.quick.busy { opacity: .55; pointer-events: none; }
.quick.adding { border-style: dashed; color: var(--ink-2); }

/* ------------------------------------------------------------- timeline ---- */

.entries { display: flex; flex-direction: column; }
.entry {
  display: flex; gap: 10px; padding: 10px 4px;
  border-top: 1px solid var(--line); cursor: pointer; text-align: left; width: 100%;
  background: none; border-left: 0; border-right: 0; border-bottom: 0;
}
.entries .entry:first-child { border-top: 0; }
.entry .icon { font-size: 1.2rem; width: 26px; flex: none; text-align: center; }
.entry .body { flex: 1; min-width: 0; }
.entry .line1 { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.entry .name { font-weight: 620; }
.entry .time { color: var(--ink-2); font-size: .84rem; }
.entry .note { color: var(--ink-2); font-size: .86rem; margin-top: 2px; overflow-wrap: anywhere; }
.entry .thumbs { display: flex; gap: 6px; margin-top: 6px; }
.entry .thumbs img { width: 54px; height: 54px; border-radius: 9px; object-fit: cover; border: 1px solid var(--line); }
.entry.removed { opacity: .55; }
.entry.removed .name { text-decoration: line-through; }

/* ---------------------------------------------------------------- chips ---- */

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .7rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.chip.provisional { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.chip.estimate { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.maybe-dup { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.removed { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.ok { background: var(--sage-soft); color: var(--sage); border-color: transparent; }

/* -------------------------------------------------------------- since ------ */

.since-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.since {
  padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--line); text-align: left; cursor: pointer; width: 100%;
}
.since .k { font-size: .78rem; color: var(--ink-2); display: flex; align-items: center; gap: 5px; }
.since .v { display: block; font-weight: 650; font-size: .95rem; margin-top: 3px; }
.since .q { display: block; font-size: .72rem; color: var(--ink-3); margin-top: 2px; line-height: 1.3; }

/* -------------------------------------------------------------- notices ---- */

.notice {
  display: flex; gap: 9px; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: .85rem; line-height: 1.4;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}
.notice.warn { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.notice.alert { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.notice .icon { flex: none; }
.notice strong { color: inherit; }

.banner {
  position: sticky; top: 0; z-index: 40;
  padding: 8px 14px; font-size: .82rem; font-weight: 600;
  background: var(--amber-soft); color: var(--amber);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.banner.error { background: var(--danger-soft); color: var(--danger); }
.banner button { background: none; border: 0; font-weight: 700; text-decoration: underline; cursor: pointer; }

/* -------------------------------------------------------------- buttons ---- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: var(--tap); padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font-weight: 650; cursor: pointer; white-space: nowrap; transition: transform .08s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: none; border-color: transparent; color: var(--ink-2); }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .84rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------------- fields ---- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: .8rem; font-weight: 650; color: var(--ink-2); }
input[type="text"], input[type="time"], input[type="date"], input[type="number"], textarea, select {
  font: inherit; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 12px; width: 100%; min-height: var(--tap);
}
textarea { min-height: 74px; resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible, .btn:focus-visible,
.quick:focus-visible, .dose:focus-visible, .entry:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.option-row { display: flex; flex-direction: column; gap: 8px; }
.option {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); cursor: pointer; text-align: left; width: 100%;
}
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option .t { font-weight: 650; font-size: .92rem; }
.option .d { font-size: .8rem; color: var(--ink-2); }
.option .mark { flex: none; width: 20px; text-align: center; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.switch .t { font-weight: 620; }
.switch .d { font-size: .8rem; color: var(--ink-2); }
.switch input { width: 46px; height: 28px; flex: none; }

/* --------------------------------------------------------------- sheet ----- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(30, 22, 16, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { transform: translateY(18px); opacity: .6 } }
.sheet {
  background: var(--bg); width: 100%; max-width: 620px;
  border-radius: 22px 22px 0 0; padding: 8px 14px calc(18px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  animation: rise .18s ease;
}
.sheet-grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 2px; }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head h2 { flex: 1; }
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 22px; margin: 20px; }
}

/* --------------------------------------------------------------- toast ----- */

.toast-root {
  position: fixed; left: 0; right: 0; bottom: calc(66px + var(--safe-bottom));
  z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 12px;
}
.toast {
  pointer-events: auto; background: var(--ink); color: var(--bg);
  border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px; max-width: 560px; width: 100%;
  font-size: .88rem; animation: rise .16s ease;
}
.toast .msg { flex: 1; min-width: 0; }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 4px; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- tabs ----- */

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
/* Translucency only where the engine supports it — an unsupported color-mix
   would leave the bar transparent over scrolling content. */
@supports (background: color-mix(in srgb, red 50%, transparent)) {
  .tabs { background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); }
}

.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; color: var(--ink-3); font-size: .68rem; font-weight: 600;
}
.tab .tab-icon { font-size: 1.2rem; line-height: 1; filter: grayscale(1); opacity: .75; }
.tab.active { color: var(--accent); }
.tab.active .tab-icon { filter: none; opacity: 1; }

/* --------------------------------------------------------------- misc ------ */

.hero {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(160deg, var(--accent-soft), var(--surface-2));
  min-height: 168px; display: flex; align-items: flex-end;
  border: 1px solid var(--line);
}
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero svg { position: absolute; right: 8px; bottom: 0; height: 152px; width: auto; }
.hero .hero-text {
  position: relative; padding: 14px; color: #fff;
  text-shadow: 0 1px 12px rgba(0,0,0,.55);
  background: linear-gradient(transparent, rgba(0,0,0,.42));
  width: 100%;
}
.hero.no-photo .hero-text { color: var(--ink); text-shadow: none; background: none; max-width: 63%; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(102px, 1fr)); gap: 6px; }
.gallery a { min-height: 96px; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); display: block; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }

.day-strip { display: flex; gap: 6px; }
.day-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.day-col .d { font-size: .66rem; color: var(--ink-3); font-weight: 700; }
.day-col .dots { display: flex; flex-direction: column; gap: 3px; width: 100%; }
.dot { height: 9px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); }
.dot.filled { background: var(--sage); border-color: var(--sage); }
.dot.today { box-shadow: 0 0 0 2px var(--accent-soft); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .86rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }

.muted { color: var(--ink-2); font-size: .86rem; }
.tiny { font-size: .76rem; color: var(--ink-3); }
.center { text-align: center; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.empty { padding: 22px 12px; text-align: center; color: var(--ink-2); font-size: .9rem; }
.empty svg { width: 108px; height: auto; opacity: .9; margin-bottom: 6px; }

.provenance { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .84rem; color: var(--ink-2); }
.provenance ul { margin: 6px 0 0; padding-left: 18px; }
.provenance li { margin: 2px 0; }

.rev { border-left: 2px solid var(--line); padding: 6px 0 6px 12px; font-size: .84rem; }
.rev .when { color: var(--ink-3); font-size: .76rem; }

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

/* The UA's [hidden] rule loses to the display value above it. */
.banner[hidden], .stack[hidden], [hidden] { display: none !important; }
.provenance a { color: var(--accent); text-decoration: underline; font-weight: 600; }
.sheet-actions {
  position: sticky; bottom: 0; margin-top: 4px;
  padding: 8px 0 2px; background: var(--bg);
  box-shadow: 0 -10px 14px -12px rgba(0,0,0,.35);
}
.sheet-actions:empty { display: none; }
.sheet-actions .btn { flex: 1; }

/* ------------------------------------------------------------- calendar --- */

.segmented { display: flex; gap: 4px; padding: 4px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; }
.segmented .seg { flex: 1; text-align: center; padding: 9px 12px; border-radius: 999px;
  font-size: .88rem; font-weight: 650; color: var(--ink-2); }
.segmented .seg.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 2px; }
.month-nav h2 { text-align: center; flex: 1; }

.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  font-size: .68rem; font-weight: 700; color: var(--ink-3); text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell {
  min-height: 44px; aspect-ratio: 1; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface-2); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; color: var(--ink);
}
.cal-cell .n { font-size: .74rem; font-weight: 650; }
.cal-cell.blank { background: none; border-color: transparent; color: var(--ink-3); opacity: .4; }
.cal-cell.silent { background: repeating-linear-gradient(135deg,
  var(--surface-2), var(--surface-2) 4px, var(--surface) 4px, var(--surface) 8px); }
.cal-cell.untracked { background: none; border-style: dashed; color: var(--ink-3); }
.cal-cell.is-today { border-color: var(--accent); border-width: 2px; }

.marks { display: flex; flex-direction: column; gap: 2px; width: 60%; }
.mark { height: 5px; border-radius: 2px; background: none; border: 1px solid var(--line); }
.mark.filled { background: var(--sage); border-color: var(--sage); }

.act-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px 4px; }
/* The grid box must be as wide as its columns, or the sticky row labels lose
   their containing block and scroll away with the content. */
.act-grid { display: grid; gap: 3px; align-items: center; width: max-content; }
.act-corner { position: sticky; left: 0; z-index: 3; background: var(--surface); align-self: stretch; min-height: 14px; }
.act-day { font-size: .6rem; color: var(--ink-3); text-align: center; font-weight: 700; }
.act-day.is-today { color: var(--accent); }
.act-label {
  position: sticky; left: 0; z-index: 2; background: var(--surface);
  display: flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600;
  padding-right: 8px; height: 30px;
}
.act-label { position: sticky; }
.act-label .act-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.act-label::after { content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 6px;
  background: linear-gradient(to right, var(--surface), transparent); }
.act-label .act-total { color: var(--ink-3); font-size: .7rem; font-weight: 700; }
.act-cell {
  height: 30px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: .68rem; font-weight: 700; color: var(--ink-2);
}
.act-cell.has { background: var(--sage-soft); border-color: var(--sage); color: var(--sage); }
.act-cell.silent { background: repeating-linear-gradient(135deg,
  var(--surface-2), var(--surface-2) 3px, var(--surface) 3px, var(--surface) 6px); }
.act-cell.untracked { background: none; border-style: dashed; }
.act-cell.blank { background: none; border-color: transparent; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: .72rem; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend .swatch {
  width: 18px; height: 18px; border-radius: 5px; border: 1px solid var(--line);
  background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center;
  font-size: .62rem; font-weight: 700; color: var(--ink-2); flex: none;
}
.legend .swatch.has { background: var(--sage-soft); border-color: var(--sage); color: var(--sage); }
.legend .swatch.silent { background: repeating-linear-gradient(135deg,
  var(--surface-2), var(--surface-2) 3px, var(--surface) 3px, var(--surface) 6px); }
.legend .swatch.untracked { background: none; border-style: dashed; }
.legend .marks { width: 18px; }
