:root {
  --bg: #fafaf8; --fg: #1d1d1b; --muted: #6b6b66; --line: #e2e1dc;
  --panel: #ffffff; --accent: #2457a8; --ok: #2d7a4f; --warn: #a65b00; --bad: #b2362c;
  --chip: #eeede8; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171716; --fg: #ebeae6; --muted: #9a9993; --line: #2f2f2c;
    --panel: #1f1f1d; --accent: #7fa7ea; --ok: #6fc08f; --warn: #e0a24a; --bad: #e6766b;
    --chip: #2a2a27;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  display: flex; flex-direction: column;
}
a { color: var(--accent); }
header {
  display: flex; align-items: center; gap: 20px; padding: 10px 20px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
header h1 { font-size: 16px; margin: 0; font-weight: 600; }
/* Which version this copy runs (core.version), filled in by the server. */
header h1 .version { margin-left: 6px; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }
header h1 .version:empty { display: none; }
nav button {
  background: none; border: none; color: var(--muted); font: inherit; padding: 6px 10px;
  cursor: pointer; border-radius: 6px;
}
nav button.active { color: var(--fg); background: var(--chip); }
nav .count { display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px;
  border-radius: 9px; background: var(--warn); color: var(--bg); font-size: 11px;
  font-weight: 600; line-height: 18px; text-align: center; }
.status { margin-left: auto; color: var(--muted); font-size: 13px; }
.status.err { color: var(--bad); }
.usage { font: inherit; font-size: 13px; padding: 3px 10px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); color: var(--fg); cursor: pointer; white-space: nowrap; }
.usage:hover { border-color: var(--accent); }
.usage.warn { border-color: var(--warn); color: var(--warn); }
.usage.bad { border-color: var(--bad); color: var(--bad); }
.usage.checking { opacity: .6; }
.usage.news { border-color: var(--accent); color: var(--accent); }

main { flex: 1; min-height: 0; }
.tab { display: none; height: 100%; }
.tab.active { display: flex; }
.side {
  width: 280px; flex: none; overflow: auto; border-right: 1px solid var(--line);
  padding: 12px; background: var(--panel);
}
.content { flex: 1; overflow: auto; padding: 20px 28px; max-width: 980px; }
.muted { color: var(--muted); }

.side .item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--fg); font: inherit; padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.side .item:hover { background: var(--chip); }
.side .item.active { background: var(--chip); font-weight: 600; }
.side .item small { display: block; color: var(--muted); font-weight: normal; font-size: 12px; }
.side h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 14px 10px 6px; }

.entry {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin: 14px 0;
  background: var(--panel);
}
.entry.applied { border-color: var(--ok); }
.entry.skipped { opacity: .72; }
.entry h3 { margin: 0 0 6px; font-size: 16px; }
.entry .meta { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.score { display: inline-block; min-width: 38px; text-align: center; padding: 1px 7px;
  border-radius: 6px; background: var(--chip); font-weight: 600; margin-right: 8px; }
.marks { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 8px 0 10px; }
.marks label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.marks input[type=text] {
  flex: 1; min-width: 220px; font: inherit; padding: 4px 8px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); color: var(--fg);
}
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px;
  background: var(--chip); margin-right: 6px; }
.chip.ok { color: var(--ok); } .chip.warn { color: var(--warn); } .chip.bad { color: var(--bad); }
.body p { margin: 6px 0; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; }
button.action {
  font: inherit; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--fg); cursor: pointer;
}
button.action:hover { border-color: var(--accent); }
button.action:disabled { opacity: .5; cursor: default; }
button.action.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

pre.out, pre.text {
  font: 13px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px;
}
pre.out { max-height: 60vh; overflow: auto; }
.run { margin: 0 0 18px; }
.run .head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.run .head .st { font-size: 13px; }
.st.running { color: var(--warn); } .st.done { color: var(--ok); } .st.failed { color: var(--bad); }

.small { font-size: 13px; }
.banner { margin: 0 0 10px; padding: 8px 10px; border-radius: 6px; background: var(--chip); font-size: 13px; }
.side .item:disabled { opacity: .45; cursor: default; }
.skill-form { padding: 6px 10px 10px; }
.pick { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 2px 10px 8px; font-size: 13px;
  color: var(--muted); }
.pick select { font: inherit; padding: 1px 4px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg); }
.side .item small.route { color: var(--accent); }
.skill-form textarea, .skill-form select, textarea.reply {
  width: 100%; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg); resize: vertical;
}
.run.claude .head { position: sticky; top: -20px; background: var(--bg); padding: 6px 0; z-index: 1; }
button.action.small { padding: 2px 8px; font-size: 13px; margin-left: auto; }
.chat { display: flex; flex-direction: column; gap: 8px; }
.bubble { padding: 10px 14px; border-radius: 10px; max-width: 100%; }
.bubble.user { background: var(--chip); align-self: flex-end; white-space: pre-wrap; max-width: 85%; }
.bubble.assistant { background: var(--panel); border: 1px solid var(--line); }
.bubble.error { border: 1px solid var(--bad); color: var(--bad); background: var(--panel); }
.note { color: var(--muted); font-size: 12px; padding: 0 4px; }
details.tool { font-size: 13px; color: var(--muted); padding: 2px 4px; }
details.tool summary { cursor: pointer; } details.tool code { color: var(--fg); }
details.tool pre { margin: 6px 0 0; max-height: 240px; overflow: auto; }
details.tool.failed summary { color: var(--bad); }
.replybox { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.replybox textarea { flex: 1; }
.card { margin: 12px 0; padding: 14px 16px; border: 2px solid var(--accent); border-radius: 10px; background: var(--panel); }
.card.guard { border-color: var(--warn); }
.card h4 { margin: 0 0 8px; font-size: 15px; }
.card .toolbar { margin: 10px 0 0; }
.card input[type=text] { flex: 1; min-width: 200px; font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.diff .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
pre.old { border-color: var(--bad); } pre.new { border-color: var(--ok); }
.question { margin: 8px 0 12px; }
.qtext { margin-bottom: 6px; }
.options label { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; cursor: pointer; }
.options small { color: var(--muted); }
@media (max-width: 700px) { .diff { grid-template-columns: 1fr; } }

iframe.pdf { width: 100%; height: 80vh; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; }
.tracker { margin: 6px 0 18px; border-top: 1px solid var(--line); }
.app-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px;
  align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.app-row .role { font-weight: 600; }
.app-row .role.muted { font-weight: normal; }
.app-row .chips { margin-left: 8px; }
.app-row .set { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.app-row select, .app-row input { font: inherit; font-size: 14px; padding: 3px 6px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
.app-row input[type=date] { color-scheme: light dark; }
.app-row input.note { grid-column: 1 / -1; width: 100%; }
.app-row .history { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.app-row .set button.action.small { margin-left: 0; }
.app-row.answered select { border-color: var(--ok); }
.app-row.ended .who { opacity: .75; }
.banner.bad { color: var(--bad); }
@media (max-width: 700px) { .app-row { grid-template-columns: 1fr; } .app-row .set { justify-content: flex-start; } }
.files { list-style: none; padding: 0; margin: 0 0 16px; }
.files li { padding: 4px 0; display: flex; gap: 10px; align-items: baseline; }
.files li small { color: var(--muted); }

.md h1, .md h2, .md h3 { margin: 18px 0 8px; } .md h1 { font-size: 22px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; vertical-align: top; }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md code { font-family: var(--mono); font-size: 13px; background: var(--chip); padding: 0 4px; border-radius: 4px; }
.md pre code { display: block; padding: 10px; overflow: auto; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.md ul { padding-left: 22px; }

.demo-banner {
  padding: 8px 20px; font-size: 13px; background: var(--chip); border-bottom: 1px solid var(--line);
}
.demo-banner a { color: var(--accent); }

#setup-view h2 { margin: 0; font-size: 20px; }
.step { display: flex; gap: 14px; margin: 22px 0; }
.step .num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--chip);
  display: flex; align-items: center; justify-content: center; font-weight: 600; }
.step-body { flex: 1; min-width: 0; }
.step-body h3 { margin: 3px 0 2px; font-size: 16px; }
.step-body > p.muted { margin: 0 0 8px; }
ul.checks { list-style: none; padding: 0; margin: 6px 0 10px; }
ul.checks li { padding: 3px 0; }
.fix { font-size: 13px; color: var(--muted); margin: 2px 0 2px 4px; }
.cmd { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.cmd code { flex: 1; min-width: 0; font: 13px/1.45 var(--mono); padding: 6px 10px; overflow-x: auto;
  white-space: pre; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.cmd button.action.small { margin-left: 0; }
.key { padding: 8px 0 10px; border-bottom: 1px solid var(--line); }
.key-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.key-form input { flex: 1; min-width: 180px; font: inherit; padding: 4px 8px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); color: var(--fg); }
.ready { margin: 10px 0 0; padding: 12px 14px; border: 1px solid var(--ok); border-radius: 8px;
  background: var(--panel); }
.ready .toolbar { margin: 8px 0 0; }

.copy { margin: 14px 0 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); }
.copy-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.copy-head > div { flex-basis: 100%; }
.copy-row { margin: 10px 0 0; }
.copy-row .key-form { margin-top: 8px; }
.copy-row .fix { margin: 6px 0 0; }
ul.copy-files { margin: 4px 0 0; padding-left: 20px; font: 13px/1.5 var(--mono); }
details.notes { margin: 8px 0 0; font-size: 14px; }
details.notes summary { cursor: pointer; color: var(--accent); }
.note-entry { margin: 8px 0 0 2px; padding-left: 10px; border-left: 2px solid var(--line); }
.note-entry .md p { margin: 4px 0; }
.copy-result { margin: 10px 0 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 14px; }
.copy-result:empty { display: none; }
.copy-result.ok { border-color: var(--ok); }
.copy-result.warn { border-color: var(--warn); }
.copy-result.bad { border-color: var(--bad); color: var(--bad); }
.copy-result button.action.small { margin: 6px 0 0; display: block; }
.banner.warn { border: 1px solid var(--warn); margin: 8px 0 0; }

/* The fold bar above each sidebar (index.html): only phones show it. */
.side-toggle { display: none; }

/* Phones and narrow windows. The page scrolls as a whole, the tabs become a
   bar along the bottom where a thumb reaches them, and each tab's sidebar
   folds into one bar that names what is open: a tap unfolds the list, picking
   from it folds it again (app.js, setSide). The status line becomes a toast
   above the tab bar, so saving never shifts the page. Wider than this, nothing
   changes. */
@media (max-width: 700px) {
  :root { --bar: 54px; }
  html, body { height: auto; }
  body { font-size: 16px; }
  /* Room under the page for the tab bar, and for the phone's own home bar. */
  main { padding-bottom: calc(var(--bar) + env(safe-area-inset-bottom, 0px)); }
  header { gap: 8px; padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  header h1 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; height: calc(var(--bar) + env(safe-area-inset-bottom, 0px));
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: var(--panel); border-top: 1px solid var(--line);
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  nav::-webkit-scrollbar { display: none; }
  nav button {
    flex: 1 0 auto; min-width: 64px; padding: 0 6px; border-radius: 0; font-size: 12px;
    line-height: 1.2; display: flex; align-items: center; justify-content: center;
    border-top: 2px solid transparent; margin-top: -1px; -webkit-tap-highlight-color: transparent;
  }
  nav button.active { background: none; color: var(--accent); font-weight: 600; border-top-color: var(--accent); }
  nav .count { margin-left: 4px; }
  /* While a field has the keyboard up, the bar hides, so the keyboard does
     not push it over what is being typed (app.js, body.typing). */
  body.typing nav { display: none; }
  .status {
    position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top, 0px));
    transform: translateX(-50%); z-index: 21; max-width: calc(100% - 32px);
    margin: 0; padding: 8px 14px; border-radius: 18px; font-size: 14px; cursor: pointer;
    background: var(--fg); color: var(--bg); box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
  }
  .status.err { background: var(--bad); color: #fff; }
  .status:empty { display: none; }
  .usage { font-size: 12px; padding: 4px 10px; }

  .tab { height: auto; }
  .tab.active { flex-direction: column; }
  .side-toggle {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px;
    padding: 8px 16px; border: none; border-bottom: 1px solid var(--line);
    background: var(--panel); color: var(--fg); font: inherit; font-weight: 600;
    text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .side-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-label small { font-weight: normal; color: var(--muted); font-size: 13px; }
  .side-arrow { flex: none; width: 9px; height: 9px; margin-right: 3px;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
    transform: translateY(-3px) rotate(45deg); transition: transform .15s; }
  .side-toggle[aria-expanded="true"] .side-arrow { transform: translateY(2px) rotate(225deg); }
  .side { display: none; width: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 8px 10px 12px; }
  .tab.side-open .side { display: block; }
  .side .item { padding: 10px 12px; }
  .content { overflow: visible; max-width: none; padding: 16px; }
  .demo-banner, .server-banner { padding: 8px 16px; }

  /* A digest entry's marks: the three boxes on one line, the reason under them. */
  .marks { gap: 6px 16px; }
  .marks input[type=text] { order: 10; min-width: 0; flex-basis: 100%; }
  .md table { display: block; overflow-x: auto; max-width: 100%; }
  .md a, .bubble, .files a, .run .filed { overflow-wrap: anywhere; }
  .files li { flex-wrap: wrap; }

  /* A run: its head wraps, and stays at the top while it scrolls past. */
  .run .head { flex-wrap: wrap; gap: 4px 10px; }
  .run .head .muted { white-space: nowrap; }
  .run.claude .head { top: 0; margin: 0 -16px; padding: 8px 16px; }
  .run.claude .head b { flex-basis: 100%; }
  pre.out { max-height: 60svh; }
  /* The reply box stays in reach at the bottom while its run waits for a reply. */
  .replybox { position: sticky; bottom: calc(var(--bar) + env(safe-area-inset-bottom, 0px));
    margin: 10px -16px 0; padding: 8px 16px 10px; background: var(--bg); border-top: 1px solid var(--line); }
  .app-row .set > * { flex: 1 1 auto; }
  .app-row .set button.action.small { flex: 0 0 auto; }
  .toolbar > h2 { flex: 1; }
  iframe.pdf { height: 70svh; }
}

/* Touch screens. iOS zooms the page into any field whose text is under 16px
   when it gets focus, and leaves it zoomed; at 16px it leaves the page as it
   is. !important, since several fields set a smaller size of their own. And
   everything tapped is at least 40px tall, which a thumb hits. */
@media (pointer: coarse) {
  input, textarea, select { font-size: 16px !important; }
  button.action, .usage, select, .pick select, .skill-form select,
  input:not([type=checkbox]):not([type=radio]), .marks input[type=text], .app-row select, .app-row input,
  .key-form input, .card input[type=text] { min-height: 40px; }
  button.action.small, .cmd button.action.small { min-height: 36px; padding: 4px 12px; }
  .pick select { padding: 4px 6px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }
  .marks label, .options label { min-height: 40px; }
  .options label { align-items: center; }
  .side .item { min-height: 44px; }
  details.tool summary { padding: 6px 0; }
  .files li { padding: 8px 0; }
  a { -webkit-tap-highlight-color: rgba(36, 87, 168, .15); }
}

/* The server has stopped, or is restarting (app.js, heartbeat). */
.server-banner {
  padding: 8px 20px; font-size: 13px; background: var(--chip); border-bottom: 1px solid var(--warn);
}
.server-banner.bad { color: var(--bad); border-bottom-color: var(--bad); }

/* What a skill run filed under Applications/ (app.js, showFiled). */
.run .filed:empty { display: none; }
.run .filed { margin-top: 10px; }
.run .filed a { overflow-wrap: anywhere; }

/* Changes made on the phone that the Mac has not taken yet (app.js, outbox). */
.outbox { padding: 8px 20px; font-size: 13px; background: var(--chip); border-bottom: 1px solid var(--warn); }
.outbox-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-bottom: 6px; }
.outbox-item { padding: 4px 0; }
.outbox-item.conflict { color: var(--bad); }
.outbox-item .toolbar { margin: 4px 0 0; }
.entry.waiting { border-style: dashed; }

/* This phone, in Setup (app.js, thisPhoneView). */
.choice { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; font-size: 14px; cursor: pointer; }
.choice input { margin-top: 3px; }
