:root {
  --bg: #313338;
  --panel: #2b2d31;
  --panel-soft: #383a40;
  --text: #f2f3f5;
  --muted: #b5bac1;
  --border: #1e1f22;
  --accent: #5865f2;
  --win: #3ba55d;
  --loss: #ed4245;
  --dota: #9aa341;
  --valorant: #ff4655;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #2b2d31;
  border-bottom: 1px solid var(--border);
}

.header-content {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
  font-weight: 700;
}

.subtitle,
.muted,
footer {
  color: var(--muted);
}

.subtitle {
  margin-top: 5px;
  font-size: 14px;
}

.stat-pill,
.result-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #45474f;
  background: #232428;
  color: var(--muted);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.stat-pill span:first-child {
  color: var(--text);
  font-weight: 700;
}

main {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.toolbar-panel {
  background: var(--panel);
  border: 1px solid #404249;
  border-radius: 12px;
  margin-bottom: 22px;
  overflow: hidden;
}

.toolbar-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  background: rgba(40, 42, 48, 0.98);
  border-bottom: 1px solid #404249;
}

.toolbar-panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.toolbar-panel-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#toggle-filters {
  background: #3a3c43;
  border-color: #3a3c43;
}

.toolbar-panel.collapsed .toolbar {
  display: none;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  padding: 18px 20px 20px;
}

.toolbar-column {
  display: grid;
  gap: 12px;
}

.toolbar-column--filters {
  display: grid;
  gap: 12px;
}

.toolbar-column--players {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field-date-range .flatpickr-input {
  cursor: pointer;
}

.flatpickr-day.has-matches {
  position: relative;
  padding-bottom: 14px;
}

/* Give all day cells enough height to show the count badge */
.flatpickr-calendar .flatpickr-day {
  height: 46px;
  line-height: 32px;
}

.flatpickr-day-count {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 12px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  white-space: nowrap;
}

.game-toggles,
.player-toggles {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.game-toggle {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid #44464d;
  background: #1e1f22;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.game-toggle:hover {
  background: #2e3035;
  color: var(--text);
  border-color: #5a5c65;
}

.game-toggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.game-toggle.active:hover {
  background: #4752c4;
}

.player-field {
  min-height: auto;
}

.field-date-range {
  width: 100%;
}

.player-field {
  min-height: auto;
}

.field-date-range {
  width: 100%;
}

.search-field {
  grid-column: 1 / 2;
}

.actions {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
}

@media (max-width: 980px) {
  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-field,
  .player-field,
  .actions,
  .field-game {
    grid-column: span 2;
  }

  .player-field,
  .actions {
    justify-self: stretch;
  }

  .actions {
    justify-content: flex-end;
  }
}

@media (max-width: 680px) {
  .header-content,
  .section-heading,
  .match-header,
  .match-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .teams-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .search-field,
  .player-field,
  .actions,
  .field-game {
    grid-column: auto;
  }

  .player-field,
  .actions {
    justify-self: stretch;
  }

  .actions {
    justify-content: flex-end;
  }
}


label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid #44464d;
  background: #1e1f22;
  color: var(--text);
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 8px 10px;
}

select[multiple] {
  min-height: 88px;
  padding: 4px;
}

select[multiple] option {
  padding: 5px 7px;
  border-radius: 4px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(88, 101, 242, 0.6);
  outline-offset: 1px;
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  padding: 0 13px;
  cursor: pointer;
  background: #3a3c43;
  font-weight: 700;
}

button:hover {
  background: #454854;
}

#refresh {
  background: var(--accent);
  border-color: var(--accent);
}

.matches-shell {
  display: grid;
  gap: 14px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.section-heading-actions {
  display: grid;
  gap: 6px;
  justify-items: end;
}

.section-heading-actions button {
  width: max-content;
}

.match-day-group {
  display: grid;
  gap: 16px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid #404249;
  border-radius: 14px;
}

.match-day-heading {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.match-group-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.match-card {
  min-width: 0;
  width: 100%;
}

@media (max-width: 1120px) {
  .match-group-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .match-group-grid {
    grid-template-columns: 1fr;
  }
}

h2 {
  font-size: 18px;
}

.muted {
  margin-top: 4px;
  font-size: 13px;
}

.match-grid {
  display: grid;
  gap: 14px;
}

.match-grid[hidden],
#calendar-view[hidden] {
  display: none;
}

.match-card,
.empty-state,
.loading {
  background: var(--panel);
  border: 1px solid #404249;
  border-left: 4px solid #747f8d;
  border-radius: 8px;
}

.match-card {
  overflow: hidden;
}

.spotlight-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.65);
  cursor: pointer;
}

.match-card.spotlight {
  position: relative;
  z-index: 1000;
  box-shadow: 0 0 24px rgba(88, 101, 242, 0.7);
  transition: box-shadow 0.2s;
}

.match-card.tracked-win {
  border-left-color: var(--win);
}

.match-card.tracked-loss {
  border-left-color: var(--loss);
}

.match-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.14);
  border-bottom: 1px solid #404249;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.match-header h3 {
  margin-top: 3px;
  font-size: 16px;
  line-height: 1.3;
}

.match-header h3 a {
  color: inherit;
  text-decoration: none;
}

.match-header h3 a:hover {
  text-decoration: underline;
}

.result-pill {
  color: var(--text);
  font-weight: 700;
}

.teams-grid,
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: #404249;
}

.team-column,
.embed-field,
.tracked-list {
  background: var(--panel);
  padding: 14px 16px;
}

.team-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.team-list,
.tracked-list {
  display: grid;
  gap: 8px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.player-row.win .player-name {
  color: #d8f3df;
}

.player-row.loss .player-name {
  color: #ffd7d9;
}

.player-row.tracked-player {
  background: rgba(88, 101, 242, 0.12);
  border-radius: 6px;
  padding: 3px 6px;
  margin: 0 -6px;
}

.player-row.tracked-player .player-name {
  color: #c9ceff;
}

.hero-icon {
  width: 32px;
  height: 32px;
  border-radius: 5px;
  overflow: hidden;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: #1e1f22;
  border: 1px solid #4a4c54;
}

.hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.emoji-icon,
.fallback-icon {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
}

.player-copy {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.player-name,
.hero-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-name {
  font-size: 14px;
  font-weight: 700;
}

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

.kda {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.embed-field pre {
  margin: 0;
  color: var(--text);
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.empty-team {
  color: var(--muted);
  font-size: 13px;
}

.match-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 16px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid #404249;
}

.match-footer span:last-child {
  text-align: right;
  overflow-wrap: anywhere;
}

.empty-state,
.loading {
  padding: 28px;
  text-align: center;
}

.empty-state h3 {
  margin-bottom: 6px;
}

.empty-state p,
.loading {
  color: var(--muted);
}

footer {
  border-top: 1px solid var(--border);
  padding: 22px;
  text-align: center;
  font-size: 12px;
}

/* ── View toggle ─────────────────────────────────────────────────────────── */

.view-toggle {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #44464d;
}

.view-btn {
  min-height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 0;
  background: #1e1f22;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.view-btn + .view-btn {
  border-left: 1px solid #44464d;
}

.view-btn.view-active {
  background: var(--accent);
  color: #fff;
}

.view-btn:hover:not(.view-active) {
  background: #2e3035;
  color: var(--text);
}

/* ── Big calendar ────────────────────────────────────────────────────────── */

.cal-grid {
  display: grid;
  gap: 18px;
}

.cal-month-block {
  background: var(--panel);
  border: 1px solid #404249;
  border-radius: 14px;
  overflow: hidden;
}

.cal-month-heading {
  padding: 14px 18px;
  background: rgba(0,0,0,.18);
  border-bottom: 1px solid #404249;
  font-size: 16px;
  font-weight: 700;
}

.cal-weekday-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid #404249;
}

.cal-weekday-cell {
  padding: 8px 0;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
}

.cal-days-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-day-cell {
  border-right: 1px solid #404249;
  border-bottom: 1px solid #404249;
  min-height: 120px;
  padding: 6px 7px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  vertical-align: top;
}

.cal-day-cell:nth-child(7n) {
  border-right: none;
}

.cal-day-cell.cal-day-empty {
  background: rgba(0,0,0,.06);
}

.cal-day-number {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  flex: 0 0 auto;
  line-height: 1;
  margin-bottom: 2px;
}

.cal-day-cell.cal-day-today .cal-day-number {
  color: var(--accent);
}

/* ── Mini match card ─────────────────────────────────────────────────────── */

.mini-card {
  border-radius: 5px;
  border: 1px solid #505260;
  border-left: 3px solid #747f8d;
  background: var(--panel-soft);
  padding: 5px 6px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1.3;
  min-width: 0;
  transition: background 0.1s;
  overflow: hidden;
}

.mini-card:hover {
  background: #454854;
}

.mini-card.tracked-win {
  border-left-color: var(--win);
}

.mini-card.tracked-loss {
  border-left-color: var(--loss);
}

.mini-card-eyebrow {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-card-title {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-card-icons {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-top: 3px;
}

.mini-card-icons .hero-img {
  width: 18px;
  height: 18px;
  border-radius: 3px;
}

.mini-card-icons .fallback-icon,
.mini-card-icons .emoji-icon {
  font-size: 9px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  background: #1e1f22;
  border-radius: 3px;
}

.mini-card-more {
  font-size: 9px;
  color: var(--muted);
  align-self: center;
  white-space: nowrap;
}

/* ── Match detail modal ──────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  position: relative;
  background: var(--panel);
  border: 1px solid #404249;
  border-radius: 14px;
  max-width: 720px;
  width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 20px;
  display: grid;
  gap: 0;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  border: none;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: rgba(255,255,255,.16);
  color: var(--text);
}

.modal-content .match-card {
  border-radius: 8px;
  border-left-width: 4px;
}

/* ── Graph view ──────────────────────────────────────────────────────────── */

#graph-view {
  display: grid;
  gap: 16px;
}

#graph-view[hidden] {
  display: none;
}

.graph-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bucket-toggles {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #44464d;
}

.bucket-btn {
  min-height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 0;
  background: #1e1f22;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.bucket-btn + .bucket-btn {
  border-left: 1px solid #44464d;
}

.bucket-btn.active {
  background: var(--accent);
  color: #fff;
}

.bucket-btn:hover:not(.active) {
  background: #2e3035;
  color: var(--text);
}

.chart-wrapper {
  background: var(--panel);
  border: 1px solid #404249;
  border-radius: 12px;
  padding: 20px;
  min-height: 400px;
  position: relative;
}

#match-chart {
  width: 100%;
  height: 100%;
  max-height: 500px;
}

.pictograph {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0;
  height: 320px;
  position: relative;
}

.picto-yaxis {
  position: relative;
  width: 32px;
  flex-shrink: 0;
}

.picto-ytick {
  position: absolute;
  right: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  transform: translateY(50%);
  line-height: 1;
}

.picto-body {
  position: relative;
  height: 100%;
  overflow-x: auto;
  overflow-y: visible;
}

.picto-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.picto-gridline {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255,255,255,0.06);
}

.picto-cols {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: 100%;
  padding: 0 4px;
  position: relative;
  z-index: 1;
}

.picto-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 48px;
  position: relative;
}

.picto-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  width: 100%;
  min-height: 20px;
}

.picto-icon {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  flex-shrink: 0;
  object-fit: cover;
}

.picto-fallback {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: #1e1f22;
  font-size: 9px;
  font-weight: 800;
  color: var(--muted);
}

.picto-overflow {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  background: rgba(0,0,0,0.25);
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.4;
}

.picto-xlabel {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  padding: 6px 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

@media (max-width: 980px) {
  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-field,
  .player-field,
  .actions {
    grid-column: span 2;
  }

  .actions {
    justify-content: flex-end;
  }
}

@media (max-width: 680px) {
  .header-content,
  .section-heading,
  .match-header,
  .match-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .teams-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .search-field,
  .player-field,
  .actions {
    grid-column: auto;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .match-footer span:last-child {
    text-align: left;
  }

  .graph-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .bucket-toggles {
    width: 100%;
  }

  .bucket-btn {
    flex: 1;
    text-align: center;
  }

  .pictograph {
    height: 240px;
  }

  .picto-col {
    min-width: 36px;
  }

  .picto-icon,
  .picto-fallback {
    width: 18px;
    height: 18px;
  }

  .picto-xlabel {
    font-size: 8px;
  }
}
