/* ============================================================================
   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; align-items: center; }
.chat .card-head h2 { flex: 1; text-align: center; }

/* hamburger (past chats) + new-chat buttons flanking the title */
.hist-btn, .newchat-btn {
  flex: 0 0 auto; background: none; border: none; cursor: pointer;
  color: var(--ink-soft); padding: 4px;
  border-radius: 8px; transition: background 0.15s, color 0.15s;
}
/* the hamburger: three horizontal bars stacked as a flex COLUMN (grid would pile
   them into one cell and render a vertical sliver) */
.hist-btn {
  width: 30px; height: 26px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
}
.hist-btn span {
  display: block; width: 17px; height: 2px; border-radius: 2px;
  background: var(--ink-soft); transition: background 0.15s;
}
.hist-btn:active, .newchat-btn:active { background: rgba(169,156,138,0.16); }
.newchat-btn {
  width: 30px; height: 30px; font-size: 21px; line-height: 1;
  color: var(--terra); font-weight: 300;
  display: grid; place-items: center;
}

/* Segmented Claude / GPT / Grok control under the chat title */
.provider-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  min-height: 36px;
  margin: 0 0 12px;
  padding: 3px;
  border: 1px solid var(--paper-edge);
  border-radius: 10px;
  background: rgba(169,156,138,0.16);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35);
}
.provider-picker button {
  appearance: none;
  -webkit-appearance: none;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  padding: 7px 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--body);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
}
.provider-picker button[aria-checked="true"] {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(43,38,34,0.14);
}
.provider-picker button:hover:not(:disabled):not([aria-checked="true"]) {
  color: var(--ink);
  background: rgba(244,236,224,0.45);
}
.provider-picker button:focus-visible {
  outline: 2px solid var(--terra);
  outline-offset: 1px;
}
.provider-picker button:disabled {
  cursor: default;
  opacity: 0.48;
}

/* slide-over: list of past conversations */
.hist-panel { position: fixed; inset: 0; z-index: 60; }
.hist-panel.hidden { display: none; }
.hist-scrim {
  position: absolute; inset: 0; background: rgba(43,38,34,0.32);
  animation: scrimIn 0.25s ease both;
}
@keyframes scrimIn { from { opacity: 0; } to { opacity: 1; } }
.hist-sheet {
  position: absolute; top: 0; left: 0; bottom: 0;
  width: min(82vw, 340px);
  background: var(--paper-2); border-right: 1px solid var(--paper-edge);
  box-shadow: 2px 0 30px rgba(43,38,34,0.16);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 18px) 16px 16px;
  animation: sheetIn 0.28s cubic-bezier(.2,.7,.2,1) both;
}
@keyframes sheetIn { from { transform: translateX(-100%); } to { transform: none; } }
.hist-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.hist-head h3 { font-family: var(--display); font-weight: 500; font-size: 17px; color: var(--ink); }
.hist-close {
  background: none; border: none; font-size: 26px; line-height: 1;
  color: var(--ink-faint); cursor: pointer; padding: 0 4px;
}
.hist-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 2px; }
.hist-item {
  text-align: left; background: none; border: none; cursor: pointer;
  padding: 11px 12px; border-radius: 12px; font: inherit;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  transition: background 0.15s;
}
.hist-item:active { background: rgba(169,156,138,0.16); }
.hist-item.active { background: rgba(199,91,57,0.10); }
.hist-item .hi-label { font-size: 15px; color: var(--ink); }
.hist-item.active .hi-label { color: var(--terra-deep); }
.hist-item .hi-meta { font-size: 11.5px; color: var(--ink-faint); flex: 0 0 auto; }
.hist-empty { padding: 16px 12px; font-size: 13.5px; color: var(--ink-faint); font-style: italic; }
.hist-new {
  margin-top: 12px; padding: 12px; border-radius: 12px; cursor: pointer;
  background: var(--paper); border: 1px solid var(--paper-edge);
  font: inherit; font-size: 14.5px; color: var(--terra); letter-spacing: 0.01em;
}
.hist-new:active { background: rgba(199,91,57,0.08); }

/* a faint banner shown when viewing a past (read-only) chat */
.viewing-banner {
  align-self: center; font-size: 12px; color: var(--ink-soft); font-style: italic;
  background: rgba(169,156,138,0.14); border-radius: 999px;
  padding: 4px 12px; margin: 2px 0 4px;
}
.viewing-banner button {
  background: none; border: none; color: var(--terra); font: inherit;
  font-size: 12px; cursor: pointer; text-decoration: underline; margin-left: 6px;
}
.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; 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; } }

/* Live word-status (claude.ai-style): pulsing dot + word + animated ellipsis */
.status-line {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 4px; margin: 2px 0;
  font-size: 13.5px; color: var(--ink-soft);
  animation: rise 0.3s cubic-bezier(.2,.7,.2,1) both;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--terra);
  animation: statusPulse 1.3s ease-in-out infinite;
}
.status-word {
  font-style: italic; letter-spacing: 0.01em;
  background: linear-gradient(90deg, var(--ink-soft) 30%, var(--ink-faint) 50%, var(--ink-soft) 70%);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: statusShimmer 2s linear infinite;
}
.status-ellipsis::after {
  content: '';
  animation: statusEllipsis 1.5s steps(4, end) infinite;
}
@keyframes statusPulse {
  0%, 100% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 1; }
}
@keyframes statusShimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes statusEllipsis {
  0% { content: ''; } 25% { content: '·'; } 50% { content: '··'; } 75%, 100% { content: '···'; }
}

.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; } }
