/* radar.monosoftware.xyz
 *
 * Built on shadcn/ui's token contract: the same semantic names, the same oklch
 * values for the neutral scale, the same radius scale, and the same component
 * anatomy (card header/content/footer, primary/outline/ghost buttons, badges,
 * input group, switch, toggle group, select, separator, field rows).
 *
 * Both themes are real: light is the default document theme and `.dark` on
 * <html> swaps every token. Nothing here is a dark design with a light filter -
 * text, borders, shadows, the canvas plate and the contact palette each have a
 * value per theme.
 *
 * Canvas colors are NOT taken from the oklch UI tokens. Canvas needs a string
 * it can parse on every engine, so the four instrument colors live as hex/rgba
 * in --radar-* and app.js reads them back with getComputedStyle. UI tokens stay
 * in oklch where only CSS consumes them.
 */

:root {
  color-scheme: light;

  /* shadcn neutral, light */
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.52 0.09 180);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  /* shadcn's 0.556 is 4.35:1 on --muted; 0.52 clears AA for the 12px
     card-footer metadata without changing the neutral hue. */
  --muted-foreground: oklch(0.52 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.52 0.09 180);
  --radius: 0.625rem;

  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.05);
  --ring-weak: color-mix(in oklab, var(--ring) 40%, transparent);

  /* Instrument colors. Canvas-parsable on purpose. */
  --radar-plate: #fafafa;
  --radar-ring: rgba(23, 23, 23, 0.18);
  --radar-ring-soft: rgba(23, 23, 23, 0.08);
  --radar-halo: rgba(255, 255, 255, 0.94);
  --radar-player: #171717;
  --radar-pin: #0f766e;
  --radar-blip-ring: rgba(23, 23, 23, 0.55);

  /* Contact colors are written by app.js per theme; these are the light
     defaults so a blocked script still leaves readable dots. */
  --c-team: #15803d;
  --c-enemy: #dc2626;
  --c-occl: #a1625d;
  --c-down: #b45309;
  --c-look: #be185d;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

.dark {
  color-scheme: dark;

  /* shadcn neutral, dark */
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.205 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.78 0.11 180);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.78 0.11 180);

  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
  --ring-weak: color-mix(in oklab, var(--ring) 35%, transparent);

  --radar-plate: #171717;
  --radar-ring: rgba(250, 250, 250, 0.22);
  --radar-ring-soft: rgba(250, 250, 250, 0.10);
  --radar-halo: rgba(10, 10, 10, 0.88);
  --radar-player: #fafafa;
  --radar-pin: #5eead4;
  --radar-blip-ring: rgba(0, 0, 0, 0.72);

  --c-team: #4ade80;
  --c-enemy: #f87171;
  --c-occl: #cf5b5b;
  --c-down: #fbbf24;
  --c-look: #f472b6;
}

/* ---- base ---------------------------------------------------------------- */

*,
*::before,
*::after { box-sizing: border-box; }

* { border-color: var(--border); }

[hidden] { display: none !important; }

html,
body { height: 100%; }

html { background: var(--background); }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}

:where(button, input, select, a):focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

::selection {
  background: color-mix(in oklab, var(--primary) 30%, transparent);
}

/* ---- card ---------------------------------------------------------------- */

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-xs);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
}

.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-description {
  margin: 4px 0 0;
  max-width: 46ch;
  font-size: 12.5px;
  color: var(--muted-foreground);
}

.card-content {
  padding: 16px;
  padding-top: 12px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--muted);
  border-radius: 0 0 calc(var(--radius) + 3px) calc(var(--radius) + 3px);
  font-size: 12px;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}

/* ---- button -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 120ms ease, border-color 120ms ease,
    color 120ms ease, box-shadow 120ms ease;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover {
  background: color-mix(in oklab, var(--primary) 90%, var(--foreground));
}

.btn-outline {
  background: var(--background);
  border-color: var(--input);
  box-shadow: var(--shadow-xs);
}

.btn-outline:hover { background: var(--accent); color: var(--accent-foreground); }

.btn-ghost { background: transparent; }

.btn-ghost:hover { background: var(--accent); color: var(--accent-foreground); }

.btn-icon {
  width: 36px;
  padding: 0;
}

[data-theme-toggle] svg { display: none; }
html:not(.dark) [data-theme-toggle] .icon-moon { display: block; }
html.dark [data-theme-toggle] .icon-sun { display: block; }

/* ---- badge --------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 3px);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
}

.badge-outline {
  border-color: var(--border);
  color: var(--muted-foreground);
}

.led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
  background: var(--muted-foreground);
}

.led[data-tone="ok"] {
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 22%, transparent);
}

.led[data-tone="warn"] {
  background: var(--c-down);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--c-down) 22%, transparent);
}

.led[data-tone="bad"] {
  background: var(--destructive);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--destructive) 22%, transparent);
}

/* ---- input / select / kbd ------------------------------------------------ */

.input,
.select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 14px;
  box-shadow: var(--shadow-xs);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.input::placeholder { color: var(--muted-foreground); }

.input:focus-visible,
.select:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px var(--ring-weak);
}

.input[type="search"]::-webkit-search-cancel-button { appearance: none; }

.select {
  width: auto;
  min-width: 132px;
  padding-right: 30px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted-foreground) 50%),
    linear-gradient(135deg, var(--muted-foreground) 50%, transparent 50%);
  background-position: calc(100% - 16px) 15px, calc(100% - 11px) 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.select option { background: var(--popover); color: var(--popover-foreground); }

.input-group { position: relative; }

.input-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--muted-foreground);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.input-icon-padded {
  padding-left: 34px;
  padding-right: 42px;
}

.kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  min-width: 20px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--muted);
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 10px;
  pointer-events: none;
}

/* ---- switch -------------------------------------------------------------- */

.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 32px;
  height: 18.4px;
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.switch-track {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--input);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--foreground) 8%, transparent);
  transition: background-color 140ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 1.2px;
  left: 1.2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--background);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
  transition: transform 140ms ease;
}

.switch input:checked + .switch-track { background: var(--primary); }

.switch input:checked + .switch-track::after {
  transform: translateX(13.6px);
  background: var(--primary-foreground);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* ---- toggle group / separator / field rows ------------------------------- */

.toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  box-shadow: var(--shadow-xs);
}

.toggle-group-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: calc(var(--radius) - 5px);
  background: transparent;
  color: var(--muted-foreground);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.toggle-group-item:hover { color: var(--foreground); }

.toggle-group-item[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-foreground);
  /* An inset ring, because --accent is 4% off the card in light and the
     selected range has to be findable at a glance, not just by text weight. */
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-xs);
}

.separator {
  height: 1px;
  background: var(--border);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--foreground);
}

.switch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--foreground);
  cursor: pointer;
  min-height: 24px;
}

/* ---- roster -------------------------------------------------------------- */

.roster {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  margin: 0 -6px;
  padding: 0 6px;
}

.roster::-webkit-scrollbar { width: 8px; }
.roster::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.roster-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted-foreground);
}

.roster-group:first-child { padding-top: 2px; }

.roster-total {
  font-variant-numeric: tabular-nums;
}

.roster-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 3px);
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background-color 110ms ease;
}

.roster-item:hover { background: var(--accent); color: var(--accent-foreground); }

.roster-item[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--border);
  color: var(--accent-foreground);
}

.roster-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--c-enemy);
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 12%, transparent);
}

.roster-item[data-kind="team"] .roster-dot { background: var(--c-team); }
.roster-item[data-kind="enemy"] .roster-dot { background: var(--c-enemy); }
.roster-item[data-kind="occl"] .roster-dot { background: var(--c-occl); }
.roster-item[data-kind="down"] .roster-dot { background: var(--c-down); }
.roster-item[data-kind="look"] .roster-dot { background: var(--c-look); }

.roster-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roster-name mark {
  background: color-mix(in oklab, var(--primary) 24%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.roster-dist {
  flex: none;
  color: var(--muted-foreground);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.roster-empty {
  padding: 14px 8px;
  color: var(--muted-foreground);
  font-size: 13px;
}

/* ---- gate ---------------------------------------------------------------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--background);
}

.gate-card {
  width: min(430px, 100%);
}

.gate-head { align-items: flex-start; padding-bottom: 4px; }

.gate-head .card-description { font-size: 13px; }

.gate-head .card-title {
  margin-top: 10px;
  font-size: 16px;
}

.gate-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  color: var(--primary);
  stroke-width: 1.4;
  fill: none;
}

.form-error {
  margin: 0;
  min-height: 1.2em;
  font-size: 12.5px;
  color: var(--destructive);
}

.form-error:empty { display: none; }

/* ---- app shell ----------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: 56px minmax(0, 1fr);
  height: 100dvh;
  min-height: 0;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand .brand-mark { width: 22px; height: 22px; }

.brand-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.age {
  min-width: 44px;
  text-align: right;
  font-size: 12px;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}

.stage {
  min-width: 0;
  min-height: 0;
  padding: 16px;
  padding-right: 8px;
  display: flex;
}

.radar-card {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.radar-view {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 12px 12px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--radar-plate);
  overflow: hidden;
}

#radar {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  margin: 0;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--popover);
  color: var(--popover-foreground);
  font-size: 11.5px;
  box-shadow: var(--shadow-xs);
  pointer-events: none;
  white-space: nowrap;
}

.radar-foot {
  margin-top: 12px;
  border-radius: 0 0 calc(var(--radius) + 3px) calc(var(--radius) + 3px);
  border-top: 1px solid var(--border);
  background: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---- sidebar ------------------------------------------------------------- */

.side {
  grid-column: 2;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 16px 16px 8px;
}

.players-card {
  flex: 1;
  min-height: 0;
}

.players-card .card-header {
  align-items: center;
  padding-bottom: 10px;
}

.players-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
  padding-top: 0;
}

.display-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---- responsive ---------------------------------------------------------- */

@media (max-width: 980px) {
  body { overflow: auto; }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 56px minmax(320px, 52dvh) auto;
    height: auto;
    min-height: 100dvh;
  }

  .stage {
    grid-column: 1;
    grid-row: 2;
    padding: 12px 12px 0;
  }

  .side {
    grid-column: 1;
    grid-row: 3;
    padding: 12px;
    gap: 12px;
  }

  .players-card { flex: none; max-height: 420px; }

  .roster { max-height: 300px; }

  .topbar { padding: 0 12px; }
}

@media (max-width: 520px) {
  .switch-grid { grid-template-columns: 1fr; }
  .topbar-actions .age { display: none; }
  .field-row { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { transition-duration: 0.01ms !important; }
}
