:root {
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --ink: #111111;
  --ink-2: #1D1D1F;
  --muted: #6E6E73;
  --line: #E5E5EA;
  --line-2: #D2D2D7;
  --accent: #0A5BD8;
  --accent-soft: #EAF1FD;
  --user: #111111;
  --user-ink: #F5F5F7;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
  --serif: 'IBM Plex Serif', Georgia, serif;
  --radius: 16px;
  --measure: 640px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font-family: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 6px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.icon {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 10px;
}
.icon:active { background: var(--line); }
.icon-space { width: 44px; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 1px; text-decoration: none; color: var(--ink); }
.brand-name { font-size: 15px; font-weight: 600; }
.brand-sub { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 0.08em; }

/* Thread */
.thread {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px; display: flex; flex-direction: column; gap: 16px;
  width: 100%; max-width: var(--measure); margin: 0 auto;
}
.msg-user {
  align-self: flex-end; max-width: 78%;
  padding: 10px 14px; background: var(--user); color: var(--user-ink);
  border-radius: 16px 16px 4px 16px; font-size: 15px; line-height: 1.4;
  overflow-wrap: anywhere;
}
.msg-answer {
  align-self: flex-start; max-width: 92%;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px; background: var(--card); border-radius: 4px 16px 16px 16px;
}
.msg-answer .lead { font-size: 17px; line-height: 1.35; font-weight: 600; margin: 0; }
.msg-answer .body { font-size: 15px; line-height: 1.55; color: var(--ink-2); margin: 0; }
.cite {
  font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent); text-decoration: none; border: 0; cursor: pointer;
  vertical-align: baseline;
}
.unless {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 8px 10px; background: var(--bg); border-radius: 8px; font-size: 13px; line-height: 1.5; margin: 0;
}
.unless .tag { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--accent); padding-top: 3px; flex-shrink: 0; }
.revised { font-size: 13px; line-height: 1.5; color: var(--muted); margin: 0; }
.revised .tag { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; }
.msg-actions { display: flex; justify-content: flex-end; gap: 14px; font-family: var(--mono); font-size: 11px; }
.msg-actions button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 6px 0; letter-spacing: 0.06em; }
.msg-miss .lead { font-weight: 500; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  height: 36px; flex-shrink: 0; display: inline-flex; align-items: center; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 18px; background: transparent;
  font-size: 13px; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.feedback { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.feedback button { height: 32px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 16px; background: transparent; font-size: 12px; cursor: pointer; color: var(--ink); }
.feedback .done { color: var(--muted); }

/* Home state */
.home { display: flex; flex-direction: column; gap: 14px; }
.home h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.home .sub { margin: 0; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; text-decoration: none; color: var(--ink); }
.card-label { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.card-label .n { color: var(--accent); }
.turn { display: flex; gap: 12px; align-items: flex-start; }
.turn .yr { font-family: var(--mono); font-size: 13px; width: 44px; flex-shrink: 0; padding-top: 3px; color: var(--muted); }
.turn .yr.now { color: var(--accent); }
.turn .was { font-size: 16px; line-height: 1.35; color: var(--muted); text-decoration: line-through; text-decoration-color: #C7C7CC; }
.turn .is { font-size: 16px; line-height: 1.35; font-weight: 600; }
.card-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 4px; border-top: 1px solid var(--line); font-size: 14px; color: var(--ink-2); }
.card-foot .go { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.home .chips .chip { background: var(--card); border-color: transparent; height: 40px; font-size: 14px; }

/* Composer */
.composer {
  position: sticky; bottom: 0; z-index: 5;
  padding: 8px 12px; padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--bg); display: flex; flex-direction: column; gap: 6px;
  width: 100%; max-width: var(--measure); margin: 0 auto;
}
.composer form {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px;
  background: var(--card); border: 1px solid var(--line-2); border-radius: 14px;
}
.composer input { flex: 1; min-width: 0; height: 44px; border: 0; outline: 0; background: transparent; font: inherit; font-size: 16px; color: var(--ink); }
.composer input::placeholder { color: var(--muted); }
.composer button[type=submit] { width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.fine { margin: 0; font-family: var(--mono); font-size: 10px; line-height: 1.5; text-align: center; color: var(--muted); }
.link { border: 0; background: transparent; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }

/* Drawer */
.drawer[hidden], .sheet[hidden] { display: none; }
.drawer, .sheet { position: fixed; inset: 0; z-index: 20; }
.drawer-scrim, .sheet-scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.35); }
.drawer-panel {
  position: absolute; top: 0; bottom: 0; left: 0; width: min(88vw, 360px);
  background: var(--bg); display: flex; flex-direction: column; gap: 16px; padding: 0 16px 16px;
  padding-top: env(safe-area-inset-top); overflow-y: auto;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; margin: 0 -10px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.primary { min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 16px; background: var(--accent); color: #fff; border: 0; border-radius: 12px; font-size: 15px; font-weight: 500; cursor: pointer; }
.session-list { display: flex; flex-direction: column; gap: 14px; }
.session-group { background: var(--card); border-radius: 12px; padding: 4px 16px; display: flex; flex-direction: column; }
.session-group h3 { margin: 0; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); padding: 10px 0 4px; font-weight: 500; }
.session { min-height: 52px; display: flex; flex-direction: column; justify-content: center; gap: 2px; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; color: var(--ink); padding: 6px 0; }
.session .t { font-size: 15px; font-weight: 500; }
.session .m { font-size: 12px; color: var(--muted); }
.session.current .t { color: var(--accent); }

/* Sheet */
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 80vh; overflow-y: auto;
  background: var(--card); border-radius: 16px 16px 0 0; padding: 8px 20px; padding-bottom: max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; max-width: var(--measure); margin: 0 auto;
}
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line-2); margin: 4px auto 0; }
.sheet-meta { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.passage { margin: 0; font-family: var(--serif); font-size: 16px; line-height: 1.6; color: var(--ink-2); }
.passage mark { background: var(--accent-soft); color: var(--ink); padding: 1px 2px; border-radius: 2px; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }

@media (min-width: 720px) {
  .thread { padding: 24px 16px; }
  .msg-answer .lead { font-size: 19px; }
  .msg-answer .body { font-size: 16px; }
}
