/* ============ RESET & BIẾN ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0e14;
  --bg-panel:  #131820;
  --bg-panel2: #1a212c;
  --bg-panel3: #212a38;
  --border:    #262f3d;
  --border-2:  #38445a;
  --text:      #e6ebf2;
  --muted:     #8896ab;
  --muted-2:   #5d6b80;
  --accent:    #ef4444;
  --accent-2:  #f87171;
  --green:     #22c55e;
  --yellow:    #eab308;
  --blue:      #3b82f6;
  --radius:    14px;
  --radius-sm: 8px;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at top, #10161f 0%, #070a0f 70%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  padding: 24px 16px 60px;
  transition: background 0.6s ease;
}

/* Khi mức dàn xếp cao, nền đỏ nhẹ */
body[data-corruption="high"] {
  background: radial-gradient(ellipse at top, #1f0e12 0%, #070a0f 70%);
}
body[data-corruption="max"] {
  background: radial-gradient(ellipse at top, #2a0a0e 0%, #06080c 70%);
}

.wrap { max-width: 1180px; margin: 0 auto; }

/* ============ HEADER ============ */
header { text-align: center; margin-bottom: 26px; }

h1 {
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}
h1 .accent { color: var(--accent-2); }

.sub {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 720px;
  margin: 0 auto;
}
.sub strong { color: var(--yellow); }
.sub em { color: var(--muted-2); font-size: 0.85rem; }

/* ============ PANEL ============ */
.panel {
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.panel h2 {
  font-size: 1rem;
  margin-bottom: 14px;
  color: var(--text);
  letter-spacing: 0.2px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h2 { margin-bottom: 0; }

/* ============ BADGE ============ */
.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(34,197,94,0.15);
  color: var(--green);
  border: 1px solid rgba(34,197,94,0.35);
  transition: all 0.25s ease;
  white-space: nowrap;
}
.badge.warn {
  background: rgba(234,179,8,0.15);
  color: var(--yellow);
  border-color: rgba(234,179,8,0.4);
}
.badge.danger {
  background: rgba(239,68,68,0.18);
  color: var(--accent-2);
  border-color: rgba(239,68,68,0.5);
}

/* ============ SLIDER ============ */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green) 0%, var(--yellow) 45%, var(--accent) 100%);
  outline: none;
  margin: 6px 0 16px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  cursor: grab;
  transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.15); cursor: grabbing; }
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: grab;
}

/* ============ PRESETS ============ */
.presets {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px;
}
.presets button {
  flex: 1 1 auto; min-width: 80px;
  padding: 8px 12px;
  font-size: 0.82rem; font-weight: 600;
  color: var(--text);
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.18s ease;
}
.presets button:hover {
  background: var(--bg-panel3);
  border-color: var(--border-2);
  transform: translateY(-1px);
}

/* ============ HINT ============ */
.hint {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 10px 14px;
  background: rgba(255,255,255,0.03);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  margin-bottom: 16px;
  transition: color 0.25s, border-color 0.25s;
}

/* ============ ACTIONS ============ */
.actions-row {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.actions-row button {
  flex: 1 1 auto; min-width: 140px;
  padding: 12px 18px;
  font-size: 0.9rem; font-weight: 700;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.18s ease;
  letter-spacing: 0.2px;
}
.actions-row button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  background: var(--bg-panel3);
}
.actions-row button:disabled { opacity: 0.45; cursor: not-allowed; }
.actions-row button.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: var(--accent);
  color: #fff;
}
.actions-row button.primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(239,68,68,0.5);
}

/* ============ STATS ============ */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  text-align: center;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.stat .num {
  font-size: 1.7rem; font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}
.stat .lbl {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}
.stat.danger .num { color: var(--accent-2); }
.stat.warn   .num { color: var(--yellow); }
.stat.good   .num { color: var(--green); }

/* ============ CHAMPION BANNER ============ */
.champion {
  background: linear-gradient(90deg, rgba(234,179,8,0.2), rgba(239,68,68,0.2));
  border: 1px solid rgba(234,179,8,0.5);
  border-radius: var(--radius);
  padding: 16px 22px;
  margin-bottom: 18px;
  font-size: 1rem;
  text-align: center;
  animation: fadeInUp 0.5s ease;
}
.champion.hidden { display: none; }
.champion strong { color: var(--yellow); font-size: 1.1rem; }
.champion .dirty { color: var(--accent-2); font-weight: 700; }

/* ============ MAIN GRID ============ */
.main-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
  align-items: start;
}

/* ============ LEAGUE TABLE ============ */
.table-wrap { overflow-x: auto; }

table.league {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
table.league th {
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  padding: 6px 6px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
table.league th:nth-child(n+3),
table.league td:nth-child(n+3) { text-align: center; }

table.league td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
}
table.league tr:last-child td { border-bottom: none; }

table.league tr.top-1 td { background: rgba(234,179,8,0.06); }
table.league tr.top-1 td:first-child { box-shadow: inset 3px 0 0 var(--yellow); }
table.league tr.relegation td { background: rgba(239,68,68,0.05); }
table.league tr.relegation td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.team-cell {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600;
  white-space: nowrap;
}
.team-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.team-shield {
  font-size: 0.75rem;
  color: var(--accent-2);
  margin-left: 4px;
}

.pts     { font-weight: 800; color: var(--text); }
.dirty   { color: var(--accent-2); font-weight: 700; }
.pos     { color: var(--muted); font-weight: 700; }

/* ============ FIXTURES ============ */
.fixtures {
  max-height: 640px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;

  /* Firefox */
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

.fixtures > * {
  flex-shrink: 0;
}

.fixtures::-webkit-scrollbar {
  width: 8px;
}
.fixtures::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
}
.fixtures::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 4px;
}
.fixtures::-webkit-scrollbar-thumb:hover {
  background: #4a5877;
}

.matchday {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-panel2);
  flex-shrink: 0;
}
.matchday.latest { animation: fadeInUp 0.4s ease; }

.md-header {
  background: var(--bg-panel3);
  padding: 7px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.match {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: 0.86rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background 0.2s;
}
.match:last-child { border-bottom: none; }
.match:hover { background: rgba(255,255,255,0.025); }

.match.rigged {
  background: rgba(239,68,68,0.07);
  border-left: 3px solid var(--accent);
}
.match.rigged:hover { background: rgba(239,68,68,0.12); }

.match .team-home { text-align: right; }
.match .team-away { text-align: left; }

.match .team-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.match .score {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  background: rgba(0,0,0,0.35);
  padding: 3px 10px;
  border-radius: 6px;
  letter-spacing: 1px;
  white-space: nowrap;
}
.match.rigged .score {
  background: rgba(239,68,68,0.25);
  color: #fecaca;
}

.match .fix-flag {
  display: inline-block;
  margin-left: 6px;
  color: var(--accent-2);
  font-size: 0.75rem;
}

.fixtures .empty {
  text-align: center;
  color: var(--muted-2);
  font-size: 0.9rem;
  padding: 40px 12px;
  font-style: italic;
}

/* ============ GIẢI THÍCH ============ */
.explain .muted {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}
.explain .muted.small {
  font-size: 0.82rem;
  font-style: italic;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
  margin-top: 14px;
  line-height: 1.7;
}

.list { list-style: none; margin: 12px 0; }
.list li {
  padding: 8px 0 8px 26px;
  position: relative;
  font-size: 0.9rem;
  color: #cbd3e0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  line-height: 1.6;
}
.list li::before {
  content: "▸";
  position: absolute;
  left: 6px;
  color: var(--accent-2);
  font-weight: 900;
}
.list li:last-child { border-bottom: none; }
.list b { color: var(--text); }

/* ============ FOOTER ============ */
.foot {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 20px 8px 0;
  opacity: 0.75;
}

/* ============ ANIMATIONS ============ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ CHỌN ĐỘI VÔ ĐỊCH ============ */
.champion-pick {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.champion-pick label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.2px;
}

.champion-pick select {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

.champion-pick select:hover {
  border-color: var(--border-2);
  background-color: var(--bg-panel3);
}

.champion-pick select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.18);
}

.champion-pick select option {
  background: var(--bg-panel2);
  color: var(--text);
  font-weight: 500;
}

.pick-hint {
  font-size: 0.78rem;
  color: var(--muted-2);
  font-style: italic;
  margin-top: 2px;
}

.pick-hint.active {
  color: var(--yellow);
  font-style: normal;
  font-weight: 600;
}

/* ============ HÀO QUANG ĐỘI ĐƯỢC CHỌN ============ */
table.league tr.chosen td {
  background: rgba(234, 179, 8, 0.08);
}
table.league tr.chosen td:first-child {
  box-shadow: inset 3px 0 0 var(--yellow);
}
.team-crown {
  font-size: 0.8rem;
  filter: drop-shadow(0 0 3px rgba(234,179,8,0.8));
  margin-left: 2px;
}

/* Banner khi đội được chọn vô địch */
.champion.conspiracy {
  background: linear-gradient(90deg, rgba(234,179,8,0.25), rgba(239,68,68,0.25));
  border-color: rgba(234,179,8,0.7);
  box-shadow: 0 0 24px rgba(234,179,8,0.25);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 520px) {
  .actions-row button { min-width: 100%; }
  .presets button { flex: 1 1 calc(33.333% - 8px); min-width: 0; }
  .stat .num { font-size: 1.4rem; }
  table.league { font-size: 0.78rem; }
  table.league th:nth-child(3),
  table.league td:nth-child(3),
  table.league th:nth-child(4),
  table.league td:nth-child(4),
  table.league th:nth-child(5),
  table.league td:nth-child(5),
  table.league th:nth-child(6),
  table.league td:nth-child(6) { display: none; }
  .match { font-size: 0.78rem; padding: 8px; }
  .match .score { font-size: 0.85rem; padding: 2px 8px; }
}