/* Backed design system.
   Dark by commitment, not by default: the palette below is the whole product,
   so there is no light variant to fall out of sync. Tokens first, components
   second, and every component is sized for a thumb before a cursor. */

:root {
  color-scheme: dark;

  /* surfaces */
  --canvas: #0f131c;
  --surface-low: #181c24;
  --surface: #1c2028;
  --surface-high: #262a33;
  --surface-highest: #31353e;

  /* ink */
  --ink: #dfe2ee;
  --ink-2: #a8adbd;
  --ink-3: #7d8496;
  --ink-warm: #dbc2b0;

  /* lines */
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);

  /* reward amber - value, pledges, primary action */
  --amber: #ffb77d;
  --amber-deep: #d97707;
  --amber-ink: #4d2600;
  --amber-tint: rgba(217, 119, 6, 0.15);
  --amber-edge: rgba(217, 119, 6, 0.4);

  /* verified emerald - completion, streaks kept */
  --emerald: #4edea3;
  --emerald-deep: #00a572;
  --emerald-ink: #00311f;
  --emerald-tint: rgba(78, 222, 163, 0.14);

  /* contested rose */
  --rose: #ffb4ab;
  --rose-tint: rgba(255, 180, 171, 0.14);

  --display: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --body: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-sm: 0.5rem;
  --r: 1rem;
  --r-md: 1.5rem;
  --r-lg: 2rem;
  --r-full: 9999px;

  --tap: 44px;
  --edge: 16px;
  --gap: 12px;
  --shell: 680px;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

img, svg { max-width: 100%; height: auto; }
a { color: var(--amber); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: var(--r-sm); }

h1, h2, h3 {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 .5rem;
}
h1 { font-size: 32px; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0 0 1rem; }

.lede { color: var(--ink-2); margin-bottom: 1.25rem; }
.muted { color: var(--ink-3); font-size: 14px; }
.caps {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-3);
}
.caps-amber { color: var(--amber-deep); }
.metric { font-family: var(--display); font-weight: 800; font-size: 24px; letter-spacing: -0.02em; }

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

.app-header {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, rgba(217,119,6,.10), transparent), var(--canvas);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.app-header .bar {
  max-width: var(--shell); margin: 0 auto;
  padding: 10px var(--edge);
  display: flex; align-items: center; gap: 12px; min-height: var(--tap);
}
.brand {
  font-family: var(--display); font-weight: 800; font-size: 20px;
  letter-spacing: -0.03em; color: var(--amber); text-decoration: none;
  display: inline-flex; align-items: center; gap: 9px;
}
.brand-mark { display: block; flex-shrink: 0; width: 24px; height: 24px; }
.brand:hover { text-decoration: none; }
.spacer { margin-left: auto; }

.points {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-high); color: var(--amber);
  font-family: var(--display); font-weight: 800; font-size: 14px;
  padding: 6px 14px; border-radius: var(--r-full);
}

.bell {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--tap); min-height: var(--tap);
  color: var(--ink-2); text-decoration: none; font-size: 18px;
}
.bell:hover { text-decoration: none; color: var(--amber); }
.bell .badge {
  position: absolute; top: 4px; right: 2px;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--amber-deep); color: #fff;
  font-family: var(--display); font-weight: 800; font-size: 11px; line-height: 1;
}

.note-row {
  display: block; color: inherit; text-decoration: none;
  background: var(--surface-low); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 14px 16px; margin-bottom: 10px;
}
.note-row:hover { text-decoration: none; border-color: var(--line-strong); }
.note-row.unread { border-left: 3px solid var(--amber-deep); background: var(--surface); }
.note-row .who { font-weight: 600; }
.note-row .what { color: var(--ink-2); }

.nav-wide { display: none; gap: 18px; align-items: center; }
.nav-wide a { color: var(--ink-2); font-size: 14px; }
.nav-wide a[aria-current="page"] { color: var(--amber); }

main.app-main {
  max-width: var(--shell); margin: 0 auto;
  padding: 20px var(--edge) calc(var(--tap) + 48px + env(safe-area-inset-bottom, 0px));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-low); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar a {
  min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 8px 4px; color: var(--ink-3);
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--amber); }
.tabbar .glyph { font-size: 18px; line-height: 1; }

@media (min-width: 768px) {
  .nav-wide { display: flex; }
  .tabbar { display: none; }
  main.app-main { padding-bottom: 48px; }
  h1 { font-size: 40px; }
}

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

.card {
  background: var(--surface-low);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  margin-bottom: var(--gap);
}
.card > :last-child { margin-bottom: 0; }
.card-tight { padding: 14px 16px; border-radius: var(--r-md); }
.card-raised { background: var(--surface-high); box-shadow: inset 0 1px 0 rgba(255,255,255,.12); }
.card-glow { box-shadow: 0 0 32px -4px rgba(217, 119, 6, 0.25); }
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; border-color: var(--line-strong); }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }

/* ---- buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px;
  border: 1px solid transparent; border-radius: var(--r-full);
  background: linear-gradient(180deg, #f59e0b, var(--amber-deep));
  color: var(--amber-ink);
  font-family: var(--display); font-weight: 800; font-size: 16px;
  cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(1.06); }
.btn:active { box-shadow: 0 0 16px rgba(245, 158, 11, 0.5); }
.btn-block { display: flex; width: 100%; }
.btn-ghost {
  background: var(--surface-high); color: var(--ink);
  border-color: var(--line-strong); font-family: var(--body); font-weight: 600;
}
.btn-quiet { background: transparent; color: var(--ink-2); border-color: var(--line-strong); font-family: var(--body); font-weight: 600; }
.btn-sm { min-height: var(--tap); padding: 0 16px; font-size: 14px; }
.btn-done { background: var(--emerald-deep); color: #ffffff; }
.btn-danger { background: transparent; border-color: var(--rose); color: var(--rose); font-family: var(--body); font-weight: 600; }

/* ---- forms -------------------------------------------------------------- */

.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field input[type="text"], .field input[type="email"], .field input[type="url"],
.field input[type="password"], .field input[type="date"], .field input[type="number"],
.field select, .field textarea {
  width: 100%; min-height: 48px; padding: 12px 16px;
  background: var(--canvas); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r);
  font: inherit;
}
.field textarea { min-height: 96px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--amber-deep);
  box-shadow: 0 0 0 2px var(--amber-tint);
}
.field .help { display: block; margin-top: 6px; color: var(--ink-3); font-size: 12px; }
.field .errors { margin: 6px 0 0; padding: 0; list-style: none; color: var(--rose); font-size: 13px; }
/* An empty date input renders today's date in placeholder grey, which reads as
   filled. A field that failed validation has to look unmistakably unfinished. */
.field-invalid > label { color: var(--rose); }
.field-invalid input, .field-invalid select, .field-invalid textarea {
  border-color: var(--rose); background: var(--rose-tint);
}
.field-check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.field-check input { width: 24px; height: 24px; min-height: 0; accent-color: var(--emerald-deep); }
.field-check label { margin: 0; font-size: 14px; color: var(--ink); font-weight: 600; }

/* Radio groups render as segmented pills - visibility and habit cadence. */
.field ul, .segmented {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 6px;
  background: var(--canvas); border-radius: var(--r-full); padding: 4px;
}
.field li { flex: 1 1 auto; }
.field li label {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 12px;
  border-radius: var(--r-full); cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap;
}
.field li input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.field li:has(input:checked) label { background: var(--amber); color: var(--amber-ink); }
.field li:has(input:focus-visible) label { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---- pills, chips, badges ----------------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 12px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 700; letter-spacing: .01em;
  background: var(--amber-tint); color: var(--amber); border: 1px solid var(--amber-edge);
}
.chip-emerald { background: var(--emerald-tint); color: var(--emerald); border-color: rgba(78,222,163,.35); }
.chip-quiet { background: rgba(148,163,184,.12); color: var(--ink-3); border-color: var(--line-strong); }
.streak { display: inline-flex; align-items: center; gap: 5px; color: var(--amber); font-size: 13px; font-weight: 600; }

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

.bar { height: 8px; border-radius: var(--r-full); background: var(--surface-high); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: var(--r-full); background: linear-gradient(90deg, var(--amber-deep), var(--amber)); }

/* ---- milestone track ---------------------------------------------------- */

.track { list-style: none; margin: 0; padding: 0; }
.track li { display: grid; grid-template-columns: 32px 1fr; gap: 12px; padding: 10px 0; align-items: start; }
.track .node {
  width: 26px; height: 26px; border-radius: var(--r-full);
  border: 2px solid var(--ink-3); background: transparent;
  display: grid; place-items: center; font-size: 13px; color: var(--canvas); font-weight: 700;
}
.track li.done .node { background: var(--emerald-deep); border-color: var(--emerald-deep); color: #fff; }
.track li.next .node { border-color: var(--amber-deep); background: var(--amber-deep); color: var(--amber-ink); }
.track .label { font-weight: 600; }
.track li.done .label { color: var(--ink-2); }

/* ---- habit rows --------------------------------------------------------- */

.habit {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-low); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 14px 14px 14px 18px; margin-bottom: 10px;
}
.habit .who { min-width: 0; flex: 1; }
.habit .name { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.habit .meta { font-size: 13px; color: var(--emerald); margin-top: 2px; }
.habit form { margin: 0; }

/* ---- misc --------------------------------------------------------------- */

.msgs { list-style: none; margin: 0 0 16px; padding: 0; }
.msgs li {
  padding: 12px 16px; border-radius: var(--r); margin-bottom: 8px; font-size: 14px;
  background: var(--surface-high); border: 1px solid var(--line);
}
.msgs li.success { background: var(--emerald-tint); border-color: rgba(78,222,163,.3); color: var(--emerald); }
.msgs li.error { background: var(--rose-tint); border-color: rgba(255,180,171,.3); color: var(--rose); }

.empty {
  text-align: center; padding: 40px 20px;
  border: 1px dashed var(--line-strong); border-radius: var(--r-lg); color: var(--ink-2);
}
.empty h3 { color: var(--ink); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 28px 0 12px; }
.section-head h2 { margin: 0; }

.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.bubble {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: var(--r-md);
  font-size: 15px;
  line-height: 1.45;
}
.bubble.user {
  align-self: flex-end;
  background: var(--amber-tint);
  border: 1px solid var(--amber-edge);
  color: var(--ink);
  border-bottom-right-radius: var(--r-sm);
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--surface-low);
  border: 1px solid var(--line);
  border-bottom-left-radius: var(--r-sm);
}

.plain-list { margin: 6px 0 0; padding-left: 1.1rem; }
.plain-list li { margin-bottom: 4px; }

.stack > * + * { margin-top: var(--gap); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.split { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.formset-item { border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; margin-bottom: 12px; background: var(--surface-low); }
.formset-item .caps { margin-bottom: 10px; }

.sharebox {
  display: flex; gap: 8px; align-items: center;
  background: var(--canvas); border: 1px solid var(--line-strong);
  border-radius: var(--r); padding: 10px 14px; word-break: break-all; font-size: 13px; color: var(--ink-2);
}

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