/* Evidence — design tokens.

   Six palettes, seven variables each. Any component that hardcodes a colour
   is a bug: a screen built later must theme itself correctly for free, which
   is the entire reason palettes are a preference and layout is not. */

:root {
  --bg: #F1F3F8; --surface: #FFFFFF; --fg: #1B1F2A;
  --muted: #626A7D; --line: #DFE3ED;
  --accent: #4A57E8; --on-accent: #FFFFFF;

  --fs-base: 16px;
  --radius: 16px;
  --radius-lg: 22px;
  --gap: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 5px 14px rgb(0 0 0 / .07);
  --serif: Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-palette="paper"] {
  --bg: #F7F5F0; --surface: #FFFFFF; --fg: #14140F;
  --muted: #706C58; --line: #E7E2D7; --accent: #2F5D45; --on-accent: #F7F5F0;
}
[data-palette="cloud"] {
  --bg: #F1F3F8; --surface: #FFFFFF; --fg: #1B1F2A;
  --muted: #626A7D; --line: #DFE3ED; --accent: #4A57E8; --on-accent: #FFFFFF;
}
[data-palette="clay"] {
  --bg: #FBF3F1; --surface: #FFFFFF; --fg: #26191A;
  --muted: #806763; --line: #EEDFDB; --accent: #B44A34; --on-accent: #FFFFFF;
}
[data-palette="midnight"] {
  --bg: #0C0E11; --surface: #16191E; --fg: #EFF2F3;
  --muted: #949DA9; --line: #232830; --accent: #C8FF4D; --on-accent: #0C0E11;
  --shadow: 0 1px 2px rgb(0 0 0 / .5), 0 6px 18px rgb(0 0 0 / .45);
}
[data-palette="deepsea"] {
  --bg: #0B1418; --surface: #132025; --fg: #E6F0F2;
  --muted: #93A9B0; --line: #1E2E35; --accent: #3FD6C4; --on-accent: #06171A;
  --shadow: 0 1px 2px rgb(0 0 0 / .5), 0 6px 18px rgb(0 0 0 / .45);
}
[data-palette="ember"] {
  --bg: #14161A; --surface: #1D2026; --fg: #E9ECEF;
  --muted: #9AA2AE; --line: #2A2F37; --accent: #F2A65A; --on-accent: #1A1206;
  --shadow: 0 1px 2px rgb(0 0 0 / .5), 0 6px 18px rgb(0 0 0 / .45);
}

[data-text-size="s"] { --fs-base: 15px; }
[data-text-size="m"] { --fs-base: 16px; }
[data-text-size="l"] { --fs-base: 18px; }

* { box-sizing: border-box; }

/* No transition on colour here, deliberately.

   `color` and `background` derive from custom properties, and transitioning
   them across a theme swap leaves the computed colour stranded on the old
   palette's value while --fg already holds the new one — body text rendered
   at 1.07:1 against a dark card, which is invisible. It only showed up when
   switching palettes live, which is precisely what the settings screen does.

   A theme swap should be instant anyway: animating it means a quarter of a
   second where text sits on a background it was never checked against. */
body {
  margin: 0;
  font-family: var(--sans);
  font-size: var(--fs-base);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

.identity-line {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.45rem;
  line-height: 1.22;
  margin: 0;
}

.section-label {
  font-size: .6rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 15px;
}

.meter { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 3px;
              transition: width .4s ease; }

.check {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); background: none; color: var(--on-accent);
  display: grid; place-items: center; cursor: pointer; flex: 0 0 auto;
  font-size: .8rem; line-height: 1;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.check[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.check:active { transform: scale(.9); }

/* .btn is used on both <button> and <a>. The anchor needs the underline reset
   and the flex centring a button gets for free, or link-buttons render
   underlined and with the label sitting off-centre. */
.btn {
  font: inherit; padding: 11px 18px; min-height: 44px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; text-align: center;
}
.btn-primary { background: var(--accent); border-color: var(--accent);
               color: var(--on-accent); font-weight: 600; }

.chip {
  font: inherit; font-size: .8rem; padding: 9px 14px; min-height: 40px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent);
                             color: var(--on-accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- app shell ---------- */

.app-shell { max-width: 560px; margin: 0 auto; padding: 22px 18px 90px; }
.boot { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---------- auth ---------- */

.auth-title { margin: 6px 0 6px; }
.auth-sub { color: var(--muted); font-size: .88rem; margin: 0 0 26px; }
.auth-form { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: .72rem; color: var(--muted); margin-top: 10px; }
.field {
  font: inherit; padding: 13px 15px; min-height: 46px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); width: 100%;
}
.field::placeholder { color: var(--muted); opacity: .75; }

/* Not red. An unknown password is not an error to be shouted at. */
.field-error {
  color: var(--fg); background: var(--line);
  border-radius: 12px; padding: 10px 13px; font-size: .82rem; margin: 14px 0 0;
}

.auth-form .btn-primary { margin-top: 18px; width: 100%; }
.auth-alt { width: 100%; margin-top: 10px; border-color: transparent; color: var(--muted); }
.auth-divider {
  text-align: center; color: var(--muted); font-size: .68rem;
  letter-spacing: .14em; text-transform: uppercase; margin: 20px 0 12px;
}
.auth-demo { width: 100%; }
.auth-fine {
  color: var(--muted); font-size: .72rem; line-height: 1.5;
  margin: 14px 0 0; text-align: center;
}
.btn[disabled] { opacity: .6; cursor: default; }

/* ---------- sync status ---------- */

.sync-status {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px;
  background: var(--surface); color: var(--muted); box-shadow: var(--shadow);
  border-radius: 999px; padding: 9px 16px; font-size: .78rem; max-width: 90vw;
  text-align: center;
}

/* ---------- today ---------- */

.today-head { margin-bottom: 20px; }
.today-head .identity-line { margin: 6px 0 18px; }
.meter-row { display: flex; justify-content: space-between; align-items: baseline;
             margin-bottom: 7px; }
.meter-label { font-size: .74rem; color: var(--muted); }
.meter-value { font-size: .78rem; font-weight: 700; color: var(--accent);
               font-variant-numeric: tabular-nums; }

.strip { display: flex; gap: 6px; margin: 4px 0 22px; }
.strip-day {
  flex: 1; min-height: 54px; padding: 7px 0; border-radius: 14px;
  border: 1px solid transparent; background: var(--surface); color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font: inherit; cursor: pointer; box-shadow: var(--shadow);
  transition: background .15s ease, color .15s ease;
}
.strip-day[aria-pressed="true"] { color: var(--on-accent); background: var(--accent); }
.strip-dow { font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; }
.strip-num { font-size: .95rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.viewing-note { font-size: .78rem; color: var(--muted); margin: 0 0 14px; }
.link-btn {
  font: inherit; font-size: .78rem; background: none; border: 0; padding: 0;
  color: var(--accent); cursor: pointer; text-decoration: underline;
}

.group-label { margin: 22px 0 9px; }
.habit-row { display: flex; align-items: center; gap: 12px; margin-bottom: 9px; }
.habit-off { opacity: .55; }
.habit-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.habit-name { font-size: .95rem; }
.habit-note { font-size: .68rem; color: var(--muted); }
.habit-meta { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums;
              white-space: nowrap; }
.habit-meta.accent { color: var(--accent); font-weight: 700; }
.count-btn { min-height: 36px; padding: 5px 15px; font-size: 1.05rem; line-height: 1; }

.empty { text-align: center; padding: 46px 20px; }
.empty-title { font-family: var(--serif); font-size: 1.15rem; margin: 0 0 6px; }
.empty-sub { color: var(--muted); font-size: .86rem; margin: 0; }

/* ---------- tab bar ---------- */

.view { min-height: 40vh; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 12px; min-height: 56px;
  color: var(--muted); text-decoration: none; font-size: .66rem;
}
.tab[aria-current="page"] { color: var(--accent); font-weight: 700; }
.tab-icon { font-size: 1.05rem; line-height: 1; }

/* ---------- placeholder tabs ---------- */

.placeholder-panel { padding: 40px 4px; }
.placeholder-title { margin: 8px 0 12px; }
.placeholder-body { color: var(--muted); font-size: .88rem; line-height: 1.6; margin: 0; }

/* ---------- sheet ---------- */

body.sheet-open { overflow: hidden; }
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgb(0 0 0 / .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg); color: var(--fg);
  width: 100%; max-width: 560px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 92vh; overflow-y: auto;
  padding: 10px 18px calc(24px + env(safe-area-inset-bottom, 0));
}
.sheet-grip {
  width: 38px; height: 4px; border-radius: 2px; background: var(--line);
  margin: 4px auto 14px;
}
.sheet-title { font-size: 1.25rem; margin: 0 0 6px; }
.sheet-sub { color: var(--muted); font-size: .85rem; line-height: 1.55; margin: 0 0 18px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 22px; }
.sheet-actions .btn { flex: 1; }

@media (min-width: 560px){
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--radius-lg); max-height: 86vh; }
}

/* ---------- settings ---------- */

.palette-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.palette-swatch {
  border: 2px solid var(--line); border-radius: var(--radius);
  padding: 14px 8px; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
}
.palette-swatch[aria-pressed="true"] { border-color: var(--accent); }
.palette-dot { width: 20px; height: 20px; border-radius: 50%; display: block; }
.palette-name { font-size: .72rem; font-weight: 600; }

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

.setting-row { display: flex; flex-direction: column; gap: 10px; }
.setting-label { font-size: .8rem; color: var(--muted); line-height: 1.45; }
.select { min-height: 44px; }

.account-email { margin: 0 0 12px; font-size: .9rem; }
.account-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.danger-btn { color: var(--fg); border-color: var(--line); }
.danger-btn:hover { border-color: var(--fg); }

/* ---------- habit editor ---------- */

.head-row { display: flex; align-items: center; justify-content: space-between; }
.add-btn {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  font-size: 1.15rem; line-height: 1; cursor: pointer; font-family: inherit;
}

/* The habit name is a button so it can be tapped to edit, but it must look
   like text: no border, no chrome, left-aligned. */
.habit-text {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  background: none; border: 0; padding: 0; margin: 0; font: inherit;
  color: inherit; text-align: left; cursor: pointer;
}

.editor { display: flex; flex-direction: column; }
.field-group { margin-bottom: 18px; }
.field-group .field-label { margin-top: 0; margin-bottom: 7px; display: block; }
.field-hint { font-size: .72rem; color: var(--muted); margin: 7px 0 0; line-height: 1.45; }

.seg { display: flex; gap: 7px; }
.seg-btn {
  flex: 1; font: inherit; font-size: .84rem; min-height: 44px; padding: 10px 8px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); cursor: pointer;
}
.seg-btn[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent);
  color: var(--on-accent); font-weight: 600;
}

.limit-row { display: flex; gap: 9px; }
.limit-num { max-width: 92px; text-align: center; }

.day-row { display: flex; gap: 6px; }
.day-btn {
  flex: 1; min-height: 44px; font: inherit; font-size: .8rem;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); cursor: pointer;
}
.day-btn[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent);
  color: var(--on-accent); font-weight: 700;
}

.editor-delete { width: 100%; margin-top: 14px; }
.empty-cta { margin-top: 18px; }

/* ---------- onboarding ---------- */

.ob-progress { display: flex; gap: 6px; margin: 0 0 26px; }
.ob-dot { flex: 1; height: 3px; border-radius: 2px; background: var(--line); }
.ob-dot.on, .ob-dot.done { background: var(--accent); }

.ob-title { margin: 8px 0 10px; }
.ob-sub { color: var(--muted); font-size: .88rem; line-height: 1.6; margin: 0 0 22px; }

.ob-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.ob-chip { text-align: left; }

.ob-next { width: 100%; margin-top: 20px; }
.ob-back { width: 100%; margin-top: 10px; border-color: transparent; color: var(--muted); }

.ob-list { display: flex; flex-direction: column; gap: 9px; margin-bottom: 20px; }
.ob-kind {
  font-size: .6rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); flex: 0 0 auto;
}
.ob-name { flex: 1; min-width: 0; }

.ob-form {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 15px; margin-bottom: 18px;
}
.ob-form .field-label { margin-top: 0; }
.ob-seg { margin-top: 10px; }
.ob-add { width: 100%; margin-top: 12px; }

/* ---------- progress ---------- */

.prog-section { margin-bottom: 30px; }
.prog-head { display: flex; justify-content: space-between; align-items: baseline;
             gap: 12px; margin-bottom: 11px; }
.prog-stat { font-size: .74rem; font-weight: 700; color: var(--accent);
             font-variant-numeric: tabular-nums; margin: 0; white-space: nowrap; }
.prog-note { font-size: .78rem; color: var(--muted); line-height: 1.55; margin: 12px 0 0; }

.heatmap {
  display: flex; gap: 3px; overflow-x: auto;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 13px;
  /* `safe` matters: plain `center` would make the leftmost weeks unreachable
     once the grid overflows its container. */
  justify-content: safe center;
}
.heat-week { display: flex; flex-direction: column; gap: 3px; }
.heat-cell { width: 11px; height: 11px; border-radius: 2px; background: var(--line); flex: 0 0 auto; }
.heat-none { background: transparent; }
.heat-zero { background: var(--line); }
.heat-low  { background: var(--accent); opacity: .3; }
.heat-mid  { background: var(--accent); opacity: .62; }
.heat-full { background: var(--accent); }
.heat-legend {
  display: flex; align-items: center; gap: 5px; justify-content: flex-end;
  margin-top: 9px; font-size: .66rem; color: var(--muted);
}

.weekbars { display: flex; gap: 6px; align-items: flex-end; }
.weekbar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.weekbar-pct { font-size: .62rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.weekbar-pct.is-best { color: var(--accent); font-weight: 700; }
.weekbar-track {
  width: 100%; height: 78px; background: var(--line);
  border-radius: 7px; display: flex; align-items: flex-end; overflow: hidden;
  border: 2px solid transparent;
}
/* Outlined rather than recoloured: the worst day is information, not an
   error, and colouring it red would break the rule the whole app runs on. */
.weekbar-track.is-best { border-color: var(--accent); }
.weekbar-track.is-worst { border-style: dashed; border-color: var(--muted); }
.weekbar-fill { width: 100%; background: var(--accent); border-radius: 5px;
                transition: height .4s ease; min-height: 2px; }
.weekbar-label { font-size: .66rem; color: var(--muted); }

.prog-habit { margin-bottom: 10px; }
.prog-habit-top { display: flex; justify-content: space-between; align-items: baseline;
                  gap: 12px; margin-bottom: 9px; }
.prog-habit-foot { display: flex; justify-content: space-between; gap: 12px;
                   margin-top: 8px; font-size: .7rem; color: var(--muted);
                   font-variant-numeric: tabular-nums; }

.trigger-list { display: flex; flex-direction: column; gap: 9px; }
.trigger-row { display: flex; align-items: center; gap: 10px; }
.trigger-name { font-size: .8rem; min-width: 88px; }
.trigger-track { flex: 1; height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; }
.trigger-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.trigger-count { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- identity ---------- */

.ident-card { margin-bottom: 14px; }
.ident-statement {
  font-family: var(--serif); font-size: 1.15rem; line-height: 1.25;
  background: none; border: 0; padding: 0; margin: 0 0 12px; color: inherit;
  text-align: left; cursor: pointer; width: 100%;
}
.ident-stats { display: flex; justify-content: space-between; gap: 12px;
               align-items: baseline; margin-bottom: 7px; }
.ident-habits { list-style: none; padding: 0; margin: 15px 0 0;
                display: flex; flex-direction: column; gap: 9px; }
.ident-habit { display: flex; align-items: center; gap: 10px; }
.ident-dot {
  width: 19px; height: 19px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-size: .8rem; line-height: 1;
  background: var(--line); color: var(--fg);
}
.ident-habit-name {
  background: none; border: 0; padding: 0; margin: 0; font: inherit;
  font-size: .9rem; color: inherit; text-align: left; cursor: pointer; flex: 1;
}
.ident-add { width: 100%; margin-top: 15px; }

/* ---------- slip sheet ---------- */

/* The meta column is a button but must read as text: a habit row is not a
   toolbar, and a bordered control here would shout. */
.meta-btn {
  background: none; border: 0; padding: 4px 0 4px 6px; margin: 0;
  font: inherit; font-size: .74rem; cursor: pointer;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  color: var(--muted);
}
.meta-btn.accent { color: var(--accent); font-weight: 700; }
.meta-btn:hover { text-decoration: underline; }

.trigger-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.slip-when .seg { margin-bottom: 12px; }
.slip-hours { display: flex; flex-direction: column; gap: 6px; }
.slip-range { width: 100%; accent-color: var(--accent); }
.slip-note {
  resize: vertical; min-height: 62px; font-family: inherit;
  padding: 12px 14px; line-height: 1.5;
}
.slip-insight {
  font-size: .76rem; color: var(--muted); line-height: 1.55;
  background: var(--line); border-radius: 12px; padding: 11px 13px; margin: 16px 0 0;
}
