:root {
  --bg: #fafaf9;
  --card: #ffffff;
  --text: #1c1917;
  --text-dim: #78716c;
  --border: #e7e5e4;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --done: #059669;
  --done-soft: #ecfdf5;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --card: #1e1d1b;
    --text: #f5f5f4;
    --text-dim: #a8a29e;
    --border: #33312e;
    --accent: #818cf8;
    --accent-soft: #27263a;
    --done: #34d399;
    --done-soft: #16302a;
    --danger: #f87171;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0 auto;
  max-width: 520px;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

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

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(20px + env(safe-area-inset-top)) 0 16px;
}

.app-logo {
  width: 44px;
  height: 44px;
  flex: none;
}

.app-title { flex: 1; min-width: 0; }

.app-title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.today-label {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--text-dim);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--card);
  color: var(--text-dim);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:active { transform: scale(0.96); }

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

.metric-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.metric-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  border-left: 3px solid var(--border);
}

.metric-card.entered { border-left-color: var(--done); }

.metric-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.metric-name {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.status-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  white-space: nowrap;
  background: var(--bg);
  color: var(--text-dim);
}

.metric-card.entered .status-pill {
  background: var(--done-soft);
  color: var(--done);
}

.edit-metric-btn {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 6px;
  margin: -6px -6px -6px 0;
  cursor: pointer;
  border-radius: 8px;
}

/* integer stepper */

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-btn {
  width: 52px;
  height: 48px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 24px;
  font-weight: 500;
  cursor: pointer;
}

.step-btn:active { background: var(--accent-soft); }
.step-btn:disabled { opacity: 0.35; }

.stepper-value {
  flex: 1;
  height: 48px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  -moz-appearance: textfield;
}

.stepper-value::-webkit-outer-spin-button,
.stepper-value::-webkit-inner-spin-button { -webkit-appearance: none; }

.stepper-value:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* category chips */

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

.chip {
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* float slider */

.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.slider-value {
  flex: none;
  min-width: 58px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.slider-row input[type="range"] {
  flex: 1;
  height: 44px;
  margin: 0;
  accent-color: var(--accent);
}

.metric-card:not(.entered) input[type="range"] { opacity: 0.4; }
.metric-card:not(.entered) .slider-value { color: var(--text-dim); }

.slider-bounds {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* clear entry */

.clear-btn {
  margin-top: 10px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  padding: 4px 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- add button & footer ---------- */

.add-btn {
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  border: 1.5px dashed var(--border);
  border-radius: 16px;
  background: none;
  color: var(--text-dim);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.add-btn:active { background: var(--accent-soft); color: var(--accent); }

.footnote {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 20px;
}

.empty-state {
  text-align: center;
  padding: 48px 16px 8px;
}

.empty-title { font-size: 18px; font-weight: 700; margin: 0 0 8px; }
.empty-hint { color: var(--text-dim); margin: 0; }

/* ---------- sheets (dialogs) ---------- */

.sheet {
  width: 100%;
  max-width: 520px;
  margin: auto auto 0;
  border: none;
  border-radius: 20px 20px 0 0;
  background: var(--card);
  color: var(--text);
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
}

.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 14px;
}

.sheet h2 { margin: 0 0 4px; font-size: 19px; }

.sheet-hint {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--text-dim);
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.sheet-btn:active { background: var(--accent-soft); }
.sheet-btn-title { font-size: 16px; font-weight: 600; }
.sheet-btn-sub { font-size: 13px; color: var(--text-dim); }

.sheet-close {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- metric form ---------- */

.field { display: block; margin-bottom: 14px; min-width: 0; }

.field > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
}

.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.type-picker {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.type-picker label { flex: 1; }
.type-picker input { position: absolute; opacity: 0; }

.type-picker span {
  display: block;
  text-align: center;
  padding: 11px 4px;
  font-size: 15px;
  font-weight: 500;
  background: var(--bg);
  cursor: pointer;
}

.type-picker label + label span { border-left: 1px solid var(--border); }

.type-picker input:checked + span {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.form-error {
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
  margin: 0 0 10px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.spacer { flex: 1; }

.primary-btn,
.ghost-btn,
.danger-btn {
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.primary-btn { background: var(--accent); color: #fff; }
.ghost-btn { background: var(--bg); color: var(--text); }
.danger-btn { background: none; color: var(--danger); padding: 12px 8px; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
