/* Weight — dark-first, one-handed, phone-legible.
   No external fonts or assets: system stack only. */

:root {
  color-scheme: dark light;

  --bg: #14161f;
  --surface: #1c1f2b;
  --surface-2: #262a38;
  --line: #333849;
  --text: #eef0f7;
  --muted: #9aa1b8;
  --accent: #7f9cff;
  --accent-ink: #0d1020;
  --danger: #ff6b6b;
  --ok: #52d1a4;

  --raw-point: #9aa1b8;
  --trend-line: #52d1a4;

  --tap: 56px;          /* minimum touch target, everywhere */
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #eef0f6;
    --line: #dce0ea;
    --text: #15171f;
    --muted: #5c6379;
    --accent: #3a5bd9;
    --accent-ink: #ffffff;
    --danger: #c62d2d;
    --ok: #12855f;

    --raw-point: #8890a6;
    --trend-line: #12855f;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body { padding-bottom: calc(32px + var(--safe-b)); }

[hidden] { display: none !important; }

button, input, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); font-weight: 600; }

/* ── Setup ───────────────────────────────────────────────────────────────- */

.setup {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.setup-inner { width: 100%; max-width: 380px; text-align: center; }
.setup-icon { border-radius: 22px; }
.setup h1 { margin: 12px 0 4px; font-size: 30px; }
.setup p { margin: 0 0 24px; }
.setup form { text-align: left; }

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

input, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 17px;   /* >=16px stops iOS zooming on focus */
}
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.btn-primary, .btn-ghost, .btn-danger {
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 17px;
  font-weight: 700;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn-ghost   { background: var(--surface-2); color: var(--text); }
.btn-danger  { background: transparent; color: var(--danger); border-color: var(--line); }
.btn-danger[data-armed="true"] { background: var(--danger); color: #fff; border-color: var(--danger); }
button[disabled] { opacity: 0.5; cursor: default; }

/* ── Top bar ─────────────────────────────────────────────────────────────- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top, 0px)) 16px 10px;
}
.brand { font-weight: 800; letter-spacing: 0.02em; }
.linkish {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 15px;
  padding: 10px 4px;      /* keeps the hit area comfortable without looking big */
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Entry form ──────────────────────────────────────────────────────────- */

.entry { padding: 4px 16px 20px; }
.entry-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.entry-field label { margin-top: 0; }
#log-error { margin: 10px 0 0; }
#log-submit { margin-top: 14px; }

/* ── Window controls ─────────────────────────────────────────────────────- */

.window-controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 0 16px 12px;
}
.win-btn {
  min-height: 44px;
  padding: 0 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}
.win-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* ── Chart ───────────────────────────────────────────────────────────────- */

.chart-wrap {
  margin: 0 16px 24px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}
#chart {
  display: block;
  width: 100%;
  height: 320px;
}
.chart-point {
  fill: var(--raw-point);
}
.chart-point-hit {
  fill: transparent;
  cursor: pointer;
}
.chart-trend {
  fill: none;
  stroke: var(--trend-line);
  stroke-width: 0.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart-axis {
  stroke: var(--line);
  stroke-width: 0.3;
}
.chart-axis-label {
  fill: var(--muted);
  font-size: 3.4px;
}

/* ── Edit panel (reuses baby's "sheet" shape) ───────────────────────────── */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.55);
}
.sheet {
  position: fixed;
  z-index: 21;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88svh;
  overflow-y: auto;
  padding: 20px 20px calc(20px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
}
@media (min-width: 640px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: 24px;
    width: 420px;
    transform: translateX(-50%);
    border-radius: 22px;
    border: 1px solid var(--line);
  }
}
.sheet h2 { margin: 0 0 4px; font-size: 22px; }

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}
.sheet-actions .btn-primary { flex: 1 1 auto; width: auto; }

/* ── Toast ───────────────────────────────────────────────────────────────- */

.toast {
  position: fixed;
  z-index: 30;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-b));
  padding: 16px 12px;
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  text-align: center;
}
@media (min-width: 640px) {
  .toast { left: 50%; right: auto; width: 420px; transform: translateX(-50%); }
}

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