/*
 * TAG Legal Desk v2.1: Fred's take over ask (register J217, js\v21_takeoverask.js). Theme tokens only, no inline
 * styles (the page's policy): the gauge's arc through the CSSOM as stroke-dashoffset, the reading line as --tko-p.
 * A warm card over the job: above the job layer, the sheets and the Ask Fred orb's own layer (120, J155), since it is a
 * short question that must be answered; below the cover (150). Light and dark come from the desk's own tokens. Reduced motion, Calm, a day that matters, High contrast and forced colours hold it still.
 */

/* ---------- the card and its scrim ---------- */
.tko-scrim { position: fixed; inset: 0; z-index: 124; background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.tko {
  --tko-accent: var(--ok);
  --tko-soft: color-mix(in srgb, var(--brand-text) 9%, transparent);
  position: fixed; z-index: 125; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(600px, calc(100% - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  overscroll-behavior: contain; display: grid; gap: 14px; padding: 22px 24px 20px; border-radius: var(--r-card);
  background: var(--solid); color: var(--ink);
  box-shadow: inset 0 1px 0 var(--glass-hi), 0 0 0 1px var(--glass-rim), var(--shadow-2), inset 0 4px 0 var(--brand-text);
}
.tko:focus { outline: none; }
.tko-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.tko-bot { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--tko-soft); color: var(--brand-text); box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand-text) 25%, transparent); }
.tko .v21-robot-mark { display: block; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.tko .v21-robot-mark .rm-dot { fill: currentColor; stroke: none; }
.tko-t { margin: 0; font-size: 1.25rem; line-height: 1.3; font-weight: 700; color: var(--ink); text-wrap: balance; }
.tko-t:focus { outline: none; }
.tko-t:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
.tko-x { flex: none; align-self: start; }
.tko-body { display: grid; gap: 14px; min-width: 0; }

/* ---------- the question and the gauge ---------- */
.tko-conf { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 16px; padding: 14px 16px; border-radius: 16px; background: var(--tko-soft); }
.tko-lead { margin: 0; font-size: 1rem; line-height: 1.55; color: var(--ink); }
.tko-lead b { font-weight: 700; }
.tko-lead .tko-kind { color: var(--brand-text); }
.tko-gauge { position: relative; flex: none; width: 64px; height: 64px; display: grid; place-items: center; }
.tko-g-svg { position: absolute; inset: 0; width: 64px; height: 64px; }
.tko-g-track { fill: none; stroke: color-mix(in srgb, var(--ink) 12%, transparent); stroke-width: 6; }
.tko-g-arc { fill: none; stroke: var(--tko-accent); stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 1100ms var(--ease-glide); }
.tko-g-n { position: relative; display: inline-flex; align-items: baseline; gap: 1px; color: var(--ink); font-variant-numeric: tabular-nums; }
.tko-g-n b { font-size: 1.1875rem; font-weight: 800; line-height: 1; }
.tko-g-n small { font-size: .6875rem; font-weight: 700; color: var(--ink-2); }
.tko-nums { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-size: .8125rem; line-height: 1.45; color: var(--ink-2); }
.tko-nums .ico { flex: none; margin-top: 2px; color: var(--ink-3); }

/* ---------- How I know ---------- */
.tko-know { position: relative; border-radius: 14px; background: var(--solid-2); box-shadow: 0 0 0 1px var(--glass-rim); overflow: hidden; }
.tko-know-s { list-style: none; display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 14px; cursor: pointer; font-weight: 700; color: var(--ink); border-radius: 14px; }
.tko-know-s::-webkit-details-marker { display: none; }
.tko-know-s::marker { content: ""; }
.tko-know-s:hover { background: var(--glass-hover); }
.tko-know-s:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tko-know-i { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--tko-soft); color: var(--brand-text); }
.tko-know-l { flex: 1; min-width: 0; }
.tko-know-tag { flex: none; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; color: var(--warn); background: color-mix(in srgb, var(--warn) var(--tint-alpha), transparent); }
.tko-know-tag.tko-done { color: var(--ok); background: color-mix(in srgb, var(--ok) var(--tint-alpha), transparent); }
.tko-chev { flex: none; display: inline-flex; color: var(--ink-3); transition: transform var(--t-small) var(--ease-out); }
.tko-know[open] .tko-chev { transform: rotate(180deg); }
.tko-know-b { max-height: min(40vh, 340px); overflow: auto; overscroll-behavior: contain; padding: 4px 18px 14px 52px; font-size: .9375rem; line-height: 1.6; color: var(--ink); scroll-behavior: smooth; }
.tko-know-b:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tko-know.tko-more .tko-know-b { -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent); mask-image: linear-gradient(to bottom, #000 72%, transparent); }
.tko-know-b p { margin: 0 0 10px; }
.tko-points { margin: 0 0 10px; padding-left: 18px; }
.tko-points li { margin: 0 0 6px; }
.tko-know-b .tko-end { display: flex; align-items: center; gap: 6px; margin: 4px 0 0; font-size: .8125rem; font-weight: 700; color: var(--ok); }
/* The reading line: it fills as How I know is scrolled to its end, or kept open long enough. */
.tko-read { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.tko-read > i { display: block; height: 100%; background: var(--tko-accent); transform-origin: 0 50%; transform: scaleX(var(--tko-p, 0)); transition: transform 260ms linear; }

/* ---------- the gate and the choices ---------- */
.tko-hint { display: flex; align-items: center; gap: 8px; margin: 0; min-height: 24px; font-size: .875rem; font-weight: 600; color: var(--ink-2); }
.tko-hint .ico { flex: none; color: var(--warn); }
.tko-hint.tko-ok { color: var(--ok); }
.tko-hint.tko-ok .ico { color: var(--ok); }
.tko-hint.tko-nudge, .tko-shint.tko-nudge { animation: tko-nudge 420ms var(--ease-out); color: var(--warn); }
@keyframes tko-nudge { 0%, 100% { transform: none; } 20% { transform: translateX(-5px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }
.tko-acts { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.tko-acts .btn { min-height: 48px; padding: 0 22px; }
.tko .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; box-shadow: none; }
.tko.tko-unlocked .tko-take { animation: tko-ready 900ms var(--ease-out) 1; }
@keyframes tko-ready { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
.tko-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--glass-rim); }
.tko-notme { font-weight: 600; }
.tko-coins { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: .8125rem; font-weight: 700; color: var(--ink-2); }
.tko-coin, .tko-toast-coin, .tko-toast-bot { display: inline-flex; flex: none; }
.tko-coin-svg .tko-coin-rim { fill: #B8901F; }
.tko-coin-svg .tko-coin-face { fill: #E9C349; stroke: #F6DE8A; stroke-width: .8; }
.tko-coin-svg .tko-coin-leaf { fill: #4F7F5C; }
.tko-toast-bot { color: var(--brand-text); }

/* ---------- the follow up question ---------- */
.tko-you { display: flex; align-items: center; gap: 8px; margin: 0; font-size: .9375rem; line-height: 1.5; color: var(--ink-2); }
.tko-you .ico { flex: none; color: var(--ok); }
.tko[data-choice="keep_learning"] .tko-you .ico { color: var(--info); }
.tko-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tko-chip {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--glass-rim);
  background: var(--solid-2); color: var(--ink); font: inherit; font-size: .875rem; font-weight: 600; cursor: pointer; text-align: left;
  transition: background-color var(--t-micro) var(--ease-out), box-shadow var(--t-micro) var(--ease-out);
}
.tko-chip:hover { background: var(--glass-hover); box-shadow: 0 0 0 1px var(--edge-strong); }
.tko-chip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tko-chip[aria-pressed="true"] { background: color-mix(in srgb, var(--brand-text) 16%, var(--solid)); box-shadow: 0 0 0 2px var(--brand-text); color: var(--ink); }
.tko-chip[aria-pressed="true"]::before { content: ""; width: 7px; height: 12px; margin: 0 9px 3px 0; border: solid var(--brand-text); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.tko-ta { width: 100%; min-height: 84px; resize: vertical; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--edge-strong); background: var(--solid); color: var(--ink); font: inherit; font-size: .9375rem; line-height: 1.5; }
.tko-ta:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.tko-shint { margin: -4px 0 0; font-size: .8125rem; color: var(--ink-2); }
.tko-acts-follow { justify-content: space-between; align-items: center; }
.tko-acts-follow:has(> :only-child) { justify-content: flex-end; }
.tko-skip { color: var(--ink-2); font-weight: 600; }
/* J217 review finding 3: Back to the ask, quiet, beside Skip. */
.tko-follow-l { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.tko-acts .tko-follow-l .btn { padding: 0 14px; }
.tko-back { color: var(--ink-2); font-weight: 600; gap: 6px; }
.tko[aria-busy="true"] .tko-body { opacity: .7; pointer-events: none; }

/* ---------- the thank you toast ---------- */
.toast.tko-toast .row { align-items: center; }
.toast.tko-toast .msg { line-height: 1.45; }

/* ---------- arriving: a short lift, only where motion is welcome ---------- */
@media (prefers-reduced-motion: no-preference) {
  :root:not([data-motion="reduced"]):not([data-calm="on"]) .tko { animation: tko-in 260ms var(--ease-out) both; }
  :root:not([data-motion="reduced"]):not([data-calm="on"]) .tko-scrim { animation: tko-fade 180ms var(--ease-out) both; }
}
:root[data-motion="full"]:not([data-calm="on"]) .tko { animation: tko-in 260ms var(--ease-out) both; }
@keyframes tko-in { from { opacity: 0; transform: translate(-50%, calc(-50% + 14px)) scale(.985); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes tko-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- still: reduced motion, Calm, a day that matters ---------- */
:root[data-motion="reduced"] .tko-g-arc, :root[data-calm="on"] .tko-g-arc, :root[data-day-matters] .tko-g-arc { transition: none; }
:root[data-motion="reduced"] .tko-read > i, :root[data-calm="on"] .tko-read > i { transition: none; }
:root[data-motion="reduced"] .tko-hint.tko-nudge, :root[data-calm="on"] .tko-hint.tko-nudge, :root[data-day-matters] .tko-hint.tko-nudge,
:root[data-motion="reduced"] .tko-shint.tko-nudge, :root[data-calm="on"] .tko-shint.tko-nudge, :root[data-day-matters] .tko-shint.tko-nudge { animation: none; text-decoration: underline; }
:root[data-motion="reduced"] .tko.tko-unlocked .tko-take, :root[data-calm="on"] .tko.tko-unlocked .tko-take, :root[data-day-matters] .tko.tko-unlocked .tko-take { animation: none; }
:root[data-motion="reduced"] .tko-chev, :root[data-calm="on"] .tko-chev { transition: none; }
:root[data-motion="reduced"] .tko-know-b, :root[data-calm="on"] .tko-know-b { scroll-behavior: auto; }
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) .tko-g-arc, :root:not([data-motion="full"]) .tko-read > i, :root:not([data-motion="full"]) .tko-chev { transition: none; }
  :root:not([data-motion="full"]) .tko-hint.tko-nudge, :root:not([data-motion="full"]) .tko-shint.tko-nudge { animation: none; text-decoration: underline; }
  :root:not([data-motion="full"]) .tko.tko-unlocked .tko-take { animation: none; }
  :root:not([data-motion="full"]) .tko-know-b { scroll-behavior: auto; }
}

/* ---------- High contrast and forced colours ---------- */
:root[data-theme="high_contrast"] .tko { background: #FFFFFF; color: #000000; box-shadow: 0 0 0 3px #000000, inset 0 6px 0 #000000; }
:root[data-theme="high_contrast"] .tko-scrim { -webkit-backdrop-filter: none; backdrop-filter: none; }
:root[data-theme="high_contrast"] .tko-conf, :root[data-theme="high_contrast"] .tko-know { background: #FFFFFF; box-shadow: 0 0 0 2px #000000; }
:root[data-theme="high_contrast"] .tko-bot, :root[data-theme="high_contrast"] .tko-know-i { background: #FFFFFF; color: #000000; box-shadow: 0 0 0 2px #000000; }
:root[data-theme="high_contrast"] .tko-g-track { stroke: #BFBFBF; }
:root[data-theme="high_contrast"] .tko-g-arc { stroke: #000000; }
:root[data-theme="high_contrast"] .tko-lead .tko-kind, :root[data-theme="high_contrast"] .tko-nums, :root[data-theme="high_contrast"] .tko-hint,
:root[data-theme="high_contrast"] .tko-you, :root[data-theme="high_contrast"] .tko-shint, :root[data-theme="high_contrast"] .tko-coins { color: #000000; }
:root[data-theme="high_contrast"] .tko-know-tag, :root[data-theme="high_contrast"] .tko-know-tag.tko-done { color: #000000; background: #FFFFFF; box-shadow: 0 0 0 1px #000000; }
:root[data-theme="high_contrast"] .tko-read { background: #E6E6E6; }
:root[data-theme="high_contrast"] .tko-read > i { background: #000000; }
:root[data-theme="high_contrast"] .tko-chip { background: #FFFFFF; color: #000000; border: 2px solid #000000; }
:root[data-theme="high_contrast"] .tko-chip[aria-pressed="true"] { background: #000000; color: #FFFFFF; box-shadow: none; }
:root[data-theme="high_contrast"] .tko-chip[aria-pressed="true"]::before { border-color: #FFFFFF; }
:root[data-theme="high_contrast"] .tko-ta { border: 2px solid #000000; }
:root[data-theme="high_contrast"] .tko-coin-svg .tko-coin-rim { fill: #000000; }
:root[data-theme="high_contrast"] .tko-coin-svg .tko-coin-face { fill: #FFFFFF; stroke: #000000; }
:root[data-theme="high_contrast"] .tko-coin-svg .tko-coin-leaf { fill: #000000; }
@media (forced-colors: active) {
  .tko { border: 2px solid CanvasText; box-shadow: none; }
  .tko-conf, .tko-know { border: 1px solid CanvasText; }
  .tko-bot, .tko-know-i, .tko-know-tag { border: 1px solid CanvasText; }
  .tko-g-track { stroke: GrayText; }
  .tko-g-arc { stroke: Highlight; }
  .tko-read > i { background: Highlight; }
  .tko-chip { border: 1px solid ButtonText; }
  .tko-chip[aria-pressed="true"] { border: 3px solid Highlight; }
  .tko .btn[aria-disabled="true"] { color: GrayText; border: 1px solid GrayText; }
}

/* ---------- phone width: the card fills the width; the buttons go full width ---------- */
@media (max-width: 599px) {
  .tko { width: calc(100% - 24px); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); padding: 18px 16px 16px; gap: 12px; }
  .tko-head { gap: 10px; }
  .tko-bot { width: 38px; height: 38px; }
  .tko-t { font-size: 1.125rem; }
  .tko-conf { grid-template-columns: 1fr; justify-items: start; gap: 10px; padding: 12px 14px; }
  .tko-know-b { max-height: 46vh; padding: 4px 14px 14px 16px; }
  .tko-acts { flex-direction: column-reverse; }
  .tko-acts .btn { width: 100%; }
  .tko-acts-follow { flex-direction: row; }
  .tko-acts-follow .tko-send { flex: 1; }
  .tko-acts .tko-follow-l .btn { width: auto; }
  .tko-foot { flex-direction: column; align-items: stretch; }
  .tko-notme { justify-content: center; }
  .tko-coins { justify-content: center; }
}
@media print { .tko, .tko-scrim { display: none; } }
