/*
 * TAG Legal Desk v2.1: Fred as a teammate (lane t22-fredmate, js\v21_fredmate.js). Nothing here applies until that file
 * draws (features.fredTeammate). Only transform and opacity animate; every animation stops with reduced motion, Calm and
 * the quiet states. Colours are the desk's tokens, with Fred's own few below for each theme.
 */
:root {
  --fm-bg-1: #2E6E8E; --fm-bg-2: #1D4F6B;
  --fm-metal: #E4EAEE; --fm-metal-lo: #AEB9C2; --fm-shine: #FFFFFF; --fm-face: #18303F;
  --fm-eye: #6EF0C2; --fm-bulb: #FFC861; --fm-glow: rgba(110,240,194,.55);
  --fm-code: #1E9E5A; --fm-code-head: #0E6B3A; --fm-ptr: rgba(14,107,58,.55); --fm-ptr-edge: rgba(255,255,255,.9);
  --fm-ai: #5B4FC4; --fm-code-c: #2E6B3A; --fm-flow: #1D4F91; --fm-client: #B42A6A;
  --fm-coin-1: #F2C14E; --fm-coin-2: #B7862A;
}
:root[data-theme="dark"] {
  --fm-bg-1: #2A6684; --fm-bg-2: #163E54;
  --fm-face: #0E1E28; --fm-glow: rgba(110,240,194,.45);
  --fm-code: #5BE39A; --fm-code-head: #C9FFE0; --fm-ptr: rgba(91,227,154,.55); --fm-ptr-edge: rgba(10,20,14,.85);
  --fm-ai: #B3A8FF; --fm-code-c: #7FD39A; --fm-flow: #9CC2F5; --fm-client: #F472B6;
}
:root[data-theme="high_contrast"] { --fm-ai: var(--ink); --fm-code-c: var(--ink); --fm-flow: var(--ink); --fm-client: var(--ink); }

/* ---------- the portrait ---------- */
.av.fm-av { --pc: var(--fm-bg-1); background: radial-gradient(circle at 32% 26%, var(--fm-bg-1), var(--fm-bg-2) 78%); overflow: visible; }
.av.fm-av > .fm-robot { display: block; border-radius: 50%; overflow: hidden; }
.fm-r-body { fill: var(--fm-metal-lo); }
.fm-r-seam { fill: none; stroke: var(--fm-metal); stroke-width: 1.2; stroke-linecap: round; opacity: .7; }
.fm-r-chest { fill: var(--fm-eye); }
.fm-r-neck { fill: var(--fm-metal-lo); }
.fm-r-stalk { fill: none; stroke: var(--fm-metal-lo); stroke-width: 1.8; stroke-linecap: round; }
.fm-r-bulb { fill: var(--fm-bulb); }
.fm-r-ear { fill: var(--fm-metal-lo); }
.fm-r-head { fill: var(--fm-metal); }
.fm-r-shine { fill: none; stroke: var(--fm-shine); stroke-width: 1.6; stroke-linecap: round; opacity: .8; }
.fm-r-face { fill: var(--fm-face); }
.fm-r-eye { fill: var(--fm-eye); }
.fm-r-glint { fill: #FFFFFF; opacity: .85; }
.fm-r-smile { fill: none; stroke: var(--fm-eye); stroke-width: 1.3; stroke-linecap: round; }
.av.fm-av .fm-dot { background: var(--ok); box-shadow: none; z-index: 2; }
.fm-av-glow { position: absolute; inset: -3px; border-radius: 50%; box-shadow: 0 0 0 2px var(--fm-glow), 0 0 14px 2px var(--fm-glow); opacity: 0; transform: scale(.92); pointer-events: none; }
.fm-av.is-pulse .fm-av-glow { animation: fm-glow 1.3s var(--ease-out, ease-out) 1; }
.fm-av.is-pulse .fm-r-eye, .fm-av.is-pulse .fm-r-chest, .fm-av.is-pulse .fm-r-bulb { animation: fm-blink 1.3s ease-in-out 1; }
@keyframes fm-glow { 0% { opacity: 0; transform: scale(.92); } 30% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.12); } }
@keyframes fm-blink { 0%, 100% { opacity: 1; } 35% { opacity: .55; } 60% { opacity: 1; } }
.fm-crew-i .crew-b:hover > .av.fm-av, .fm-crew-i .crew-b:focus-visible > .av.fm-av { filter: none; opacity: 1; }
.crew-dots i.fm-cdot.on { background: var(--fm-eye); }

/* ---------- the panel ---------- */
.fm-panel { display: grid; gap: 16px; min-width: 0; }
.fm-hero { display: grid; gap: 4px; }
.fm-hero-line { margin: 0; display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
.fm-hero-big { margin: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.fm-hero-n { font-size: 2rem; line-height: 2.5rem; font-weight: 700; color: var(--brand-text); letter-spacing: -.01em; }
.fm-hero-u { font-size: 1rem; color: var(--ink-2); }
.fm-asat { margin: 0; }
.fm-live { position: relative; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.fm-live::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--ok); opacity: 0; animation: fm-live 2.6s ease-out infinite; }
@keyframes fm-live { 0% { opacity: .6; transform: scale(.5); } 100% { opacity: 0; transform: scale(1.4); } }
.fm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 12px; align-items: start; }
.fm-group, .fm-fred { display: grid; gap: 10px; padding: 14px 16px; border-radius: var(--r-card); min-width: 0; }
.fm-group-h, .fm-fred-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.fm-group-ico { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; flex: none; color: #FFFFFF; }
.fm-group-ai .fm-group-ico { background: var(--fm-ai); }
.fm-group-code .fm-group-ico { background: var(--fm-code-c); }
.fm-group-flow .fm-group-ico { background: var(--fm-flow); }
.fm-group-client .fm-group-ico { background: color-mix(in srgb, var(--fm-client) 16%, transparent); }
:root[data-theme="dark"] .fm-group-ico { color: #111311; }
.fm-emoji { font-size: 1.125rem; line-height: 1; }
.fm-group-tt { display: grid; min-width: 0; }
.fm-group-tt h3 { margin: 0; font-size: 1rem; line-height: 1.375rem; }
.fm-group-sub { font-size: .8125rem; color: var(--ink-2); }
.fm-rows { list-style: none; margin: 0; padding: 0; display: grid; }
.fm-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 92px; gap: 10px; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--glass-rim); }
.fm-row:first-child { border-top: 0; }
.fm-row-head { padding: 0 0 2px; font-size: .6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.fm-row-head .fm-row-t, .fm-row-head .fm-row-a { font-size: .6875rem; font-weight: 700; color: var(--ink-3); white-space: nowrap; }
.fm-row-l { display: grid; min-width: 0; }
.fm-row-name { font-size: .875rem; line-height: 1.25rem; color: var(--ink); }
.fm-row-sub { font-size: .75rem; line-height: 1rem; color: var(--ink-2); }
.fm-row-t { font-size: 1.0625rem; font-weight: 700; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.fm-row-t.is-zero { color: var(--ink-3); font-weight: 600; }
.fm-row-a { font-size: .8125rem; text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.fm-fred { grid-column: 1 / -1; border: 1px solid color-mix(in srgb, var(--fm-bg-1) 40%, var(--glass-edge)); }
.fm-fred-body { display: grid; gap: 8px 24px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; }
.fm-stats .fm-fred-body, .fm-ai-extra { grid-template-columns: 1fr; }
.fm-fred-big { margin: 0; line-height: 1.5rem; }
.fm-fred-big .fm-coin { margin-right: 6px; vertical-align: 1px; }
.fm-fred-big b { font-size: 1.5rem; line-height: 1.75rem; color: var(--brand-text); }
.fm-fred-est, .fm-fred-help { margin: 0; }
.fm-fred-kinds { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.fm-fred-kinds li { display: flex; justify-content: space-between; gap: 8px; font-size: .875rem; }
.fm-coin { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, var(--fm-coin-1), var(--fm-coin-2)); flex: none; align-self: center; }
.fm-foot { margin: 0; }
.fm-mouse-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 12px; }
.fm-sheet .sheet-b { min-width: 0; }

/* ---------- the tile, Stats, Cleared by Fred ---------- */
.fm-tile-h { display: flex; align-items: center; gap: 8px; }
.fm-tile-h h2 { flex: 1; }
.fm-minis { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.fm-mini { display: grid; }
.fm-mini b { font-size: 1.25rem; line-height: 1.5rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.fm-mini span { font-size: .75rem; color: var(--ink-2); }
.fm-tile-fred { margin: 0; }
.fm-tile-b { justify-self: start; }
.fm-stats { display: grid; gap: 12px; }
.fm-stats .fm-hero-n { font-size: 1.5rem; line-height: 2rem; }
.fm-ai-extra { display: grid; gap: 6px; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--glass-rim); }
.fm-ai-extra .fm-fred-big b { font-size: 1.125rem; }
.fm-cl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; align-items: start; padding: 12px 14px; border-radius: var(--r-card); margin: 0 0 12px; }
.fm-cl-w { display: grid; gap: 2px; min-width: 0; }
.fm-cl-w p { margin: 0; }
.fm-cl-big b { font-size: 1.25rem; color: var(--brand-text); }
.fm-cl > .btn { grid-column: 2; justify-self: start; padding-left: 0; }
@media (max-width: 560px) { .fm-row { grid-template-columns: minmax(0, 1fr) auto 84px; } .fm-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- the Grove ---------- */
.fm-grove-host { position: relative; }
.fm-grove-glow { animation: fm-tree 4.8s ease-in-out infinite; }
@keyframes fm-tree { 0%, 100% { opacity: 1; } 50% { opacity: .86; } }
.v21-fred.fm-grove-glow { box-shadow: 0 0 0 2px var(--fm-glow); }
.fm-grove-badge { position: absolute; transform: translate(-50%, -100%); display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; background: var(--glass-2); border: 1px solid var(--glass-edge); box-shadow: var(--shadow-1); font-size: .75rem; font-weight: 700; color: var(--ink); white-space: nowrap; pointer-events: none; }
.fm-spark { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--fm-eye); box-shadow: 0 0 6px var(--fm-glow); pointer-events: none; opacity: .75; animation: fm-spark 3.6s ease-in-out infinite; }
.fm-spark-1 { animation-delay: 1.2s; background: var(--fm-coin-1); }
.fm-spark-2 { animation-delay: 2.4s; }
@keyframes fm-spark { 0%, 100% { opacity: .25; transform: translateY(0) scale(.8); } 50% { opacity: .85; transform: translateY(-4px) scale(1); } }
.fm-grove-line { margin: 0 0 8px; display: flex; align-items: center; gap: 8px; font-size: .875rem; color: var(--ink-2); }

/* ---------- Fred's pointer ---------- */
.fm-mouse { position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none; opacity: 0; transition: opacity .6s ease; will-change: transform, opacity; }
.fm-mouse.is-on { opacity: .7; }
.fm-ptr { display: block; filter: drop-shadow(0 0 3px var(--fm-glow)); }
.fm-ptr-p { fill: var(--fm-ptr); stroke: var(--fm-ptr-edge); stroke-width: 1.2; stroke-linejoin: round; }
.fm-glyphc { position: fixed; z-index: 39; pointer-events: none; font: 700 11px/1 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--fm-code); opacity: 0; animation: fm-code 1.2s linear 1 forwards; }
@keyframes fm-code { 0% { opacity: .75; transform: translateY(0); } 100% { opacity: 0; transform: translateY(14px); } }
.card.fm-touched, [data-anchor^="card:"].fm-touched { box-shadow: 0 0 0 2px var(--fm-glow); transition: box-shadow .5s ease; }

/* ---------- never moving where it must not ---------- */
@media (prefers-reduced-motion: reduce) {
  .fm-av.is-pulse .fm-av-glow, .fm-av.is-pulse .fm-r-eye, .fm-av.is-pulse .fm-r-chest, .fm-av.is-pulse .fm-r-bulb,
  .fm-live::after, .fm-grove-glow, .fm-spark { animation: none !important; }
  .fm-mouse, .fm-glyphc { display: none !important; }
}
:root[data-calm="on"] .fm-av-glow, :root[data-calm="on"] .fm-live::after, :root[data-calm="on"] .fm-grove-glow, :root[data-calm="on"] .fm-spark { animation: none !important; }
:root[data-calm="on"] .fm-mouse, :root[data-calm="on"] .fm-glyphc,
:root[data-quiet="on"] .fm-mouse, :root[data-quiet="on"] .fm-glyphc { display: none !important; }
:root[data-quiet="on"] .fm-av-glow, :root[data-quiet="on"] .fm-live::after { animation: none !important; }
@media print { .fm-mouse, .fm-glyphc, .fm-grove-badge, .fm-spark { display: none !important; } }
@media (forced-colors: active) { .fm-mouse, .fm-glyphc { display: none !important; } .fm-group-ico { forced-color-adjust: auto; } }
.fm-stats > .btn { justify-self: start; }
