:root {
  --bg: #e9ebef;
  --ink: #16181d;
  --ink-2: #5b616e;
  --panel: rgba(255, 255, 255, 0.92);
  --line: rgba(22, 24, 29, 0.12);
  --accent: #2f6bff;
  --accent-ink: #fff;
  --ok: #1f9d55;
  --warn: #c77700;
  --bad: #d93838;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d22;
    --ink: #eceef2;
    --ink-2: #9aa1ad;
    --panel: rgba(30, 32, 38, 0.92);
    --line: rgba(255, 255, 255, 0.12);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; }

.bar.top {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-top) + 8px) 8px 8px;
  display: flex; justify-content: center;
  pointer-events: none;
}
.bar.top > * { pointer-events: auto; }
.version { color: var(--ink-2); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; margin: 0 6px 0 8px; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

.tools {
  display: flex; align-items: center; gap: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
}
.tools::-webkit-scrollbar { display: none; }
.tool {
  border: 0; background: transparent; padding: 7px 10px; border-radius: 999px;
  font-size: 13.5px; font-weight: 560; white-space: nowrap; min-height: 38px;
}
.tool[aria-pressed="true"], .tool[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); }

.popover {
  position: fixed; right: 10px; top: calc(var(--safe-top) + 58px); z-index: 5;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; min-width: 220px; display: grid; gap: 6px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
.popover label { display: flex; gap: 10px; align-items: center; min-height: 34px; }
.popover input { width: 18px; height: 18px; accent-color: var(--accent); }
.popover hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
.popover .link { text-align: left; padding: 6px 0; }

.hint { color: var(--ink-2); font-size: 12.5px; margin: 4px 0 0; }
.link { border: 0; background: none; color: var(--accent); padding: 4px 2px; font-size: 13.5px; font-weight: 550; }
.link.danger { color: var(--bad); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 6px 5px 12px; font-size: 13px;
}
.chip button { border: 0; background: var(--line); border-radius: 50%; width: 24px; height: 24px; line-height: 1; }
.selection span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.readout {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--safe-top) + 60px);
  padding: 7px 14px; font-weight: 600; font-variant-numeric: tabular-nums; z-index: 3;
}
.banner {
  position: fixed; left: 10px; right: 10px; top: calc(var(--safe-top) + 60px); z-index: 4;
  background: #fff4d6; color: #533b00; border: 1px solid #f0d58a; border-radius: var(--radius);
  padding: 10px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13.5px;
}
.banner .link { color: #7a4f00; text-decoration: underline; }
.loading {
  position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px;
  color: var(--ink-2);
}

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 0 10px calc(var(--safe-bottom) + 10px);
  display: grid; gap: 8px; pointer-events: none;
  max-width: 720px; margin: 0 auto;
}
.sheet > * { pointer-events: auto; }

.activity, .composer {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}
.activity { padding: 10px 12px; max-height: 42vh; overflow-y: auto; }
.activity-head { display: flex; align-items: center; gap: 8px; }
.status {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 999px; background: var(--line); white-space: nowrap;
}
.status.running, .status.queued { background: #dce6ff; color: #1d47b8; }
.status.done { background: #d8f3e3; color: #156c3b; }
.status.failed, .status.cancelled { background: #fde0e0; color: #a12424; }
.job-prompt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); font-size: 13px; }
.job-step { color: var(--ink-2); font-size: 13px; margin-top: 6px; overflow-wrap: anywhere; }
.job-step:empty { display: none; }
.job-summary { margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.job-summary:empty { display: none; }
.job-summary.error { color: var(--bad); }
.job-log { margin: 8px 0 0; padding: 0 0 0 18px; font-size: 12.5px; color: var(--ink-2); display: grid; gap: 3px; }
.job-log li.text { color: var(--ink); }
.job-log code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }

.composer { padding: 8px; display: grid; gap: 6px; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer .meta { align-items: center; justify-content: space-between; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; background: transparent;
  padding: 9px 12px; max-height: 30vh; min-height: 42px; font-size: 16px; /* 16px: no iOS zoom */
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.send {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  font-size: 20px; font-weight: 700; flex: none;
}
.send:disabled { opacity: 0.45; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.segmented button {
  border: 0; background: none; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 550; min-height: 32px;
}
.segmented button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.segmented button.unavailable { color: var(--ink-2); }
.segmented button.unavailable::after { content: " · off"; font-weight: 400; }

.panel {
  position: fixed; inset: auto 0 0 0; z-index: 6; max-height: 78vh; overflow-y: auto;
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(var(--safe-bottom) + 16px);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
  max-width: 720px; margin: 0 auto;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel h2 { margin: 0; font-size: 18px; }
.history-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; }
.history-list li { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.history-list .subject { font-weight: 550; overflow-wrap: anywhere; }
.history-list .when { color: var(--ink-2); font-size: 12.5px; }
.history-list .actions { display: flex; gap: 14px; }
.history-list .current { color: var(--ok); font-size: 12.5px; font-weight: 650; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 150px); transform: translateX(-50%); z-index: 9;
  background: var(--ink); color: var(--bg); border-radius: 999px; padding: 9px 16px; font-size: 13.5px;
  max-width: calc(100vw - 40px);
}

.picked {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 3;
  bottom: calc(var(--safe-bottom) + 18px); padding: 8px 16px; font-weight: 550;
  max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viewer .toast { bottom: calc(var(--safe-bottom) + 70px); }

.room-label {
  font-size: 11.5px; font-weight: 600; color: #20232a; background: rgba(255, 255, 255, 0.85);
  padding: 2px 7px; border-radius: 999px; white-space: nowrap; pointer-events: none;
}

@media (min-width: 900px) {
  .sheet { left: auto; right: 16px; width: 420px; margin: 0; }
  .panel { left: auto; right: 16px; width: 420px; top: 70px; bottom: 16px; max-height: none; border-radius: 18px; }
}
