/* ---------- Colors (light mode, then dark mode) ---------- */

:root {
  color-scheme: light;
  --bg: #f3f2ee;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --text: #161615;
  --text-2: #52514e;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.2);
  --grid: #e1e0d9;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e2eee9;
  --danger: #b42318;
  /* Chart series: slots 1 and 2 of the dataviz reference palette */
  --series-mood: #2a78d6;
  --series-energy: #eb6834;
  --radius: 14px;
  --tabbar: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #252524;
    --text: #f4f4f2;
    --text-2: #c3c2b7;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    --grid: #2c2c2a;
    --accent: #5fb39b;
    --accent-text: #0b1f19;
    --accent-soft: #1c2c27;
    --danger: #f28b7d;
    --series-mood: #3987e5;
    --series-energy: #d95926;
  }
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 32px);
}

.muted, .hint { color: var(--text-2); }
.hint { font-size: 13px; margin: 6px 0 0; }

/* ---------- Top bar and tabs ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 640px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { font-weight: 700; font-size: 15px; color: var(--text-2); }
.sync-status { margin-left: auto; font-size: 13px; color: var(--text-2); }

/* Phone: tabs are a bar at the bottom of the screen */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 600;
  color: var(--text-2); text-decoration: none;
}
.tab.active { color: var(--accent); }

/* PC: tabs sit in the top bar */
@media (min-width: 800px) {
  .topbar-inner { max-width: 760px; }
  .tabs {
    position: static; height: auto; padding: 0; gap: 4px;
    background: none; border: 0;
  }
  .tab { flex-direction: row; gap: 8px; font-size: 15px; padding: 8px 14px; border-radius: 999px; }
  .tab svg { width: 18px; height: 18px; }
  .tab:hover { background: var(--surface-2); }
  .tab.active { background: var(--accent-soft); }
  .container { padding-bottom: 48px; }
}

/* ---------- Headings, cards, sections ---------- */

.view h2 { font-size: 28px; line-height: 1.2; margin: 4px 0 16px; letter-spacing: -0.01em; }
.eyebrow { margin: 8px 0 0; color: var(--text-2); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 20px 0;
}
.card h3 { margin: 0 0 12px; font-size: 17px; }
.card p { margin: 0 0 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

.section { margin: 24px 0; }
.section > h3, .section > summary {
  display: flex; align-items: center; gap: 8px;
  margin: 0 4px 8px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-2);
}
.section.danger > h3 { color: var(--danger); }
.count { font-weight: 600; letter-spacing: 0; opacity: 0.8; }

.fold > summary { cursor: pointer; list-style: none; min-height: 32px; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary svg { transition: transform 0.15s; }
.fold[open] > summary svg { transform: rotate(90deg); }

.empty {
  margin: 0; padding: 16px;
  text-align: center; color: var(--text-2);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}

/* ---------- Buttons, inputs, chips ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: none; color: var(--accent); }
label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.link {
  background: none; border: 0; padding: 0;
  color: var(--accent); font-weight: 600; font-size: 14px; text-decoration: none;
}
.link:hover { text-decoration: underline; }

.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border: 1px solid var(--border-strong); border-radius: 50%;
  background: var(--surface);
}
.icon-btn:disabled { opacity: 0.35; cursor: default; }

input[type="text"], input[type="date"], select, textarea {
  width: 100%; min-height: 44px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px;
}
textarea { resize: vertical; line-height: 1.5; }

.chips {
  display: flex; gap: 8px;
  overflow-x: auto; padding: 2px 2px 4px; margin: 12px -2px;
  scrollbar-width: none;
}
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); font-size: 14px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ---------- Adding tasks ---------- */

.quick-add { display: grid; gap: 8px; margin: 16px 0; }
.quick-add-row { display: flex; gap: 8px; }
.quick-add-row input[type="text"] { flex: 1; }
.quick-add-row.extras > * { flex: 1; min-width: 0; }

/* ---------- Task list ---------- */

.tasks {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.task { display: flex; align-items: flex-start; }
.task + .task { border-top: 1px solid var(--border); }

.check {
  flex: none; width: 48px; height: 48px;
  display: grid; place-items: center;
  background: none; border: 0;
}
.check .box {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border: 2px solid var(--text-2); border-radius: 50%;
  color: transparent;
}
.check:hover .box { border-color: var(--accent); }
.task.done .check .box { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.task-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 16px 12px 0;
  background: none; border: 0; text-align: left;
}
.task-title { overflow-wrap: anywhere; }
.task.done .task-title { color: var(--text-2); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; color: var(--text-2); }
.due.overdue { color: var(--danger); font-weight: 600; }
.cat, .has-notes { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Task editor dialog ---------- */

dialog.sheet {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 0; border-radius: 16px;
  background: var(--surface); color: var(--text);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog.sheet form { padding: 20px; }
dialog.sheet h2 { margin: 0 0 16px; font-size: 20px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 14px; color: var(--text-2); }
.field > input, .field > select, .field > textarea { color: var(--text); font-size: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }

/* ---------- Journal ---------- */

.score { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.score-label { display: flex; align-items: center; gap: 8px; width: 72px; flex: none; font-size: 14px; color: var(--text-2); }
.score-buttons { display: flex; gap: 6px; flex: 1; }
.score-btn {
  flex: 1; height: 40px; min-width: 0;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); font-weight: 600;
}
.score-btn:hover { background: var(--surface-2); }
.score-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* A short line in the series color, used as a key in the legend, tooltip and editor */
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; flex: none; }
.key-mood { background: var(--series-mood); }
.key-energy { background: var(--series-energy); }

.entry-text { margin-top: 8px; min-height: 110px; }
.entry-text.tall { min-height: 200px; }

.day-nav { display: flex; align-items: center; gap: 12px; }
.day-label { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; font-size: 14px; color: var(--text-2); }
.day-label strong { font-size: 17px; color: var(--text); }

/* Chart */
.legend { display: flex; gap: 16px; margin: -4px 0 8px; font-size: 13px; color: var(--text-2); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.chart { position: relative; height: 180px; touch-action: pan-y; border-radius: 8px; }
.chart svg { display: block; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--text-2); font-size: 11px; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart .line-mood { stroke: var(--series-mood); }
.chart .line-energy { stroke: var(--series-energy); }
.chart .mark { stroke: var(--surface); stroke-width: 2; }
.chart .mark-mood { fill: var(--series-mood); }
.chart .mark-energy { fill: var(--series-energy); }

.tooltip {
  position: absolute; pointer-events: none;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 13px; white-space: nowrap;
}
.tip-date { color: var(--text-2); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-row strong { font-size: 15px; min-width: 10px; }
.tip-row span:last-child { color: var(--text-2); }

/* Past entries */
.entries {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.entries li + li { border-top: 1px solid var(--border); }
.entry-row {
  width: 100%;
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 12px;
  padding: 12px 16px;
  background: none; border: 0; text-align: left;
}
.entry-row:hover { background: var(--surface-2); }
.entry-row.current { background: var(--accent-soft); }
.entry-date { font-weight: 600; }
.entry-scores { display: flex; gap: 12px; justify-content: flex-end; font-size: 13px; color: var(--text-2); }
.badge { display: inline-flex; align-items: center; gap: 6px; }
.entry-preview {
  grid-column: 1 / -1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px; color: var(--text-2);
}

/* ---------- Settings ---------- */

.sign-in { display: grid; gap: 4px; }
.sign-in input { color: var(--text); font-size: 16px; }
.sign-in .btn { justify-self: start; margin-top: 4px; }
.sign-in .notice { margin-top: 8px; }
.sync-status .link { font-size: 13px; }
input[type="email"], input[type="password"] {
  width: 100%; min-height: 44px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px;
}

.notice { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); }
.notice.error { background: none; border: 1px solid var(--danger); color: var(--danger); }
