:root {
  --bg: #14120f; --panel: #1d1a16; --panel2: #262119; --ink: #e9e2d6; --muted: #9a8f80; --line: #332d25;
  --accent: #d9a45b; --accent-ink: #1a1408; --user: #2a3a45; --red: #c9563f; --green: #7fa66b; --dim: #6e6558;
  --pad: 14px; --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, "SF Pro Text", "Inter", Georgia, serif; -webkit-text-size-adjust: 100%; }
#app { height: 100%; }
.view { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
button { font: inherit; }
.bar { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) var(--pad) 8px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.bar .title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.title-wrap .title { flex: none; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.error { color: var(--red); }
.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.ghost:active { background: var(--panel2); }

/* login */
#login { align-items: center; justify-content: center; padding: var(--pad); }
#login-form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
#login h1 { margin: 0; font-size: 40px; letter-spacing: 2px; color: var(--accent); font-weight: 500; }
input, textarea { width: 100%; background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font: inherit; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
#login button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 12px; font-weight: 600; }

/* vault list */
#vault-list { list-style: none; margin: 0; padding: var(--pad); display: flex; flex-direction: column; gap: 10px; overflow: auto; }
#vault-list li { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; }
#vault-list li:active { background: var(--panel2); }
#vault-list .name { font-weight: 600; font-size: 18px; }
#vault-list .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
#vault-list .open { color: var(--green); }

/* play */
#messages { flex: 1; overflow-y: auto; padding: var(--pad); display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.msg { max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--user); border-radius: 16px 16px 4px 16px; padding: 10px 14px; white-space: pre-wrap; }
.msg.gm { align-self: stretch; max-width: 100%; }
.msg.gm .prose > *:first-child { margin-top: 0; }
.msg.gm .prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0 0 12px; }
.prose h1, .prose h2, .prose h3 { font-size: 17px; margin: 14px 0 8px; color: var(--accent); }
.prose blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.prose code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.prose pre { background: var(--panel2); padding: 10px; border-radius: 10px; overflow-x: auto; font-size: 13px; }
.prose ul, .prose ol { padding-left: 22px; margin: 0 0 12px; }
.prose strong { color: #fff; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.tools { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 8px; }
.tool { font-size: 13px; color: var(--dim); }
.tool summary { cursor: pointer; list-style: none; display: flex; gap: 6px; align-items: baseline; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "›"; color: var(--dim); }
.tool[open] summary::before { content: "⌄"; }
.tool.err summary { color: var(--red); }
.tool pre { margin: 4px 0 0 12px; white-space: pre-wrap; font-size: 12px; color: var(--muted); background: var(--panel); padding: 8px; border-radius: 8px; }
.tool .pending { animation: pulse 1.2s infinite; }
.divider { text-align: center; color: var(--dim); font-size: 12px; }
.divider::before, .divider::after { content: " — "; }
.msg.err { color: var(--red); font-size: 14px; }
.thinking { color: var(--dim); font-size: 13px; font-style: italic; }
.typing { color: var(--dim); font-size: 13px; }
.typing::after { content: "…"; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: .4 } 50% { opacity: 1 } }

.debt { background: var(--red); color: #fff; text-align: center; padding: 6px; font-weight: 600; font-size: 14px; }
.offline { background: var(--panel2); color: var(--muted); text-align: center; padding: 4px; font-size: 13px; }

#composer { display: flex; gap: 8px; padding: 10px var(--pad) calc(env(safe-area-inset-bottom) + 10px); background: var(--panel); border-top: 1px solid var(--line); }
#input { resize: none; max-height: 40vh; line-height: 1.4; }
#send { width: 46px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-size: 20px; font-weight: 700; }
#send:disabled { background: var(--line); color: var(--dim); }

/* drawer + menu */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 10; display: flex; align-items: flex-end; }
.drawer-card { background: var(--panel); width: 100%; max-height: 85vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; }
.drawer-card pre { margin: 0; padding: var(--pad) var(--pad) calc(env(safe-area-inset-bottom) + var(--pad)); overflow: auto; white-space: pre-wrap; font-size: 13px; }
.menu { position: fixed; top: calc(env(safe-area-inset-top) + 50px); right: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; z-index: 11; overflow: hidden; }
.menu button { background: transparent; color: var(--ink); border: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; text-align: left; }
.menu button:last-child { border-bottom: 0; }
.menu button.active { color: var(--accent); }

/* new campaign */
#new-form { padding: var(--pad); display: flex; flex-direction: column; gap: 14px; overflow: auto; }
#new-form label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
#new-form select { width: 100%; background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font: inherit; }
#new-form button[type=submit] { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 12px; font-weight: 600; }
#new-form button:disabled { opacity: .5; }

#new-form textarea { min-height: 90px; }
#new-form label.row { flex-direction: row; align-items: center; gap: 10px; }
#new-form label.row input { width: auto; }
.joblog { flex: 1; overflow: auto; padding: var(--pad); display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.joblog .line { color: var(--muted); }
.joblog .line:last-child { color: var(--ink); }
.joblog .line.fail { color: var(--red); }
.jobactions { padding: var(--pad); }
.drawer-card #drawer-body { overflow: auto; }
.drawer-card #drawer-body pre { margin: 0; padding: var(--pad) var(--pad) calc(env(safe-area-inset-bottom) + var(--pad)); white-space: pre-wrap; font-size: 13px; }
.roles { padding: var(--pad) var(--pad) calc(env(safe-area-inset-bottom) + var(--pad)); display: flex; flex-direction: column; gap: 18px; }
.role { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.role h3 { margin: 0; font-size: 15px; color: var(--accent); display: flex; justify-content: space-between; }
.role h3 span { color: var(--muted); font-weight: 400; font-size: 12px; }
.role label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.role select, .role input[type=text] { width: 100%; background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font: inherit; }
.role .row { flex-direction: row; align-items: center; gap: 8px; }
.role .row input[type=range] { flex: 1; }
.role .row input[type=checkbox] { width: auto; }
.roles .save { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 12px; font-weight: 600; }
.roles .hint { font-size: 12px; color: var(--dim); }

.jump { position: fixed; right: 14px; bottom: calc(env(safe-area-inset-bottom) + 78px); width: 40px; height: 40px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--accent); font-size: 18px; z-index: 3; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.earlier { align-self: center; font-size: 13px; }
