/* Marv's home. The page is the day. Chat, Talk and Settings open on top of it.
   Light by default, clean and quiet; dark when asked. Marv's own touch is the green. */

:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-2: #eef0f4;
  --line: #e3e4e9;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #3f8f62;
  --accent-soft: rgba(63,143,98,0.12);
  --on-accent: #ffffff;
  --danger: #c9503b;
  --ok: #2f8f57;
  --now: #7bb28f;
  --now-soft: rgba(123,178,143,0.16);
  --james: #e8eef8;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 6px 20px rgba(0,0,0,0.06);
  --shadow-up: 0 -8px 30px rgba(0,0,0,0.12);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --panel: #1c1f25;
  --panel-2: #23272f;
  --line: #2e333c;
  --text: #ece6d8;
  --muted: #9a9484;
  --accent: #7fb37a;
  --accent-soft: rgba(127,179,122,0.14);
  --on-accent: #14161a;
  --danger: #c96b5c;
  --ok: #7fb37a;
  --now: #7fb37a;
  --now-soft: rgba(127,179,122,0.18);
  --james: #2b3444;
  --shadow: none;
  --shadow-up: 0 -12px 40px rgba(0,0,0,0.5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #14161a; --panel: #1c1f25; --panel-2: #23272f; --line: #2e333c; --text: #ece6d8; --muted: #9a9484;
    --accent: #7fb37a; --accent-soft: rgba(127,179,122,0.14); --on-accent: #14161a; --danger: #c96b5c; --ok: #7fb37a; --now: #7fb37a; --now-soft: rgba(127,179,122,0.18); --james: #2b3444;
    --shadow: none; --shadow-up: 0 -12px 40px rgba(0,0,0,0.5); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 16px) 20px 12px;
  max-width: 760px; margin: 0 auto;
  background: linear-gradient(var(--bg) 78%, rgba(245,245,247,0));
}
:root[data-theme="dark"] .top { background: linear-gradient(var(--bg) 78%, rgba(20,22,26,0)); }
.date { font-family: var(--serif); font-size: 26px; font-weight: 700; letter-spacing: -0.4px; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.top-right { display: flex; align-items: center; gap: 12px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%; border: 0; padding: 0;
  background: var(--muted); box-shadow: 0 0 0 4px var(--accent-soft);
}
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }
.dot.busy { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: 0.4; } to { opacity: 1; } }
.gear {
  width: 36px; height: 36px; border-radius: 50%; padding: 0;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  display: grid; place-items: center; box-shadow: var(--shadow);
}

/* ---------- The day ---------- */
main {
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 160px);
  max-width: 760px; margin: 0 auto;
}
.plan { display: flex; flex-direction: column; gap: 8px; }
.plan-empty { color: var(--muted); padding: 24px 4px; text-align: center; }
.allday { color: var(--muted); font-size: 13px; padding: 2px 6px 6px; }
.block {
  display: grid; grid-template-columns: 70px 1fr; gap: 12px;
  padding: 12px 14px 12px 16px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.block::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--bar, var(--line)); }
.block.fixed { background: var(--panel-2); box-shadow: none; }
.block.past { opacity: 0.5; }
.block.now { outline: 1.5px solid var(--now); box-shadow: 0 0 0 4px var(--now-soft); }
.block.happened { opacity: 0.6; }
.block.missed { opacity: 0.45; text-decoration: line-through; }
.block .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; padding-top: 3px; line-height: 1.5; }
.block .title { font-size: 16px; font-weight: 500; }
.block .task { color: var(--muted); font-size: 13px; margin-top: 3px; }
.block .task.done { color: var(--ok); }
.block .tag { position: absolute; right: 12px; top: 10px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* The now marker: only in a gap between blocks. Inside a block, the lit block is the marker. */
.needle {
  display: flex; align-items: center; gap: 8px;
  color: var(--now); font-size: 12px; font-variant-numeric: tabular-nums;
  padding: 4px 0 4px 12px;
}
.needle::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--now); }
.needle span::after { content: " · free until the next block"; color: var(--muted); }

/* ---------- Bottom bar ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 12px);
  background: rgba(245,245,247,0.86);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
:root[data-theme="dark"] .bar { background: rgba(20,22,26,0.9); }
.quick { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; max-width: 732px; margin: 0 auto; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button {
  flex: 0 0 auto;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; box-shadow: var(--shadow);
}
.actions { display: flex; gap: 10px; max-width: 732px; margin: 0 auto; }
.actions button {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font-size: 16px; font-weight: 500; box-shadow: var(--shadow);
}
.actions button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.actions button:disabled { opacity: 0.5; }

/* ---------- Sheets: chat, talk, settings, on top of the day ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: 78vh; max-height: 720px;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-up);
  animation: rise 0.22s ease-out;
}
.sheet.tall { height: 92vh; max-height: none; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: -0.2px;
}
.sheet-head button {
  background: var(--panel); color: var(--accent);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 14px; font-family: var(--font); font-weight: 500;
}
.scrim { position: fixed; inset: 0; z-index: 19; background: rgba(0,0,0,0.28); }

.thread { flex: 1; overflow-y: auto; padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 16px; font-size: 15px; white-space: pre-line; position: relative; }
.msg.james { align-self: flex-end; background: var(--james); border-bottom-right-radius: 6px; }
.msg.marv { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); padding-right: 42px; border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.msg.marv.brief { font-size: 15px; line-height: 1.5; }
.msg .when { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.msg .speak {
  position: absolute; right: 8px; top: 8px;
  width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: var(--panel-2); color: var(--muted);
  display: grid; place-items: center;
}
.msg .speak.on { color: var(--accent); background: var(--accent-soft); }
.thread-empty { color: var(--muted); padding: 12px 4px; }
#composer {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--line);
  background: var(--bg);
}
#composer input {
  flex: 1; min-width: 0;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 12px 16px; font-size: 16px;
}
#composer input:focus { outline: none; border-color: var(--accent); }
#send {
  width: 46px; height: 46px; border-radius: 50%; flex: 0 0 auto;
  border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
}
#send:disabled { opacity: 0.5; }

.voice-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 12px 24px calc(env(safe-area-inset-bottom) + 24px); text-align: center; }
.orb {
  width: 104px; height: 104px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #bfe3c8, var(--accent) 60%, #2c6646);
  box-shadow: 0 0 0 0 var(--accent-soft);
  transition: transform 0.2s;
}
.orb.listening { animation: breathe 1.4s ease-in-out infinite; }
.orb.thinking { animation: pulse 0.7s infinite alternate; transform: scale(0.8); }
.orb.speaking { animation: talk 0.5s ease-in-out infinite alternate; }
.orb.idle { transform: scale(0.85); opacity: 0.6; }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); } 50% { box-shadow: 0 0 0 24px rgba(0,0,0,0); } }
@keyframes talk { from { transform: scale(0.95); } to { transform: scale(1.08); } }
.voice-state { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em; }
.voice-transcript { margin: 0; color: var(--muted); font-size: 16px; min-height: 1.4em; }
.voice-reply { margin: 0; font-size: 19px; font-weight: 500; line-height: 1.45; max-width: 560px; }
#voice-tap {
  margin-top: 6px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; box-shadow: var(--shadow);
}

#voice-form { display: flex; gap: 8px; width: 100%; max-width: 560px; margin-top: 6px; }
#voice-form input { flex: 1; font: inherit; font-size: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text); }
#voice-form input:focus { outline: none; border-color: var(--accent); }
#voice-form button { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
#voice-mode.quiet { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; padding: 8px; }

/* ---------- Settings ---------- */
.settings { flex: 1; overflow-y: auto; padding: 0 16px calc(env(safe-area-inset-bottom) + 24px); }
.settings h3 { font-weight: 600; font-size: 18px; letter-spacing: -0.2px; margin: 22px 0 4px; }
.settings .hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; line-height: 1.45; }
.settings .card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
.settings .card .name { font-size: 16px; font-weight: 500; margin-bottom: 4px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.settings label.f { display: block; margin-top: 10px; }
.settings label.f span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.settings input[type="text"], .settings input[type="time"], .settings input[type="number"], .settings textarea, .settings select {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 15px; font-family: var(--font);
}
.settings input:focus, .settings textarea:focus, .settings select:focus { outline: none; border-color: var(--accent); }
.settings textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
.settings select { width: auto; padding: 5px 8px; font-size: 13px; }
.settings .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.settings .save { margin-top: 12px; background: var(--accent); color: var(--on-accent); border: 0; border-radius: 10px; padding: 9px 16px; font-size: 14px; font-weight: 500; }
.settings .ghost { margin-top: 12px; margin-left: 8px; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; font-size: 14px; }
.settings .danger { margin-top: 12px; margin-left: 8px; background: transparent; color: var(--danger); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; font-size: 14px; }
.settings .saved { color: var(--ok); font-size: 13px; margin-left: 10px; }
.settings .budget-row { display: grid; grid-template-columns: 1fr 84px 80px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.settings .budget-row:last-child { border-bottom: 0; }
.settings .budget-row .lbl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.settings .swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.settings .actual { color: var(--muted); font-size: 12px; text-align: right; }
.settings .toggle { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.settings .toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.settings .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--panel); }
.settings .seg button { border: 0; background: transparent; padding: 8px 16px; font-size: 14px; color: var(--muted); }
.settings .seg button.on { background: var(--accent); color: var(--on-accent); }
.settings .addrow { display: flex; gap: 8px; align-items: center; }
.settings .addrow input { flex: 1; }
.settings .addrow .save { margin-top: 0; }

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--panel); color: var(--text);
  padding: 20px; width: min(92vw, 440px); box-shadow: var(--shadow-up);
}
dialog::backdrop { background: rgba(0,0,0,0.35); }
dialog h2 { font-weight: 600; margin: 0 0 8px; font-size: 20px; letter-spacing: -0.2px; }
dialog p { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
dialog input[type="password"], dialog input[type="text"] {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 16px;
}
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
dialog button { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; }
dialog button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.field { display: block; margin-top: 12px; }
.field span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.check .label { flex: 1; }
.check .hint { color: var(--muted); font-size: 12px; }
.group-title { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin: 12px 0 2px; }

@media (min-width: 760px) {
  .sheet { left: 50%; right: auto; width: 760px; transform: translateX(-50%); }
  @keyframes rise { from { transform: translate(-50%, 24px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
}

/* Earlier blocks fold away so the current block sits near the top. */
.earlier {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: var(--radius);
  background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 14px; width: 100%;
}
.earlier .chev { transition: transform 0.2s; }
.earlier.open .chev { transform: rotate(180deg); }

/* Marv is thinking: three dots in a bubble. */
.msg.thinking { display: flex; gap: 5px; align-items: center; padding: 14px 16px; }
.msg.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; animation: dots 1.2s infinite ease-in-out; }
.msg.thinking i:nth-child(2) { animation-delay: 0.2s; }
.msg.thinking i:nth-child(3) { animation-delay: 0.4s; }
@keyframes dots { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

/* Focus area cards: read first, edit on request. */
.settings .view p { margin: 6px 0 0; font-size: 14px; white-space: pre-line; line-height: 1.45; }
.settings .view p.objective { font-weight: 500; }
.settings .view p.muted { color: var(--muted); }
.settings .badge { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
