/* The Mayor chat: a character docked at the bottom left, and a chat panel above it (a bottom sheet on phones).
   It speaks the page's card language: --surface, 12px radius, --shadow, Figtree for text, Big Shoulders for titles. */
.mc-root {
  --mc-medal: color-mix(in srgb, var(--accent) 30%, var(--surface));
  --mc-skin: #f5c9a4; --mc-cheek: #ee8c7c; --mc-nose: #e9a487; --mc-ink: #2a221d; --mc-brow: #7b685b;
  --mc-stache: #857367; --mc-hair: #cfc7bf; --mc-smile: #8f3d2d;
  --mc-hat: #262d3a; --mc-hat-top: #3a4252; --mc-hat-edge: transparent; --mc-band: #e1352d;
  --mc-suit: #2f4a78; --mc-shirt: #ffffff; --mc-bow: #e1352d;
  --mc-user: color-mix(in srgb, var(--accent) 24%, var(--surface));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mc-root {
    --mc-medal: color-mix(in srgb, var(--accent) 30%, var(--surface-2));
    --mc-hat: #10141d; --mc-hat-top: #242b39; --mc-hat-edge: rgba(255, 255, 255, .22); --mc-suit: #3b5a92; --mc-shirt: #e8edf4;
    --mc-user: color-mix(in srgb, var(--accent) 20%, var(--surface-2));
  }
}
:root[data-theme="dark"] .mc-root {
  --mc-medal: color-mix(in srgb, var(--accent) 30%, var(--surface-2));
  --mc-hat: #10141d; --mc-hat-top: #242b39; --mc-hat-edge: rgba(255, 255, 255, .22); --mc-suit: #3b5a92; --mc-shirt: #e8edf4;
  --mc-user: color-mix(in srgb, var(--accent) 20%, var(--surface-2));
}

/* ---------- the Mayor himself */
.mc-root svg { display: block; width: 100%; height: 100%; }
.mc-suit { fill: var(--mc-suit); }
.mc-shirt { fill: var(--mc-shirt); }
.mc-sash { fill: var(--accent); }
.mc-rosette { fill: var(--mc-band); }
.mc-rosette-c { fill: #ffe08a; }
.mc-bow { fill: var(--mc-bow); }
.mc-skin { fill: var(--mc-skin); }
.mc-hair { fill: var(--mc-hair); }
.mc-cheek { fill: var(--mc-cheek); opacity: .55; }
.mc-eyes { fill: var(--mc-ink); transform-box: fill-box; transform-origin: center; }
.mc-brow { fill: none; stroke: var(--mc-brow); stroke-width: 1.4; stroke-linecap: round; }
.mc-nose { fill: var(--mc-nose); }
.mc-smile { fill: none; stroke: var(--mc-smile); stroke-width: 1.4; stroke-linecap: round; }
.mc-stache { fill: var(--mc-stache); }
.mc-hat { transform-box: fill-box; transform-origin: 50% 92%; transform: rotate(-7deg); }
.mc-hat-c { fill: var(--mc-hat); stroke: var(--mc-hat-edge); stroke-width: .8; }
.mc-hat-top { fill: var(--mc-hat-top); }
.mc-band { fill: var(--mc-band); }

/* ---------- the dock */
.mc-dock {
  position: absolute; z-index: 5; left: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: 72px; padding: 0; border: 0; background: none; color: inherit;
  display: grid; justify-items: center; -webkit-tap-highlight-color: transparent;
}
.mc-medal {
  position: relative; width: 64px; height: 64px; border-radius: 50%; overflow: hidden; box-sizing: border-box;
  background: var(--mc-medal); border: 3px solid var(--surface); box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.mc-plate {
  position: relative; margin-top: -8px; padding: 2px 9px 3px; border-radius: 4px; line-height: 1.1;
  background: var(--fg); color: var(--bg); box-shadow: 0 2px 6px rgba(0, 0, 0, .22);
  font-family: var(--font-display); font-weight: 800; font-size: 13px; letter-spacing: .08em; text-transform: uppercase;
}
.mc-badge {
  position: absolute; top: -3px; right: -1px; min-width: 22px; height: 22px; padding: 0 5px; box-sizing: border-box;
  border-radius: 999px; border: 2px solid var(--surface); background: var(--bad); color: #fff;
  display: grid; place-items: center; font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1;
}
.mc-badge[data-kind="ask"] { background: var(--accent); color: var(--accent-ink); }
.mc-hello {
  position: absolute; left: calc(100% + 2px); top: 16px; white-space: nowrap; pointer-events: none;
  background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 10px 10px 10px 3px;
  padding: 6px 10px; font-size: 12px; font-weight: 600; box-shadow: var(--shadow);
  opacity: 0; transform: translateX(-4px); transition: opacity .15s ease, transform .15s ease;
}
.mc-dock:hover .mc-hello, .mc-dock:focus-visible .mc-hello { opacity: 1; transform: none; }
.mc-root.is-open .mc-hello { display: none; }
.mc-dock:hover .mc-medal { transform: translateY(-2px); }
.mc-dock[aria-expanded="true"] .mc-medal { border-color: var(--accent); }
.mc-dock:focus-visible { outline: none; }
.mc-dock:focus-visible .mc-medal { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- the panel */
.mc-panel {
  position: absolute; z-index: 7; left: 16px; bottom: calc(104px + env(safe-area-inset-bottom, 0px));
  width: min(400px, calc(100% - 32px)); height: min(720px, calc(100% - 180px)); min-height: 280px; box-sizing: border-box;
  background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.mc-head {
  display: grid; grid-template-columns: 42px minmax(0, 1fr) auto auto; gap: 4px 10px; align-items: center;
  padding: 12px 10px 12px 14px; border-bottom: 1px solid var(--line);
}
.mc-avatar, .mc-av { border-radius: 50%; overflow: hidden; background: var(--mc-medal); box-shadow: inset 0 0 0 1px var(--line); flex: none; }
.mc-avatar { width: 42px; height: 42px; }
.mc-titles { min-width: 0; }
.mc-titles h2 { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: 24px; line-height: 1; letter-spacing: .02em; text-transform: uppercase; }
.mc-titles p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }
.mc-icon {
  width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  display: grid; place-items: center;
}
.mc-icon svg { width: 19px; height: 19px; }
.mc-icon:hover:not(:disabled) { background: var(--surface-2); color: var(--fg); }
.mc-icon:disabled { opacity: .4; cursor: not-allowed; }
.mc-x { font-size: 22px; line-height: 1; }

.mc-strip {
  display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; padding: 7px 14px;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.mc-strip > span { display: inline-flex; gap: 6px; align-items: center; }
.mc-strip-go { border: 0; background: none; padding: 0; color: var(--bad); font-size: 12px; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; text-align: left; }

/* ---------- the conversation */
.mc-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 14px 8px; display: grid; gap: 14px; align-content: start; }
.mc-log:focus-visible { outline: none; }
.mc-turns { display: grid; gap: 14px; min-width: 0; }
.mc-msg { min-width: 0; }
.mc-mayor { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: start; }
.mc-av { width: 28px; height: 28px; }
.mc-body { display: grid; gap: 8px; min-width: 0; font-size: 14px; line-height: 1.5; }
.mc-user { display: flex; justify-content: flex-end; }
.mc-bubble {
  max-width: 85%; box-sizing: border-box; padding: 8px 12px; border-radius: 14px 14px 4px 14px;
  background: var(--mc-user); font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
}
.mc-text { overflow-wrap: anywhere; }
.mc-plain { white-space: pre-wrap; }
.mc-md > :first-child, .mc-brief-text > :first-child { margin-top: 0; }
.mc-md > :last-child, .mc-brief-text > :last-child { margin-bottom: 0; }
.mc-md p, .mc-brief-text p { margin: 0 0 8px; }
.mc-md ul, .mc-md ol, .mc-brief-text ul { margin: 0 0 8px; padding-left: 20px; }
.mc-md li, .mc-brief-text li { margin: 2px 0; }
.mc-md h3, .mc-md h4, .mc-md h5 { margin: 12px 0 4px; line-height: 1.25; }
.mc-md h3 { font-size: 16px; } .mc-md h4 { font-size: 14.5px; } .mc-md h5 { font-size: 13px; color: var(--muted); }
.mc-md strong, .mc-brief-text b { font-weight: 700; }
.mc-md code { font-family: var(--font-mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.mc-md pre { margin: 0 0 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; overflow-x: auto; }
.mc-md pre code { border: 0; padding: 0; background: none; }

.mc-tool, .mc-thinking { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); font-weight: 500; line-height: 1.35; }
.mc-tool-i { width: 12px; height: 12px; box-sizing: border-box; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.mc-tool.is-running .mc-tool-i, .mc-card-st.is-running .mc-tool-i { border-color: var(--accent); border-top-color: transparent; animation: spin .8s linear infinite; }
.mc-card-st.is-approved .mc-tool-i { border-color: var(--accent); }
.mc-tool.is-done .mc-tool-i, .mc-card-st.is-done .mc-tool-i { background: var(--ok); border-color: var(--ok); }
.mc-tool.is-failed, .mc-card-st.is-failed { color: var(--bad); }
.mc-tool.is-failed .mc-tool-i, .mc-card-st.is-failed .mc-tool-i { background: var(--bad); border-color: var(--bad); }
.mc-card-st.is-denied .mc-tool-i { border-color: var(--idle); }
.mc-dots { display: inline-flex; gap: 3px; margin-left: -4px; }
.mc-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .35; animation: mc-dot 1.2s ease-in-out infinite; }
.mc-dots i:nth-child(2) { animation-delay: .15s; }
.mc-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes mc-dot { 30% { opacity: 1; transform: translateY(-2px); } }
.mc-error { margin: 0; color: var(--bad); font-size: 13px; font-weight: 600; line-height: 1.45; }
.mc-aside { margin: 0; color: var(--muted); font-size: 12.5px; font-style: italic; }

.mc-sugg { display: flex; flex-wrap: wrap; gap: 6px; }
.mc-brief .mc-sugg { margin-top: 2px; }
.mc-chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); border-radius: 999px;
  padding: 5px 11px; font-size: 12.5px; font-weight: 600; line-height: 1.3; text-align: left; max-width: 100%;
}
.mc-chip:hover { border-color: var(--fg); }
.mc-chip.is-go { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.mc-chip.is-go::after { content: " ›"; }

/* ---------- approval cards */
.mc-card {
  display: grid; gap: 6px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--accent);
}
.mc-card[data-status="done"] { border-left-color: var(--ok); }
.mc-card[data-status="failed"] { border-left-color: var(--bad); }
.mc-card[data-status="denied"] { border-left-color: var(--idle); }
.mc-card-k { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.mc-card-s { margin: 0; font-weight: 700; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.mc-card-d { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.mc-card-d.is-folded {
  max-height: calc(1.45em * 5); overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent);
}
.mc-more {
  justify-self: start; border: 0; background: none; padding: 0; color: var(--fg); font-size: 12.5px; font-weight: 600;
  text-decoration: underline; text-underline-offset: 2px;
}
.mc-card-dl { margin: 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; font-size: 12.5px; line-height: 1.4; }
.mc-card-dl dt { color: var(--muted); font-weight: 600; }
.mc-card-dl dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.mc-card-dl dd.is-long { max-height: 96px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 12px; }
.mc-card-b { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.mc-card-b .btn, .mc-all .btn { box-shadow: none; padding: 6px 14px; }
.mc-card-b .btn.quiet { background: var(--surface); }
.mc-card-st { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: 12.5px; font-weight: 600; }
.mc-card-st.is-done { color: var(--ok); }
.mc-card-st.is-denied { color: var(--muted); }
.mc-card-r { flex-basis: 100%; color: var(--muted); font-weight: 500; }
.mc-card .mc-sugg { margin-top: 2px; }
.mc-all { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 10px; font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* ---------- writing to the Mayor */
.mc-foot { display: grid; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.mc-note { margin: 0; color: var(--warn); font-size: 12.5px; font-weight: 600; }
.mc-off {
  display: grid; gap: 8px; justify-items: start; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
}
.mc-off p { margin: 0; font-size: 13px; line-height: 1.45; }
.mc-off .btn { box-shadow: none; }
.mc-compose { position: relative; margin: 0; }
.mc-compose textarea {
  display: block; width: 100%; box-sizing: border-box; min-height: 44px; max-height: 150px; resize: none; overflow-y: auto;
  padding: 11px 50px 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  font-size: 14px; line-height: 1.4;
}
.mc-compose textarea::placeholder { color: var(--muted); opacity: 1; }
.mc-compose textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.mc-send {
  position: absolute; right: 6px; bottom: 6px; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.mc-send svg { width: 18px; height: 18px; }
.mc-send:disabled { opacity: .4; cursor: default; }
.mc-send.is-stop { background: var(--fg); color: var(--bg); }
.mc-keys { margin: 0; font-size: 11px; color: var(--muted); text-align: right; }

/* ---------- motion: a little life on the dock, none when you ask for less */
@media (prefers-reduced-motion: no-preference) {
  .mc-dock .mc-medal svg { animation: mc-bob 3.6s ease-in-out infinite; }
  .mc-dock.is-busy .mc-medal svg { animation-duration: 1.1s; }
  .mc-eyes { animation: mc-blink 5.4s infinite; }
  .mc-dock .mc-hat { animation: mc-tip 10s ease-in-out infinite; }
  .mc-panel:not([hidden]) { animation: mc-in .18s ease-out; }
}
@keyframes mc-bob { 50% { transform: translateY(-1.6px); } }
@keyframes mc-blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.12); } }
@keyframes mc-tip { 0%, 82%, 94%, 100% { transform: rotate(-7deg); } 87% { transform: translateY(-3px) rotate(-15deg); } }
@keyframes mc-in { from { transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) {
  .mc-tool.is-running .mc-tool-i, .mc-card-st.is-running .mc-tool-i { animation: none; border-top-color: var(--accent); opacity: .6; }
  .mc-dots i { animation: none; opacity: .7; }
  .mc-medal, .mc-hello { transition: none; }
}

/* ---------- phones: a bottom sheet, like the page's own panels */
@media (max-width: 720px) {
  .mc-dock { left: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .mc-hello { display: none; }
  .mc-panel {
    left: 0; right: 0; bottom: 0; width: auto; height: min(84%, 720px); min-height: 0;
    border-radius: 14px 14px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mc-keys { display: none; }
}
@media (pointer: coarse) { .mc-keys { display: none; } }
