:root {
  --bg: #f7f7f5;
  --fg: #1d1d1b;
  --muted: #8a8a85;
  --card: #ffffff;
  --line: #e4e4e0;
  --accent: #1d1d1b;
  --accent-fg: #ffffff;
  --ok: #2fa84f;
  --warn: #d9822b;
  --term-bg: #1e1e1e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --fg: #ececec;
    --muted: #8d8d8d;
    --card: #222222;
    --line: #333333;
    --accent: #ececec;
    --accent-fg: #161616;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button {
  font: inherit;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px;
  cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.icon { border: none; background: none; font-size: 26px; line-height: 1; padding: 0 8px; }
.muted { color: var(--muted); }
code { font-family: Menlo, monospace; font-size: 0.9em; }

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 18px; margin: 0; flex: 1; }
.title { display: flex; flex-direction: column; min-width: 0; }
.title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title span { font-size: 12px; }

/* List */
#list-view { max-width: 720px; margin: 0 auto; }
.pad { padding: 24px 16px; }
.pad-x { padding: 12px 16px 0; }
.tabs { display: flex; gap: 20px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 10px 0; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--fg); border-color: var(--fg); font-weight: 600; }
.filters { display: flex; flex-direction: column; gap: 8px; }
#search, #project {
  width: 100%; font: inherit; color: var(--fg); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
}
.cards { list-style: none; margin: 0; padding: 8px 16px; }
.cards li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px;
  margin: 8px 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
}
.cards li > div { min-width: 0; flex: 1; }
.cards .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; color: var(--muted); flex: none; }
.badge.live { color: var(--ok); border-color: var(--ok); }
.badge.busy { color: var(--warn); border-color: var(--warn); }
#sessions .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
#sessions .dot.exited { background: var(--muted); }
.cards .name { font-weight: 600; }
.cards .meta { font-size: 12px; color: var(--muted); }

/* Session */
#session-view { display: flex; flex-direction: column; height: 100dvh; }
#banner { padding: 8px 16px; background: var(--warn); color: #fff; font-size: 13px; }
#banner button { margin-left: 8px; padding: 2px 10px; }
#terminal { flex: 1; min-height: 0; background: var(--term-bg); padding: 4px; }
#terminal.watching { overflow: auto; } /* controller's screen may be wider than ours */
#session-view { position: relative; }
#toast {
  position: absolute; top: 68px; left: 16px; right: 16px; margin: 0 auto; width: fit-content;
  padding: 9px 16px; border-radius: 12px; border: 1px solid #d0d0cc;
  background: #ffffff; color: #1d1d1b; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); z-index: 10;
}
#composer {
  border-top: 1px solid var(--line);
  padding: 8px 12px max(8px, env(safe-area-inset-bottom));
  background: var(--bg);
}
#keys { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
#keys button { flex: none; font-family: Menlo, monospace; font-size: 13px; padding: 4px 10px; }
.input-row { display: flex; gap: 6px; align-items: flex-end; }
#input {
  flex: 1;
  resize: none;
  max-height: 140px;
  font: inherit;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}

/* Conversation */
#conversation-view { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
#messages { flex: 1; overflow-y: auto; padding: 12px 16px; }
.msg { margin: 10px 0; white-space: pre-wrap; word-break: break-word; }
.msg.user {
  margin-left: 15%; padding: 10px 14px; border-radius: 16px 16px 4px 16px;
  background: var(--accent); color: var(--accent-fg);
}
.msg.assistant { padding: 2px 0; white-space: normal; }
.msg.assistant p { margin: 4px 0; }
.msg.assistant h3, .msg.assistant h4, .msg.assistant h5, .msg.assistant h6 { margin: 14px 0 4px; font-size: 15px; }
.msg.assistant h3 { font-size: 17px; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0; padding-left: 20px; }
.msg.assistant code { background: var(--line); border-radius: 4px; padding: 0 4px; }
.msg.assistant pre { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-x: auto; font: 12px/1.4 Menlo, monospace; margin: 6px 0; }
.msg.assistant pre.table { border: none; background: none; padding: 0; margin: 0; }
.msg.assistant a { color: inherit; }
details.tools { margin: 6px 0; font-size: 13px; color: var(--muted); }
details.tools summary { cursor: pointer; list-style: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
details.tools summary::before { content: "▸ "; }
details.tools[open] summary::before { content: "▾ "; }
details.tools div { font-family: Menlo, monospace; font-size: 12px; padding: 2px 0 2px 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#conv-actions { border-top: 1px solid var(--line); padding: 10px 16px max(10px, env(safe-area-inset-bottom)); }
#conv-warning { margin: 0 0 8px; font-size: 13px; color: var(--warn); }
button.wide { width: 100%; padding: 10px; }

/* Pairing */
.pair-box { max-width: 420px; margin: 18vh auto 0; padding: 0 24px; text-align: center; }
.pair-box h2 { font-size: 22px; margin: 0 0 12px; }
#pair-code { margin: 28px 0; font: 700 48px/1 Menlo, monospace; letter-spacing: 12px; }
#host { font-size: 13px; font-weight: 400; margin-left: 6px; }
