:root{
  --bg:#1E1F22; --main:#313338; --panel:#2B2D31; --raise:#3A3C42; --deep:#232428;
  --line:#3F4147; --line2:#393B40; --btnline:#4E5058;
  --text:#F2F3F5; --text2:#DBDEE1; --muted:#A7ADB6;
  --red:#C62828; --redtext:#FF8A8A; --redlink:#FF7A7D; --redline:#ED4245;
  --redbg:#4A1D20; --redbg2:#3A1F22; --redborder:#6E2A2D; --redborder2:#8C2F33;
  --sent:#404249;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{background:var(--bg);color:var(--text);font-family:'IBM Plex Sans',system-ui,sans-serif;font-size:15px;line-height:1.45}
a{color:var(--redlink)}a:hover{color:#FFA3A5}
button,input,textarea,select{font-family:inherit;font-size:inherit;color:inherit}
button{cursor:pointer}
:focus-visible{outline:2px solid var(--redline);outline-offset:2px}
.sr{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}
.mono{font-family:'IBM Plex Mono',ui-monospace,monospace;font-size:13px}

/* buttons */
.btn{min-height:44px;padding:0 16px;border-radius:8px;border:1px solid var(--btnline);background:var(--panel);color:var(--text);font-size:15px}
.btn:hover{background:var(--raise)}
.btn.primary{background:var(--red);border-color:var(--red);color:#fff;font-weight:600}
.btn.primary:hover{background:#B02323}
.btn.outline{border-color:var(--redline);color:var(--redlink);font-weight:500}
.btn.danger{color:var(--redtext)}
.btn.small{min-height:36px;padding:0 12px;font-size:13px;white-space:nowrap}
.btn:disabled{opacity:.5;cursor:default}
.input{width:100%;height:44px;padding:0 12px;border-radius:8px;border:1px solid var(--line);background:var(--bg);color:var(--text)}
textarea.input{height:auto;padding:10px 12px;line-height:1.5;resize:vertical}
label.lab{font-size:13px;font-weight:600;color:var(--text2)}
.pill{display:inline-block;font-size:12px;font-weight:600;padding:2px 8px;border-radius:999px;background:var(--raise);color:var(--text2)}
.pill.red{background:var(--redbg2);color:var(--redtext)}
.pill.hot{background:var(--redbg);color:var(--redtext)}
.pill.dim{background:var(--deep);color:var(--muted)}

/* login */
.login{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:16px}
.login form{width:100%;max-width:400px;padding:32px;border-radius:12px;background:var(--panel);border:1px solid var(--line);display:flex;flex-direction:column;gap:14px}
.login h1{margin:0;font-size:22px;font-weight:600}
.err{color:var(--redtext);font-size:14px;min-height:20px}

/* shell */
.shell{min-height:100vh;display:flex}
.nav{flex:0 0 340px;max-width:360px;background:var(--panel);border-right:1px solid var(--line);display:flex;flex-direction:column;height:100vh;position:sticky;top:0}
.nav-head{padding:18px 18px 12px;display:flex;justify-content:space-between;align-items:center;gap:10px}
.brand{font-size:18px;font-weight:600}
.sub{font-size:12px;color:var(--muted)}
.nav-sec{padding:0 18px 12px;display:flex;flex-direction:column;gap:10px}
.filters{display:flex;gap:8px;flex-wrap:wrap}
.fbtn{font-size:13px;padding:6px 12px;min-height:32px;border-radius:999px;border:1px solid var(--line);background:var(--panel);color:var(--text2)}
.fbtn.on{background:var(--red);border-color:var(--red);color:#fff;font-weight:600}
.alert{padding:10px 12px;border-radius:8px;background:var(--redbg);border:1px solid var(--redborder2);display:flex;justify-content:space-between;gap:8px;align-items:center;font-size:13px}
.alert b{color:var(--redtext)}
.list{overflow-y:auto;flex:1 1 auto}
.row{display:flex;flex-direction:column;gap:5px;width:100%;text-align:left;padding:13px 18px;border:0;border-top:1px solid var(--line2);background:var(--panel);color:var(--text)}
.row:hover{background:#303237}
.row.on{background:var(--raise)}
.row .top{display:flex;justify-content:space-between;gap:8px;align-items:baseline}
.row .nm{font-weight:600}
.row .tm{font-size:12px;color:var(--muted)}
.row .pv{font-size:13px;color:var(--text2);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.row .tags{display:flex;gap:6px;flex-wrap:wrap}
.empty{padding:24px 18px;color:var(--muted);font-size:14px}
.newc{margin:0 18px 12px;padding:14px;border-radius:10px;background:var(--deep);border:1px solid var(--line);display:flex;flex-direction:column;gap:8px}

.main{flex:1 1 auto;min-width:0;background:var(--main);display:flex;flex-direction:column;height:100vh;overflow-y:auto}
.chat-head{position:sticky;top:0;z-index:2;padding:14px 22px;background:var(--panel);border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap}
.chat-head .nm{font-size:17px;font-weight:600}
.head-r{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.back{display:none}
.stream{padding:22px;display:flex;flex-direction:column;gap:14px;max-width:780px;width:100%;margin:0 auto}
.day{align-self:center;font-size:12px;color:var(--muted)}
.bub{max-width:80%;display:flex;flex-direction:column;gap:6px;padding:12px 14px;border-radius:12px 12px 12px 4px;background:var(--panel);border:1px solid var(--line)}
.bub.us{align-self:flex-end;border-radius:12px 12px 4px 12px;background:var(--sent);border-color:var(--sent)}
.bub .tx{white-space:pre-wrap;word-break:break-word}
.bub .meta{font-size:11px;color:var(--muted);align-self:flex-end}
.shot{border-radius:10px;background:var(--raise);padding:10px}
.shot summary{cursor:pointer;font-size:12px;font-weight:600;color:var(--text2)}
.shot pre{margin:8px 0 0;white-space:pre-wrap;word-break:break-word;font-family:'IBM Plex Mono',ui-monospace,monospace;font-size:12px;color:var(--text2);max-height:320px;overflow:auto}
.card{border:1px solid var(--redborder);background:var(--panel);border-radius:12px;overflow:hidden}
.card.sel{box-shadow:0 0 0 2px var(--redline)}
.card .ch{padding:10px 16px;background:var(--redbg2);display:flex;justify-content:space-between;gap:8px;flex-wrap:wrap;align-items:center}
.card .ch .t{font-size:13px;font-weight:600;color:var(--redtext)}
.card.hand{border-color:var(--redborder2)}
.card.hand .ch{background:var(--redbg)}
.card .cb{padding:16px;display:flex;flex-direction:column;gap:12px}
.draft{white-space:pre-wrap;word-break:break-word;font-size:15px;line-height:1.5}
.alt{display:flex;flex-direction:column;gap:4px;padding:10px 12px;border-radius:8px;background:var(--main)}
.alt .k{font-size:12px;font-weight:600;color:var(--muted)}
.acts{display:flex;gap:8px;flex-wrap:wrap}
.chk{display:flex;gap:8px;align-items:center;font-size:13px;color:var(--text2)}
.chk input{width:18px;height:18px}
.done-note{align-self:center;font-size:13px;color:var(--muted);padding:8px 12px;border:1px dashed var(--btnline);border-radius:8px}
.archived-bar{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;font-size:13px;color:var(--text2);padding:10px 12px;border-radius:8px;background:var(--raise)}
.welcome{border:1px solid var(--line);background:var(--panel);border-radius:12px;padding:16px;display:flex;flex-direction:column;gap:8px}

.aside{flex:0 0 340px;max-width:380px;background:var(--panel);border-left:1px solid var(--line);height:100vh;position:sticky;top:0;overflow-y:auto}
.tabs{display:flex;border-bottom:1px solid var(--line);position:sticky;top:0;background:var(--panel)}
.tab{flex:1 1 0;min-height:48px;border:0;border-bottom:2px solid transparent;background:var(--panel);color:var(--muted);font-size:14px}
.tab.on{border-bottom-color:var(--redline);color:var(--text);font-weight:600}
.pane{padding:20px;display:flex;flex-direction:column;gap:18px}
.kv{display:flex;flex-direction:column;gap:6px}
.kv .k{font-size:12px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:.06em}
.kv .v{font-size:14px;line-height:1.5;white-space:pre-wrap;word-break:break-word}
.books div{display:flex;justify-content:space-between;gap:8px;font-size:14px}
.yes{font-size:12px;font-weight:600;color:var(--text2)}
.no{font-size:12px;font-weight:600;color:var(--redtext)}

/* engine page */
.eng{max-width:1200px;margin:0 auto;padding:28px 22px;display:flex;flex-direction:column;gap:22px;width:100%}
.eng h1{margin:0;font-size:28px;font-weight:600}
.eng h2{margin:0;font-size:17px;font-weight:600}
.tiles{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:14px}
.tile{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:18px;display:flex;flex-direction:column;gap:6px}
.tile .n{font-size:32px;font-weight:600}
.tile .n.red{color:var(--redtext)}
.box{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:20px;display:flex;flex-direction:column;gap:14px}
.bars{display:flex;flex-direction:column;gap:10px}
.bar{display:grid;grid-template-columns:110px minmax(0,1fr) 60px;gap:12px;align-items:center;font-size:14px}
.track{height:14px;background:var(--raise);border-radius:4px;overflow:hidden}
.fill{height:14px;background:var(--red);border-radius:4px}
.grid3{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}
.hrow{display:flex;justify-content:space-between;gap:8px;padding:12px;border:1px solid var(--line2);border-radius:8px;font-size:14px}
.ok{color:var(--text2);font-weight:600;font-size:13px}
.bad{color:var(--redtext);font-weight:600;font-size:13px}

#toast{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);background:var(--text);color:var(--bg);padding:10px 16px;border-radius:8px;font-size:14px;font-weight:500;opacity:0;pointer-events:none;transition:opacity .2s;z-index:50;max-width:90vw}
#toast.show{opacity:1}

/* narrow screens: one pane at a time */
@media (max-width: 1100px){ .aside{display:none} .aside.open{display:block;position:fixed;right:0;top:0;bottom:0;z-index:20;width:min(380px,100vw);box-shadow:-8px 0 24px rgba(0,0,0,.4)} }
@media (max-width: 760px){
  .nav{flex:1 1 auto;max-width:none;width:100%}
  .shell.in-chat .nav{display:none}
  .shell:not(.in-chat) .main{display:none}
  .back{display:inline-flex;align-items:center}
  .head-r .pill{display:none}
  .stream{padding:14px}
  .bub{max-width:92%}
  .tiles{grid-template-columns:repeat(2,minmax(0,1fr))}
  .grid3{grid-template-columns:minmax(0,1fr)}
  .bar{grid-template-columns:80px minmax(0,1fr) 48px}
}
