/* v26: DOM contract in docs/contract.md. Keep the canvas drag surface clear. */
#core-ui {
  --core-tracker-width: 320px;
  --core-diameter: min(70vh, 720px);
  --core-cyan: #8ce4fa;
  --core-amber: #e8b981;
  --core-line: rgb(140 228 250 / 20%);
  display: none;
  position: fixed;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  color: #deedf2;
  font: inherit;
}
body.core #core-ui { display: block; }
#core-ui *, #core-ui *::before, #core-ui *::after { box-sizing: border-box; }
#core-ui :is(button, form, aside, summary) { pointer-events: auto; }
#core-ui [hidden] { display: none !important; }
#core-ui button {
  font: inherit;
  color: #deedf2;
  background: #0b1626;
  border: 1px solid var(--core-line);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease;
}
#core-ui button:hover:not(:disabled) {
  border-color: var(--core-cyan);
  background-color: #142736;
}
#core-ui :is(button, input, summary):focus-visible {
  outline: 2px solid var(--core-cyan);
  outline-offset: 3px;
}
#core-ui button:disabled { opacity: .4; cursor: not-allowed; }
#core-ui button[aria-pressed="true"] { color: var(--core-cyan); border-color: currentColor; }

#core-ui .core-ring {
  position: absolute;
  top: 50%;
  left: calc((100% - var(--core-tracker-width) - 32px) / 2);
  width: var(--core-diameter);
  height: var(--core-diameter);
  transform: translate(-50%, -50%);
  border: 1px solid rgb(140 228 250 / 12%);
  border-radius: 50%;
  background: radial-gradient(circle, transparent 56%, rgb(140 228 250 / 3%) 70%, transparent 71%);
}
#core-node {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(clamp(300px, 23vw, 340px), calc(var(--core-diameter) * .866 - 184px));
  /* Reserve space for the north/south cards even with expanded references. */
  max-height: calc(var(--core-diameter) - 170px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 22px 18px 16px;
  border: 1px solid var(--core-line);
  border-radius: 20px;
  background: linear-gradient(155deg, rgb(11 22 38 / 94%), rgb(4 8 15 / 87%));
  box-shadow: 0 16px 48px rgb(4 8 15 / 45%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  text-align: center;
}
#core-ui .core-halo {
  position: absolute;
  inset: -8px;
  border: 1px solid rgb(140 228 250 / 24%);
  border-radius: 27px;
  box-shadow: 0 0 26px rgb(140 228 250 / 7%);
  pointer-events: none;
}
#core-ui .core-glyph { color: var(--core-cyan); font-size: 42px; font-weight: 200; line-height: 1; }
#core-state { color: var(--core-cyan); font-size: 11px; letter-spacing: .14em; }
#core-reply {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 76px;
  overflow: auto;
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#core-reply.error { color: var(--core-amber); }
#core-chat {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 6px;
  min-width: 0;
  border: 1px solid var(--core-line);
  border-radius: 8px;
  background: #04080f;
  box-shadow: none;
}
#core-prompt {
  width: 100%;
  min-width: 0;
  flex: 1;
  padding: 7px 4px;
  border: 0;
  background: transparent;
  color: #deedf2;
  font: inherit;
  font-size: 12px;
}
#core-prompt::placeholder { color: #80959e; }
#core-ui #core-send { flex: 0 0 auto; min-width: 36px; min-height: 34px; color: var(--core-cyan); }
#core-ui .core-keys { display: flex; flex: 0 0 auto; flex-wrap: wrap; justify-content: center; gap: 5px; }
#core-ui .core-keys button { padding: 7px; font-size: 10px; color: #80959e; }

#core-ui .core-module {
  --core-angle: calc(var(--i, 0) * 60deg - 90deg);
  position: absolute;
  top: 50%;
  left: 50%;
  width: 160px;
  height: 122px;
  margin: -61px 0 0 -80px;
  transform: rotate(var(--core-angle)) translateX(calc(var(--core-diameter) / 2)) rotate(calc(-1 * var(--core-angle)));
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-content: center;
  gap: 4px 8px;
  padding: 12px;
  text-align: left;
  border-radius: 10px;
  background: linear-gradient(135deg, rgb(11 22 38 / 94%), rgb(4 8 15 / 82%));
  box-shadow: 0 8px 24px rgb(4 8 15 / 30%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
#core-ui .cm-glyph { grid-row: span 2; align-self: center; color: var(--core-cyan); font-size: 23px; }
#core-ui .cm-title { font-size: 11px; font-weight: 500; letter-spacing: .04em; }
#core-ui .cm-sub { font-size: 10px; color: #80959e; }
#core-ui .cm-status { grid-column: 1 / -1; font-size: 10px; font-style: normal; color: var(--core-cyan); }
#core-ui :is(.cm-title, .cm-sub, .cm-status) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#core-ui .cm-alt { grid-column: 1 / -1; justify-self: end; padding: 3px 7px; font-size: 10px; color: #80959e; }

#core-tracker {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: var(--core-tracker-width);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #80959e #04080f;
  padding: 16px;
  border: 1px solid var(--core-line);
  border-radius: 14px;
  background: linear-gradient(165deg, rgb(11 22 38 / 89%), rgb(4 8 15 / 85%));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 12px 40px rgb(4 8 15 / 35%);
}
#core-ui .ct-head { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; color: var(--core-cyan); font-size: 10px; letter-spacing: .12em; }
#ct-count { color: #80959e; font-variant-numeric: tabular-nums; }
#core-ui #ct-clear { margin-left: auto; padding: 6px; font-size: 10px; letter-spacing: normal; color: #80959e; }
#ct-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
#core-ui .ct-task {
  min-width: 0;
  padding: 12px 10px;
  border: 1px solid var(--core-line);
  border-left: 3px solid #80959e;
  border-radius: 7px;
  background: rgb(11 22 38 / 75%);
  overflow-wrap: anywhere;
}
#core-ui .ct-task[data-state="proposed"] { border-left-style: dashed; }
#core-ui .ct-task[data-state="waiting"] { border-left-color: var(--core-amber); }
#core-ui .ct-task[data-state="queued"] { border-left-color: rgb(140 228 250 / 50%); }
#core-ui .ct-task[data-state="running"] { border-left-color: var(--core-cyan); }
#core-ui .ct-task[data-state="done"] { border-left-color: #8ce4da; }
#core-ui .ct-task:is([data-state="failed"], [data-state="cancelled"]) { border-left-color: var(--core-amber); }
#core-ui .ct-title { display: block; font-size: 12px; font-weight: 500; line-height: 1.6; }
#core-ui .ct-stages { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 12px 0 10px; padding: 0; list-style: none; }
#core-ui .ct-stages li { position: relative; padding: 6px 0; border-top: 2px solid var(--core-line); border-radius: 2px; color: #80959e; text-align: center; font-size: 10px; white-space: nowrap; }
#core-ui .ct-stages li.reached { border-top-color: var(--core-cyan); background: rgb(140 228 250 / 13%); color: #deedf2; }
#core-ui .ct-stages li.current::before { content: ""; position: absolute; top: -4px; left: calc(50% - 3px); width: 6px; height: 6px; border-radius: 50%; background: var(--core-cyan); box-shadow: 0 0 9px var(--core-cyan); }
#core-ui .ct-stages li.failed { color: var(--core-amber); border-top-color: var(--core-amber); background: rgb(232 185 129 / 10%); }
#core-ui .ct-stages li.failed::before { background: var(--core-amber); box-shadow: 0 0 9px var(--core-amber); }
#core-ui .ct-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 10px; line-height: 1.6; }
#core-ui .ct-state { font-style: normal; color: #deedf2; }
#core-ui .ct-activity, #core-ui .ct-empty { color: #80959e; }
#core-ui .ct-empty { margin: 24px 0; font-size: 12px; line-height: 1.8; }
#core-ui .ct-actions, #core-ui .se-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#core-ui :is(.ct-actions, .se-actions) button { padding: 6px 9px; font-size: 10px; }
#core-ui :is(.ct-open, .ct-run, .ct-approve, .se-retry) { color: var(--core-cyan); }
#core-ui .ct-deny { color: var(--core-amber); }
#core-ui .staged-error { margin-top: 10px; padding-top: 8px; border-top: 1px solid rgb(232 185 129 / 22%); text-align: left; }
#core-ui .staged-error p.se-headline { margin: 0; color: var(--core-amber); font-size: 11px; line-height: 1.7; }
#core-ui .staged-error p.se-detail { margin: 8px 0 0; max-height: 140px; overflow: auto; color: #80959e; font: 10px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
#core-ui .staged-error p.se-detail[hidden] { display: none; }

#core-node .url-reference { flex: 0 1 auto; min-height: 0; width: 100%; margin: 0; color: #80959e; text-align: left; font-size: 10px; }
#core-node .url-reference[open] { max-height: 130px; overflow: auto; pointer-events: auto; overscroll-behavior: contain; }
#core-node .url-reference summary { padding: 5px 0; font-size: 11px; cursor: pointer; overflow-wrap: anywhere; }
#core-node .url-reference form { display: flex; flex-wrap: wrap; gap: 5px; padding: 6px; background: #04080f; border-color: var(--core-line); box-shadow: none; }
#core-node .url-reference input { flex: 1 0 100%; min-width: 0; width: 100%; padding: 6px; color: #deedf2; background: #0b1626; border: 1px solid var(--core-line); border-radius: 4px; font: inherit; font-size: 11px; }
#core-node .url-reference button { padding: 5px 8px; font-size: 10px; }
#core-node .url-reference p { margin: 5px 0; overflow-wrap: anywhere; }
#core-node .url-reference pre { max-height: 90px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 10px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }

#core-ui[data-activity="thinking"] .core-halo { animation: core-halo-think 3.6s ease-in-out infinite; }
#core-ui[data-activity="speaking"] .core-halo { border-color: var(--core-cyan); box-shadow: 0 0 32px rgb(140 228 250 / 26%), inset 0 0 18px rgb(140 228 250 / 8%); }
#core-ui[data-activity="listening"] .core-halo { border-color: var(--core-amber); box-shadow: 0 0 26px rgb(232 185 129 / 20%); }
#core-ui[data-activity="listening"] :is(.core-glyph, #core-state) { color: var(--core-amber); }
#core-ui[data-pulse="done"] #core-node, #core-ui [data-pulse="done"] { animation: core-pulse-done 1.6s ease-out 1; }
#core-ui[data-pulse="failed"] #core-node, #core-ui [data-pulse="failed"] { animation: core-pulse-failed 1.6s ease-out 1; }
@keyframes core-halo-think { 0%, 100% { opacity: .5; } 50% { opacity: 1; box-shadow: 0 0 30px rgb(140 228 250 / 17%); } }
@keyframes core-pulse-done { 0%, 100% { box-shadow: 0 0 0 transparent; } 25% { box-shadow: 0 0 22px rgb(140 228 250 / 28%); } }
@keyframes core-pulse-failed { 0%, 100% { box-shadow: 0 0 0 transparent; } 25% { box-shadow: 0 0 22px rgb(232 185 129 / 28%); } }

@media (width < 1100px) {
  #core-ui { --core-tracker-width: 260px; --core-diameter: min(60vh, 520px); }
  #core-node { width: min(240px, calc(var(--core-diameter) * .866 - 174px)); padding: 18px 12px 12px; gap: 8px; }
  #core-ui .core-module { width: 150px; margin-left: -75px; padding: 10px; }
  #core-tracker { padding: 12px; }
}
/* Fit the complete orbit, including the card widths, beside the tracker. */
@media (760px <= width < 950px) {
  #core-ui .core-ring { transform: translate(-50%, -50%) scale(.78); }
}
@media (width < 760px) {
  #core-ui .core-ring {
    top: 12px;
    left: 12px;
    width: calc(100% - 24px);
    height: calc(62vh - 36px);
    transform: none;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-content: start;
    gap: 8px;
    padding: 8px 4px 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: 0;
    background: none;
  }
  #core-node { position: relative; top: auto; left: auto; transform: none; grid-column: 1 / -1; justify-self: center; width: min(340px, 100%); max-height: none; margin-bottom: 6px; padding: 12px; gap: 6px; }
  #core-ui .core-glyph { font-size: 28px; }
  #core-ui .core-module { position: relative; top: auto; left: auto; width: 100%; height: 112px; margin: 0; transform: none; grid-template-columns: 18px minmax(0, 1fr); gap: 4px; padding: 8px 6px; }
  #core-ui .cm-glyph { font-size: 18px; }
  #core-ui .cm-title { font-size: 9px; letter-spacing: 0; }
  #core-ui .cm-sub, #core-ui .cm-status { font-size: 9px; }
  #core-tracker { top: auto; right: 12px; bottom: 12px; left: 12px; width: auto; height: 38vh; padding: 12px; }
  #core-ui .ct-head { margin-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  #core-ui, #core-ui *, #core-ui *::before, #core-ui *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
