/* ============================================================================
   Reckon — "warm almanac" aesthetic.
   A quiet personal ledger: cream paper, ink serif, one terracotta accent.
   Glanceable, used between things. Calm over clever.
   ============================================================================ */

:root {
  /* Paper & ink */
  --paper:      #f4ece0;   /* warm cream base */
  --paper-2:    #efe4d4;   /* slightly deeper cream for cards */
  --paper-edge: #e6d8c3;   /* card hairline */
  --ink:        #2b2622;   /* near-black warm ink */
  --ink-soft:   #6f655a;   /* muted ink for labels */
  --ink-faint:  #a99c8a;   /* faintest ink for footnotes */

  /* The single accent — terracotta — plus a sage for "good / on track" */
  --terra:      #c75b39;
  --terra-deep: #a8462a;
  --sage:       #6f8b6b;
  --sage-deep:  #56714f;

  --gold:       #d9a441;   /* warm highlight (today's ring) */

  --shadow:     22px 22px 48px rgba(120, 96, 64, 0.18);
  --shadow-sm:  0 2px 10px rgba(120, 96, 64, 0.12);
  --radius:     20px;

  --display: "Fraunces", "Hoefler Text", Georgia, serif;
  --body:    "Fraunces", Georgia, serif;
  --mono:    "Courier New", ui-monospace, monospace;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Paper grain — a faint film grain so the cream feels felt, not flat. */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(199,91,57,0.04), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(111,139,107,0.05), transparent 45%);
}

.grain {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  opacity: 0.045; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── App shell ─────────────────────────────────────────────────────────── */
#app {
  position: relative; z-index: 2;
  max-width: 480px; margin: 0 auto;
  min-height: 100%;
  padding: calc(var(--safe-top) + 18px) 20px calc(var(--safe-bottom) + 24px);
  display: flex; flex-direction: column;
}

.hidden { display: none !important; }

/* ── Header ────────────────────────────────────────────────────────────── */
.masthead {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1.5px solid var(--paper-edge);
  margin-bottom: 22px;
}
.masthead .wordmark {
  font-family: var(--display);
  font-weight: 600; font-size: 23px; letter-spacing: -0.02em;
  font-variation-settings: "opsz" 40;
}
.masthead .wordmark em {
  font-style: italic; color: var(--terra); font-weight: 500;
}
.masthead .who {
  font-size: 12.5px; color: var(--ink-soft); letter-spacing: 0.02em;
  display: flex; align-items: center; gap: 9px;
}
.masthead .who button {
  font: inherit; font-size: 11px; color: var(--ink-faint);
  background: none; border: none; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}

/* ── Hero: current weight ──────────────────────────────────────────────── */
.hero {
  text-align: center;
  padding: 8px 0 18px;
}
.hero .eyebrow {
  font-size: 11.5px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 6px;
}
.hero .weight {
  font-family: var(--display);
  font-weight: 360; font-size: 86px; line-height: 0.92;
  letter-spacing: -0.04em; color: var(--ink);
  font-variation-settings: "opsz" 144;
}
.hero .weight .unit {
  font-size: 26px; font-weight: 400; color: var(--ink-soft);
  letter-spacing: -0.01em; margin-left: 4px;
}
.hero .trend {
  margin-top: 12px; font-size: 14px; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: 7px;
}
.hero .trend .pill {
  font-size: 12.5px; padding: 3px 11px; border-radius: 999px;
  font-weight: 500;
}
.trend--losing  .pill { background: rgba(111,139,107,0.16); color: var(--sage-deep); }
.trend--gaining .pill { background: rgba(199,91,57,0.14);  color: var(--terra-deep); }
.trend--stable  .pill { background: rgba(169,156,138,0.18); color: var(--ink-soft); }

/* ── Card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--paper-2);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  margin-bottom: 18px;
}
.card .card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.card .card-head h2 {
  font-family: var(--display); font-weight: 500; font-size: 15px;
  letter-spacing: 0.01em; color: var(--ink);
}
.card .card-head .note { font-size: 11.5px; color: var(--ink-faint); }

/* Chart */
#chart { width: 100%; height: 180px; display: block; }
.chart-legend {
  display: flex; gap: 16px; margin-top: 8px; padding-top: 10px;
  border-top: 1px dashed var(--paper-edge);
  font-size: 11.5px; color: var(--ink-soft);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 16px; height: 3px; border-radius: 2px; }
.swatch--weight { background: var(--ink-faint); }
.swatch--ma { background: var(--terra); }

/* ── Today: eaten / target / remaining ─────────────────────────────────── */
.today-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
.today-grid .stat { text-align: center; padding: 4px 2px; }
.today-grid .stat .n {
  font-family: var(--display); font-weight: 380; font-size: 30px;
  letter-spacing: -0.02em; color: var(--ink);
  font-variation-settings: "opsz" 72;
}
.today-grid .stat .l {
  font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink-soft); margin-top: 2px;
}
.today-grid .stat.remaining .n { color: var(--terra); }
.today-grid .divider { width: 1px; background: var(--paper-edge); margin: 6px 0; }

/* fuel bar — how much of today's budget is spent */
.fuelbar {
  height: 7px; border-radius: 999px; background: rgba(169,156,138,0.22);
  margin-top: 14px; overflow: hidden;
}
.fuelbar > i {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--sage), var(--gold) 70%, var(--terra));
  width: 0; transition: width 0.8s cubic-bezier(.2,.7,.2,1);
}
.fuelbar.over > i { background: var(--terra); }

/* ── Chat ──────────────────────────────────────────────────────────────── */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 280px; }
.chat .card-head { margin-bottom: 10px; }
.chat-log {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 10px;
  padding: 4px 2px 8px;
}
.bubble {
  max-width: 86%; padding: 10px 14px; border-radius: 16px;
  font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
  animation: rise 0.32s cubic-bezier(.2,.7,.2,1) both;
}
.bubble.me {
  align-self: flex-end; background: var(--ink); color: var(--paper);
  border-bottom-right-radius: 5px;
}
.bubble.agent {
  align-self: flex-start; background: var(--paper);
  border: 1px solid var(--paper-edge); color: var(--ink);
  border-bottom-left-radius: 5px;
}
.bubble.tool {
  align-self: flex-start; font-family: var(--mono); font-size: 12px;
  color: var(--ink-soft); background: rgba(169,156,138,0.12);
  border-radius: 10px; padding: 6px 10px; max-width: 92%;
}
.bubble .model-tag {
  display: block; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 3px;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint);
  animation: blink 1.2s infinite both;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.25; } 40% { opacity: 1; } }

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding-top: 10px; border-top: 1px solid var(--paper-edge);
}
.composer textarea {
  flex: 1; resize: none; font: inherit; font-size: 15px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--paper-edge); border-radius: 14px;
  padding: 10px 13px; max-height: 120px; line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--terra); }
.composer textarea::placeholder { color: var(--ink-faint); }
.composer button {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 14px;
  background: var(--terra); color: var(--paper); border: none; cursor: pointer;
  font-size: 18px; display: grid; place-items: center;
  transition: transform 0.12s, background 0.2s;
}
.composer button:active { transform: scale(0.92); }
.composer button:disabled { background: var(--ink-faint); cursor: default; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; z-index: 50;
  background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0 30px; text-align: center;
}
.login .mark {
  font-family: var(--display); font-weight: 600; font-size: 38px;
  letter-spacing: -0.03em; margin-bottom: 8px;
}
.login .mark em { font-style: italic; color: var(--terra); }
.login .tag { font-size: 14px; color: var(--ink-soft); margin-bottom: 38px; font-style: italic; }
.login form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login input {
  font: inherit; font-size: 16px; text-align: center;
  background: var(--paper-2); border: 1px solid var(--paper-edge);
  border-radius: 14px; padding: 13px 16px; color: var(--ink);
}
.login input:focus { outline: none; border-color: var(--terra); }
.login button {
  font: inherit; font-size: 16px; font-weight: 500;
  background: var(--ink); color: var(--paper); border: none;
  border-radius: 14px; padding: 14px; cursor: pointer; margin-top: 6px;
  transition: transform 0.12s;
}
.login button:active { transform: scale(0.98); }
.login .err { color: var(--terra-deep); font-size: 13px; min-height: 18px; }

/* skeleton shimmer while loading */
.skeleton { color: transparent !important; background: rgba(169,156,138,0.18);
  border-radius: 8px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }
