/* ============================================================
   ladd.au V23 — AFL Ladder Styles
   V23: Centered trophies, col-form 80px, mobile finals tighter.
   DO NOT MODIFY COLUMN WIDTHS WITHOUT UPDATING BOTH
   DESKTOP AND MOBILE SECTIONS.
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
  --bg: #0A0E17;
  --row-bg: #1E2536;
  --row-hover: #283048;
  --border: #2A3040;
  --surface: #283048;
  --header-bg: #1A2030;
  --muted: #4B5563;
  --text: #E5E7EB;

  --neon-green: #00FF9C;
  --neon-blue: #39B5E0;
  --neon-yellow: #FFE162;
  --neon-orange: #FC6B3F;
  --neon-red: #FF004D;
  --neon-pink: #F21170;

  --font: 'JetBrains Mono', monospace;

  /* Grid column widths — FIXED pixels except finals (1fr) */
  --col-position: 28px;
  --col-logo: 32px;
  --col-form: 80px;      /* centered trophies + left/right padding */
  --col-w: 26px;
  --col-l: 26px;
  --col-pts: 28px;
  --col-pct: 32px;        /* percentage e.g. "134.0" */
  --col-next: 160px;      /* FIXED — venue + logo + bar + % */
  /* finals chance gets 1fr — takes ALL remaining space */
}

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- App Container --- */
#app {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(4px, 0.8vh, 12px) 0;
}

/* --- Header --- */
#header {
  text-align: center;
  flex-shrink: 0;
  padding-bottom: clamp(17px, calc(0.4vh + 15px), 21px);
}

.logo-img {
  height: clamp(28px, 4vh, 52px);
  width: auto;
  display: inline-block;
  image-rendering: auto;
}

/* ============================================
   GRID LAYOUT — DO NOT MODIFY COLUMN WIDTHS
   WITHOUT UPDATING BOTH DESKTOP AND MOBILE
   ============================================ */

.table-container {
  width: 100%;
  max-width: 670px;
  margin: 0 auto;
  padding: 0 16px;
  box-sizing: border-box;
}

.grid-row {
  display: grid;
  grid-template-columns:
    var(--col-position)
    var(--col-logo)
    var(--col-form)
    var(--col-w)
    var(--col-l)
    var(--col-pts)
    var(--col-pct)
    var(--col-next)
    1fr;
  align-items: center;
  column-gap: 4px;
  padding: 6px 12px;
  box-sizing: border-box;
}

/* Header row — SAME grid class, different styling */
.grid-row.header {
  background: #1A2030;
  border-radius: 4px;
  border-bottom: 1px solid #2A3040;
  margin-bottom: 8px;
  padding: 8px 12px;
  color: #8B95A5;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Data row */
.grid-row.data {
  background: #1E2536;
  border: 2px solid #2A3040;
  border-radius: 4px;
  margin-bottom: 4px;
  transition: background 0.15s ease;
  font-size: clamp(10px, 1.3vh, 14px);
  white-space: nowrap;
}

.grid-row.data:hover {
  background: #283048;
}

/* --- Column alignment --- */
.col-position {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.col-position.top8 {
  color: var(--text);
}

.col-position.bottom10 {
  color: var(--muted);
}

.team-logo {
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.team-logo img {
  width: 24px;
  height: 24px;
  display: block;
  object-fit: contain;
}

.col-form {
  text-align: left;
}

.col-w {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.col-l {
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.col-pts {
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.col-pct {
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: clamp(8px, 1vh, 11px);
}

.col-next {
  padding: 0;
  min-width: 0;
}

.col-finals {
  padding: 0;
  min-width: 0;
}

/* --- Header column text alignment — all centered --- */
.grid-row.header > * {
  text-align: center;
}

.header-text {
  text-align: center;
  line-height: 1.2;
  font-size: 9px;
}

.next-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 9px;
  min-width: 0;
  overflow: hidden;
  padding-left: 16px;
  padding-right: 16px;
  box-sizing: border-box;
}

.grid-row.header .col-next,
.grid-row.header .col-finals {
  overflow: hidden;
  min-width: 0;
}

.grid-row.header .col-finals {
  white-space: nowrap;
  font-size: 8px;
  text-align: center;
  letter-spacing: 0.3px;
  width: 100%;
}

/* --- Desktop/mobile text toggle --- */
.mobile-text { display: none; }
.full-text { display: inline; }

/* --- Form Guide --- */
.form-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0 4px;
}

.form-icon {
  width: 10px;
  height: 10px;
  image-rendering: pixelated;
  display: block;
  flex-shrink: 0;
}

.form-icon.win {
  filter: drop-shadow(0 0 3px rgba(218, 165, 32, 0.5));
}

.form-icon.loss,
.form-icon.draw {
  filter: none;
}

/* --- Logo styling (team column and opponent in next match) --- */
.team-logo img,
.next-match-box .opponent-logo img {
  object-fit: contain;
  /* filter set by JS with white contour + tier glow */
}

.next-match-box .opponent-logo img {
  width: 24px;
  height: 24px;
  display: block;
  vertical-align: middle;
  margin-top: 1px;
}

/* --- Next Match Box --- */
.next-match-box {
  display: flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  padding: 2px 10px 2px 6px;
  border-radius: 4px;
  box-sizing: border-box;
  /* border set by JS: 1px solid <win-tier-colour at 50% opacity> */
}

.next-match-box .venue-code {
  font-size: 9px;
  font-weight: bold;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.5px;
  line-height: 1;
  flex-shrink: 0;
  /* colour set by JS: #00FF9C for home, #F21170 for away */
}

.next-match-box .win-bar {
  min-width: 60px;
  max-width: 90px;
  flex-shrink: 0;
}

.next-match-box .win-pct {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 26px;
  text-align: right;
  opacity: 0;
  transition: opacity 0.3s ease 0.5s;
}

.next-match-box .win-pct.show {
  opacity: 1;
}

.next-game-empty {
  color: var(--muted);
  font-size: clamp(9px, 1.1vh, 12px);
  text-align: center;
}

/* --- Finals Chance --- */
.finals-chance {
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: visible;
  margin-left: 8px;
  min-width: 100px;
}

.finals-chance .probability-bar {
  flex: 1;
  min-width: 50px;
  max-width: 120px;
}

.finals-chance .finals-pct {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 28px;
  text-align: right;
  opacity: 0;
  transition: opacity 0.3s ease 0.5s;
}

.finals-chance .finals-pct.show {
  opacity: 1;
}

/* --- Shared Probability Bar (used by BOTH next match and finals chance) --- */
.probability-bar {
  height: 14px;
  border-radius: 2px;
  background: #283048;
  overflow: hidden;
  box-sizing: border-box;
  /* border set by JS: 1px solid <tier-colour at 50% opacity> */
}

.probability-bar .fill {
  height: 100%;
  min-width: 3px;
  /* background and width set by JS */
  /* NO border-radius on fill — blocky */
}

/* --- Divider Row (between position 8 and 9) --- */
.divider-row {
  position: relative;
  height: 6px;
  min-height: 6px !important;
  display: block !important;
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

.divider-line {
  position: absolute;
  top: 50%;
  left: 8px;
  right: 8px;
  height: 1px;
  background: var(--muted);
  opacity: 0.4;
  transform: translateY(-50%);
}

.divider-dot {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--neon-green);
  box-shadow: 0 0 8px var(--neon-green), 0 0 16px #00FF9C60;
  animation: travel 4s linear infinite;
  z-index: 1;
}

@keyframes travel {
  0% {
    left: 8px;
    opacity: 0;
  }
  5% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    left: calc(100% - 14px);
    opacity: 0;
  }
}

/* --- Ladder Body --- */
#ladder-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* --- Loading State --- */
.loading-msg {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: 14px;
}

/* --- Error State --- */
.error-msg {
  text-align: center;
  color: var(--neon-red);
  padding: 40px 0;
  font-size: 13px;
}

/* --- Desktop-only trophy spacing --- */
@media (min-width: 769px) {
  #header {
    padding-top: 17px;
  }

  .col-form {
    padding-left: 8px;
    padding-right: 12px;
  }

  .next-header {
    padding-left: 20px;
    padding-right: 20px;
  }
}

/* ============================================
   MOBILE — 768px
   ============================================ */
@media (max-width: 768px) {
  :root {
    --col-position: 24px;
    --col-logo: 32px;
    --col-form: 52px;   /* 3 icons × 10px + 2 gaps × 3px + padding */
    --col-w: 22px;
    --col-l: 22px;
    --col-pts: 28px;
    --col-pct: 36px;
    --col-next: 140px;
  }

  .table-container {
    padding: 0 8px;
  }

  .grid-row {
    column-gap: 4px;
    padding: 4px 8px 4px 8px;
    padding-right: 16px;
    font-size: 11px;
  }

  /* Show L column on mobile — do NOT hide it */
  /* Show % column on mobile — do NOT hide it */

  .team-logo img {
    width: 20px;
    height: 20px;
  }

  .form-icon {
    width: 10px;
    height: 10px;
  }

  /* Form shows most recent 3 games on mobile — hide first 2 (oldest) */
  .form-container .form-icon:nth-child(1):first-child:nth-last-child(5),
  .form-container .form-icon:nth-child(2):nth-last-child(4) {
    display: none;
  }

  .next-match-box .win-bar {
    min-width: 25px;
    max-width: 40px;
  }

  .next-match-box .opponent-logo img {
    width: 18px;
    height: 18px;
  }

  .probability-bar {
    height: 10px;
  }

  .next-match-box .win-pct {
    font-size: 9px;
    min-width: 22px;
  }

  .finals-chance {
    overflow: visible;
    padding-right: 8px;
    gap: 1px;
  }

  .finals-chance .probability-bar {
    min-width: 20px;
    max-width: 40px;
    flex-shrink: 1;
  }

  .finals-chance .finals-pct {
    font-size: 10px;
    flex-shrink: 0;
    white-space: nowrap;
    min-width: 24px;
  }

  .full-text { display: none; }
  .mobile-text { display: inline; }

  .grid-row.header {
    font-size: 8px;
  }

  .next-header {
    padding-left: 6px;
    padding-right: 10px;
  }

  .logo-img {
    height: 24px;
  }
}

/* ============================================
   MOBILE — 480px
   ============================================ */
@media (max-width: 480px) {
  :root {
    --col-position: 20px;
    --col-logo: 28px;
    --col-form: 44px;
    --col-w: 20px;
    --col-l: 20px;
    --col-pts: 24px;
    --col-pct: 32px;
    --col-next: 110px;
  }

  /* Still show L and % — do NOT hide them */

  .team-logo img {
    width: 18px;
    height: 18px;
  }

  .next-match-box .opponent-logo img {
    width: 16px;
    height: 16px;
  }

  .form-icon {
    width: 9px;
    height: 9px;
  }

  .next-match-box .win-pct {
    font-size: 8px;
  }

  .finals-chance .finals-pct {
    font-size: 9px;
  }

  .finals-chance .probability-bar {
    min-width: 15px;
    max-width: 30px;
  }
}

/* --- Very tall screens --- */
@media (min-height: 900px) {
  .grid-row.data {
    padding: 8px 12px;
  }
}

/* --- Short screens --- */
@media (max-height: 700px) {
  .logo-img {
    height: 24px;
  }

  .team-logo img {
    width: 20px;
    height: 20px;
  }

  .next-match-box .opponent-logo img {
    width: 20px;
    height: 20px;
  }

  .form-icon {
    width: 14px;
    height: 14px;
  }

  .divider-row {
    height: 4px;
    min-height: 4px !important;
  }

  .divider-dot {
    width: 4px;
    height: 4px;
  }
}

@media (max-height: 580px) {
  .logo-img {
    height: 20px;
  }

  #header {
    padding-bottom: 1px;
  }

  .form-icon {
    width: 12px;
    height: 12px;
  }

  .form-container {
    gap: 1px;
  }

  .team-logo img {
    width: 18px;
    height: 18px;
  }

  .next-match-box .opponent-logo img {
    width: 18px;
    height: 18px;
  }

  .next-match-box {
    gap: 3px;
    padding: 2px 3px;
  }

  .divider-row {
    height: 3px;
    min-height: 3px !important;
  }

  .divider-dot {
    width: 3px;
    height: 3px;
  }
}
