:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1d2433; --muted: #667085; --line: #e3e6ec;
  --brand: #0b4f6c; --brand-2: #127ea8; --ok: #12805c; --warn: #b54708; --bad: #c4320a; --flag: #7a5af8;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--ink); background: var(--bg); }
button, select, input, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 10px; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.danger { color: var(--bad); border-color: #f4c7b8; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
a { color: var(--brand-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #eef2f6; font-size: 12px; margin: 1px 2px; }
.pill.bad { background: #fde8e1; color: var(--bad); }
.pill.ok { background: #e3f5ee; color: var(--ok); }
.pill.flag { background: #efeaff; color: var(--flag); }

/* login */
#login { max-width: 380px; margin: 9vh auto; background: var(--panel); padding: 28px; border-radius: 12px; border: 1px solid var(--line); }
#login h1 { font-size: 20px; margin: 0 0 4px; color: var(--brand); }
#login label { display: block; margin: 12px 0 4px; font-weight: 600; }
#login input, #login select { width: 100%; }
#login .row { display: flex; gap: 8px; margin-top: 10px; }
#login .err { color: var(--bad); margin-top: 10px; min-height: 1.4em; }

/* app shell */
#app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
header { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 14px; background: var(--brand); color: #fff; }
header .title { font-weight: 700; font-size: 15px; margin-right: 6px; }
header select { padding: 3px 6px; }
header a, header button.link { color: #fff; background: none; border: 0; text-decoration: underline; padding: 0 2px; }
header .sp { flex: 1; }
header .badge { background: rgba(255,255,255,.15); padding: 2px 8px; border-radius: 6px; font-size: 12px; }
main { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1fr); gap: 10px; padding: 10px; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; min-height: 0; }

/* chat */
#chat-head { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); }
#messages { flex: 1; overflow: auto; padding: 12px; }
.msg { margin: 0 0 12px; max-width: 92%; }
.msg.user { margin-left: auto; }
.msg .bubble { padding: 9px 12px; border-radius: 10px; background: #eef4f8; white-space: normal; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--brand); color: #fff; white-space: pre-wrap; }
.msg.error .bubble { background: #fff3ed; }
.msg .foot { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.msg .foot button { padding: 0 6px; font-size: 12px; }
.bubble img { max-width: 220px; border: 1px dashed var(--line); }
.bubble pre { background: #0f172a; color: #e2e8f0; padding: 8px; border-radius: 6px; overflow: auto; font-size: 12px; }
.bubble code { font-family: var(--mono); font-size: 12px; }
.bubble p { margin: 0 0 6px; }
.blocked-link { color: var(--warn); text-decoration: line-through; }
#composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
#composer textarea { flex: 1; resize: vertical; min-height: 48px; max-height: 240px; }
.thinking { color: var(--muted); font-style: italic; }

/* side tabs */
.tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-radius: 0; background: none; padding: 9px 12px; border-bottom: 2px solid transparent; }
.tabs button.active { border-bottom-color: var(--brand); color: var(--brand); font-weight: 600; }
.tabbody { flex: 1; overflow: auto; padding: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 5px 6px; vertical-align: top; }
th { background: #f8fafc; position: sticky; top: 0; }
tr.click { cursor: pointer; } tr.click:hover { background: #f5f9fc; }
.step { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 8px; }
.step > .sh { display: flex; gap: 8px; align-items: center; padding: 6px 10px; background: #f8fafc; border-radius: 8px 8px 0 0; cursor: pointer; }
.step > .sh .t { font-weight: 600; }
.step > .sh .ms { margin-left: auto; color: var(--muted); font-size: 12px; }
.step > .sb { padding: 8px 10px; }
.step pre, .kv pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-family: var(--mono); font-size: 12px; background: #fbfcfe; }
.step.untrusted > .sh { background: #fff6e6; }
.step.err > .sh { background: #fde8e1; }
.step.tool-write > .sh { background: #efeaff; }
.doc { border-left: 3px solid var(--line); padding: 2px 8px; margin: 6px 0; }
.doc.staff { border-left-color: var(--bad); }
.doc.untrusted { border-left-color: var(--warn); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 2px 10px; font-size: 13px; margin-bottom: 10px; }
.kv div:nth-child(odd) { color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.form label { display: block; font-weight: 600; margin: 8px 0 3px; }
.form textarea { width: 100%; min-height: 110px; }
.flagrow { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.flagrow .big { font-size: 20px; }

/* modal */
#modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 10; }
#modal .box { background: #fff; border-radius: 12px; width: min(920px, 94vw); max-height: 88vh; overflow: auto; padding: 18px 22px; }
#modal .box h1, #modal .box h2 { color: var(--brand); }
#modal .close { float: right; }
.md table { margin: 8px 0; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }

/* leaderboard */
.lb { max-width: 1000px; margin: 30px auto; padding: 0 16px; }
.lb h1 { color: var(--brand); font-size: 30px; }
.lb table { font-size: 20px; background: #fff; }
.lb td, .lb th { padding: 14px; }
.lb .got { color: var(--flag); font-weight: 700; }

@media (max-width: 980px) { main { grid-template-columns: 1fr; } }
