:root {
  --bg: #f6f5f1; --panel: #ffffff; --line: #d9d6cc; --text: #1f1e1d; --muted: #6f6d66;
  --chip: #efede6; --shadow: 0 1px 2px rgba(0,0,0,.06);
  --claude: #e08a1e; --codex: #7f77dd; --ci: #378add; --human: #e24b4a; --wip: #ba7517;
  --pass: #1d9e75; --fail: #d04a3a; --done-bg: #e3f2dc; --done-line: #6aa84f; --done-text: #2f5e1a;
  --edge: #9c9a92; --edge-faint: #c9c6bc;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a19; --panel: #262523; --line: #3b3a37; --text: #ecebe6; --muted: #a3a199;
    --chip: #33322f; --shadow: none;
    --done-bg: #22351c; --done-line: #5d8f45; --done-text: #b9dca6;
    --edge: #8a887f; --edge-faint: #4a4945;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
button.ghost { background: transparent; border-color: transparent; }
button.danger { border-color: var(--human); color: var(--human); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; }
textarea { width: 100%; min-height: 60px; resize: vertical; }
a { color: var(--ci); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }

/* 로그인 */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 360px; }
.login-card h1 { font-size: 20px; font-weight: 600; margin: 0 0 8px; }
.login-card form { display: flex; gap: 8px; margin-top: 14px; }
.login-card input { flex: 1; font-size: 20px; letter-spacing: 4px; text-align: center; }
.msg { min-height: 20px; color: var(--muted); font-size: 13px; }

/* 상단 */
#app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex-wrap: wrap; }
.brand { font-weight: 700; }
.loopstate { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); }
.pill { background: var(--chip); border-radius: 999px; padding: 2px 10px; color: var(--text); }
.pill.live { background: color-mix(in srgb, var(--claude) 20%, transparent); }
.top-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.qbtn { border-color: var(--human); color: var(--human); animation: blink 1s ease-in-out infinite; }

.main { flex: 1; display: flex; min-height: 0; }
.board-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.board-tools { display: flex; gap: 6px; align-items: center; padding: 8px 12px; flex-wrap: wrap; }
.chk { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; margin-left: 6px; }
.scroller { flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; position: relative; touch-action: pan-x pan-y; }
#sizer { position: relative; }
.board { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; padding: 8px 12px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px;
  border: 2px solid var(--line); }
.lg.claude { border-color: var(--claude); } .lg.codex { border-color: var(--codex); } .lg.ci { border-color: var(--ci); }
.lg.human { border-color: var(--human); } .lg.wip { border-color: var(--wip); border-style: dashed; }
.lg.pass { border-color: var(--pass); } .lg.fail { border-color: var(--fail); background: var(--fail); }
.lg.done { background: var(--done-bg); border-color: var(--done-line); } .lg.blocked { border-style: dotted; }

/* 줄 (모듈) */
.rowlabel { position: absolute; left: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.rowline { position: absolute; left: 0; height: 1px; background: var(--line); }

/* 상자 */
.box { position: absolute; background: var(--panel); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 7px 10px; cursor: pointer; box-shadow: var(--shadow); overflow: hidden; }
.box:focus-visible { outline: 2px solid var(--ci); outline-offset: 2px; }
.box .t { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box .num { color: var(--muted); font-weight: 500; margin-right: 4px; }
.box.issue .t { padding-right: 34px; }
.box.pr { border-radius: 8px; padding: 4px 10px; }
.box.pr .t { font-size: 12px; font-weight: 500; }
.box .tag { display: inline-block; font-size: 11px; border-radius: 4px; padding: 0 5px; margin-right: 4px;
  background: var(--chip); color: var(--muted); }
.box .score { position: absolute; right: 8px; top: 7px; font-size: 11px; color: var(--muted); }
.link-bar { position: absolute; width: 4px; border-radius: 2px; background: var(--edge); }

.box.done { background: var(--done-bg); border-color: var(--done-line); }
.box.done .t, .box.done .s { color: var(--done-text); }
.box.blocked { opacity: .55; border-style: dotted; }
.box.ready { border-color: var(--muted); }
.box.wip { border-color: var(--wip); border-style: dashed; }
.box.pass { border-color: var(--pass); }
.box.fail { border-color: var(--fail); border-width: 2px; }
.box.dropped { opacity: .4; text-decoration: line-through; }
.box.claude { border-color: var(--claude); border-width: 2px; --glow: var(--claude); }
.box.codex { border-color: var(--codex); border-width: 2px; --glow: var(--codex); }
.box.ci { border-color: var(--ci); border-width: 2px; --glow: var(--ci); }
.box.human { border-color: var(--human); border-width: 2px; --glow: var(--human); }
.box.sel { outline: 2px solid var(--text); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
  .box.claude, .box.codex { animation: glow 1.6s ease-in-out infinite; }
  .box.ci { animation: glow 2.6s ease-in-out infinite; }
  .box.human { animation: glow .9s ease-in-out infinite; }
  .edge.live { animation: flow .8s linear infinite; }
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--glow) 0%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--glow) 35%, transparent), 0 0 14px 2px color-mix(in srgb, var(--glow) 45%, transparent); }
}
@keyframes flow { to { stroke-dashoffset: -16; } }
@keyframes blink { 50% { opacity: .55; } }

.edge { fill: none; stroke: var(--edge); stroke-width: 1.4; }
.edge.done { stroke: var(--done-line); }
.edge.live { stroke-dasharray: 6 4; stroke-width: 2; }
.edge.faint { stroke: var(--edge-faint); stroke-dasharray: 2 4; }
.edge.hl { stroke: var(--text); stroke-width: 2.4; }

/* 완성도 */
.side { width: 270px; border-left: 1px solid var(--line); background: var(--panel); overflow: auto; }
.side-toggle { display: none; }
.progress { padding: 14px; }
.p-total { font-size: 34px; font-weight: 700; line-height: 1.1; }
.p-sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.bar { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--pass); }
.p-mod { margin: 12px 0; }
.p-mod .h { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.p-legend { font-size: 12px; color: var(--muted); margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.p-legend div { display: flex; justify-content: space-between; }

/* 세부내역 */
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(520px, 100vw); background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.12); display: flex; flex-direction: column; z-index: 20; }
.drawer-head { display: flex; align-items: flex-start; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.d-title { flex: 1; font-weight: 600; font-size: 15px; }
.d-body { flex: 1; overflow: auto; padding: 12px 14px 40px; }
.d-sec { margin: 14px 0; }
.d-sec > h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 6px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { background: var(--chip); border-radius: 6px; padding: 1px 7px; font-size: 12px; }
.chip.st { color: #fff; }
.chip.st.claude { background: var(--claude); } .chip.st.codex { background: var(--codex); } .chip.st.ci { background: var(--ci); }
.chip.st.human { background: var(--human); } .chip.st.fail { background: var(--fail); } .chip.st.pass { background: var(--pass); }
.chip.st.done { background: var(--done-line); } .chip.st.wip { background: var(--wip); }
.chip.st.blocked, .chip.st.ready, .chip.st.open, .chip.st.dropped { background: var(--muted); }
.acts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.acts input[type=text] { flex: 1; min-width: 120px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.cmt { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.cmt .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.cmt.codex { border-left: 3px solid var(--codex); }
.cmt.me { border-left: 3px solid var(--claude); }
details > summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.doc { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin: 6px 0; }
details.doc > summary { color: var(--text); }
.events { font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all;
  background: var(--chip); border-radius: 8px; padding: 8px; max-height: 260px; overflow: auto; }
.q { border: 1.5px solid var(--human); border-radius: 10px; padding: 10px; margin: 8px 0; }
.q .opts { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.q .opts button { text-align: left; white-space: normal; }
.md { font-size: 13.5px; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { font-size: 14px; margin: 12px 0 4px; }
.md h1 { font-size: 16px; } .md h2 { font-size: 15px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 4px 0; padding-left: 20px; }
.md pre { background: var(--chip); padding: 8px; border-radius: 6px; overflow: auto; font-size: 12px; }
.md code { background: var(--chip); padding: 0 4px; border-radius: 4px; font-size: 12px; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; font-size: 12px; display: block; overflow: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 6px; }
.md blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 14px; border-radius: 10px; max-width: min(560px, 92vw); white-space: pre-wrap; z-index: 30; font-size: 13px; }

/* 휴대폰 */
@media (max-width: 760px) {
  .top { padding: 8px 10px; gap: 6px; }
  .top-actions { margin-left: 0; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .main { flex-direction: column-reverse; }
  .side { width: 100%; border-left: 0; border-bottom: 1px solid var(--line); max-height: 45vh; flex-shrink: 0; }
  .side-toggle { display: block; width: 100%; border: 0; border-radius: 0; text-align: left; }
  .side.collapsed .progress { display: none; }
  .drawer { top: auto; left: 0; width: 100%; height: 82vh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; box-shadow: 0 -8px 24px rgba(0,0,0,.18); }
  .legend { display: none; }
}
