/* Tortle 작업실: 사이트와 같은 예능 자막 톤(흰 종이 + 검정 잉크, 색은 블록에만). 휴대폰 우선, 넓으면 두 칸 */
:root {
  --paper: #fff;
  --ink: #111;
  --ink-2: #5a5a5a;
  --soft: #f3f3f0;
  --yellow: #ffd400;
  --red: #e4002b;
  --blue: #1b48d6;
  --green: #11a35a;
  --tint: #fff6c4;
  --display: "Black Han Sans", "Pretendard", sans-serif;
  --sans: "Pretendard", "Apple SD Gothic Neo", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { height: 100dvh; overflow-x: hidden; } /* 휴대폰 주소창이 줄었다 늘어도 입력창이 화면 안에 */
body { background: var(--tint); color: var(--ink); font-family: var(--sans); font-size: 15px; display: flex; flex-direction: column; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.cap { display: inline-block; font-family: var(--display); font-weight: 400; line-height: 1.1; padding: 0.15em 0.4em; background: var(--ink); color: var(--paper); }
.cap-red { background: var(--red); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-family: var(--display); font-size: 16px; padding: 8px 14px; border: 3px solid var(--ink); background: var(--paper); cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn:active { transform: translate(2px, 2px); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn-primary { background: var(--yellow); box-shadow: 3px 3px 0 var(--ink); }
.btn-primary:hover { background: #ffdf3d; }
.btn-danger { background: var(--red); color: var(--paper); box-shadow: 3px 3px 0 var(--ink); }
.btn-ghost { border-color: transparent; text-decoration: underline; }
.btn-small { font-size: 13px; padding: 4px 8px; border-width: 2px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; padding: 6px 8px; cursor: pointer; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--yellow); border-bottom: 3px solid var(--ink); position: sticky; top: 0; z-index: 10; }
.brand { margin: 0; font-family: var(--display); font-weight: 400; font-size: 18px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.brand .cap { font-size: 16px; }
.status { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 12px; font-weight: 700; }
.dot { width: 10px; height: 10px; border: 2px solid var(--ink); border-radius: 50%; display: inline-block; vertical-align: -1px; margin-right: 4px; background: var(--soft); }
.dot.on { background: var(--green); }
.dot.busy { background: var(--blue); }
.dot.off { background: var(--red); }

.layout { flex: 1; display: flex; min-height: 0; }
.list-pane { width: 100%; padding: 12px; overflow-y: auto; }
.chat-pane { display: none; flex: 1; min-width: 0; flex-direction: column; background: var(--paper); }
body.is-chat .list-pane { display: none; }
body.is-chat .chat-pane { display: flex; }
@media (min-width: 900px) {
  .list-pane { width: 360px; flex: none; border-right: 3px solid var(--ink); }
  .chat-pane { display: flex; }
  body.is-chat .list-pane { display: block; }
  #back { display: none !important; }
}

.list-actions { display: flex; gap: 8px; }
.list-actions .btn-primary { flex: 1; }
.filter { display: flex; gap: 6px; margin: 12px 0 8px; }
.chip { border: 2px solid var(--ink); background: var(--paper); padding: 3px 10px; font-size: 13px; font-weight: 700; cursor: pointer; }
.chip.is-on { background: var(--ink); color: var(--paper); }
.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.conv { display: block; width: 100%; text-align: left; border: 3px solid var(--ink); background: var(--paper); padding: 10px 12px; cursor: pointer; }
.conv.is-active { box-shadow: 4px 4px 0 var(--ink); }
.conv-top { display: flex; align-items: center; gap: 6px; }
.conv-title { font-weight: 800; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { margin-top: 4px; font-size: 12px; color: var(--ink-2); display: flex; gap: 8px; }
.conv-snippet { margin-top: 4px; font-size: 13px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { font-size: 11px; font-weight: 800; padding: 2px 6px; border: 2px solid var(--ink); white-space: nowrap; }
.b-running { background: var(--yellow); }
.b-queued { background: var(--soft); }
.b-reply { background: var(--blue); color: var(--paper); }
.b-failed { background: var(--red); color: var(--paper); }
.b-closed { background: var(--paper); color: var(--ink-2); border-color: var(--ink-2); }
.empty, .chat-placeholder { color: var(--ink-2); padding: 24px 8px; text-align: center; }
.chat-placeholder { margin: auto; }

.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 3px solid var(--ink); }
.chat-title-wrap { flex: 1; min-width: 0; }
.chat-title { margin: 0; font-size: 16px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { font-size: 12px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; margin-top: 2px; }

.pr-card { margin: 10px 12px 0; border: 3px solid var(--ink); padding: 10px 12px; background: var(--tint); display: flex; flex-direction: column; gap: 6px; }
.pr-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pr-title { font-weight: 800; flex: 1; min-width: 0; }
.pr-stats { font-size: 12px; color: var(--ink-2); }
.pr-checks { font-size: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.pr-checks a { color: inherit; }

.messages { list-style: none; margin: 0; padding: 12px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; border: 3px solid var(--ink); padding: 10px 12px; background: var(--paper); word-break: break-word; }
.msg.me { align-self: flex-end; background: #fff3a8; }
.msg.claude { align-self: flex-start; box-shadow: 3px 3px 0 var(--ink); }
.msg.running { border-style: dashed; box-shadow: none; }
.msg.failed { border-color: var(--red); }
.msg-who { font-family: var(--display); font-size: 13px; margin-bottom: 4px; display: flex; gap: 8px; align-items: baseline; }
.msg-time { font-family: var(--sans); font-size: 11px; color: var(--ink-2); }
.msg-body { line-height: 1.55; }
.msg-body p { margin: 0 0 8px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 4px 0 8px; padding-left: 20px; }
.msg-body pre { background: var(--soft); border: 2px solid var(--ink); padding: 8px; overflow-x: auto; font-size: 12px; }
.msg-body code { background: var(--soft); padding: 0 3px; font-size: 0.92em; }
.msg-body pre code { background: none; padding: 0; }
.msg-body table { border-collapse: collapse; font-size: 13px; margin: 6px 0; display: block; overflow-x: auto; }
.msg-body th, .msg-body td { border: 1px solid var(--ink); padding: 3px 6px; }
.msg-body a { color: var(--blue); }
.msg-body hr { border: 0; border-top: 2px solid var(--ink); margin: 8px 0; }
.msg-body sub { color: var(--ink-2); }
.typing::after { content: " ●●●"; animation: blink 1.2s infinite; letter-spacing: 2px; }
@keyframes blink { 50% { opacity: 0.3; } }

.composer { display: flex; gap: 8px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 3px solid var(--ink); background: var(--paper); }
.composer textarea, .new-conv textarea, .field input { flex: 1; border: 3px solid var(--ink); border-radius: 4px; padding: 8px 10px; resize: none; max-height: 40vh; background: var(--paper); }
.composer textarea:focus, .new-conv textarea:focus, .field input:focus { outline: none; box-shadow: 3px 3px 0 var(--yellow); }

.new-conv { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.new-conv h2 { align-self: flex-start; margin: 0; font-size: 18px; }
.row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

dialog { border: 3px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); padding: 0; max-width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(17, 17, 17, 0.55); }
.dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body h2 { margin: 0; align-self: flex-start; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; }
.hint { margin: 0; font-size: 12px; color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 14px; font-weight: 700; font-size: 13px; z-index: 50; max-width: calc(100vw - 32px); }

/* 저장소 버튼 */
.repo-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.repo-btn { border: 3px solid var(--ink); background: var(--paper); padding: 4px 12px; font-family: var(--display); font-size: 15px; cursor: pointer; }
.repo-btn.is-on { background: var(--yellow); box-shadow: 3px 3px 0 var(--ink); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack .btn { width: 100%; }

/* 누르자마자 반응: 버튼 "…중" + 회전 표시 */
.btn.is-busy { opacity: 1; cursor: progress; }
.btn.is-busy::before { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 진행 단계 표시(보냄 → 맥이 받음 → 작업 중 → 검사·마무리) + 경과 시간 */
.track { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 2px 0 8px; }
.track-steps { display: flex; gap: 0; margin: 0; padding: 0; list-style: none; flex-wrap: wrap; }
.track-steps li { font-size: 12px; font-weight: 700; padding: 2px 8px; border: 2px solid var(--ink-2); color: var(--ink-2); margin-right: -2px; background: var(--paper); }
.track-steps li.done { border-color: var(--ink); color: var(--ink); background: var(--soft); }
.track-steps li.done::before { content: "✓ "; }
.track-steps li.now { border-color: var(--ink); color: var(--ink); background: var(--yellow); position: relative; z-index: 1; }
.track-steps li.now::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; background: var(--ink); vertical-align: middle; animation: blink 1s infinite; }
.track-time { font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.track-hint { margin: 0; font-size: 13px; color: var(--ink-2); }

/* 내 메시지 전달 상태 */
.delivery { font-family: var(--sans); font-size: 11px; color: var(--ink-2); }
.delivery.is-sent { color: var(--green, #11a35a); }

/* 불러오는 중 */
.msg.loading, .loading-row { color: var(--ink-2); border-style: dashed; animation: blink 1.4s infinite; }
.loading-row { list-style: none; padding: 12px; text-align: center; border: 0; }

/* 끝난 대화 지우기 */
.conv-list li.has-del { position: relative; }
.conv-list li.has-del .conv { padding-bottom: 34px; }
.conv-del { position: absolute; right: 8px; bottom: 8px; border: 2px solid var(--ink); background: var(--paper); font-size: 12px; font-weight: 700; padding: 2px 8px; cursor: pointer; }
.conv-del:hover { background: var(--red); color: var(--paper); }
.toast-action { margin-left: 12px; border: 2px solid currentColor; background: transparent; color: inherit; font-weight: 800; padding: 2px 8px; cursor: pointer; }

/* PR 카드 접기: 제목 줄의 "PR #4 초안 ▾" 버튼 */
.chat-sub { flex-wrap: wrap; }
.pr-toggle { border: 2px solid var(--ink); background: var(--paper); font-size: 11px; font-weight: 800; padding: 1px 6px; cursor: pointer; white-space: nowrap; }
.pr-toggle::after { content: " ▾"; }
.pr-toggle.is-open { background: var(--ink); color: var(--paper); }
.pr-toggle.is-open::after { content: " ▴"; }
.pr-toggle.is-merged:not(.is-open) { background: var(--blue); color: var(--paper); }
.pr-toggle.is-new { animation: blink 0.6s 4; background: var(--yellow); }

/* ---------- 대화 화면 머리말 ---------- */
.chat-head { position: relative; min-width: 0; }
.chat-back, .chat-more { display: none; }
.chat-menu { position: absolute; right: 8px; top: calc(100% - 4px); z-index: 20; background: var(--paper); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); display: flex; flex-direction: column; min-width: 170px; }
.chat-menu a, .chat-menu button { display: block; text-align: left; padding: 12px 14px; border: 0; border-bottom: 2px solid var(--soft); background: none; font-weight: 700; font-size: 15px; color: var(--ink); text-decoration: none; cursor: pointer; }
.chat-menu > :last-child { border-bottom: 0; }
.chat-menu #menu-close { color: var(--red); }

/* 휴대폰 대화 화면: 위 노란 띠와 대화 머리말을 한 줄로 합쳐 대화창을 넓게 쓴다 */
@media (max-width: 899px) {
  body.in-thread .topbar { display: none; }
  body.in-thread .chat-head {
    background: var(--yellow);
    padding: 4px 4px 6px 0;
    padding-top: max(4px, env(safe-area-inset-top));
    gap: 2px;
  }
  body.in-thread .chat-back, body.in-thread .chat-more { display: block; font-size: 22px; padding: 8px 10px; }
  body.in-thread #chat-gh, body.in-thread #chat-close { display: none; }
  body.in-thread .chat-title { font-size: 15px; }
  body.in-thread .chat-sub { flex-wrap: nowrap; overflow: hidden; gap: 6px; margin-top: 1px; color: var(--ink); }
  body.in-thread .chat-sub > span:not(.badge) { white-space: nowrap; }
  body.in-thread .pr-card { margin: 8px 8px 0; }
  body.in-thread .messages { padding: 10px 8px; gap: 10px; }
  body.in-thread .msg { max-width: 94%; padding: 8px 10px; }
  body.in-thread .composer { padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); gap: 6px; }
  body.in-thread .composer .btn { padding: 6px 12px; }
}
