:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #17202b; --muted: #5d6b7a; --line: #dde2e8;
  --brand: #C37A5B; --brand-text: #ffffff; --me: #f6e6df; --danger: #a4262c;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11161c; --panel: #1a2129; --text: #e8edf2; --muted: #9aa8b6; --line: #2b3540;
          --brand: #C37A5B; --me: #47302a; --danger: #ef6b6b; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); display: flex; flex-direction: column;
       font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
       padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
[hidden] { display: none !important; }
.bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
       background: var(--brand); color: var(--brand-text); }
.bar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 22px; padding: 4px 8px; cursor: pointer; }
.menu { position: absolute; right: 12px; top: calc(52px + env(safe-area-inset-top)); z-index: 5; display: flex;
        flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
        box-shadow: 0 6px 24px rgba(0,0,0,.18); overflow: hidden; }
.menu button { background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text);
               padding: 12px 18px; text-align: left; font-size: 15px; cursor: pointer; }
.menu button:last-child { border-bottom: 0; }
.danger { color: var(--danger) !important; }
main#chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.log { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 100%; padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; max-width: 85%; background: var(--me); }
.msg.piper { align-self: stretch; background: var(--panel); border: 1px solid var(--line);
             font: 14px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.msg.note { align-self: center; color: var(--muted); font-size: 14px; background: none; }
.chips { display: flex; gap: 8px; padding: 4px 16px; overflow-x: auto; }
.chip { flex: none; border: 1px solid var(--line); background: var(--panel); color: var(--text);
        border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.composer { display: flex; gap: 8px; padding: 8px 16px 12px; border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 40vh; padding: 10px 12px; border-radius: 10px;
                     border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-size: 16px; }
.primary { display: inline-block; background: var(--brand); color: var(--brand-text); border: 0; border-radius: 10px;
           padding: 10px 16px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; text-align: center; }
.primary:disabled { opacity: .5; }
.plain { background: none; border: 0; color: var(--muted); font: inherit; padding: 10px; cursor: pointer; }
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
          gap: 16px; padding: 24px 16px; text-align: center; }
.lead { max-width: 32ch; margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
.panel { position: fixed; inset: 0; z-index: 10; background: var(--bg); padding: calc(16px + env(safe-area-inset-top)) 16px 16px;
         display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.panel h2 { margin: 0; font-size: 20px; }
.keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.keys li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px;
           background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.keys li button { flex: none; }
