/* AI 경기장 — design/arena.pen 기준. 모든 간격은 4px 단위 (4·8·12·16·20·24·32) */
:root {
  --bg: #ffffff; --panel: #f8f8f9; --soft: #f2f2f4; --line: #e6e6ea;
  --ink: #17171a; --text: #2a2a2f; --muted: #6e6e78; --subtle: #a0a0aa; --on-ink: #ffffff;
  --ok: #15803d; --warn: #b45309; --err: #c2342b; --run: #2563eb;
  --ok-bg: #e7f4ec; --warn-bg: #fbf0e2; --err-bg: #fbeae8; --run-bg: #e8effd;
  --a-claude: #c2613f; --a-codex: #0e7a6e; --a-chatgpt: #4f5bd5; --a-pickle: #5e8e1e; --a-me: #17171a;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
  --r1: 6px; --r2: 8px; --r3: 12px;
  --shadow-1: 0 1px 2px rgb(0 0 0 / .1);
  --shadow-2: 0 2px 8px rgb(0 0 0 / .06);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --top: 56px;
  --col: 760px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --panel: #19191c; --soft: #222226; --line: #2e2e33;
    --ink: #f2f2f4; --text: #dcdce0; --muted: #9a9aa4; --subtle: #6a6a74; --on-ink: #141416;
    --ok: #4ade80; --warn: #f0a94b; --err: #f2766d; --run: #7aa7f7;
    --ok-bg: #15301f; --warn-bg: #33250f; --err-bg: #3a1a17; --run-bg: #18264a;
    --a-claude: #e08a66; --a-codex: #3fbfae; --a-chatgpt: #8e98f2; --a-pickle: #98c45f; --a-me: #f2f2f4;
    --on-avatar: #141416;
    --shadow-1: 0 1px 2px rgb(0 0 0 / .4); --shadow-2: 0 2px 8px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.6 var(--font); letter-spacing: -0.005em;
  word-break: keep-all; overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono, code { font-family: var(--mono); font-size: 12px; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 상단 바 ---------- */
.top { display: flex; align-items: center; justify-content: space-between; height: var(--top); padding: 0 var(--s6); border-bottom: 1px solid var(--line); background: var(--bg); }
.brand { display: flex; align-items: center; gap: var(--s2); text-decoration: none; color: var(--ink); font-size: 16px; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 24px; height: 24px; border-radius: var(--r1); background: var(--ink); color: var(--on-ink); }
.brand-mark svg.i { width: 14px; height: 14px; }
.tabs { display: flex; gap: var(--s1); padding: var(--s1); border-radius: var(--r2); background: var(--soft); }
.tabs a { display: flex; align-items: center; height: 28px; padding: 0 var(--s3); border-radius: var(--r1); font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none; }
.tabs a.on { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-1); }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 40px; padding: 0 var(--s4); border-radius: var(--r2);
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: 500 14px/1 var(--font); white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--soft); }
.btn:focus-visible { outline: 2px solid var(--run); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); font-weight: 600; }
.btn-primary:hover { background: var(--ink); opacity: .88; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--soft); color: var(--ink); }
.btn-danger { color: var(--err); }
.btn-sm { height: 32px; padding: 0 var(--s3); font-size: 13px; }
.btn-xs { height: 24px; padding: 0 var(--s2); gap: var(--s1); font-size: 12px; border-radius: var(--r1); }
.btn-xs svg.i { width: 12px; height: 12px; }
.btn-block { width: 100%; }

/* ---------- 입력 ---------- */
.input, .select, textarea.input {
  width: 100%; height: 40px; padding: 0 var(--s3);
  border: 1px solid var(--line); border-radius: var(--r2); background: var(--bg); color: var(--text);
  font: 14px/1.6 var(--font);
}
textarea.input { height: auto; padding: var(--s3); resize: vertical; }
.input::placeholder, textarea::placeholder { color: var(--subtle); }
.input:focus, .select:focus, textarea:focus { outline: none; border-color: var(--ink); }
.select {
  appearance: none; padding-right: var(--s8); cursor: pointer;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236e6e78' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
}
.field { display: flex; flex-direction: column; gap: var(--s2); }
.label { font-size: 13px; font-weight: 600; color: var(--text); }
.label .muted { font-weight: 400; }
.hint { font-size: 12px; color: var(--muted); }

.dropzone { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r2); background: var(--bg); overflow: hidden; transition: border-color .12s; }
.dropzone:focus-within { border-color: var(--ink); }
.dropzone.drop { border-color: var(--run); box-shadow: 0 0 0 3px var(--run-bg); }
.dropzone textarea { display: block; width: 100%; min-height: 176px; padding: var(--s3); border: 0; background: transparent; color: var(--text); font: 14px/1.6 var(--font); resize: vertical; }
.dropzone textarea:focus { outline: none; }
.dropzone .bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); min-height: 44px; padding: var(--s1) var(--s2) var(--s1) var(--s3); border-top: 1px solid var(--line); background: var(--panel); }

.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.pick { position: relative; display: inline-flex; align-items: center; gap: var(--s2); height: 32px; padding: 0 var(--s3); border: 1px solid var(--line); border-radius: 16px; background: var(--bg); color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer; user-select: none; }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick .char { width: 20px; height: 20px; margin-left: -6px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 1px rgb(0 0 0 / .08); filter: grayscale(1); opacity: .5; transition: filter .12s, opacity .12s; }
.pick:has(input:checked) { border-color: var(--ink); color: var(--ink); font-weight: 600; }
.pick:has(input:checked) .char { filter: none; opacity: 1; }
.pick:has(input:focus-visible) { outline: 2px solid var(--run); outline-offset: 2px; }
.pick .sub { font-size: 12px; font-weight: 400; color: var(--muted); }

.segment { display: flex; gap: var(--s1); padding: var(--s1); border-radius: var(--r2); background: var(--soft); }
.segment label { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; height: 32px; border-radius: var(--r1); font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment label:has(input:checked) { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-1); }
.segment label:has(input:focus-visible) { outline: 2px solid var(--run); }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

/* ---------- 2분할 ---------- */
.split { display: grid; grid-template-columns: 440px minmax(0, 1fr); height: calc(100vh - var(--top)); }
.left { overflow-y: auto; display: flex; flex-direction: column; gap: var(--s8); padding: var(--s6); background: var(--panel); border-right: 1px solid var(--line); }
.right { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.form { display: flex; flex-direction: column; gap: var(--s5); }
.form-head { display: flex; flex-direction: column; gap: var(--s1); }
.form-head h1 { font-size: 18px; font-weight: 700; color: var(--ink); line-height: 1.4; }
.form-head p { font-size: 13px; color: var(--muted); }

/* 지난 경기 */
.history { display: flex; flex-direction: column; gap: var(--s2); }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.sess-list { display: flex; flex-direction: column; gap: var(--s1); }
.sess { display: flex; align-items: center; gap: var(--s3); min-height: 48px; padding: var(--s1) var(--s3); border: 1px solid transparent; border-radius: var(--r2); text-decoration: none; }
.sess:hover { background: var(--soft); }
.sess.on { background: var(--bg); border-color: var(--line); }
.sess .t { display: flex; flex-direction: column; min-width: 0; }
.sess .t b { font-size: 14px; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess .t span { font-size: 12px; color: var(--muted); }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--subtle); }
.dot.running { background: var(--run); } .dot.stalled { background: var(--warn); }
.dot.consensus, .dot.closed { background: var(--ok); } .dot.paused { background: var(--subtle); }

/* ---------- 채팅 머리 ---------- */
.chat-head { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s4) var(--s6); border-bottom: 1px solid var(--line); }
.chat-head .row1 { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.chat-head .title { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.chat-head h1 { font-size: 18px; font-weight: 700; color: var(--ink); line-height: 1.4; }
.toolbar { display: flex; align-items: center; gap: var(--s1); flex-wrap: wrap; }
.who-line { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; font-size: 12px; }
.who-line span { display: inline-flex; align-items: center; gap: var(--s1); }
.who-line b { font-weight: 600; color: var(--text); }
.who-line i { font-style: normal; color: var(--muted); }
.who-line .char { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 1px rgb(0 0 0 / .08); }

.status { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 var(--s2); border-radius: var(--r3); font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--muted); background: var(--soft); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.running { color: var(--run); background: var(--run-bg); }
.status.stalled { color: var(--warn); background: var(--warn-bg); }
.status.consensus, .status.closed { color: var(--ok); background: var(--ok-bg); }

/* 문서 서랍 (최신안·원본) */
.drawer { max-height: 45vh; overflow-y: auto; padding: var(--s4) var(--s6); border-bottom: 1px solid var(--line); background: var(--panel); }
.drawer .head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s3); }
.drawer .head b { font-size: 14px; color: var(--ink); }
.plan { white-space: pre-wrap; font-size: 14px; line-height: 1.7; max-width: var(--col); }

/* ---------- 채팅 본문 ---------- */
.chat-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--s6); }
.thread { display: flex; flex-direction: column; gap: var(--s4); max-width: var(--col); margin: 0 auto; padding-bottom: var(--s6); }

.round-title { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; height: 48px; background: var(--bg); border-bottom: 1px solid var(--line); }
.round-title b { font-size: 14px; font-weight: 700; color: var(--ink); }
.round-title span { font-size: 12px; color: var(--muted); }

.divider { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) 0; font-size: 12px; font-weight: 500; color: var(--muted); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.divider.live { color: var(--run); }
.divider.live::before, .divider.live::after { background: color-mix(in srgb, var(--run) 30%, transparent); }
.divider.live .pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--run); animation: pulse 1.4s infinite; }
.divider.good { color: var(--ok); } .divider.warn { color: var(--warn); }
.divider-wrap { display: inline-flex; align-items: center; gap: 6px; }
.stall { text-align: center; font-size: 13px; color: var(--warn); }

.msg { display: flex; gap: var(--s3); align-items: flex-start; }
.avatar { flex: none; position: relative; width: 32px; height: 32px; border-radius: 50%; overflow: hidden; background: var(--soft); }
.avatar::after { content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08); }
.avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.avatar img[src$="me.svg"] { width: 20px; height: 20px; margin: 6px; }
.panel-head .avatar { width: 40px; height: 40px; }
.bubble { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--s2); }
.bubble .who { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; min-height: 32px; }
.bubble .who b { font-size: 14px; font-weight: 700; color: var(--c); }
.bubble .meta { font-size: 12px; color: var(--muted); }
.card { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s3) var(--s4); border: 1px solid var(--line); border-radius: var(--r3); background: var(--bg); }
.msg.mod .card { background: var(--panel); }
.actions { display: flex; align-items: center; gap: var(--s1); flex-wrap: wrap; margin: 0 calc(-1 * var(--s2)); }
.actions .btn { color: var(--muted); }

.verdict { display: inline-flex; align-items: center; gap: var(--s1); height: 24px; padding: 0 var(--s2); border: 1px solid currentColor; border-radius: var(--r3); font-size: 12px; font-weight: 600; white-space: nowrap; }
.verdict::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.v-동의 { color: var(--ok); } .v-조건부 { color: var(--warn); } .v-반대 { color: var(--err); }

.typing { display: flex; align-items: center; gap: var(--s1); height: 24px; font-size: 12px; color: var(--muted); }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--run); animation: pulse 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; margin-right: var(--s1); }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* 마크다운 본문 */
.md { display: flex; flex-direction: column; gap: var(--s1); font-size: 14px; line-height: 1.6; color: var(--text); }
.md h4 { margin: var(--s2) 0 0; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.md h4:first-child { margin-top: 0; }
.md table { border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: var(--s1) var(--s2); text-align: left; vertical-align: top; }
.md th { background: var(--soft); font-weight: 600; }
.point { display: flex; flex-direction: column; gap: var(--s1); align-items: flex-start; padding-top: var(--s1); }
.clamp { max-height: 360px; overflow: hidden; position: relative; }
.clamp::after { content: ""; position: absolute; inset: auto 0 0 0; height: 64px; background: linear-gradient(transparent, var(--bg)); }
.msg.mod .clamp::after { background: linear-gradient(transparent, var(--panel)); }

.tag { display: inline-flex; align-items: center; height: 24px; padding: 0 var(--s2); border-radius: var(--r1); font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--soft); color: var(--muted); }
.tag-반박, .tag-재반박 { background: var(--err-bg); color: var(--err); }
.tag-이어가기 { background: var(--run-bg); color: var(--run); }
.tag-수용, .tag-인정 { background: var(--ok-bg); color: var(--ok); }
.tag-새 { background: var(--warn-bg); color: var(--warn); }

.err { color: var(--err); font-family: var(--mono); font-size: 12px; white-space: pre-wrap; }
.manual { display: flex; flex-direction: column; gap: var(--s2); }
.manual summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.manual[open] summary { margin-bottom: var(--s2); }
.manual .row { display: flex; gap: var(--s2); }
.manual textarea { min-height: 112px; margin-bottom: var(--s2); }

/* 내 지시 */
.msg.me { justify-content: flex-end; }
.me-bubble { max-width: 480px; display: flex; flex-direction: column; gap: var(--s1); padding: var(--s3) var(--s4); border-radius: var(--r3); background: var(--ink); color: var(--on-ink); }
.me-bubble .meta { font-size: 12px; font-weight: 600; opacity: .66; }
.me-bubble p { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }

/* 비어 있을 때 */
.empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s8) var(--s6); text-align: center; color: var(--muted); }
.empty .art { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: var(--s2); border-radius: var(--r3); background: var(--soft); color: var(--ink); }
.empty .art svg.i { width: 24px; height: 24px; }
.empty b { font-size: 16px; color: var(--ink); }

/* ---------- 지시 입력 ---------- */
.composer { padding: var(--s3) var(--s6) var(--s6); }
.composer .box { max-width: var(--col); margin: 0 auto; border: 1px solid var(--line); border-radius: var(--r3); background: var(--bg); box-shadow: var(--shadow-2); transition: border-color .12s; }
.composer .box:focus-within { border-color: var(--ink); }
.composer textarea { display: block; width: 100%; min-height: 64px; max-height: 200px; padding: var(--s3) var(--s4); border: 0; background: transparent; color: var(--text); font: 14px/1.6 var(--font); resize: vertical; }
.composer textarea:focus { outline: none; }
.composer .bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s2) var(--s2) var(--s2) var(--s4); }
.composer .btns { display: flex; align-items: center; gap: var(--s2); }

/* ---------- 연결 설정·로그인 ---------- */
.page { max-width: 760px; margin: 0 auto; padding: var(--s8) var(--s6) 80px; display: flex; flex-direction: column; gap: var(--s6); }
.page-head { display: flex; flex-direction: column; gap: var(--s1); }
.page-head h1 { font-size: 24px; font-weight: 700; color: var(--ink); line-height: 1.4; }
.page-head p { color: var(--muted); }
.panel { display: flex; flex-direction: column; gap: var(--s4); padding: var(--s6); border: 1px solid var(--line); border-radius: var(--r3); background: var(--bg); }
.panel-head { display: flex; align-items: center; gap: var(--s3); }
.panel-head .avatar { width: 40px; height: 40px; }
.panel-head h2 { font-size: 16px; font-weight: 700; color: var(--ink); }
.panel-head p { font-size: 13px; color: var(--muted); }
.copyline { display: flex; align-items: center; gap: var(--s2); }
.copyline code { flex: 1; min-width: 0; display: flex; align-items: center; height: 40px; padding: 0 var(--s3); border: 1px solid var(--line); border-radius: var(--r2); background: var(--panel); overflow-x: auto; white-space: nowrap; }
.guide { max-height: 320px; overflow: auto; padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r2); background: var(--panel); white-space: pre-wrap; font-family: var(--mono); font-size: 12px; line-height: 1.7; }
.note { display: flex; gap: var(--s2); padding: var(--s3) var(--s4); border-radius: var(--r2); background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.note.err-note { background: var(--err-bg); color: var(--err); }
.note svg.i { margin-top: 3px; }
.login { max-width: 400px; }

#toast { position: fixed; bottom: var(--s6); left: 50%; transform: translateX(-50%); z-index: 10; padding: var(--s3) var(--s4); border-radius: var(--r2); background: var(--ink); color: var(--on-ink); font-size: 14px; box-shadow: var(--shadow-2); }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; height: auto; }
  .left { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .right { height: calc(100vh - var(--top)); height: calc(100dvh - var(--top)); }
}
@media (max-width: 640px) {
  .top { padding: 0 var(--s4); }
  .left { padding: var(--s6) var(--s4); }
  .chat-head, .chat-body, .drawer { padding-left: var(--s4); padding-right: var(--s4); }
  .composer { padding: var(--s2) var(--s4) var(--s4); }
  .composer .hint { display: none; }
  .composer .bar { justify-content: flex-end; }
  .page { padding: var(--s6) var(--s4) 64px; }
  .panel { padding: var(--s4); }
  .me-bubble { max-width: 88%; }
}
.thread .wait-note { margin: 0 0 var(--s4); }
.wake-row { justify-content: space-between; align-items: center; gap: var(--s2); }
.wake-row .hint { display: inline-flex; align-items: center; gap: var(--s1); }
.wake-row .hint.err { color: var(--err); }
