/* The Matchday — Component styles
 *
 * Wrapped in @layer components (declared in global.css). Keeps specificity
 * flat and predictable; component rules can be overridden by utilities layer.
 * Mobile-first breakpoints (min-width). Hardcoded values are tokenised.
 */

@layer components {

  /* === NAV === */

  .nav {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--mt-sp-3) 0;
    position: sticky; top: 0; z-index: var(--mt-z-nav);
    background: color-mix(in srgb, var(--mt-bg) 85%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid color-mix(in srgb, var(--mt-border) 50%, transparent);
  }
  .nav__logo {
    font-family: var(--mt-font-display);
    font-weight: var(--mt-fw-black);
    font-size: var(--mt-fs-rank);
    letter-spacing: var(--mt-tracking-tight);
  }
  .nav__logo-the { font-weight: var(--mt-fw-medium); opacity: 0.55; margin-right: 0.25em; }
  .nav__links { display: flex; gap: var(--mt-sp-2); }
  .nav__link {
    font-size: var(--mt-fs-caption);
    font-weight: var(--mt-fw-medium);
    color: var(--mt-text-muted);
    transition: color var(--mt-dur-fast) var(--mt-ease);
  }
  .nav__link:hover, .nav__link--active { color: var(--mt-text); }
  .nav__link:focus-visible {
    outline: 2px solid var(--mt-pitch);
    outline-offset: 4px;
    border-radius: 4px;
  }

  /* Generic .logo — shared logo styles for use outside .nav (e.g. footer). */
  .logo {
    display: inline-flex;
    align-items: center;
    gap: var(--mt-sp-1);
    font-family: var(--mt-font-display);
    font-weight: var(--mt-fw-semibold);
    color: var(--mt-text);
  }

  /* === BUTTONS === */

  .btn {
    display: inline-flex; align-items: center; gap: 0.5em;
    padding: 0.875em 1.5em;
    border-radius: var(--mt-radius-pill);
    font-weight: var(--mt-fw-semibold);
    font-size: var(--mt-fs-body);
    transition: transform var(--mt-dur-fast) var(--mt-ease),
                background var(--mt-dur-fast) var(--mt-ease),
                color var(--mt-dur-fast) var(--mt-ease),
                border-color var(--mt-dur-fast) var(--mt-ease);
  }
  .btn:hover { transform: translateY(-1px); }
  .btn:active { transform: translateY(0); }
  .btn:focus-visible {
    outline: 2px solid var(--mt-pitch);
    outline-offset: 2px;
  }
  .btn:disabled,
  .btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
  }

  .btn--primary { background: var(--mt-text); color: var(--mt-bg); }
  .btn--primary:hover { background: var(--mt-pitch); }

  .btn--secondary {
    background: var(--mt-bg-elevated);
    color: var(--mt-text);
    border: 1px solid var(--mt-border);
  }
  .btn--secondary:hover { background: var(--mt-bg); border-color: var(--mt-neutral-400); }

  .btn--ghost { background: transparent; color: var(--mt-text); border: 1px solid var(--mt-border); }
  .btn--ghost:hover { background: var(--mt-bg-elevated); }

  .btn__arrow { transition: transform var(--mt-dur-fast) var(--mt-ease); }
  .btn:hover .btn__arrow { transform: translateX(3px); }

  /* === CARDS === */

  .card {
    background: var(--mt-bg);
    border: 1px solid var(--mt-border);
    border-radius: var(--mt-radius-md);
    padding: var(--mt-sp-4);
    transition: transform var(--mt-dur-base) var(--mt-ease), box-shadow var(--mt-dur-base) var(--mt-ease);
  }
  .card--elevated { background: var(--mt-bg-elevated); border-color: transparent; }
  .card--hoverable:hover { transform: translateY(-2px); box-shadow: var(--mt-shadow-md); }

  /* === COUNTDOWN BLOCK === */

  .countdown {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--mt-sp-2);
    font-family: var(--mt-font-mono);
  }
  .countdown__cell {
    text-align: center;
    padding: var(--mt-sp-3) var(--mt-sp-2);
    background: var(--mt-bg-elevated);
    border-radius: var(--mt-radius-md);
  }
  .countdown__value {
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: var(--mt-fw-bold);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    color: var(--mt-text);
  }
  .countdown__label {
    margin-top: var(--mt-sp-1);
    font-size: var(--mt-fs-micro);
    text-transform: uppercase;
    letter-spacing: var(--mt-tracking-wide);
    color: var(--mt-text-muted);
  }
  .countdown--live .countdown__value { color: var(--mt-live); }

  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

  /* === MATCH CARD === */

  .match {
    display: grid;
    grid-template-columns: 1fr;
    text-align: center;
    align-items: center;
    gap: var(--mt-sp-2);
    padding: var(--mt-sp-3) var(--mt-sp-4);
    background: var(--mt-bg);
    border: 1px solid var(--mt-border);
    border-radius: var(--mt-radius-md);
    transition: border-color var(--mt-dur-fast) var(--mt-ease);
  }
  .match:hover { border-color: var(--mt-neutral-400); }
  .match--locked { background: var(--mt-bg-elevated); opacity: 0.6; }
  .match--locked input { pointer-events: none; }

  .match__team {
    display: flex; align-items: center; justify-content: center; gap: var(--mt-sp-2);
    font-weight: var(--mt-fw-semibold);
  }
  .match__flag {
    width: 32px; height: 24px;
    border-radius: 3px;
    object-fit: cover;
    box-shadow: var(--mt-shadow-sm);
  }
  .match__time {
    font-family: var(--mt-font-mono);
    font-size: var(--mt-fs-small);
    color: var(--mt-text-muted);
  }

  /* === SCORE CELL === */

  .score-cells {
    display: flex; align-items: center; gap: var(--mt-sp-1);
    font-family: var(--mt-font-mono); font-weight: var(--mt-fw-bold);
  }
  .score-cell {
    width: 3rem; height: 3.5rem;
    display: grid; place-items: center;
    background: var(--mt-bg-elevated);
    border-radius: var(--mt-radius-sm);
    font-size: var(--mt-fs-display-number);
    font-variant-numeric: tabular-nums;
    border: 2px solid transparent;
    transition: border-color var(--mt-dur-fast) var(--mt-ease), background var(--mt-dur-base) var(--mt-ease);
  }
  .score-cell:focus-within { border-color: var(--mt-pitch); }
  .score-cell input { width: 100%; height: 100%; text-align: center; font: inherit; }
  .score-cell input:focus-visible {
    outline: 2px solid var(--mt-pitch);
    outline-offset: 2px;
    border-radius: 4px;
  }
  .score-cell input:disabled,
  .score-cell input[disabled] {
    opacity: 0.5;
    background: var(--mt-bg);
    cursor: not-allowed;
  }
  .score-cell input::-webkit-outer-spin-button,
  .score-cell input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
  .score-cell input[type=number] { -moz-appearance: textfield; }
  .score-cell--bloom { background: var(--mt-pitch-50); animation: bloom var(--mt-dur-slow) var(--mt-ease); }

  @keyframes bloom { 0% { transform: scale(1); } 30% { transform: scale(1.08); background: var(--mt-pitch-50); } 100% { transform: scale(1); } }

  .score-separator { font-size: var(--mt-fs-display-number); color: var(--mt-text-muted); }

  /* === LEADERBOARD ROW === */

  /* Selector supports both <ol class="lb"> (semantic) and <div class="lb"> (legacy). */
  ol.lb,
  .lb {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
  }
  .lb__row {
    display: grid;
    grid-template-columns: 3rem auto 1fr auto;
    align-items: center;
    gap: var(--mt-sp-3);
    padding: var(--mt-sp-3) var(--mt-sp-4);
    border-bottom: 1px solid var(--mt-border);
    transition: background var(--mt-dur-fast) var(--mt-ease);
  }
  .lb__row:hover { background: var(--mt-bg-elevated); }
  .lb__row--you { background: var(--mt-pitch-50); border-color: var(--mt-pitch); }
  .lb__row--first .lb__rank { color: var(--mt-gold); }
  .lb__rank {
    font-family: var(--mt-font-mono);
    font-weight: var(--mt-fw-bold);
    font-size: var(--mt-fs-rank);
    color: var(--mt-text-muted);
  }
  .lb__avatar {
    width: 2.5rem; height: 2.5rem;
    border-radius: 50%;
    display: grid; place-items: center;
    color: var(--mt-white);
    font-weight: var(--mt-fw-bold);
    font-size: var(--mt-fs-label);
  }
  .lb__name { font-weight: var(--mt-fw-semibold); }
  .lb__points {
    font-family: var(--mt-font-mono);
    font-variant-numeric: tabular-nums;
    font-weight: var(--mt-fw-bold);
    font-size: var(--mt-fs-rank);
  }

  /* Standalone .crown — visual marker for leaderboard #1 (and other contexts).
   * CSS-only implementation via ::before with Unicode chess-queen glyph (\2654 = "♔").
   * Wrapped as inline-block so the HTML-agent can either: (a) use <span class="crown"></span>
   * and let CSS render the glyph, OR (b) place an inline-SVG inside, in which case the
   * ::before will be hidden by the SVG occupying the slot. Both paths work.
   * Color uses --mt-color-warning (status warning ≈ gold) with --mt-gold as runtime fallback. */
  .crown {
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1;
    vertical-align: middle;
    color: var(--mt-gold);
    text-align: center;
  }
  .crown:empty::before {
    content: "\2654"; /* "♔" — robust crown glyph; renders across modern fonts. */
    display: inline-block;
  }
  /* Legacy support: rows marked --first still get a leading crown via ::before. */
  .lb__row--first .lb__name::before {
    content: "\2654";
    color: var(--mt-gold);
    margin-right: 0.4em;
  }

  /* === TOGGLE === */

  .toggle {
    display: inline-flex; gap: 0; padding: 4px;
    background: var(--mt-bg-elevated);
    border-radius: var(--mt-radius-pill);
  }
  .toggle__option {
    padding: 0.5em 1.25em;
    font-size: var(--mt-fs-small);
    font-weight: var(--mt-fw-medium);
    color: var(--mt-text-muted);
    border-radius: var(--mt-radius-pill);
    transition: background var(--mt-dur-fast) var(--mt-ease), color var(--mt-dur-fast) var(--mt-ease);
  }
  .toggle__option--active { background: var(--mt-bg); color: var(--mt-text); box-shadow: var(--mt-shadow-sm); }
  .toggle__option:focus-visible {
    outline: 2px solid var(--mt-pitch);
    outline-offset: 2px;
  }
  .toggle__option:disabled,
  .toggle__option[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
  }

  /* === BADGES === */

  .badge {
    display: inline-flex; align-items: center; gap: 0.4em;
    padding: 0.25em 0.7em;
    border-radius: var(--mt-radius-pill);
    background: var(--mt-bg-elevated);
    color: var(--mt-text-muted);
    font-size: var(--mt-fs-micro);
    font-weight: var(--mt-fw-semibold);
    text-transform: uppercase;
    letter-spacing: var(--mt-tracking-wide);
  }
  .badge--live { background: var(--mt-live-50); color: var(--mt-live); }
  .badge--live::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--mt-live);
    animation: pulse 1.4s var(--mt-ease) infinite;
  }
  .badge--lock { background: var(--mt-bg-elevated); color: var(--mt-text-muted); }

  /* === STATE COMPONENTS === */

  /* Empty / error states — used by tippen.js + leaderboard.js. */
  .empty-state,
  .error-state {
    padding: var(--mt-sp-4);
    text-align: center;
    color: var(--mt-text-muted);
    font-size: var(--mt-fs-label);
    border-radius: var(--mt-radius-md);
  }
  .error-state {
    color: var(--mt-color-error);
    background: var(--mt-color-error-bg);
  }

  /* Note: .sr-only utility lives in global.css @layer base — do not duplicate here. */

  /* === FOOTER === */

  .footer {
    padding: var(--mt-sp-6) 0;
    border-top: 1px solid var(--mt-border);
    color: var(--mt-text-muted);
    font-size: var(--mt-fs-small);
  }
  .footer__row {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap;
    gap: var(--mt-sp-2);
  }

  /* === Responsive: tablet / desktop (mobile-first) === */

  /* >= 481px: re-enable hero defaults (overrides narrow-mobile compression). */
  @media (min-width: 481px) {
    .section--hero { padding-block: var(--mt-sp-8) var(--mt-sp-6); }
    .display--hero { font-size: var(--mt-fs-hero); }
  }

  /* >= 641px: expand nav, countdown, match-card to comfortable layout. */
  @media (min-width: 641px) {
    .nav { padding: var(--mt-sp-3) 0; }
    .nav__links { gap: var(--mt-sp-3); }
    .nav__link { font-size: var(--mt-fs-small); }

    .countdown { grid-template-columns: repeat(4, 1fr); }

    .match {
      grid-template-columns: 1fr auto 1fr;
      text-align: initial;
      gap: var(--mt-sp-3);
    }
    .match__team { justify-content: flex-start; }
    .match__team--away { justify-content: flex-end; flex-direction: row-reverse; }
  }

  /* Narrow-mobile compression: only applied below 481px. */
  @media (max-width: 480px) {
    .section--hero { padding-block: var(--mt-sp-5) var(--mt-sp-4); }
    .display--hero { font-size: clamp(3rem, 18vw, 6rem); }
  }

} /* end @layer components */
