/* Mood Log — calm, low-stimulation UI. */

:root {
  /* Light palette (spec §5) */
  --bg:        #F7F4EF;
  --card:      #FFFFFF;
  --text:      #2D2A26;
  --text-mut:  #6B665E;
  --accent:    #7BA098;
  --accent2:   #C9A87C;
  --divider:   #E8E2D8;
  --divider-strong: #D8D1C2;
  --error:     #8C5C5C;
  --shadow:    0 1px 3px rgba(45, 42, 38, 0.06), 0 4px 12px rgba(45, 42, 38, 0.04);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;

  --s-1: 8px;
  --s-2: 12px;
  --s-3: 16px;
  --s-4: 24px;

  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #1C1A17;
    --card:      #26231F;
    --text:      #EDE7DC;
    --text-mut:  #9B958B;
    --accent:    #8FB5AC;
    --accent2:   #D4B68C;
    --divider:   #34302A;
    --divider-strong: #443F37;
    --error:     #C28C8C;
    --shadow:    0 1px 3px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  /* Safe-area insets for notch/home-indicator on iOS. */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 var(--s-3) 0; letter-spacing: -0.005em; }
.muted { color: var(--text-mut); font-size: 15px; }
.error { color: var(--error); font-size: 14px; margin-top: var(--s-2); }

button { font: inherit; color: inherit; }

/* ---------- View scaffolding ---------- */
.view {
  min-height: 100vh;
  min-height: 100svh;
  padding: var(--s-3) var(--s-3) 96px var(--s-3);
  max-width: 560px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-2) 0 var(--s-4) 0;
}
.topbar h1 { flex: 1; text-align: center; }
.topbar-actions { display: flex; gap: var(--s-1); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--divider);
  border-radius: 50%;
  width: var(--tap);
  height: var(--tap);
  font-size: 18px;
  color: var(--text-mut);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 200ms ease-out;
}
.icon-btn:hover { background: var(--divider); }
.icon-btn:active { background: var(--divider-strong); }

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-4);
  box-shadow: var(--shadow);
}

/* ---------- Date toggle ---------- */
.date-toggle {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  padding: 4px;
  margin-bottom: var(--s-3);
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
}
.seg {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  padding: 10px 12px;
  min-height: var(--tap);
  font-size: 15px;
  color: var(--text-mut);
  cursor: pointer;
  transition: background-color 200ms ease-out, color 200ms ease-out;
}
.seg[aria-selected="true"] {
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 600;
}
.date-display {
  flex: 0 0 auto;
  padding: 0 12px;
  font-size: 14px;
}

/* ---------- Offline banner / PWA hint ---------- */
.offline-banner,
.pwa-hint {
  background: var(--accent2);
  color: #2D2A26;
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  margin-bottom: var(--s-3);
  font-size: 14px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.pwa-hint { background: var(--divider); color: var(--text); }
.pwa-hint span { flex: 1; }

/* ---------- Sleep section ---------- */
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.field-block { margin-bottom: var(--s-3); }
.field-block:last-child { margin-bottom: 0; }

.label {
  display: block;
  font-size: 15px;
  color: var(--text);
  margin-bottom: var(--s-1);
}

.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--bg);
  border-radius: var(--r-md);
  border: 1px solid var(--divider);
  overflow: hidden;
}
.step-btn {
  background: transparent;
  border: none;
  width: var(--tap);
  height: var(--tap);
  font-size: 22px;
  color: var(--accent);
  cursor: pointer;
  transition: background-color 200ms ease-out;
}
.step-btn:active { background: var(--divider); }
.step-value {
  display: inline-block;
  min-width: 60px;
  text-align: center;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.emoji-row {
  display: flex;
  gap: var(--s-1);
  justify-content: space-between;
}
.emoji-btn {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  min-height: 56px;
  font-size: 28px;
  cursor: pointer;
  transition: transform 200ms ease-out, background-color 200ms ease-out, border-color 200ms ease-out, box-shadow 200ms ease-out;
}
.emoji-btn[aria-checked="true"] {
  background: var(--card);
  border-color: var(--accent2);
  transform: scale(1.08);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent2) 30%, transparent);
}

/* ---------- 0–10 scales ---------- */
.scale-block {
  margin-bottom: var(--s-4);
}
.scale-block:last-child { margin-bottom: 0; }

.scale-label {
  font-size: 15px;
  margin-bottom: var(--s-1);
  color: var(--text);
}
.scale {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 4px;
}
.scale-num {
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: var(--r-sm);
  min-height: var(--tap);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--text-mut);
  cursor: pointer;
  transition: background-color 200ms ease-out, color 200ms ease-out, border-color 200ms ease-out;
}
.scale-num[aria-checked="true"] {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
  font-weight: 600;
}
.scale-anchors {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-top: 4px;
}

/* ---------- Segmented (meds) ---------- */
.segmented {
  display: flex;
  background: var(--bg);
  border-radius: var(--r-md);
  border: 1px solid var(--divider);
  overflow: hidden;
}
.seg-opt {
  flex: 1;
  background: transparent;
  border: none;
  min-height: var(--tap);
  font-size: 15px;
  color: var(--text-mut);
  cursor: pointer;
  border-right: 1px solid var(--divider);
  transition: background-color 200ms ease-out, color 200ms ease-out;
}
.seg-opt:last-child { border-right: none; }
.seg-opt[aria-pressed="true"] {
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 600;
}

/* ---------- Toggles (Y/N) ---------- */
.toggles {
  display: flex;
  gap: var(--s-1);
  margin-bottom: var(--s-3);
}
.toggle {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  padding: 10px var(--s-2);
  min-height: var(--tap);
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background-color 200ms ease-out, border-color 200ms ease-out;
}
.toggle[aria-pressed="true"] {
  background: var(--card);
  border-color: var(--accent);
}
.toggle-label { font-size: 14px; color: var(--text); }
.toggle-state {
  font-size: 13px;
  color: var(--text-mut);
  font-weight: 600;
}
.toggle[aria-pressed="true"] .toggle-state {
  color: var(--accent);
}

/* ---------- Free-text fields ---------- */
.field {
  display: block;
  margin-bottom: var(--s-3);
}
.field:last-child { margin-bottom: 0; }
.field span {
  display: block;
  font-size: 15px;
  margin-bottom: var(--s-1);
  color: var(--text);
}
.field input,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  padding: 12px;
  font: inherit;
  color: var(--text);
  min-height: var(--tap);
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
textarea { resize: vertical; line-height: 1.5; }

/* ---------- Chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1);
}
.chip {
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: var(--tap);
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  transition: background-color 200ms ease-out, border-color 200ms ease-out, color 200ms ease-out;
}
.chip[aria-pressed="true"] {
  background: var(--accent2);
  border-color: var(--accent2);
  color: #2D2A26;
  font-weight: 600;
}
.chip-none { color: var(--text-mut); }
.chip-none[aria-pressed="true"] {
  background: var(--divider);
  border-color: var(--divider-strong);
  color: var(--text);
}

.chip-prompt {
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px solid var(--divider);
}

/* ---------- Optional collapsibles ---------- */
.optional {
  border-top: 1px solid var(--divider);
  padding: var(--s-2) 0;
}
.optional:first-child { border-top: none; padding-top: 0; }
.optional:last-child { padding-bottom: 0; }
.optional summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: var(--tap);
  font-size: 16px;
}
.optional summary::-webkit-details-marker { display: none; }
.optional summary > span:last-child { font-size: 13px; }
.optional summary::after {
  content: "›";
  margin-left: var(--s-2);
  color: var(--text-mut);
  font-size: 20px;
  transition: transform 200ms ease-out;
}
.optional[open] summary::after { transform: rotate(90deg); }
.optional textarea { margin-top: var(--s-2); }

/* ---------- Submit bar ---------- */
.submit-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--s-2) var(--s-3) calc(var(--s-2) + env(safe-area-inset-bottom)) var(--s-3);
  background: linear-gradient(to top, var(--bg) 70%, color-mix(in srgb, var(--bg) 0%, transparent));
  pointer-events: none;
}
.submit-bar > * { pointer-events: auto; }
.submit-bar .btn-primary {
  max-width: 560px;
  margin: 0 auto;
  display: block;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  border-radius: var(--r-md);
  padding: 14px;
  min-height: 52px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 200ms ease-out;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, #000 0%); }
.btn-primary:active { background: color-mix(in srgb, var(--accent) 80%, #000 20%); }
.btn-primary:disabled {
  background: var(--divider-strong);
  color: var(--text-mut);
  cursor: default;
}
.btn-primary.is-confirm {
  background: var(--accent2);
  color: #2D2A26;
}

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--divider-strong);
  border-radius: var(--r-md);
  padding: 12px 16px;
  min-height: var(--tap);
  font-size: 15px;
  cursor: pointer;
  transition: background-color 200ms ease-out;
}
.btn-secondary:hover { background: var(--divider); }

.preset-row { display: flex; gap: var(--s-1); flex-wrap: wrap; }
.preset-row .btn-secondary { flex: 1; min-width: 110px; }

/* ---------- Form status ---------- */
.form-status {
  padding: var(--s-2) var(--s-3);
  margin: var(--s-2) 0;
  border-radius: var(--r-md);
  background: var(--divider);
  color: var(--text);
  font-size: 14px;
}
.form-status.is-error { background: color-mix(in srgb, var(--error) 18%, var(--bg)); color: var(--error); }

/* ---------- Setup view ---------- */
.setup-card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin: var(--s-4) auto;
  box-shadow: var(--shadow);
}
.setup-card h1 { margin-bottom: var(--s-2); }
.setup-card p { margin: 0 0 var(--s-4) 0; }
.setup-card code { font-size: 13px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }

/* ---------- Done view ---------- */
.done-card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin: 20vh auto var(--s-4) auto;
  box-shadow: var(--shadow);
  text-align: center;
}
.done-card h1 { margin-bottom: var(--s-2); }
.check { color: var(--accent); margin-bottom: var(--s-2); }
.link-quiet {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  padding: var(--s-2);
  font-size: 15px;
  margin: var(--s-2) 0;
}
.done-card .btn-secondary { margin-top: var(--s-3); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
    transform: none !important;
  }
  .emoji-btn[aria-checked="true"] { transform: none; }
}
