/* PillPal — dawn-to-dusk design system.
   Warm paper canvas; morning keyed to saffron, evening to deep indigo.
   Fraunces carries display + numerals, Sora carries UI. */

:root {
  --paper: #f7f1e5;
  --paper-deep: #ece3cf;
  --card: #fffdf8;
  --ink: #241d12;
  --ink-soft: #796c56;
  --line: #e2d7bf;

  --dawn: #d97a16;
  --dawn-deep: #a85a0a;
  --dawn-soft: #f9e3c4;
  --dawn-wash: #fdf4e3;

  --dusk: #4b4585;
  --dusk-deep: #37325f;
  --dusk-soft: #ddd9f0;
  --dusk-wash: #f2f0fa;

  --ember: #cf4a22;
  --danger: #b3361c;

  --font-display: 'Fraunces', Georgia, serif;
  --font-ui: 'Sora', 'Avenir Next', sans-serif;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(63, 48, 22, 0.06), 0 6px 24px -8px rgba(63, 48, 22, 0.12);
  --tap: 44px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(217, 122, 22, 0.07), transparent 60%),
    radial-gradient(1000px 600px at -10% 110%, rgba(75, 69, 133, 0.08), transparent 55%),
    var(--paper);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
}

#app {
  max-width: 660px;
  margin: 0 auto;
  padding: 0 18px calc(110px + env(safe-area-inset-bottom));
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--dawn);
  outline-offset: 2px;
}

/* ---------- Header & navigation ---------- */

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 26px 2px 4px;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.02em;
}
.wordmark .pip { color: var(--dawn); }

.topbar .date {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
}

.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 4px;
  background: rgba(36, 29, 18, 0.92);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 6px;
  box-shadow: 0 10px 30px -8px rgba(36, 29, 18, 0.45);
  z-index: 40;
}

.nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 64px;
  min-height: var(--tap);
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  color: #cdbfa6;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.nav button svg { width: 19px; height: 19px; }
.nav button.active { background: var(--paper); color: var(--ink); }
.nav button.active .icon-sunrise { color: var(--dawn); }

/* ---------- Cards & sections ---------- */

.view { animation: view-in 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes view-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.reveal { animation: view-in 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both; animation-delay: calc(var(--i, 0) * 70ms); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.section-head h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  margin: 0;
  flex: 1;
}
.section-head .meta { color: var(--ink-soft); font-size: 12.5px; font-weight: 500; }

/* ---------- Today ---------- */

.today-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}
.today-hero h1 {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0;
}
.today-hero .sub { color: var(--ink-soft); font-size: 14px; margin-top: 6px; }

.chips { display: flex; gap: 8px; align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
}
.chip svg { width: 15px; height: 15px; }
.chip.streak { color: var(--ember); border-color: #f0cdb8; background: #fdf0e7; }
.chip.progress { color: var(--ink); }

.block { border-top: 4px solid transparent; }
.block.morning { border-top-color: var(--dawn); background: linear-gradient(180deg, var(--dawn-wash), var(--card) 90px); }
.block.evening { border-top-color: var(--dusk); background: linear-gradient(180deg, var(--dusk-wash), var(--card) 90px); }
.block.morning .section-head svg { color: var(--dawn); }
.block.evening .section-head svg { color: var(--dusk); }
.section-head svg { width: 21px; height: 21px; }

.block .done-note {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.block.morning .done-note { color: var(--dawn-deep); }
.block.evening .done-note { color: var(--dusk-deep); }

.pill-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
}
.pill-row:last-child { border-bottom: none; }

.check {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card);
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.check:active { transform: scale(0.88); }
.check svg { width: 20px; height: 20px; color: #fff; opacity: 0; transform: scale(0.4); transition: opacity 0.15s, transform 0.18s cubic-bezier(0.2, 1.6, 0.4, 1); }
.morning .check.on { background: var(--dawn); border-color: var(--dawn); }
.evening .check.on { background: var(--dusk); border-color: var(--dusk); }
.check.on svg { opacity: 1; transform: scale(1); }

.pill-info { flex: 1; min-width: 0; }
.pill-info .name { font-weight: 600; font-size: 15px; transition: color 0.15s; }
.pill-row.taken .name { color: var(--ink-soft); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.pill-info .dose { color: var(--ink-soft); font-size: 12.5px; }
.pill-info .note {
  display: inline-block;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 28px 10px;
}
.empty .big { font-family: var(--font-display); font-size: 18px; color: var(--ink); margin-bottom: 4px; }

/* ---------- History ---------- */

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 8px 12px;
  text-align: center;
}
.stat .num {
  font-family: var(--font-display);
  font-size: 31px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.stat .num svg { width: 22px; height: 22px; color: var(--ember); }
.stat .lbl { color: var(--ink-soft); font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; margin-top: 6px; }

.heatmap { overflow-x: auto; padding-bottom: 4px; }
.heatmap-grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; width: max-content; }
.hm-cell { width: 13px; height: 13px; border-radius: 3.5px; background: var(--paper-deep); }
.hm-cell.l0 { background: var(--paper-deep); }
.hm-cell.l1 { background: #f3d9ae; }
.hm-cell.l2 { background: #ecb96a; }
.hm-cell.l3 { background: #df9230; }
.hm-cell.l4 { background: var(--dawn-deep); }
.hm-cell.future { background: transparent; border: 1px dashed var(--line); }
.hm-cell.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.hm-legend { display: flex; align-items: center; gap: 4px; color: var(--ink-soft); font-size: 11.5px; margin-top: 10px; justify-content: flex-end; }
.hm-legend .hm-cell { display: inline-block; }

.adh-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.adh-row:last-child { border-bottom: none; }
.adh-row .name { flex: 1; font-weight: 600; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adh-row .when { color: var(--ink-soft); font-size: 11.5px; }
.adh-bar { flex: none; width: 110px; height: 7px; border-radius: 99px; background: var(--paper-deep); overflow: hidden; }
.adh-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--dawn), var(--dawn-deep)); }
.adh-row .pct { flex: none; width: 42px; text-align: right; font-weight: 700; font-size: 13.5px; font-variant-numeric: tabular-nums; }

/* ---------- Stack ---------- */

.cost-hero { text-align: center; padding: 26px 18px 22px; }
.cost-hero .num { font-family: var(--font-display); font-size: 46px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.cost-hero .num small { font-size: 22px; vertical-align: 14px; margin-right: 2px; }
.cost-hero .lbl { color: var(--ink-soft); font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; margin-top: 8px; }
.cost-hero .alt { color: var(--ink-soft); font-size: 12.5px; margin-top: 10px; }

.stack-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.stack-row:last-child { border-bottom: none; }
.stack-row .pill-info { flex: 1; }
.stack-row .cost { font-weight: 700; font-size: 13.5px; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.stack-row .edit-btn {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; color: var(--ink-soft);
  border: 1.5px solid var(--line); background: var(--card);
}
.stack-row .edit-btn svg { width: 16px; height: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14.5px;
  background: var(--ink);
  color: var(--paper);
  transition: transform 0.1s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 17px; height: 17px; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: none; color: var(--danger); border: none; font-weight: 600; }
.btn.wide { width: 100%; }

/* ---------- Library ---------- */

.search-wrap { position: sticky; top: 0; z-index: 10; padding: 10px 0 6px; background: linear-gradient(180deg, var(--paper) 75%, transparent); }
.search-wrap input { box-shadow: var(--shadow); border-radius: 999px; padding: 12px 18px; }

.cat-chips { display: flex; gap: 7px; overflow-x: auto; padding: 8px 2px 4px; scrollbar-width: none; }
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chip {
  flex: none;
  border: 1.5px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  min-height: 36px;
}
.cat-chip.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.lib-section h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 22px 2px 4px;
}

.lib-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-top: 7px;
  min-height: 56px;
}
.lib-row .pill-info .name { font-size: 14.5px; }
.lib-row .hint { color: var(--ink-soft); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.lib-row .cost { flex: none; font-weight: 700; font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.lib-row .in-stack {
  flex: none; font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--dawn-deep); background: var(--dawn-soft); border-radius: 6px; padding: 3px 8px;
}

/* ---------- Dialogs ---------- */

dialog {
  border: none;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 50px rgba(36, 29, 18, 0.25);
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 660px;
  margin: auto auto 0;
  background: var(--card);
  max-height: 86dvh;
  overflow-y: auto;
}
@media (min-width: 700px) {
  dialog { border-radius: 18px; margin: auto; max-height: 80dvh; }
}
dialog::backdrop { background: rgba(36, 29, 18, 0.45); backdrop-filter: blur(2px); }

dialog h3 { font-family: var(--font-display); font-size: 22px; font-weight: 600; margin: 0 0 2px; }
dialog .cat-tag { color: var(--ink-soft); font-size: 12.5px; font-weight: 600; }
dialog p.desc { color: var(--ink-soft); font-size: 14px; }

.benefit-list { list-style: none; padding: 0; margin: 10px 0; }
.benefit-list li { padding: 4px 0 4px 22px; position: relative; font-size: 13.5px; }
.benefit-list li::before { content: '✦'; position: absolute; left: 2px; color: var(--dawn); }

.form-row { margin-top: 14px; }
.form-row label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; }

.seg { display: flex; border: 1.5px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { flex: 1; min-height: var(--tap); font-weight: 600; color: var(--ink-soft); display: flex; align-items: center; justify-content: center; gap: 7px; }
.seg button svg { width: 16px; height: 16px; }
.seg button.on.morning-opt { background: var(--dawn-soft); color: var(--dawn-deep); }
.seg button.on.evening-opt { background: var(--dusk-soft); color: var(--dusk-deep); }

.dialog-actions { display: flex; gap: 10px; margin-top: 22px; }
.dialog-actions .btn { flex: 1; }

.sources { color: var(--ink-soft); font-size: 12px; margin-top: 12px; }
.sources li { margin-top: 2px; }

.toast {
  position: fixed;
  bottom: calc(86px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 60;
  animation: toast-in 0.25s ease, toast-out 0.3s ease 2s both;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); } }

@media (max-width: 430px) {
  .adh-bar { width: 64px; }
  .section-head h2 { font-size: 18px; }
  .stat .num { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  .view, .reveal, .toast { animation: none !important; }
}
