/* Command-K overlay (Sprint v5-11.5 foundation)
 * -------------------------------------------------------------------------
 * Locked spec: docs/octopus/v5_11_5_sprint_brief.md §"Part 3 — Command-K"
 *
 * Self-contained overlay component. Drop the assets into any page via:
 *   <link rel="stylesheet" href="/assets/cmdk.css">
 *   <script defer src="/assets/cmdk.js"></script>
 *
 * No HTML markup required — the JS injects the overlay nodes on first
 * activation. Activation: Cmd-K (macOS) / Ctrl-K (Win/Linux) or click
 * any element with `data-cmdk-trigger`.
 *
 * Token mapping (2026-07-22, doc-90 light migration): every color var()
 * tries the legacy team-page-only token name first (so team pages, which
 * define --bg-card/--fg-primary/--accent-primary locally, render exactly
 * as before), then the real current design-system token (--page/--ink/
 * --gold/etc, from components.py's TOKENS_CSS — in scope on every page),
 * then a light literal as the final safety net. Never falls through to a
 * dark default. Fonts are hardcoded to "Archivo" directly rather than
 * chased through --font-body, which resolves to the wrong value (Fraunces,
 * the headline serif) on non-team pages.
 */

/* ---------------------------------------------------------------------
 * Backdrop + scrim
 * --------------------------------------------------------------------- */

.cmdk-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  animation: cmdk-fade-in 140ms ease-out;
}

.cmdk-backdrop[aria-hidden="false"] {
  display: block;
}

@keyframes cmdk-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------------------------------------------------------------------
 * Dialog
 * --------------------------------------------------------------------- */

.cmdk-dialog {
  position: fixed;
  top: 18vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px));
  max-height: 64vh;
  background: var(--bg-card, var(--page, #fff));
  color: var(--fg-primary, var(--ink, #222));
  border: 1px solid var(--stroke-strong, var(--rule, #d7d7d4));
  border-radius: var(--r-2, 3px);
  z-index: 10000;
  font-family: "Archivo", system-ui, sans-serif;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: cmdk-slide-in 180ms ease-out;
}

.cmdk-dialog[aria-hidden="false"] {
  display: flex;
}

@keyframes cmdk-slide-in {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------------------------------------------------------------
 * Input
 * --------------------------------------------------------------------- */

.cmdk-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--stroke-default, var(--rule, #e4e4e1));
}

.cmdk-input-icon {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
  fill: currentColor;
}

.cmdk-input {
  flex: 1;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 17px;
  font-weight: 400;
  line-height: 1.3;
  padding: 4px 0;
  outline: none;
}

.cmdk-input::placeholder {
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
}

.cmdk-shortcut {
  flex: 0 0 auto;
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
  padding: 3px 7px;
  background: color-mix(in srgb, var(--fg-primary, var(--ink, #222)) 6%, transparent);
  border: 1px solid var(--stroke-default, var(--rule, #e4e4e1));
  border-radius: var(--r-1, 2px);
}

/* ---------------------------------------------------------------------
 * Results
 * --------------------------------------------------------------------- */

.cmdk-results {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.cmdk-results:empty::before {
  content: "Start typing to search teams, players, editions…";
  display: block;
  padding: 24px 22px;
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
  font-size: 14px;
  font-style: italic;
}

.cmdk-group {
  padding: 4px 0;
}

.cmdk-group__label {
  padding: 8px 18px 6px;
  font-family: "Archivo", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: none;
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
}

.cmdk-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background-color 80ms ease;
  color: inherit;
  text-decoration: none;
}

/* Flat background-tint hover + an outline on the keyboard-selected item --
   same pattern as the homepage search panel's .hs-card.hs-active (shipped
   earlier this session), not the colored left-border-stripe this used to
   be (doc-90's own named anti-pattern). outline-offset is negative (inset)
   rather than the homepage panel's positive offset, since these rows sit
   flush against the dialog's own overflow:hidden edges with no card gap
   to expand into. */
.cmdk-item:hover {
  background: var(--row, #f7f7f6);
}

.cmdk-item[aria-selected="true"] {
  background: var(--row, #f7f7f6);
  outline: 2px solid var(--blue, #008fd5);
  outline-offset: -2px;
  border-radius: var(--r-1, 2px);
}

.cmdk-item__title {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--fg-primary, var(--ink, #222));
}

.cmdk-item__subtitle {
  flex: 0 0 auto;
  font-size: 12px;
  font-family: "Archivo", system-ui, sans-serif;
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
  letter-spacing: 0.01em;
  text-align: right;
}

/* Second destination on rivalry rows only (the /compare/ head-to-head
   page). A plain sibling link under the row, not part of keyboard
   selection -- mouse-only, same tier as a normal inline link. */
.cmdk-item__compare {
  display: block;
  padding: 0 18px 8px;
  margin-top: -6px;
  font-family: "Archivo", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-align: right;
  color: var(--blue, #008fd5);
  text-decoration: none;
}

.cmdk-item__compare:hover {
  text-decoration: underline;
}

/* Kind badge — small chip on each item. Shape/type only here; color,
   background, and border are set per-kind below (mirrors components.py's
   own .tag.fact/.tag.read pattern: matching text color + light background
   tint, not one shared tint for every kind). */
.cmdk-item__kind {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: "Archivo", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: none;
  padding: 2px 7px;
  border-radius: var(--r-1, 2px);
  margin-right: 4px;
}

/* Category glyph — one per hue-family (see cmdk.js's KIND_GLYPH), inherits
   the chip's own text color via currentColor so no new tokens are needed. */
.cmdk-item__kind svg {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
}

/* Kind-specific accents — the real 4-hue palette (blue/red/gold/green)
   plus purple/gray as neutrals, all from components.py's TOKENS_CSS.
   Related kinds share a hue rather than each inventing its own off-
   palette color. Text color + a light matching background tint mirrors
   components.py's own .tag.fact/.tag.read pattern. */
.cmdk-item__kind--profile,
.cmdk-item__kind--team,
.cmdk-item__kind--coach {
  color: var(--blue, #008fd5);
  background: color-mix(in srgb, var(--blue, #008fd5) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--blue, #008fd5) 30%, transparent);
}
.cmdk-item__kind--player {
  color: var(--green, #6d904f);
  background: color-mix(in srgb, var(--green, #6d904f) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--green, #6d904f) 30%, transparent);
}
.cmdk-item__kind--edition,
.cmdk-item__kind--canon,
.cmdk-item__kind--dossier {
  color: var(--gold, #e5ae38);
  background: color-mix(in srgb, var(--gold, #e5ae38) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold, #e5ae38) 30%, transparent);
}
.cmdk-item__kind--arc,
.cmdk-item__kind--rivalry {
  color: var(--red, #fc4f30);
  background: color-mix(in srgb, var(--red, #fc4f30) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--red, #fc4f30) 30%, transparent);
}
.cmdk-item__kind--conference {
  color: var(--purple, #810f7c);
  background: color-mix(in srgb, var(--purple, #810f7c) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--purple, #810f7c) 30%, transparent);
}
.cmdk-item__kind--mailbag,
.cmdk-item__kind--methodology {
  color: var(--ink-3, #8b8b8b);
  background: color-mix(in srgb, var(--ink-3, #8b8b8b) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink-3, #8b8b8b) 30%, transparent);
}

/* ---------------------------------------------------------------------
 * Empty state — when search yields zero results
 * --------------------------------------------------------------------- */

.cmdk-empty {
  padding: 32px 22px;
  text-align: center;
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
  font-size: 14px;
}

.cmdk-empty__hint {
  font-size: 12px;
  margin-top: 4px;
  opacity: 0.7;
}

/* ---------------------------------------------------------------------
 * Footer — keyboard hints
 * --------------------------------------------------------------------- */

.cmdk-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  border-top: 1px solid var(--stroke-default, var(--rule, #e4e4e1));
  font-size: 11px;
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
  font-family: "Archivo", system-ui, sans-serif;
}

.cmdk-footer__key {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-weight: 600;
  padding: 2px 6px;
  background: color-mix(in srgb, var(--fg-primary, var(--ink, #222)) 5%, transparent);
  border: 1px solid var(--stroke-default, var(--rule, #e4e4e1));
  border-radius: var(--r-1, 2px);
  margin-right: 6px;
  color: var(--fg-secondary, var(--ink-2, #5b5b5b));
}

/* ---------------------------------------------------------------------
 * Mobile — drop the floating dialog, use a bottom sheet
 * --------------------------------------------------------------------- */

@media (max-width: 640px) {
  .cmdk-dialog {
    top: auto;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100vw;
    max-height: 85vh;
    border-radius: var(--r-2, 3px) var(--r-2, 3px) 0 0;
    animation: cmdk-slide-up 200ms ease-out;
  }
  @keyframes cmdk-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .cmdk-shortcut { display: none; }
}

/* ---------------------------------------------------------------------
 * Trigger button — opt-in for sites that want a visible affordance
 * (mobile/Cmd-K hint). Markup: <button class="cmdk-trigger">⌘K</button>
 * --------------------------------------------------------------------- */

.cmdk-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-card, var(--page, #fff));
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
  border: 1px solid var(--stroke-default, var(--rule, #d7d7d4));
  border-radius: var(--r-2, 3px);
  font-family: "Archivo", system-ui, sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease;
}

.cmdk-trigger:hover,
.cmdk-trigger:focus-visible {
  color: var(--fg-primary, var(--ink, #222));
  border-color: var(--accent-primary, var(--gold, #e5ae38));
  outline: none;
}

.cmdk-trigger__shortcut {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 5px;
  background: color-mix(in srgb, var(--fg-primary, var(--ink, #222)) 6%, transparent);
  border: 1px solid var(--stroke-default, var(--rule, #d7d7d4));
  border-radius: var(--r-1, 2px);
  color: var(--fg-muted, var(--ink-3, #8b8b8b));
}

/* ---------------------------------------------------------------------
 * Reduced-motion: kill animations
 * --------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .cmdk-backdrop,
  .cmdk-dialog {
    animation: none;
  }
}
