:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel2: #f8f9fc;
  --line: #e2e6ee;
  --line2: #cfd6e3;
  --text: #1a2233;
  --muted: #5d6779;
  --navy: #1b2a4e;
  --navy2: #2c4178;
  --navy-soft: #e8ecf6;
  --red: #c8392f;
  --orange: #e57a1f;
  --orange-soft: #fdf1e6;
  --red-soft: #fbeceb;
  --good: #1f8a52;
  --good-soft: #e7f5ed;
  --warn: #b26a00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 4px 16px rgba(20, 30, 60, .05);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55; }
a { color: var(--navy2); }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; color: var(--navy); }
h1 { font-size: 2rem; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; border: 1px solid var(--line2); background: var(--panel); color: var(--text);
  padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; gap: 8px; align-items: center; justify-content: center;
  text-decoration: none; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel2); border-color: var(--navy2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy2); }
.btn.accent { background: var(--red); color: #fff; border-color: var(--red); }
.btn.accent:hover { background: #ad2f26; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--navy-soft); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
input[type=text], input:not([type]), select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line2); border-radius: 9px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(44, 65, 120, .25); border-color: var(--navy2); }
label { font-weight: 600; font-size: .9rem; display: block; margin-bottom: 4px; }
textarea { resize: vertical; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--navy-soft); color: var(--navy); white-space: nowrap; }
.tag.demo { background: var(--orange-soft); color: var(--warn); }
.tag.live { background: var(--good-soft); color: var(--good); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.green { background: var(--good-soft); color: var(--good); }
.tag.orange { background: var(--orange-soft); color: var(--warn); }
.warning {
  background: var(--orange-soft); border: 1px solid #f3cfa8; color: #7a4a0f; border-radius: 10px; padding: 10px 14px; font-size: .88rem; display: flex; gap: 8px; align-items: flex-start;
}
.alert-err { background: var(--red-soft); border: 1px solid #efc1bd; color: #7d211a; border-radius: 10px; padding: 10px 14px; font-size: .9rem; }

/* ---------- top bar & brand ---------- */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .inner { max-width: 1180px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--navy); }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .9rem; letter-spacing: .02em; position: relative; }
.brand .mark::after { content: ''; position: absolute; right: -3px; bottom: -3px; width: 10px; height: 10px; border-radius: 3px; background: var(--orange); }
.brand b { display: block; font-size: .98rem; line-height: 1.1; }
.brand small { display: block; font-size: .72rem; color: var(--muted); font-weight: 500; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- landing ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 28px 16px 60px; }
.hero { display: grid; grid-template-columns: 1.15fr .85fr; gap: 28px; align-items: start; }
.hero h1 span { color: var(--red); }
.tagline { font-size: 1.15rem; font-weight: 600; color: var(--navy2); margin-bottom: 14px; }
.agile { display: grid; gap: 8px; margin-top: 18px; }
.agile .p { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: start; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.agile .p .k { width: 34px; height: 34px; border-radius: 8px; background: var(--navy); color: #fff; font-weight: 800; display: grid; place-items: center; }
.agile .p:nth-child(even) .k { background: var(--red); }
.agile .p b { display: block; color: var(--navy); }
.roles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 14px 0; }
.role-card {
  text-align: left; border: 1.5px solid var(--line); background: var(--panel); border-radius: 12px; padding: 14px; cursor: pointer; font: inherit; color: inherit; transition: border-color .15s, box-shadow .15s;
}
.role-card:hover { border-color: var(--navy2); }
.role-card.sel { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(27, 42, 78, .12); }
.role-card .ic { font-size: 1.5rem; }
.role-card b { display: block; margin: 4px 0 2px; color: var(--navy); }
.role-card .small { color: var(--muted); }
.attempt-list { list-style: none; padding: 0; margin: 0; }
.attempt-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.attempt-list li:last-child { border-bottom: 0; }
.code { font-family: var(--mono); background: var(--navy-soft); padding: 2px 8px; border-radius: 6px; letter-spacing: .08em; font-weight: 700; color: var(--navy); }

/* ---------- simulation layout ---------- */
.sim { display: grid; grid-template-columns: 270px minmax(0, 1fr) 380px; height: 100vh; height: 100dvh; }
.side { background: var(--navy); color: #e9edf7; padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.side .brand { color: #fff; }
.side .brand .mark { background: #fff; color: var(--navy); }
.side .brand small { color: #aab4cc; }
.side h4 { color: #aab4cc; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; margin: 0 0 6px; }
.side .who b { color: #fff; }
.side ul { margin: 0; padding-left: 18px; font-size: .86rem; color: #d6dcec; }
.side a { color: #fff; }
.steps { list-style: none; padding: 0 !important; margin: 0; }
.steps li { display: flex; gap: 8px; align-items: center; padding: 4px 0; font-size: .86rem; color: #aab4cc; }
.steps li .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #56648a; display: grid; place-items: center; font-size: .7rem; flex: 0 0 auto; }
.steps li.done { color: #fff; }
.steps li.done .dot { background: var(--orange); border-color: var(--orange); color: #fff; }
.steps li.now { color: #fff; font-weight: 600; }
.steps li.now .dot { border-color: #fff; }
.progress { height: 6px; border-radius: 9px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.progress > div { height: 100%; background: var(--orange); }
.hist a { display: block; padding: 6px 8px; border-radius: 8px; text-decoration: none; font-size: .85rem; color: #d6dcec; }
.hist a.cur, .hist a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.side .warning { background: rgba(229, 122, 31, .14); border-color: rgba(229, 122, 31, .4); color: #ffd9b5; }

.chat { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-head { padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; align-items: center; gap: 10px; }
.chat-head h2 { margin: 0; font-size: 1.02rem; }
.msgs { flex: 1; overflow-y: auto; padding: 20px 18px 8px; }
.msg { display: flex; gap: 10px; margin: 0 auto 16px; max-width: 860px; }
.msg .av { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px; display: grid; place-items: center; font-size: .78rem; font-weight: 800; }
.msg.ai .av { background: var(--navy); color: #fff; }
.msg.me { flex-direction: row-reverse; }
.msg.me .av { background: var(--orange); color: #fff; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--navy-soft); border-color: #d3daec; }
.bubble .who { font-size: .75rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.toolchip { max-width: 860px; margin: -6px auto 12px; padding-left: 40px; font-size: .8rem; color: var(--muted); }
.toolchip span { background: var(--panel); border: 1px dashed var(--line2); border-radius: 999px; padding: 2px 10px; display: inline-block; }
.typing::after { content: '▍'; animation: blink 1s steps(1) infinite; color: var(--navy2); }
@keyframes blink { 50% { opacity: 0; } }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 18px; }
.composer .box { max-width: 860px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { min-height: 46px; max-height: 220px; resize: none; }
.composer .hint { max-width: 860px; margin: 6px auto 0; font-size: .76rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px 18px; }
.panel section { margin-bottom: 18px; }
.panel h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 6px; }
.panel ol, .panel ul { padding-left: 20px; margin: 0; }
.panel li { margin-bottom: 4px; }
.panel details { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; background: var(--panel2); }
.panel summary { cursor: pointer; font-weight: 600; color: var(--navy); }
.panel-close { display: none; }

/* ---------- markdown ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 .7em; }
.md ul, .md ol { padding-left: 1.3em; }
.md h1, .md h2, .md h3 { font-size: 1.02rem; margin: .9em 0 .4em; }
.md table { border-collapse: collapse; margin: .6em 0; font-size: .88rem; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--panel2); }
.md blockquote { margin: .6em 0; padding: 6px 12px; border-left: 3px solid var(--orange); background: var(--panel2); color: #3a4457; }
.md code { font-family: var(--mono); font-size: .86em; background: #eef1f7; padding: 1px 5px; border-radius: 5px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.codewrap { position: relative; margin: .6em 0; }
.codewrap pre { margin: 0; background: #f6f8fa; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; font-size: .84rem; line-height: 1.5; }
.codewrap pre code { background: none; padding: 0; font-size: inherit; }
.codewrap .copy { position: absolute; top: 6px; right: 6px; font-size: .72rem; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line2); background: var(--panel); cursor: pointer; opacity: .85; }
.codewrap .copy:hover { opacity: 1; }

/* ---------- modal (submission) ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 22, 40, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: min(1000px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.sm { width: min(480px, 100%); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs button { border: 0; background: none; font: inherit; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tabs button.on { color: var(--navy); border-color: var(--navy); }
.editor { font-family: var(--mono); font-size: .88rem; min-height: 52vh; line-height: 1.5; }
.preview { min-height: 52vh; border: 1px solid var(--line); border-radius: 9px; padding: 12px 16px; }

/* ---------- results ---------- */
.result-head { display: grid; grid-template-columns: 180px 1fr; gap: 24px; align-items: center; }
.ring { width: 170px; height: 170px; border-radius: 50%; display: grid; place-items: center; position: relative; }
.ring .val { position: absolute; inset: 14px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; text-align: center; }
.ring .val b { font-size: 2.6rem; color: var(--navy); line-height: 1; display: block; }
.bars .bar { margin-bottom: 14px; }
.bars .track { height: 9px; border-radius: 9px; background: var(--navy-soft); overflow: hidden; margin: 4px 0; }
.bars .track > div { height: 100%; background: var(--navy); border-radius: 9px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.list-clean { list-style: none; padding: 0; margin: 0; }
.list-clean li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-clean li:last-child { border-bottom: 0; }
.status { font-weight: 700; font-size: .75rem; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.status.found, .status.pass { background: var(--good-soft); color: var(--good); }
.status.partial { background: var(--orange-soft); color: var(--warn); }
.status.missed, .status.fail { background: var(--red-soft); color: var(--red); }
.status.not_addressed, .status.unknown { background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.cap { border-left: 3px solid var(--red); padding: 6px 10px; background: var(--red-soft); border-radius: 0 8px 8px 0; margin-bottom: 6px; font-size: .9rem; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--navy-soft); border-top-color: var(--navy); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- admin ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.tile b { display: block; font-size: 1.7rem; color: var(--navy); line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: .82rem; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th, table.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.tbl th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--panel2); }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.transcript .t { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--panel); }
.transcript .t.user { background: var(--navy-soft); }
.transcript .t.tool { background: var(--panel2); font-size: .85rem; }
.transcript pre { white-space: pre-wrap; font-size: .8rem; font-family: var(--mono); margin: 6px 0 0; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
.toast.on { opacity: 1; }
.toast.err { background: var(--red); }

/* ---------- responsive ---------- */
.only-narrow { display: none; }
.only-mobile { display: none !important; }
@media (max-width: 1180px) {
  .sim { grid-template-columns: 250px minmax(0, 1fr); }
  .panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); z-index: 40; box-shadow: -10px 0 40px rgba(0, 0, 0, .15); transform: translateX(105%); transition: transform .2s; }
  .panel.open { transform: none; }
  .panel-close { display: inline-flex; }
  .only-narrow { display: inline-flex; }
}
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .result-head { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .sim { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 88%); z-index: 40; transform: translateX(-105%); transition: transform .2s; }
  .side.open { transform: none; }
  .only-mobile { display: inline-flex !important; }
  .msgs { padding: 14px 12px 6px; }
  .composer, .chat-head { padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 520px) {
  h1 { font-size: 1.6rem; }
  .roles { grid-template-columns: 1fr; }
  .msg .av { display: none; }
  .toolchip { padding-left: 0; }
}
