/* ============================================================
   Soft, airy, rounded. Tone over borders. One warm accent.
   ============================================================ */

:root {
  --bg:        #ffffff;
  --card:      #f5f5f6;   /* the soft gray block           */
  --card-2:    #ffffff;   /* inner surfaces sitting on card */
  --line:      #ececee;
  --text:      #2b2b2e;
  --text-dim:  #8a8a90;
  --text-faint:#b7b7bd;
  --ink:       #3d3d3f;   /* charcoal: primary + selected   */
  --ink-fg:    #ffffff;
  --accent:    #ffc93c;   /* warm yellow, used sparingly    */
  --accent-fg: #2b2b2e;
  --good:      #a8e0b8;
  --bad:       #f4a3a3;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.06);
  --shadow-lg: 0 6px 28px rgba(0,0,0,.10);
  --r-lg: 22px;
  --r:    16px;
  --r-sm: 12px;
  --tabbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f0f11;
    --card:      #1a1a1d;
    --card-2:    #232327;
    --line:      #2a2a2f;
    --text:      #f0f0f2;
    --text-dim:  #8e8e96;
    --text-faint:#62626a;
    --ink:       #f0f0f2;
    --ink-fg:    #17171a;
    --accent:    #ffc93c;
    --accent-fg: #2b2b2e;
    --good:      #7fc79a;
    --bad:       #e08b8b;
    --shadow-sm: 0 2px 8px rgba(0,0,0,.4);
    --shadow-lg: 0 6px 28px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body {
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 26px);
}

button, input, select, textarea { font: inherit; color: inherit; font-size: 16px; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; border: none; background: none; }

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  min-height: 60px;
}
.topbar-title {
  text-align: center;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0;
}
.topbar-left, .topbar-right { display: flex; align-items: center; }
.topbar-right { justify-content: flex-end; }

/* floating circular icon button */
.circ {
  width: 44px; height: 44px; flex: none;
  border-radius: 50%;
  background: var(--card-2);
  box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1;
  color: var(--text);
  transition: transform .12s ease, background .15s ease;
}
@media (prefers-color-scheme: dark) { .circ { background: var(--card); } }
.circ:active { transform: scale(.9); }
.circ:disabled { opacity: .3; }

/* ---------------- layout ---------------- */
.main { max-width: 760px; margin: 0 auto; padding: 4px 18px 40px; }

.section-title {
  font-size: 13px; font-weight: 700;
  color: var(--text-dim);
  margin: 26px 6px 10px;
  letter-spacing: -.01em;
}
.section-title:first-child { margin-top: 8px; }

.empty { text-align: center; color: var(--text-dim); padding: 56px 20px; line-height: 1.7; }
.empty h2 { font-size: 19px; font-weight: 700; color: var(--text); margin: 0 0 8px; }

/* ---------------- buttons ---------------- */
.btn {
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  padding: 11px 20px;
  font-size: 15px; font-weight: 600;
  transition: transform .1s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--ink); color: var(--ink-fg); }
.btn-accent  { background: var(--accent); color: var(--accent-fg); }
.btn-ghost   { background: transparent; color: var(--text-dim); padding: 8px 12px; }
.btn-ghost:hover { color: var(--text); }
.btn-danger  { background: var(--bad); color: #3a2020; }
@media (prefers-color-scheme: dark) { .btn-danger { color: #23100f; } }
.btn-sm { padding: 8px 14px; font-size: 13.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .35; }

/* A plain .btn sitting on a .card would be card-on-card and vanish. */
.card .btn:not(.btn-primary):not(.btn-danger):not(.btn-accent):not(.btn-ghost) {
  background: var(--card-2);
}

/* ---------------- date nav ---------------- */
.datenav {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 12px 12px;
  margin-bottom: 14px;
}
.datenav-label { flex: 1; text-align: center; }
.datenav-day { font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
.datenav-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.datenav .circ { width: 40px; height: 40px; font-size: 17px; }

/* ---------------- tracker card ---------------- */
.card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-emoji {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--tcolor, var(--accent)) 32%, var(--card-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; line-height: 1;
}
.card-name { font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; }
.card-meta { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.card-head-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.logged-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--tcolor, var(--accent)); flex: none;
}

/* ---------------- controls ---------------- */
/* Selected = pastel fill with dark text (never white-on-pastel). */
.seg { display: flex; gap: 10px; }
.seg > button {
  flex: 1;
  background: var(--card-2);
  border-radius: var(--r);
  padding: 14px 8px;
  font-weight: 650; font-size: 15px;
  color: var(--text-dim);
  transition: transform .1s ease, background .18s ease, color .18s ease;
}
.seg > button:active { transform: scale(.97); }
/* Yes takes the tracker's colour, No stays neutral — same language the
   heatmap uses, and it avoids implying that "yes" is the good answer. */
.seg > button.yes[aria-pressed="true"] { background: var(--tcolor, var(--accent)); color: #2b2b2e; }
.seg > button.no[aria-pressed="true"]  {
  background: color-mix(in srgb, var(--text-faint) 30%, var(--card-2));
  color: var(--text);
}

.stepper { display: flex; align-items: center; gap: 14px; }
.stepper .val {
  flex: 1; text-align: center;
  font-size: 34px; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -.03em;
}
.stepper .val.unset { color: var(--text-faint); font-weight: 500; font-size: 24px; }
.step-btn {
  width: 52px; height: 52px; flex: none;
  border-radius: 50%;
  background: var(--card-2);
  font-size: 24px; font-weight: 500; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s ease;
}
.step-btn:active { transform: scale(.9); }

.numrow { display: flex; align-items: center; gap: 12px; }
.numrow input {
  flex: 1; min-width: 0;
  background: var(--card-2);
  border: none;
  border-radius: var(--r);
  padding: 14px 16px;
  font-size: 26px; font-weight: 700;
  font-variant-numeric: tabular-nums; text-align: center;
  letter-spacing: -.02em;
  -moz-appearance: textfield;
}
.numrow input::-webkit-outer-spin-button,
.numrow input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.numrow input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.unit { color: var(--text-dim); font-size: 14px; font-weight: 600; flex: none; min-width: 26px; }

.scale { display: flex; gap: 8px; }
.scale > button {
  flex: 1; aspect-ratio: 1/1; max-height: 54px;
  border-radius: var(--r);
  background: var(--card-2);
  font-weight: 700; font-size: 15px;
  color: var(--text-dim);
  transition: transform .1s ease, background .18s ease, color .18s ease;
}
.scale > button:active { transform: scale(.93); }
.scale > button[aria-pressed="true"] {
  background: var(--tcolor, var(--accent));
  color: #2b2b2e;
}
.scale-legend { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-faint); margin-top: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card-2);
  border-radius: 999px;
  padding: 10px 17px;
  font-size: 14px; font-weight: 600;
  color: var(--text-dim);
  transition: transform .1s ease, background .18s ease, color .18s ease;
}
.chip:active { transform: scale(.95); }
.chip[aria-pressed="true"] { background: var(--tcolor, var(--accent)); color: #2b2b2e; }

.ta {
  width: 100%;
  background: var(--card-2);
  border: none;
  border-radius: var(--r);
  padding: 14px;
  font-size: 15px; line-height: 1.65;
  resize: vertical; min-height: 92px;
  font-family: inherit;
}
.ta:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

.note-row { margin-top: 10px; }
.note-row input {
  width: 100%;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text-dim);
}
.note-row input:focus { outline: none; background: var(--card-2); color: var(--text); }

/* ---------------- stats ---------------- */
/* Fixed 4-across grid: extra stats wrap to a second row rather than
   scrolling off the edge where nobody finds them. */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  row-gap: 16px;
  background: var(--card-2);
  border-radius: var(--r);
  padding: 14px 4px;
  margin-bottom: 16px;
}
.stat {
  text-align: center;
  padding: 0 6px;
  min-width: 0;
  border-right: 1px solid var(--line);
}
.stat:nth-child(4n), .stat:last-child { border-right: none; }
.stat-v { overflow-wrap: anywhere; }

.stats.three { grid-template-columns: repeat(3, 1fr); }
.stats.three .stat:nth-child(3n) { border-right: none; }
.stat-v { font-size: 22px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-k { font-size: 12px; color: var(--text-faint); margin-top: 3px; }

/* ---------------- history ---------------- */
.picker {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 4px 0 14px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.picker::-webkit-scrollbar { display: none; }
.picker .chip { flex: none; background: var(--card); }

.heatwrap { overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.heat { display: flex; gap: 3px; }
.heat-col { display: flex; flex-direction: column; gap: 3px; }
.heat-cell {
  width: 13px; height: 13px; border-radius: 4px;
  background: var(--card-2);
  padding: 0; flex: none;
}
.heat-cell.future { opacity: .3; }
.heat-cell.sel { outline: 2px solid var(--ink); outline-offset: 1px; }
.heat-months { display: flex; gap: 3px; margin-bottom: 5px; font-size: 10px; color: var(--text-faint); height: 12px; }
.heat-months > span { width: 13px; flex: none; white-space: nowrap; }
.heat-legend { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-faint); margin-top: 10px; }

.chart { width: 100%; height: 180px; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--tcolor, var(--accent)); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart .area { fill: var(--tcolor, var(--accent)); opacity: .18; }
.chart .pt   { fill: var(--tcolor, var(--accent)); }
.chart text  { fill: var(--text-faint); font-size: 10px; }

.loglist { display: flex; flex-direction: column; gap: 8px; }
.logitem { background: var(--card); border-radius: var(--r); padding: 13px 15px; }
.logitem-d { font-size: 12px; color: var(--text-faint); margin-bottom: 4px; font-weight: 600; }
.logitem-v { font-size: 15px; white-space: pre-wrap; word-break: break-word; }

/* ---------------- manage ---------------- */
.trow {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.trow.archived { opacity: .45; }
.trow-body { flex: 1; min-width: 0; }
.trow-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.trow-meta { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.trow-actions { display: flex; gap: 4px; flex: none; align-items: center; }
.trow-actions .circ { width: 34px; height: 34px; font-size: 14px; box-shadow: none; }

/* ---------------- form ---------------- */
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; font-weight: 700; color: var(--text-dim); margin-bottom: 7px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%;
  background: var(--card);
  border: none;
  border-radius: var(--r);
  padding: 13px 14px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.field .hint { font-size: 12.5px; color: var(--text-faint); margin-top: 6px; line-height: 1.55; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 500; color: var(--text); }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2.5px solid transparent; padding: 0;
  transition: transform .12s ease;
}
.swatch[aria-pressed="true"] { border-color: var(--ink); transform: scale(1.1); }

/* ---------------- sheet ---------------- */
.backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
@media (min-width: 620px) { .backdrop { align-items: center; padding: 24px; } }
@keyframes fade { from { opacity: 0 } }
@keyframes slideup { from { transform: translateY(20px); opacity: .5 } }

.sheet {
  background: var(--bg);
  border-radius: 26px 26px 0 0;
  width: 100%; max-width: 520px;
  max-height: 88dvh; overflow-y: auto;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  animation: slideup .24s cubic-bezier(.2,.8,.3,1);
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 620px) { .sheet { border-radius: 26px; } }
.sheet h2 { margin: 0 0 18px; font-size: 19px; font-weight: 700; letter-spacing: -.02em; text-align: center; }
.sheet-actions { display: flex; gap: 10px; margin-top: 22px; }
.sheet-actions .btn { flex: 1; padding: 14px; }

/* ---------------- floating capsule tab bar ---------------- */
.tabbar {
  position: fixed; z-index: 30;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 430px;
  display: flex;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  box-shadow: var(--shadow-lg);
  border-radius: 999px;
  padding: 6px;
}
.tab {
  flex: 1;
  color: var(--text-faint);
  height: 48px;
  border-radius: 999px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-size: 10px; font-weight: 650; letter-spacing: .01em;
  transition: color .18s ease, background .18s ease;
}
.tab-ico { font-size: 17px; line-height: 1; }
.tab[aria-selected="true"] { color: var(--text); background: var(--card); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translate(-50%, 12px);
  background: var(--ink); color: var(--ink-fg);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200; max-width: 90vw; text-align: center;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hidden { display: none !important; }
