:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e4e2dc;
  --me: #2f5d50;
  --me-text: #ffffff;
  --accent: #2f5d50;
  --chip: #ecebe6;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --card: #222222;
    --text: #f2f2f2;
    --muted: #9a9a9a;
    --line: #333333;
    --me: #3d7a69;
    --chip: #2c2c2c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* Lock screen */
#lock { height: 100%; display: grid; place-items: center; padding: 24px; }
.lock-box { width: 100%; max-width: 340px; text-align: center; }
.lock-box h1 { font-size: 34px; margin: 0 0 6px; }
.lock-box p { color: var(--muted); }
#lock-form { display: flex; gap: 8px; margin-top: 16px; }
#lock-form input {
  flex: 1; font: inherit; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
#lock-form button { padding: 12px 16px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; }
.error { color: #c0392b; }

/* App layout */
#app {
  height: 100dvh; display: flex; flex-direction: column;
  max-width: 760px; margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
header h1 { font-size: 20px; margin: 0; }
.head-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn { background: none; border: 0; font-size: 20px; padding: 6px 8px; border-radius: 10px; }
.icon-btn[aria-pressed="true"], .icon-btn.on { background: var(--chip); }
.text-btn { background: var(--chip); border: 0; padding: 6px 12px; border-radius: 999px; font-size: 14px; }

#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 18px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--me); color: var(--me-text); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px; padding-left: 22px; }
.msg.assistant code { background: var(--chip); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.msg.error { align-self: center; background: none; color: #c0392b; font-size: 14px; text-align: center; }
.saved { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.saved span { font-size: 12px; background: var(--chip); color: var(--muted); padding: 3px 8px; border-radius: 999px; }
.typing { color: var(--muted); font-style: italic; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 280px; }
.empty b { color: var(--text); font-size: 18px; display: block; margin-bottom: 4px; }

/* Bottom: quick buttons + composer */
.bottom { border-top: 1px solid var(--line); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.quick { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button {
  flex: none; background: var(--card); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px; font-size: 14px; white-space: nowrap;
}
#composer { display: flex; align-items: flex-end; gap: 6px; }
#input {
  flex: 1; resize: none; font: inherit; font-size: 16px; /* 16px stops iPhone zooming in */
  padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); max-height: 140px; line-height: 1.35;
}
.send-btn {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 20px; font-weight: 700;
}
.send-btn:disabled { opacity: .4; }
#mic.listening { background: #c0392b; color: #fff; }

/* Tabs + Notes viewer */
#tabs { display: flex; gap: 6px; padding: 8px 16px 0; }
.tab { background: none; border: 0; padding: 6px 14px; border-radius: 999px; color: var(--muted); }
.tab.on { background: var(--chip); color: var(--text); font-weight: 600; }
#notes { flex: 1; overflow-y: auto; padding: 12px 16px 24px; -webkit-overflow-scrolling: touch; }
#notes-search {
  width: 100%; font: inherit; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); margin-bottom: 10px;
}
.folder { margin: 14px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.note-item {
  display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  padding: 10px 12px; border-radius: 12px; margin-bottom: 6px;
}
#note-view h2 { font-size: 20px; margin: 12px 0 8px; }
#note-body p { margin: 0 0 10px; }
#note-body ul, #note-body ol { margin: 4px 0 10px; padding-left: 22px; }
#note-body code, #note-body pre { background: var(--chip); border-radius: 6px; font-size: 14px; }
#note-body code { padding: 1px 5px; }
#note-body pre { padding: 8px 10px; overflow-x: auto; white-space: pre; margin: 0 0 10px; }
#note-body .props { color: var(--muted); }
.muted { color: var(--muted); }
