/* ==========================================================================
   KM Tracker — Design System (app.css)
   Clean & modern, Todoist-like. Mobile-first. Light + dark via
   prefers-color-scheme. All colors are CSS custom properties: light values
   live in :root, dark overrides in the media query at the bottom.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Color palette — light */
  --color-bg: #f7f8fa;            /* page background */
  --color-surface: #ffffff;       /* cards, raised surfaces */
  --color-surface-2: #f1f2f4;     /* subtle fills (hover, inputs) */
  --color-border: #e3e5e8;        /* hairline borders */
  --color-border-strong: #d2d5da; /* stronger borders (inputs, focus base) */
  --color-text: #1f2329;          /* primary text */
  --color-muted: #6b7280;         /* secondary / subtitle text */
  --color-faint: #9aa0a8;         /* tertiary text (hints, meta) */

  /* Accent — themeable via [data-theme] on <html>. Default = violet.
     Destructive actions use --color-danger (below), NOT the accent. */
  --color-accent: #7c3aed;        /* single accent (violet, default) */
  --color-accent-hover: #6d28d9;  /* accent on hover/active */
  --color-accent-contrast: #ffffff; /* text/icon on accent */
  --color-accent-soft: #ede9fe;   /* tinted accent surface (badges) */
  --color-accent-gradient: var(--color-accent); /* primary button bg (gradient themes override) */

  --color-danger: #d1453b;
  --color-danger-soft: #fdecea;
  --color-success: #2e8b57;
  --color-success-soft: #e7f4ec;
  --color-info: #2563c9;
  --color-info-soft: #e8f0fd;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter,
    system-ui, "Helvetica Neue", Arial, sans-serif;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  /* Border radius scale */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06),
    0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 2px 4px rgba(16, 24, 40, 0.06),
    0 4px 12px rgba(16, 24, 40, 0.08);

  /* Layout */
  --content-width: 520px;

  /* Motion */
  --transition: 140ms ease;

  /* Line Finder series colors — one per cup format. Fixed (not accent-themed)
     so the three formats stay distinguishable under every accent; dark
     values below. */
  --lf-wii: #2a78d6;
  --lf-switch: #e0602a;
  --lf-mixed: #159c6c;
}

/* ---------- Accent themes (light) ----------
   Each theme overrides only the accent variables via [data-theme] on <html>.
   violet is the default (already set in :root). Dark overrides live in the
   prefers-color-scheme: dark block below, mirroring these. */
[data-theme="violet"] {
  --color-accent: #7c3aed;
  --color-accent-hover: #6d28d9;
  --color-accent-soft: #ede9fe;
  --color-accent-gradient: var(--color-accent);
}
[data-theme="indigo"] {
  --color-accent: #4f46e5;
  --color-accent-hover: #4338ca;
  --color-accent-soft: #e0e7ff;
  --color-accent-gradient: var(--color-accent);
}
[data-theme="ocean"] {
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-accent-soft: #dbeafe;
  --color-accent-gradient: var(--color-accent);
}
[data-theme="teal"] {
  --color-accent: #0d9488;
  --color-accent-hover: #0f766e;
  --color-accent-soft: #ccfbf1;
  --color-accent-gradient: var(--color-accent);
}
[data-theme="emerald"] {
  --color-accent: #059669;
  --color-accent-hover: #047857;
  --color-accent-soft: #d1fae5;
  --color-accent-gradient: var(--color-accent);
}
[data-theme="rose"] {
  --color-accent: #db2777;
  --color-accent-hover: #be185d;
  --color-accent-soft: #fce7f3;
  --color-accent-gradient: var(--color-accent);
}
[data-theme="aurora"] {
  --color-accent: #8b5cf6;
  --color-accent-hover: #7c3aed;
  --color-accent-soft: rgba(139, 92, 246, 0.16);
  --color-accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
}
[data-theme="sunset"] {
  --color-accent: #f43f5e;
  --color-accent-hover: #e11d48;
  --color-accent-soft: rgba(244, 63, 94, 0.14);
  --color-accent-gradient: linear-gradient(135deg, #f97316 0%, #db2777 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #15171a;
    --color-surface: #1e2024;
    --color-surface-2: #26292e;
    --color-border: #2e3238;
    --color-border-strong: #3a3f46;
    --color-text: #e8eaed;
    --color-muted: #a0a6ae;
    --color-faint: #767c85;

    --color-accent: #8b5cf6;
    --color-accent-hover: #a78bfa;
    --color-accent-contrast: #ffffff;
    --color-accent-soft: rgba(139, 92, 246, 0.18);

    --color-danger: #f4675c;
    --color-danger-soft: #3a1f1d;
    --color-success: #4ec07e;
    --color-success-soft: #16291f;
    --color-info: #6fa3f5;
    --color-info-soft: #19222f;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.35), 0 6px 16px rgba(0, 0, 0, 0.4);

    --lf-wii: #4d94ea;
    --lf-switch: #f07a48;
    --lf-mixed: #2fbf8a;
  }

  /* Accent themes — dark overrides (mirror the light [data-theme] blocks).
     --color-accent-contrast stays #fff (set in dark :root above). */
  [data-theme="violet"] {
    --color-accent: #8b5cf6;
    --color-accent-hover: #a78bfa;
    --color-accent-soft: rgba(139, 92, 246, 0.18);
    --color-accent-gradient: var(--color-accent);
  }
  [data-theme="indigo"] {
    --color-accent: #6366f1;
    --color-accent-hover: #818cf8;
    --color-accent-soft: rgba(99, 102, 241, 0.18);
    --color-accent-gradient: var(--color-accent);
  }
  [data-theme="ocean"] {
    --color-accent: #3b82f6;
    --color-accent-hover: #60a5fa;
    --color-accent-soft: rgba(59, 130, 246, 0.18);
    --color-accent-gradient: var(--color-accent);
  }
  [data-theme="teal"] {
    --color-accent: #14b8a6;
    --color-accent-hover: #2dd4bf;
    --color-accent-soft: rgba(20, 184, 166, 0.18);
    --color-accent-gradient: var(--color-accent);
  }
  [data-theme="emerald"] {
    --color-accent: #10b981;
    --color-accent-hover: #34d399;
    --color-accent-soft: rgba(16, 185, 129, 0.18);
    --color-accent-gradient: var(--color-accent);
  }
  [data-theme="rose"] {
    --color-accent: #ec4899;
    --color-accent-hover: #f472b6;
    --color-accent-soft: rgba(236, 72, 153, 0.18);
    --color-accent-gradient: var(--color-accent);
  }
  [data-theme="aurora"] {
    --color-accent: #a78bfa;
    --color-accent-hover: #c4b5fd;
    --color-accent-soft: rgba(167, 139, 250, 0.18);
    --color-accent-gradient: linear-gradient(135deg, #a78bfa 0%, #22d3ee 100%);
  }
  [data-theme="sunset"] {
    --color-accent: #fb7185;
    --color-accent-hover: #fda4af;
    --color-accent-soft: rgba(251, 113, 133, 0.18);
    --color-accent-gradient: linear-gradient(135deg, #fb923c 0%, #f472b6 100%);
  }
}

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

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--color-accent-hover);
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- Layout ---------- */
.page {
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-7);
}

/* ---------- Header ---------- */
.page-header {
  margin-bottom: var(--space-5);
}

.page-header h1,
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.subtitle,
.page-subtitle {
  color: var(--color-muted);
  font-size: 0.95rem;
  margin-top: var(--space-1);
}

/* Back-link ("← Home") */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-muted);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: var(--space-3);
  transition: color var(--transition);
}

.back-link:hover {
  color: var(--color-text);
}

/* Section headings within a page */
.section-heading {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-faint);
  margin: var(--space-5) 0 var(--space-2);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.btn:hover {
  background: var(--color-border);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none; /* no hover/active treatment while disabled */
}

.btn-primary {
  background: var(--color-accent-gradient);
  color: var(--color-accent-contrast);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  /* brightness works for both solid and gradient accent backgrounds */
  filter: brightness(1.07);
  color: var(--color-accent-contrast);
}

.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.btn-secondary:hover {
  background: var(--color-surface-2);
}

.btn-danger {
  background: transparent;
  border-color: var(--color-border-strong);
  color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger-soft);
  border-color: var(--color-danger);
}

/* Small / ghost size — for inline row actions */
.btn-sm {
  min-height: 36px;
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
}

.btn-ghost {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}

.btn-ghost:hover {
  background: var(--color-surface-2);
}

/* Full-width block button (large CTA) */
.btn-block {
  display: flex;
  width: 100%;
  min-height: 52px;
  font-size: 1.1rem;
}

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}

.card + .card {
  margin-top: var(--space-3);
}

/* ---------- Lists (list rows) ---------- */
.list {
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  min-height: 56px;
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item:hover {
  background: var(--color-surface-2);
}

/* Left side content of a row */
.list-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.list-title {
  font-size: 1.05rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.list-meta {
  font-size: 0.85rem;
  color: var(--color-muted);
}

/* Right side actions of a row */
.list-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* A list row whose entire area is a single link.
   The anchor carries the row's padding and stretches to fill the row, so the
   WHOLE row is clickable — not just the link text. Visuals are unchanged: the
   anchor inherits the same padding / min-height the row previously held.
   Use only for single-action rows; multi-action rows keep .list-actions. */
.list-item-link {
  padding: 0;
}

.list-item-link > a {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
  min-height: 56px;
  padding: var(--space-3) var(--space-4);
}

/* Vertical stack of full-width actions (e.g. home CTAs / nav) */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  color: var(--color-muted);
}

.badge-line {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.badge-status {
  background: var(--color-success-soft);
  color: var(--color-success);
}

.badge-info {
  background: var(--color-info-soft);
  color: var(--color-info);
}

/* ---------- Forms ---------- */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field-row {
  display: flex;
  gap: var(--space-2);
}

.field-row > * {
  flex: 1;
}

label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text);
}

/* Inline checkbox label */
.check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  min-height: 36px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.75rem;
  min-height: 44px;
  transition: border-color var(--transition), box-shadow var(--transition),
    background var(--transition);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-faint);
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--color-accent);
  cursor: pointer;
}

/* ---------- Flash messages ---------- */
.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  font-size: 0.92rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.flash-error {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.flash-success {
  background: var(--color-success-soft);
  color: var(--color-success);
  border-color: var(--color-success);
}

.flash-info {
  background: var(--color-info-soft);
  color: var(--color-info);
  border-color: var(--color-info);
}

.flashes {
  margin-bottom: var(--space-4);
}

/* ---------- Photo attach indicator (score forms) ---------- */
/* Prominent success/error state for the async photo attach — the muted
   .photo-status line is for extraction progress, not attach outcome. */
.photo-attach-status {
  display: inline-block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  margin-top: var(--space-2);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-muted);
}

.photo-attach-status.is-success {
  background: var(--color-success-soft);
  color: var(--color-success);
  border-color: var(--color-success);
}

.photo-attach-status.is-error {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* The author display rule above would otherwise beat the UA [hidden] rule. */
.photo-attach-status[hidden] {
  display: none;
}

/* Extraction-in-flight spinner — sits inline beside the .photo-status text
   while the /extract-scores fetch is running (photo_score.js toggles the
   hidden attribute). Pure CSS animation; static ring under reduced motion. */
.photo-extract-spinner {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  vertical-align: -0.1em;
  margin-right: var(--space-1);
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: photo-extract-spin 0.8s linear infinite;
}

/* The author display rule above would otherwise beat the UA [hidden] rule. */
.photo-extract-spinner[hidden] {
  display: none;
}

@keyframes photo-extract-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .photo-extract-spinner {
    animation: none;
    border-color: var(--color-accent); /* solid accent ring, no motion */
  }
}

/* ---------- Photo mix-and-match mapping panel ---------- */
/* After extraction, one dropdown per roster player mapping them to the
   highlighted (human) rows the model read off the photo, so mis-matches are
   easy to correct before submit. photo_score.js populates + toggles this. */
.photo-mapping {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}

.photo-mapping[hidden] {
  display: none;
}

.photo-mapping-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: var(--space-2);
}

.photo-map-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.photo-map-name {
  flex: 1;
  font-size: 0.9rem;
}

.photo-map-select {
  flex: 1;
  max-width: 60%;
}

/* Read-only reference rows (partial-half photo — a mixed cup). No control,
   no write path: this is a transcription of what the model read, nothing more. */
.photo-map-readonly {
  font-size: 0.9rem;
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

/* Informational banners inside the panel. */
.photo-map-warning,
.photo-map-unassigned {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--color-danger-soft);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.photo-map-warning[hidden],
.photo-map-unassigned[hidden] {
  display: none;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  color: var(--color-muted);
  font-size: 0.95rem;
  padding: var(--space-6) var(--space-4);
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
}

/* ---------- Table (standings / score lists) ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  font-size: 0.95rem;
}

.table th,
.table td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-faint);
  font-weight: 600;
}

.table tr:last-child td {
  border-bottom: none;
}

.table td.num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Utilities ---------- */
.muted {
  color: var(--color-muted);
}

.text-faint {
  color: var(--color-faint);
}

.mt-4 {
  margin-top: var(--space-4);
}

.mb-4 {
  margin-bottom: var(--space-4);
}

/* ---------- Theme picker ---------- */
.theme-picker {
  position: fixed;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 50;
}

/* Circular palette trigger — shows the current accent */
.theme-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition),
    border-color var(--transition);
}

.theme-trigger:hover {
  box-shadow: var(--shadow-md);
}

.theme-trigger:active {
  transform: translateY(1px);
}

/* The colored dot inside the trigger reflects the active accent */
.theme-trigger-dot {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--color-accent-gradient);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

/* Popover menu */
.theme-menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  width: max-content;
  max-width: calc(100vw - 2 * var(--space-3));
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.theme-menu[hidden] {
  display: none;
}

.theme-menu-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-faint);
  margin-bottom: var(--space-2);
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}

/* Each theme option: a swatch button */
.theme-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  background: var(--color-surface-2);
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
}

.theme-option:hover {
  transform: translateY(-1px);
}

.theme-swatch {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-pill);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

/* Active theme gets a ring + check */
.theme-option[aria-pressed="true"] {
  border-color: var(--color-accent);
}

.theme-option[aria-pressed="true"] .theme-swatch {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12),
    0 0 0 2px var(--color-surface), 0 0 0 4px var(--color-accent);
}

/* ---------- Line Finder (/line-finder) ---------- */
/* A read-only analysis page: controls card, three format tiles, an inline-SVG
   win-% chart with a hover tooltip, per-line tables and a few insight cards.
   Series colors are the --lf-* tokens above; everything else reuses the
   design-system tokens. The page must read on a 390px phone: nothing here
   may widen the content column — wide tables scroll inside .lf-table-wrap. */
.line-finder {
  min-width: 0;
}

.lf-controls {
  gap: var(--space-3);
}

.lf-checks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
}

.lf-range-field label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.lf-range-field output {
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--color-accent);
  cursor: pointer;
  min-height: 32px;
}

.lf-range-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--color-faint);
}

.lf-status {
  font-size: 0.85rem;
  margin: 0;
}

.lf-status[hidden],
.lf-empty[hidden],
#lf-body[hidden],
.lf-tip[hidden] {
  display: none;
}

.lf-empty {
  margin-top: var(--space-4);
}

/* Tiles: one per format. Stack on phones, three across when there's room. */
.lf-tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

@media (min-width: 480px) {
  .lf-tiles {
    grid-template-columns: repeat(3, 1fr);
  }
}

.lf-tile {
  position: relative;
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3) var(--space-4);
  min-width: 0;
}

.lf-tile::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--c);
}

.lf-tile-k {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}

.lf-tile-k i,
.lf-tip-r i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
  display: inline-block;
  flex-shrink: 0;
}

.lf-tile-v {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.15;
  margin: var(--space-1) 0;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.lf-tile-v-na {
  color: var(--color-faint);
}

.lf-tile-sub {
  font-size: 0.85rem;
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.lf-tile-n {
  margin-top: var(--space-2);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--color-muted);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.lf-tile-n div:first-child {
  color: var(--color-text);
}

/* Chart card, legend, tooltip */
.lf-chart-card {
  padding: var(--space-3);
}

.lf-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-bottom: var(--space-2);
}

.lf-legend span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.lf-legend b {
  display: inline-block;
  width: 16px;
  height: 0;
  border-top: 3px solid var(--c);
  border-radius: 2px;
}

.lf-legend b.lf-dash {
  border-top-style: dashed;
  border-top-width: 2px;
}

.lf-figure {
  margin: 0;
  position: relative;
}

.lf-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
  touch-action: pan-y;
}

.lf-svg text {
  font-family: var(--font-sans);
  font-size: 11px;
  fill: var(--color-muted);
}

.lf-svg .lf-axis {
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.lf-svg .lf-cap {
  font-size: 9.5px;
  fill: var(--color-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.lf-svg .lf-lbl {
  font-size: 11.5px;
  font-weight: 600;
  fill: var(--color-text);
  paint-order: stroke;
  stroke: var(--color-surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.lf-tip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  min-width: 170px;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 0.8rem;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

.lf-tip-h {
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 2px;
}

.lf-tip-r {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--color-muted);
}

.lf-tip-r span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.lf-tip-r em {
  font-style: normal;
  color: var(--color-text);
  white-space: nowrap;
}

.lf-note {
  font-size: 0.82rem;
  color: var(--color-muted);
  margin-top: var(--space-3);
  line-height: 1.45;
}

.lf-note-top {
  margin-top: 0;
  margin-bottom: var(--space-3);
}

/* Format tabs above the per-line table */
.lf-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.lf-tab {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.lf-tab::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
  margin-right: var(--space-2);
  vertical-align: 0;
}

.lf-tab[aria-selected="true"] {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* Tables — scroll inside their own box, never the page */
.lf-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.lf-table {
  min-width: 100%;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.lf-table th,
.lf-table td {
  padding: var(--space-2) var(--space-3);
  white-space: nowrap;
}

.lf-table-sm {
  font-size: 0.82rem;
}

.lf-table-sm th,
.lf-table-sm td {
  padding: var(--space-1) var(--space-2);
}

.lf-table tr.lf-rec td {
  background: var(--color-accent-soft);
  font-weight: 600;
}

/* Actual / fitted columns follow the checkboxes */
.lf-hide-actual .lf-col-actual,
.lf-hide-fitted .lf-col-fitted {
  display: none;
}

.lf-details {
  margin-top: var(--space-3);
}

.lf-details summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: var(--space-2);
}

/* Backtest summary: four short columns that must fit a phone without
   scrolling, so every cell may wrap; tallies list one outcome per line. */
.lf-table-summary th,
.lf-table-summary td {
  white-space: normal;
  vertical-align: top;
  padding: var(--space-2);
}

.lf-tally {
  display: inline-block;
  text-align: right;
  line-height: 1.35;
}
