:root {
  color-scheme: light;
  --bg: #f3f4ef;
  --surface: #ffffff;
  --surface-2: #e9ebe5;
  --ink: #17191f;
  --muted: #5d625b;
  --soft: #7b8178;
  --line: #d3d6ce;
  --accent: #bd3d21;
  --accent-strong: #982f1a;
  --accent-soft: #f8e6df;
  --fixed: #205f73;
  --fixed-soft: #def0f3;
  --success: #22704a;
  --danger: #b52832;
  --nav-h: 76px;
  --shadow: 0 20px 55px rgba(28, 31, 38, .14);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: #e4e6e0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.app {
  position: relative;
  width: min(100%, 460px);
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  transition: background .2s ease, color .2s ease;
}
.app[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317;
  --surface: #1c1f24;
  --surface-2: #282c32;
  --ink: #f4f5f1;
  --muted: #b8bcb5;
  --soft: #9da29a;
  --line: #393d44;
  --accent: #ff6846;
  --accent-strong: #ff8064;
  --accent-soft: #3c2521;
  --fixed: #7ec5d5;
  --fixed-soft: #17343b;
  --success: #74d5a5;
  --danger: #ff7880;
  color: var(--ink);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: max(12px, env(safe-area-inset-top)) 18px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 13px 13px 13px 4px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
}
.header-copy { display: grid; flex: 1; gap: 1px; min-width: 0; }
.header-copy strong { font-size: 14px; font-weight: 700; }
.header-copy span { color: var(--muted); font-size: 10px; }
.icon-button, .avatar-button, .sheet-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.avatar-button { font-size: 12px; font-weight: 700; }

.page {
  display: none;
  min-height: calc(100dvh - 64px);
  padding: 9px 18px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}
.page.active { display: block; }
.thesis { padding: 7px 0 14px; }
.thesis h1, .section-head h1 {
  margin: 0;
  font-size: 29px;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -.045em;
}
.thesis p, .section-head p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.day-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-bottom: 16px;
}
.day-button {
  min-width: 0;
  padding: 7px 1px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  cursor: pointer;
}
.day-button small { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.day-button b {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: auto;
  border-radius: 11px;
  color: var(--ink);
  font-size: 13px;
}
.day-button.active { background: var(--surface); box-shadow: 0 6px 18px rgba(28,31,38,.07); }
.day-button.active b { background: var(--accent); color: #fff; }
.density {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  height: 10px;
  margin-top: 4px;
}
.density i { width: 3px; border-radius: 2px; background: var(--accent); opacity: .75; }

.change-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0 0 14px;
  padding: 11px 12px;
  border: 0;
  border-radius: 16px;
  background: #1d2330;
  color: #fff;
  text-align: left;
  cursor: pointer;
}
.change-banner > span:nth-child(2) { display: grid; gap: 2px; flex: 1; }
.change-banner strong { font-size: 13px; }
.change-banner small { color: #d7dbe4; font-size: 11px; }
.change-banner b { font-size: 20px; }
.spark {
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
}
.timeline {
  position: relative;
  min-height: 280px;
  padding-left: 58px;
}
.timeline::before {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 46px;
  width: 1px;
  background: var(--line);
  content: "";
}
.task-card {
  position: relative;
  display: block;
  width: 100%;
  min-height: 76px;
  margin: 0 0 10px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 5px 17px rgba(28,31,38,.045);
}
.task-card::before {
  position: absolute;
  top: 17px;
  left: -17px;
  width: 9px;
  height: 9px;
  border: 3px solid var(--bg);
  border-radius: 50%;
  background: var(--accent);
  content: "";
}
.task-card.fixed::before { background: var(--fixed); }
.task-card time {
  position: absolute;
  top: 14px;
  right: calc(100% + 23px);
  width: 48px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}
.task-card strong { display: block; padding-right: 44px; color: var(--ink); font-size: 14px; }
.task-card p { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.task-card .tag {
  float: right;
  padding: 3px 6px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 9px;
  font-weight: 700;
}
.task-card.fixed .tag { background: var(--fixed-soft); color: var(--fixed); }
.cross-day { display: inline-block; margin-left: 5px; color: var(--accent); font-size: 10px; }
.empty-state {
  padding: 52px 20px;
  color: var(--muted);
  text-align: center;
}
.empty-state strong { display: block; margin-bottom: 5px; color: var(--ink); font-size: 16px; }
.quick-ask {
  position: sticky;
  bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 12px 28px rgba(28,31,38,.12);
  cursor: pointer;
}
.quick-ask > span:first-child, .quick-ask b { color: var(--accent); }

.section-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 14px; }
.section-head h1 { font-size: 26px; }
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 15px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}
.segmented button { padding: 8px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 3px 12px rgba(28,31,38,.08); }
.calendar-view { display: none; }
.calendar-view.active { display: block; }
.day-detail {
  margin-top: 13px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
}
.day-detail header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.day-detail header strong { font-size: 14px; }
.day-detail header span { color: var(--muted); font-size: 10px; }
.compact-card {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  margin-top: 7px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.compact-card time { color: var(--muted); font-size: 11px; }
.compact-card strong, .compact-card small { display: block; }
.compact-card strong { color: var(--ink); font-size: 12px; }
.compact-card small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.compact-card b { color: var(--accent); }
.month-weekdays, .month-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.month-weekdays { padding: 4px 0 7px; color: var(--muted); font-size: 9px; text-align: center; }
.month-grid { gap: 3px; }
.month-day {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.month-day.outside { color: var(--soft); opacity: .55; }
.month-day.has-task::after {
  position: absolute;
  right: calc(50% - 2px);
  bottom: 5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}
.month-day.active { background: var(--accent); color: #fff; }
.month-day.active::after { background: #fff; }

.chat-page.active { display: flex; flex-direction: column; height: calc(100dvh - 64px); padding-bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); }
.chat-head { flex: 0 0 auto; }
.online { width: 10px; height: 10px; border-radius: 50%; background: #42b980; box-shadow: 0 0 0 4px color-mix(in srgb, #42b980 20%, transparent); }
.chat-log {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  padding: 5px 0 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.bubble {
  max-width: 86%;
  padding: 11px 13px;
  border-radius: 17px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.bubble.user { align-self: flex-end; border-bottom-right-radius: 5px; background: #202633; color: #fff; }
.bubble.ai { align-self: flex-start; border: 1px solid var(--line); border-bottom-left-radius: 5px; background: var(--surface); color: var(--ink); }
.bubble.pending { color: var(--muted); }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  padding: 7px 7px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(28,31,38,.1);
}
.composer textarea, .composer input {
  min-width: 0;
  min-height: 32px;
  flex: 1;
  padding: 7px 0;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}
.composer textarea::placeholder, .composer input::placeholder { color: var(--muted); opacity: 1; }
.composer button {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.bottom-nav {
  position: fixed;
  z-index: 25;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 460px);
  min-height: var(--nav-h);
  margin: 0 auto;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px);
}
.bottom-nav button {
  display: grid;
  justify-items: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}
.bottom-nav button span { display: grid; place-items: center; width: 31px; height: 29px; border-radius: 10px; color: inherit; font-size: 17px; }
.bottom-nav button.active { color: var(--accent); font-weight: 700; }
.bottom-nav button.active span { background: var(--accent-soft); }

.sheet-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  background: rgba(12,14,18,.5);
  backdrop-filter: blur(3px);
}
.sheet {
  position: fixed;
  z-index: 55;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(100%, 460px);
  max-height: 88dvh;
  margin: 0 auto;
  padding: 9px 18px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  border-radius: 25px 25px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  transform: translateY(105%);
  transition: transform .22s ease;
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 42px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: var(--line); }
.sheet header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet header small { color: var(--muted); font-size: 10px; }
.sheet h2 { margin: 3px 0 0; color: var(--ink); font-size: 21px; letter-spacing: -.025em; }
.locked-field {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 14px;
  padding: 13px;
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
}
.locked-field span { color: var(--muted); }
.note-field { display: grid; gap: 7px; color: var(--ink); font-size: 12px; font-weight: 700; }
.note-field textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
}
.note-field textarea::placeholder { color: var(--muted); }
.sheet-help { color: var(--muted); font-size: 10px; line-height: 1.55; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 16px; }
.primary-button, .danger-button, .danger-solid, .sheet-actions > button {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.primary-button { border-color: var(--accent); background: var(--accent); color: #fff; }
.danger-button { color: var(--danger); }
.danger-solid { border-color: var(--danger) !important; background: var(--danger) !important; color: #fff !important; }
.full-button { width: 100%; margin-top: 15px; }
.delete-confirm { margin-top: 13px; padding: 13px; border-radius: 14px; background: color-mix(in srgb, var(--danger) 9%, var(--surface)); }
.delete-confirm p { margin: 0; color: var(--ink); font-size: 12px; line-height: 1.5; }
.quick-log { display: flex; flex-direction: column; gap: 8px; min-height: 170px; max-height: 48dvh; padding: 12px 0; overflow-y: auto; }
.chat-sheet .composer { position: sticky; bottom: 0; }
.change-list { display: grid; gap: 9px; margin-top: 16px; }
.change-item { padding: 12px; border-radius: 13px; background: var(--surface-2); }
.change-item strong, .change-item span { display: block; color: var(--ink); }
.change-item strong { font-size: 12px; }
.change-item span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.change-item del { color: var(--muted); }
.change-item ins { color: var(--success); font-weight: 700; text-decoration: none; }
.account-name { padding: 16px; border-radius: 14px; background: var(--surface-2); color: var(--ink); }
.toast {
  position: fixed;
  z-index: 80;
  right: 20px;
  bottom: calc(var(--nav-h) + 18px);
  left: 20px;
  width: fit-content;
  max-width: calc(100% - 40px);
  margin: auto;
  padding: 10px 14px;
  border-radius: 12px;
  background: #202633;
  color: #fff;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

.auth-gate {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(232,234,227,.94);
  backdrop-filter: blur(18px);
}
.auth-card {
  width: min(100%, 410px);
  padding: 28px;
  border-radius: 28px 28px 28px 8px;
  background: #fff;
  color: #17191f;
  box-shadow: 0 25px 70px rgba(28,31,38,.2);
}
.auth-card .eyebrow { margin: 20px 0 6px; color: #982f1a; font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.auth-card h1 { margin: 0; font-size: 29px; line-height: 1.18; letter-spacing: -.04em; }
.auth-copy { margin: 10px 0 20px; color: #5d625b; font-size: 12px; line-height: 1.6; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 13px; background: #e9ebe5; }
.auth-tabs button { padding: 8px; border: 0; border-radius: 10px; background: transparent; color: #5d625b; cursor: pointer; }
.auth-tabs button.active { background: #fff; color: #17191f; font-weight: 700; box-shadow: 0 3px 12px rgba(28,31,38,.08); }
.auth-form { display: grid; gap: 12px; margin-top: 15px; }
.auth-form label { display: grid; gap: 6px; color: #3c403b; font-size: 11px; font-weight: 700; }
.auth-form input { height: 45px; padding: 0 12px; border: 1px solid #c9cdc4; border-radius: 12px; background: #f7f8f5; color: #17191f; }
.form-error { min-height: 17px; margin: 0; color: #b52832; font-size: 11px; }
.text-button { display: block; margin: 9px auto 0; padding: 7px; border: 0; background: transparent; color: #5d625b; text-decoration: underline; cursor: pointer; }
.filing-link { margin: 13px 0 0; text-align: center; font-size: 10px; line-height: 1.4; }
.filing-link a { color: #6b7069; text-decoration: none; }
.filing-link a:hover { text-decoration: underline; }

@media (min-width: 520px) {
  body { padding: 18px 0; }
  .app { min-height: calc(100dvh - 36px); border: 1px solid #cfd2ca; border-radius: 30px; box-shadow: var(--shadow); }
  .bottom-nav { bottom: 18px; border-radius: 0 0 30px 30px; }
  .page { min-height: calc(100dvh - 100px); }
  .chat-page.active { height: calc(100dvh - 100px); }
}

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