@import url("https://fonts.googleapis.com/css2?family=Libre+Franklin:wght@400;500;600;700&display=swap");

:root {
  --bg: #ffffff;
  --surface: #f6f8fb;
  --panel: #ffffff;
  --panel-strong: #eef3f8;
  --text: #111111;
  --heading: #1a2840;
  --muted: #5c6f86;
  --accent: #2d8cf0;
  --accent-2: #195fae;
  --accent-soft: #dbe8f6;
  --border: #d4dde7;
  --shadow: rgba(17, 24, 39, 0.08);
  --error: #c53d36;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Libre Franklin", sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
  background: linear-gradient(180deg, #ffffff 0%, #f5f8fb 100%);
  accent-color: var(--accent);
}

button,
input,
select,
textarea {
  font: inherit;
}

.page {
  max-width: 1480px;
  margin: 0 auto;
  padding: 16px 24px 80px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 24px;
  padding: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 10px;
  color: var(--heading);
  font-size: 38px;
  line-height: 1.1;
  font-weight: 600;
}

h2 {
  margin: 0;
  color: var(--heading);
  font-size: 24px;
  line-height: 1.2;
  font-weight: 600;
}

h3,
h4,
h5,
h6 {
  margin: 0;
  color: var(--heading);
  font-weight: 600;
}

.subhead {
  max-width: 900px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.65;
}

.subhead-note {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 400;
}

.filters-block {
  margin-top: 0;
  display: grid;
  gap: 10px;
}

.mode-panel {
  display: inline-grid;
  gap: 8px;
  justify-items: start;
  width: fit-content;
  max-width: 100%;
}

.mode-options {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 12px 30px var(--shadow);
  width: fit-content;
  max-width: 100%;
  justify-items: start;
}

.mode-option {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 2px 0;
  width: fit-content;
  max-width: 100%;
}

.mode-option-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  color: var(--heading);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.mode-label {
  color: var(--heading);
  font-size: 14px;
  font-weight: 600;
}

.mode-option .info-btn {
  flex: 0 0 auto;
  margin-left: 0;
}

.mode-options .control-row {
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin: 0;
  width: fit-content;
  max-width: 100%;
}

.mode-options .control-row input[type="text"] {
  width: 150px;
}

.mode-options .hint {
  max-width: 340px;
}

.filters-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--heading);
  box-shadow: 0 10px 24px var(--shadow);
  letter-spacing: 0.01em;
  font-weight: 500;
}

.filter-button::after {
  content: ">";
  margin-left: 10px;
  color: var(--accent);
  font-size: 16px;
}

.filter-button:hover {
  background: var(--surface);
  border-color: #b8c7d8;
}

.info-btn {
  width: 16px;
  height: 16px;
  margin-left: 6px;
  padding: 0;
  border: 1px solid #b8c7d8;
  border-radius: 50%;
  background: #ffffff;
  color: var(--muted);
  font-size: 11px;
  line-height: 14px;
  cursor: pointer;
}

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

.tooltip {
  position: absolute;
  z-index: 80;
  max-width: 220px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 10px 24px var(--shadow);
  font-size: 11px;
}

.help-popover.hidden {
  display: none;
}

.help-popover {
  position: fixed;
  inset: 0;
  z-index: 90;
}

.help-popover-card {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: min(340px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  transform: translate(-50%, -50%) scale(0.98);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.help-popover.active .help-popover-card {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.help-popover-body {
  display: grid;
  gap: 10px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

.help-popover-body p,
.help-popover-body ol {
  margin: 0;
}

.help-popover-body ol {
  padding-left: 18px;
}

.help-popover-body code {
  font-size: 12px;
}

.help-popover-backdrop {
  position: absolute;
  inset: 0;
  background: transparent;
}

.control-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 12px 30px var(--shadow);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.control-card h2 {
  margin-bottom: 14px;
  font-size: 24px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 15px;
}

.control-row input[type="number"],
.control-row input[type="range"] {
  width: 120px;
}

.control-row input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
}

.is-hidden {
  display: none !important;
}

.toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #ffffff;
  cursor: pointer;
  font-size: 13px;
  color: var(--heading);
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

.window-info {
  margin-top: 8px;
  color: var(--heading);
  font-size: 13px;
}

.team-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.team-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding-right: 4px;
}

.team-block {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.team-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.team-header label,
.team-players label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--heading);
}

.team-players {
  display: grid;
  gap: 6px;
  max-height: 140px;
  margin-top: 8px;
  overflow: auto;
}

.team-players.collapsed {
  display: none;
}

button {
  font-family: inherit;
}

.primary {
  padding: 10px 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
}

.ghost {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  color: var(--heading);
  cursor: pointer;
}

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

.ghost:disabled,
.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ghost.tiny {
  padding: 4px 10px;
  font-size: 12px;
}

.ghost.active {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.overlay.hidden,
.modal.hidden {
  display: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}

.overlay-panel {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: min(520px, 90vw);
  height: 100%;
  padding: 16px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 12px 0 30px var(--shadow);
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  pointer-events: auto;
}

.overlay.active .overlay-panel {
  transform: translateX(0);
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: rgba(17, 24, 39, 0.22);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: auto;
}

.overlay.active .overlay-backdrop {
  opacity: 1;
}

.overlay-header,
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.error {
  margin-top: 10px;
  color: var(--error);
  font-size: 13px;
}

.results {
  margin-top: 24px;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.summary-line {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.team-chart-card {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 12px 30px var(--shadow);
}

.team-chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.pitch-card,
.table-card,
.modal-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 12px 30px var(--shadow);
}

.pitch-card,
.table-card {
  min-width: 0;
  height: 100%;
  padding: 16px;
}

.pitch-scroll {
  width: 100%;
  height: 100%;
}

.table-card {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.pitch {
  --line-gap: 8px;
  --chip-max-width: 112px;
  position: relative;
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  height: 100%;
  min-height: 520px;
  padding: 16px;
  border: 2px solid #d5f2dc;
  border-radius: 18px;
  background: linear-gradient(180deg, #1f7a4b 0%, #16613a 100%);
}

.pitch::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 8px;
}

.line {
  --player-count: 1;
  display: grid;
  align-items: center;
  grid-template-columns: repeat(
    var(--player-count),
    minmax(
      0,
      min(
        var(--chip-max-width),
        calc((100% - (var(--player-count) - 1) * var(--line-gap)) / var(--player-count))
      )
    )
  );
  justify-content: center;
  gap: var(--line-gap);
  z-index: 1;
}

.player-chip {
  position: relative;
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid rgba(26, 40, 64, 0.14);
  border-radius: 12px;
  background: #eef2f6;
  color: var(--text);
  box-shadow: 0 6px 18px rgba(17, 24, 39, 0.14);
  text-align: center;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.player-chip.interactive {
  cursor: pointer;
}

.player-chip.interactive::after,
tbody td:nth-child(2)::after {
  content: "Show stats";
  position: absolute;
  left: 50%;
  bottom: -22px;
  transform: translateX(-50%);
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--heading);
  box-shadow: 0 10px 24px var(--shadow);
  font-size: 10px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.player-chip.interactive:hover::after,
tbody tr:hover td:nth-child(2)::after {
  opacity: 1;
}

.player-chip .name {
  color: var(--accent-2);
  font-weight: 600;
}

.player-chip .meta {
  color: var(--text);
  font-size: 11px;
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  text-align: left;
  font-weight: 500;
  cursor: pointer;
}

thead th.sort-active {
  color: var(--accent);
}

tbody td {
  padding: 8px;
  border-bottom: 1px solid #edf2f7;
}

tbody td:nth-child(2) {
  position: relative;
  cursor: pointer;
}

.name-click {
  color: var(--accent-2);
  font-weight: 600;
  cursor: pointer;
}

.name-click:hover {
  color: var(--accent);
}

.table-role-info {
  vertical-align: middle;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
}

.modal-card {
  position: absolute;
  top: 8%;
  left: 50%;
  z-index: 2;
  width: min(720px, 92vw);
  max-height: calc(100vh - 32px);
  padding: 16px;
  transform: translateX(-50%);
  overflow-y: auto;
}

.modal-body {
  display: grid;
  gap: 10px;
}

.player-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #fbfdff 0%, #f3f7fb 100%);
}

.player-summary-item {
  min-width: 0;
}

.player-summary-label {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.player-summary-value {
  color: var(--heading);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.recommendations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.recommendation-block {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #fbfdff 0%, #f4f8fc 100%);
}

.transfer-list {
  display: grid;
  gap: 10px;
}

.transfer-item {
  padding: 10px 0;
  border-top: 1px solid #e3ebf4;
}

.transfer-item:first-child {
  border-top: none;
  padding-top: 0;
}

.transfer-head {
  color: var(--heading);
  font-size: 14px;
  font-weight: 600;
}

.transfer-meta {
  color: var(--muted);
  font-size: 12px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.28);
}

.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend .dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend .dot.actual {
  background: #2d8cf0;
}

.legend .dot.predicted {
  background: #62d2a2;
}

.legend .dot.window {
  background: #cbd8e6;
}

.chart-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pinch-zoom;
}

.chart {
  width: max-content;
  min-width: 100%;
  box-sizing: border-box;
}

.chart-canvas {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-width: 640px;
  min-height: 260px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fafd 100%);
}

.chart svg {
  display: block;
}

@media (max-width: 1180px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .controls-grid,
  .grid {
    grid-template-columns: 1fr;
  }

  .team-chart-head {
    flex-direction: column;
  }
}

@media (max-width: 900px) {
  .page {
    padding: 16px 16px 64px;
  }

  h1 {
    font-size: 32px;
  }

  .control-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .control-row input[type="number"],
  .control-row input[type="range"] {
    width: 100%;
  }

  .pitch-card {
    padding: 6px;
  }

  .pitch {
    width: 92vw;
    max-width: 100%;
    --line-gap: 6px;
    --chip-max-width: 96px;
    margin: 0 auto;
    gap: 6px;
  }

  .pitch::before {
    inset: 10%;
  }

  .line {
    gap: var(--line-gap);
  }

  .player-chip {
    padding: 6px 8px;
    font-size: 11px;
  }
}

@media (max-width: 390px) {
  .pitch-card {
    padding: 4px;
  }

  .pitch-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pinch-zoom;
  }

  .pitch {
    width: 100%;
    min-height: 430px;
    --line-gap: 4px;
    --chip-max-width: 84px;
    padding: 10px 8px;
  }

  .player-chip {
    padding: 5px 4px;
    border-radius: 10px;
    font-size: 10px;
  }

  .player-chip .name {
    line-height: 1.2;
  }

  .player-chip .meta {
    display: none;
  }

  .player-summary {
    grid-template-columns: 1fr 1fr;
    padding: 10px;
  }

  .player-summary-value {
    font-size: 13px;
  }
}
