/* ==========================================================================
   CrowGoal — design tokens & custom styles
   Tailwind (via CDN) handles layout utilities; this file owns brand,
   the pitch/builder visuals, and anything Tailwind can't express cleanly.
   ========================================================================== */

:root {
  /* Color */
  --cg-bg:          #0C1512;   /* deep charcoal-green, not pure black */
  --cg-surface:     #121E19;
  --cg-surface-2:   #17251F;
  --cg-glass:       rgba(255, 255, 255, 0.045);
  --cg-glass-brd:   rgba(255, 255, 255, 0.09);
  --cg-primary:     #3ECB7E;   /* pitch green */
  --cg-primary-ink: #0C1512;
  --cg-amber:       #F2B134;
  --cg-danger:      #E5595F;
  --cg-text:        #F3F5F2;
  --cg-text-muted:  #94A39B;
  --cg-border:      rgba(255, 255, 255, 0.08);

  --cg-font-display: "Big Shoulders Display", "Inter", system-ui, sans-serif;
  --cg-font-body: "Inter", system-ui, -apple-system, sans-serif;

  --cg-radius-sm: 10px;
  --cg-radius-md: 16px;
  --cg-radius-lg: 24px;
  --cg-shadow-soft: 0 12px 30px -14px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

body.cg-body {
  background: var(--cg-bg);
  color: var(--cg-text);
  font-family: var(--cg-font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--cg-primary); color: var(--cg-primary-ink);
  padding: 10px 16px; border-radius: 0 0 8px 0; z-index: 100; font-weight: 600;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--cg-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

h1, h2, h3, .font-display {
  font-family: var(--cg-font-display);
  letter-spacing: 0.01em;
  line-height: 1;
}

.h1 { font-size: clamp(2.4rem, 6vw, 4.5rem); font-weight: 700; color: var(--cg-text); }
.h2 { font-size: clamp(1.75rem, 3.6vw, 2.6rem); font-weight: 700; }
.h3 { font-size: clamp(1.25rem, 2.4vw, 1.6rem); font-weight: 700; }
.lead { color: var(--cg-text-muted); font-size: clamp(1rem, 1.6vw, 1.2rem); max-width: 60ch; }
.eyebrow-plain { color: var(--cg-text-muted); font-size: 0.9rem; margin-bottom: 0.5rem; }

a { color: inherit; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; border-radius: 999px; padding: 0.85rem 1.6rem;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  text-decoration: none; cursor: pointer; border: 1px solid transparent; font-size: 0.98rem;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--cg-primary); color: var(--cg-primary-ink); }
.btn--primary:hover { background: #4ee092; }
.btn--ghost { background: transparent; border-color: var(--cg-glass-brd); color: var(--cg-text); }
.btn--ghost:hover { border-color: var(--cg-primary); }
.btn--danger { background: transparent; border-color: var(--cg-danger); color: var(--cg-danger); }
.btn--danger:hover { background: rgba(229, 89, 95, 0.12); }
.btn--sm { padding: 0.5rem 1.1rem; font-size: 0.88rem; }
.btn--icon { padding: 0.55rem; border-radius: 10px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Header / nav ---- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(12, 21, 18, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--cg-border);
}
.site-header__inner {
  max-width: 1280px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand__word { font-family: var(--cg-font-display); font-weight: 700; font-size: 1.3rem; color: var(--cg-text); }
.site-nav { display: none; gap: 28px; }
.nav-link { color: var(--cg-text-muted); font-weight: 500; text-decoration: none; }
.nav-link:hover, .nav-link--active { color: var(--cg-text); }
.site-header__actions { display: flex; align-items: center; gap: 10px; }
.menu-toggle { background: none; border: 1px solid var(--cg-glass-brd); color: var(--cg-text); border-radius: 10px; padding: 8px; }

@media (min-width: 860px) {
  .site-nav { display: flex; }
  .menu-toggle { display: none; }
}

.mobile-menu { display: flex; flex-direction: column; border-top: 1px solid var(--cg-border); padding: 10px 20px 16px; }
.mobile-menu a { padding: 12px 0; border-bottom: 1px solid var(--cg-border); color: var(--cg-text); text-decoration: none; }
.mobile-menu a:last-child { border-bottom: none; }
.mobile-menu[hidden] { display: none; }

/* ---- Sections ---- */
.section { max-width: 1280px; margin: 0 auto; padding: 64px 20px; }
.section--center { text-align: center; display: flex; flex-direction: column; align-items: center; padding: 120px 20px; }
.cta-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 1.75rem; }

.glass-card {
  background: var(--cg-glass);
  border: 1px solid var(--cg-glass-brd);
  border-radius: var(--cg-radius-md);
  box-shadow: var(--cg-shadow-soft);
}

/* ---- Formation preview chips (homepage / formations grid) ---- */
.formation-card {
  background: var(--cg-surface);
  border: 1px solid var(--cg-border);
  border-radius: var(--cg-radius-md);
  padding: 18px;
  text-decoration: none;
  color: var(--cg-text);
  display: flex; flex-direction: column; gap: 12px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.formation-card:hover { border-color: var(--cg-primary); transform: translateY(-2px); }
.formation-card__pitch { aspect-ratio: 3/4; border-radius: 12px; background: linear-gradient(180deg, #14261f, #0e1a16); position: relative; overflow: hidden; }
.formation-card__dot { position: absolute; width: 8%; aspect-ratio: 1; background: var(--cg-primary); border-radius: 50%; transform: translate(-50%, -50%); }
.formation-card__name { font-family: var(--cg-font-display); font-weight: 700; font-size: 1.15rem; }

/* ==========================================================================
   BUILDER
   ========================================================================== */
.builder-shell {
  display: flex; flex-direction: column;
  min-height: calc(100vh - 62px);
}

.builder-topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--cg-border);
  background: var(--cg-surface);
  position: sticky; top: 62px; z-index: 20;
}
.builder-topbar select, .builder-topbar input[type=text] {
  background: var(--cg-surface-2); border: 1px solid var(--cg-border); color: var(--cg-text);
  border-radius: 10px; padding: 8px 10px; font-size: 0.9rem;
}
.builder-topbar .spacer { flex: 1; }

.builder-main {
  display: grid; grid-template-columns: 1fr; gap: 0; flex: 1; min-height: 0;
}
@media (min-width: 1024px) {
  .builder-main { grid-template-columns: 260px 1fr 300px; }
}

.builder-panel {
  border-right: 1px solid var(--cg-border);
  background: var(--cg-surface);
  padding: 16px;
  overflow-y: auto;
}
.builder-panel--right { border-right: none; border-left: 1px solid var(--cg-border); }
.panel-heading { font-family: var(--cg-font-display); font-weight: 700; font-size: 1rem; margin-bottom: 10px; color: var(--cg-text-muted); text-transform: none; }

.pitch-column { display: flex; flex-direction: column; min-height: 0; }

.pitch-wrap {
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: radial-gradient(circle at 50% 0%, #0f1d18, var(--cg-bg));
  min-height: 420px;
}

.pitch {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 68/100;
  border-radius: 16px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  box-shadow: 0 20px 50px -20px rgba(0,0,0,0.7);
}
.pitch--classic { background: repeating-linear-gradient(180deg, #1c3a2a 0 10%, #1a3527 10% 20%); }
.pitch--dark { background: linear-gradient(180deg, #0f1d17, #0a1512); }
.pitch--tactical { background: #0d1712; }
.pitch--minimal { background: #10201a; }

.pitch-lines { position: absolute; inset: 0; pointer-events: none; }

.pitch-player {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: grab;
  touch-action: none;
  width: 15%;
  z-index: 2;
}
.pitch-player.is-dragging { cursor: grabbing; z-index: 10; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5)); }
.pitch-player.is-selected .pitch-player__marker { outline: 2px solid var(--cg-primary); outline-offset: 2px; }

.pitch-player__marker {
  width: 100%; aspect-ratio: 1; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; color: #fff;
  background: var(--kit-primary, #2e7d4f);
  border: 2px solid rgba(255,255,255,0.6);
  position: relative;
}
.pitch-player__marker .captain-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--cg-amber); color: #201502;
  font-size: 0.55rem; font-weight: 800; border-radius: 50%;
  width: 15px; height: 15px; display: flex; align-items: center; justify-content: center;
}
.pitch-player__name {
  font-size: 0.6rem; color: #fff; background: rgba(0,0,0,0.55);
  padding: 1px 5px; border-radius: 6px; white-space: nowrap; max-width: 90px; overflow: hidden; text-overflow: ellipsis;
}
.pitch-player--jersey .pitch-player__marker { border-radius: 8px; }
.pitch-player--pro .pitch-player__marker { border-radius: 12px; border-width: 3px; box-shadow: 0 4px 10px rgba(0,0,0,0.4); }

.bench-row { display: flex; gap: 10px; overflow-x: auto; padding: 10px 14px; border-top: 1px solid var(--cg-border); background: var(--cg-surface); }
.bench-slot { flex: 0 0 auto; width: 64px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bench-slot__marker {
  width: 44px; height: 44px; border-radius: 50%; background: var(--cg-surface-2);
  border: 1.5px dashed var(--cg-border); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; color: var(--cg-text-muted); cursor: grab;
}
.bench-slot__marker.filled { border-style: solid; color: #fff; background: var(--kit-primary, #2e7d4f); }
.bench-slot__name { font-size: 0.62rem; color: var(--cg-text-muted); text-align: center; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.field-row { margin-bottom: 14px; }
.field-row label { display: block; font-size: 0.8rem; color: var(--cg-text-muted); margin-bottom: 4px; }
.field-row input[type=text], .field-row select {
  width: 100%; background: var(--cg-surface-2); border: 1px solid var(--cg-border); color: var(--cg-text);
  border-radius: 10px; padding: 9px 10px; font-size: 0.9rem;
}
.field-row input[type=color] { width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--cg-border); background: var(--cg-surface-2); padding: 3px; }
.swatch-row { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; }
.swatch.is-active { border-color: var(--cg-primary); }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 12px; border-radius: 999px; font-size: 0.8rem; border: 1px solid var(--cg-border);
  background: var(--cg-surface-2); color: var(--cg-text-muted); cursor: pointer;
}
.chip.is-active { background: var(--cg-primary); color: var(--cg-primary-ink); border-color: var(--cg-primary); font-weight: 600; }

/* mobile bottom sheet for player/team/kit/pitch controls */
.bottom-sheet-tabs { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; background: var(--cg-surface); border-top: 1px solid var(--cg-border); }
.bottom-sheet-tabs button { flex: 0 0 auto; }
.bottom-sheet { display: none; }

@media (max-width: 1023px) {
  .builder-panel--right, .builder-panel--left { display: none; }
  .bottom-sheet {
    display: block;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--cg-surface);
    border-top: 1px solid var(--cg-border);
    border-radius: 20px 20px 0 0;
    max-height: 62vh; overflow-y: auto;
    padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
    transform: translateY(100%); transition: transform 0.22s ease;
  }
  .bottom-sheet.is-open { transform: translateY(0); }
  .bottom-sheet__backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 25;
  }
  .bottom-sheet__backdrop.is-open { display: block; }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  background: var(--cg-surface-2); border: 1px solid var(--cg-border);
  color: var(--cg-text); padding: 10px 18px; border-radius: 999px; font-size: 0.88rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60; box-shadow: var(--cg-shadow-soft);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

.saved-card {
  border: 1px solid var(--cg-border); border-radius: 12px; padding: 12px; background: var(--cg-surface-2);
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px;
}
.saved-card__row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.saved-card__actions { display: flex; gap: 6px; flex-wrap: wrap; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 70; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.is-open { display: flex; }
.modal { background: var(--cg-surface); border: 1px solid var(--cg-border); border-radius: 16px; padding: 20px; width: 100%; max-width: 380px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

.site-footer { border-top: 1px solid var(--cg-border); background: var(--cg-surface); margin-top: 40px; }
.site-footer__inner { max-width: 1280px; margin: 0 auto; padding: 40px 20px; display: flex; flex-wrap: wrap; gap: 24px; justify-content: space-between; align-items: flex-start; }
.site-footer__links { display: flex; flex-wrap: wrap; gap: 18px; }
.site-footer__links a { color: var(--cg-text-muted); text-decoration: none; font-size: 0.9rem; }
.site-footer__links a:hover { color: var(--cg-text); }
.site-footer__copy { width: 100%; color: var(--cg-text-muted); font-size: 0.8rem; margin-top: 10px; }
