/* The deck: ring and pool, caption, agent list, project dock, drive mode and the mini widget. */
.top { grid-row: 1; }
.offer { grid-row: 2; }
.deck { grid-row: 3; display: grid; grid-template-columns: minmax(340px, 40%) minmax(0, 1fr); min-height: 0; }
.dock { grid-row: 4; }

.stage { display: flex; flex-direction: column; min-height: 0; padding: 4px 12px 0 calc(20px + var(--safe-l)); }
.hero { display: flex; flex-direction: column; align-items: center; flex: none; }

/* ---- ring ---- */
.ring { position: relative; width: min(100%, 34vh, 400px); aspect-ratio: 1; flex: none; }
.ring::before {
  content: ""; position: absolute; inset: -8%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--glow) 14%, transparent), transparent 72%);
}
.ring > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ring-track { fill: none; stroke: var(--line); stroke-width: 2; stroke-dasharray: 2 9; stroke-linecap: round; }
.ring[data-empty="false"] .ring-track { opacity: 0; }

.arc { cursor: pointer; outline: none; }
.arc path { fill: none; stroke-linecap: round; }
.arc .hit { stroke: transparent; stroke-width: 46; pointer-events: stroke; }
.arc .base { stroke: var(--arc); stroke-width: 12; opacity: .9; transition: stroke-width .2s ease, opacity .3s ease, stroke .3s ease; }
.arc .run { stroke: var(--ink); stroke-width: 12; stroke-dasharray: 14 100; stroke-dashoffset: 14; opacity: 0; pointer-events: none; }
.arc:hover .base { opacity: 1; }
.arc[data-state="stopped"] .base { opacity: .3; }
.arc[data-state="starting"] .base { opacity: .55; }
.arc[data-state="working"] .base { opacity: .5; }
.arc[data-state="working"] .run { opacity: 1; animation: travel 1.9s linear infinite; }
.arc[data-state="permission"] .base { stroke: var(--attention); opacity: 1; animation: beat 1.1s ease-in-out infinite; }
.arc[data-state="error"] .base { stroke: var(--error); opacity: 1; }
.arc[data-selected="true"] .base, .arc[data-selected="true"] .run { stroke-width: 20; }
.arc:focus-visible .hit { stroke: color-mix(in srgb, var(--ink) 30%, transparent); stroke-width: 32; }

/* ---- pool ---- */
.pool {
  position: absolute; inset: 14.5%; border-radius: 50%; border: 0; padding: 0; overflow: hidden; cursor: pointer;
  background: var(--surface); -webkit-tap-highlight-color: transparent;
}
.pool canvas { display: block; width: 100%; height: 100%; }
.pool:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }
.pool:active { transform: scale(.985); }
.pool-hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink); opacity: .85; transition: opacity .3s ease; pointer-events: none; }
.pool-hint svg { width: 19%; height: 19%; }
:root:not([data-voice="standby"]) .pool-hint { opacity: 0; }

/* ---- caption ---- */
.caption { width: 100%; max-width: 30ch; text-align: center; padding: 10px 0 14px; font-size: clamp(22px, 2.3vw, 30px); }
.state-word { font-size: .62em; font-weight: 700; font-stretch: 85%; color: var(--glow); }
.caption-clip { display: flex; flex-direction: column-reverse; overflow: hidden; height: 2.3em; }
#caption-text { margin-bottom: auto; font-weight: 600; line-height: 1.15; letter-spacing: -.01em; text-wrap: balance; }
#caption-text[data-who="hint"] { font-weight: 300; color: var(--dim); }
#caption-text[data-who="jij"] { font-weight: 400; color: var(--dim); }

/* ---- agent list ---- */
.agents { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 16px 0; }
.group-name { font-size: 14px; font-weight: 600; color: var(--dim); padding: 14px 12px 4px; }
.agent {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 12px;
  border: 0; border-radius: 16px; background: none; text-align: left; cursor: pointer;
}
.agent:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.agent[aria-pressed="true"] { background: var(--surface); box-shadow: inset 3px 0 0 var(--arc); }
.agent-main { flex: 1; min-width: 0; display: grid; }
.agent-name { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; font-size: 18px; font-weight: 600; line-height: 1.2; }
.agent-what { font-size: 14px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch { display: inline-flex; align-items: center; gap: 4px; color: var(--arc); font-weight: 400; font-size: 13px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--arc); }
.dot-ico { color: var(--glow); width: 12px; display: grid; place-items: center; }
[data-state="stopped"] .dot { background: none; box-shadow: inset 0 0 0 2px var(--dim); }
[data-state="starting"] .dot { opacity: .6; }
[data-state="working"] .dot { background: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--arc) 60%, transparent); }
[data-state="permission"] .dot { background: var(--attention); }
[data-state="error"] .dot { background: var(--error); }
[data-state="permission"] .agent-what { color: var(--attention); }
[data-state="error"] .agent-what { color: var(--error); }
.elapsed { color: var(--dim); font-variant-numeric: tabular-nums; }
kbd { font: 500 12px var(--mono); color: var(--dim); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
@media (hover: none) { kbd { display: none; } }
.empty { color: var(--dim); padding: 16px 12px; max-width: 46ch; }

/* ---- project dock ---- */
.dock {
  display: flex; align-items: center; gap: 12px; border-top: 1.5px solid var(--line);
  padding: 10px calc(20px + var(--safe-r)) calc(10px + var(--safe-b)) calc(20px + var(--safe-l));
}
.projects { display: flex; gap: 8px; flex: 1; min-width: 0; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.projects::-webkit-scrollbar { display: none; }
.project { display: flex; align-items: center; flex: none; border-radius: 999px; background: var(--surface); padding-right: 4px; }
.project.missing { opacity: .55; }
.project-open { display: grid; text-align: left; border: 0; background: none; cursor: pointer; min-height: 48px; padding: 4px 8px 4px 18px; border-radius: 999px 0 0 999px; }
.project-name { display: flex; align-items: center; gap: 8px; font-weight: 600; line-height: 1.2; }
.project-ci { display: flex; align-items: center; gap: 4px; min-height: 12px; }
.project-ci .run { width: 8px; height: 8px; }
.ci-text { font-size: 12px; color: var(--dim); margin-left: 4px; }
.ci-text.bad { color: var(--error); }
.count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--arc); color: #14101F; font-size: 12px; font-weight: 700; text-align: center; }
.project .icon-btn { width: 40px; height: 40px; }
.dock-actions { display: flex; gap: 8px; flex: none; }

/* ---- permission request in drive mode and in the mini widget ---- */
.attention { width: 100%; display: grid; gap: 14px; padding: 16px; border-radius: 28px; border: 2px solid var(--attention); background: color-mix(in srgb, var(--attention) 10%, var(--ground)); }
.attention-text { font-size: clamp(20px, 2.6vw, 34px); line-height: 1.2; overflow-wrap: anywhere; }
.attention-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.btn.big { min-height: clamp(72px, 14vh, 150px); font-size: clamp(22px, 3vw, 40px); font-weight: 700; border-width: 3px; border-radius: 28px; }
.attention-more { color: var(--dim); }
.drive-agents { display: none; }

/* ---- drive mode: the ring, a huge caption and nothing to read ---- */
:root[data-drive="on"] .panel, :root[data-drive="on"] .dock, :root[data-drive="on"] .agents, :root[data-drive="on"] #install { display: none; }
:root[data-drive="on"] .deck { grid-template-columns: 1fr; }
:root[data-drive="on"] .stage { padding: 0 calc(28px + var(--safe-r)) calc(20px + var(--safe-b)) calc(28px + var(--safe-l)); }
:root[data-drive="on"] .hero {
  flex: 1; min-height: 0; display: grid; align-items: center; gap: 2vh 5vw;
  grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 1fr auto auto 1fr;
  grid-template-areas: "ring ." "ring caption" "ring attention" "ring agents";
}
:root[data-drive="on"] .ring { grid-area: ring; width: min(46vw, 76vh); }
:root[data-drive="on"] .caption { grid-area: caption; text-align: left; max-width: 22ch; font-size: clamp(34px, 5vw, 76px); padding: 0; }
:root[data-drive="on"] .caption-clip { height: auto; max-height: 4.6em; min-height: 1.15em; }
:root[data-drive="on"] .attention { grid-area: attention; }
:root[data-drive="on"] .drive-agents {
  grid-area: agents; align-self: start; display: flex; flex-wrap: wrap; gap: 10px 26px; font-size: clamp(18px, 2vw, 26px); font-weight: 600;
}
.drive-agents li { display: flex; align-items: center; gap: 10px; }
.drive-agents small { font-size: .75em; font-weight: 400; color: var(--dim); }
.drive-agents li[data-state="permission"] small { color: var(--attention); }
.drive-agents li[data-state="error"] small { color: var(--error); }
@media (orientation: portrait) {
  :root[data-drive="on"] .hero {
    grid-template-columns: 1fr; grid-template-rows: auto auto auto 1fr; justify-items: center;
    grid-template-areas: "ring" "caption" "attention" "agents";
  }
  :root[data-drive="on"] .ring { width: min(84vw, 46vh); }
  :root[data-drive="on"] .caption { text-align: center; font-size: clamp(28px, 8vw, 54px); }
  :root[data-drive="on"] .drive-agents { justify-content: center; }
}

/* ---- mini widget (?mini=1): ring, caption and a permission request; the background drags the window ---- */
:root[data-mini="on"] body { -webkit-app-region: drag; user-select: none; grid-template-rows: minmax(0, 1fr); }
:root[data-mini="on"] :is(button, a, input, select, textarea, .arc, dialog) { -webkit-app-region: no-drag; }
:root[data-mini="on"] :is(.top, .dock, .panel, .agents, .drive-agents, .offer) { display: none; }
:root[data-mini="on"] .toasts { top: 8px; font-size: 13px; }
:root[data-mini="on"] .deck { grid-row: 1; grid-template-columns: 1fr; }
:root[data-mini="on"] .stage { padding: 10px 12px; }
:root[data-mini="on"] .hero { flex: 1; justify-content: center; min-height: 0; }
:root[data-mini="on"] .ring { width: min(84vw, 62vh); }
:root[data-mini="on"] .caption { font-size: 18px; padding: 6px 0 0; }
:root[data-mini="on"] .caption-clip { height: 2.3em; }
:root[data-mini="on"] .attention { padding: 10px; gap: 8px; border-radius: 18px; margin-top: 6px; }
:root[data-mini="on"] .attention-text { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
:root[data-mini="on"] .attention-actions { gap: 8px; }
:root[data-mini="on"] .btn.big { min-height: 44px; font-size: 16px; border-width: 1.5px; border-radius: 999px; }
:root[data-mini="on"] .attention-more { display: none; }
:root[data-mini="on"] .hero:has(.attention:not([hidden])) .ring { width: min(58vw, 38vh); }

@keyframes travel { to { stroke-dashoffset: -100; } }
@keyframes beat { 50% { opacity: .35; } }

@media (prefers-reduced-motion: reduce) {
  .arc[data-state="working"] .run { animation: none; opacity: 0; }
  .arc[data-state="working"] .base { opacity: .9; stroke-dasharray: 3 16; }
  .arc[data-state="permission"] .base { animation: none; }
  .pool:active { transform: none; }
}
