/* ================================
   TOKENS (define once)
================================ */
:root{
    --hero-py: .48rem;    /* header vertical padding */
    --hero-px: .9rem;     /* header horizontal padding */
    --gap-xs: .35rem;
    --gap-sm: .55rem;
    --chip-border: rgba(0,0,0,.06);
  }
  
  /* Reduce Bootstrap container gutters on small screens so main card uses more width */
  @media (max-width: 768px){
    main.container{ --bs-gutter-x: .75rem; }
  }
  @media (max-width: 576px){
    main.container{ --bs-gutter-x: .5rem; }
  }
  
  /* ================================
     HEADER (no card wrapper)
     Rows: 1=title/date, 2=pills, 3=CTAs
  ================================ */
  
  /* Top line: squares count and date */
  .container .d-flex:first-child{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }
  
  /* Second line: buttons and badges */
  .container .d-flex:last-child{
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap-xs);
    overflow: visible; /* Allow dropdowns to extend in all directions */
    margin-bottom: .25rem; /* tighten space before kickoff row */
  }
  
  /* Make buttons more compact to fit on one line */
  .container .d-flex:last-child .btn {
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
    white-space: nowrap;
  }
  
  .container .d-flex:last-child .badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    white-space: nowrap;
  }
  
  /* Clickable badge styling */
  .clickable-badge {
    transition: all 0.2s ease;
  }
  
  .clickable-badge:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }
  
  .clickable-badge:active {
    transform: scale(0.98);
  }
  
  /* Ensure dropdowns appear above board content but below modals */
  .share-dropdown .dropdown-menu,
  .board-manage-dropdown .dropdown-menu {
    z-index: 1040 !important;
  }
  
  .share-dropdown,
  .board-manage-dropdown {
    position: relative;
    z-index: 1040;
  }
  
  /* Ensure navigation dropdown appears above board header elements */
  .navbar .dropdown-menu {
    z-index: 1050 !important;
  }
  
  .navbar .nav-item.dropdown {
    position: relative;
    z-index: 1050;
  }
  
  /* Ensure dropdowns are not clipped by parent containers */
  .container {
    overflow: visible !important;
  }
  
  .container .d-flex:last-child {
    overflow: visible !important;
  }
  
  .container .text-muted.small{
    color: #64748b !important;
    white-space: nowrap;
  }
  
  /* Mobile: make elements more compact to fit on one line */
  @media (max-width: 480px){
    .container .d-flex:first-child{
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      gap: var(--gap-xs);
    }
    
    /* Make squares badge more compact on mobile */
    #board-squares-count-header {
      font-size: 0.875rem;
      padding: 0.2rem 0.4rem;
    }
    
    /* Make date more compact on mobile */
    .container .text-muted.small {
      font-size: 0.75rem;
      white-space: nowrap;
    }
    
    /* Keep picks left pill consistent with other buttons on mobile */
    #picks_left {
      font-size: 0.875rem;
      padding: 0.25rem 0.5rem;
    }
    
    /* Improve second line layout on mobile */
    .container .d-flex:last-child {
      flex-wrap: wrap;
      gap: 0.3rem;
    }
  }
  
  /* Very small screens: stack if absolutely necessary */
  @media (max-width: 360px){
    .container .d-flex:first-child{
      flex-direction: column;
      align-items: flex-start;
      gap: var(--gap-xs);
    }
  }
  
  /* Badge and button styles */
  #board-squares-count-header,
  #pending-approvals-badge-header,
  #pending-approvals-badge,
  #pending-squares-badge-header,
  #picks_left{
    margin: 0;
  }
  
  /* ================================
     PILL STYLES (single, unified)
  ================================ */
  .container .badge.rounded-pill{
    padding: .26rem .52rem;
    font-weight: 700;
    border: 1px solid var(--chip-border);
  }
  #board-squares-count-header.badge{
    background: #1e40af !important;
    border-color: #1e40af !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(30, 64, 175, 0.2);
  }
  #pending-approvals-badge-header.badge,
  #pending-approvals-badge.badge{
    background: #fff4cc;
    border-color: #ffe8a3;
    color: #7a5a00;
    text-decoration: none;
  }
  #picks_left.badge{
    border-color: #9ec3ff;
    background: linear-gradient(180deg,#eef5ff,#e7f1ff);
    color: #0b4ea2;
    box-shadow: 0 2px 6px rgba(11,78,162,.08);
  }
  
  /* ================================
     BUTTON POLISH (single definition)
  ================================ */
  .container .btn{
    padding: .24rem .52rem;
    line-height: 1.18;
    border-radius: 12px;
  }
  .btn-outline-primary,
  .btn-outline-primary:focus{ border-color: #a8c7ff; }
  .btn-outline-primary:hover{
    background-color: #eaf2ff;
    border-color: #86b2ff;
    color: #0b4ea2;
  }
  .btn-outline-primary:active,
  .btn-outline-primary:active:focus{
    color: #0b4ea2;
    background-color: #e6efff;
  }
  /* Prevent badges from wrapping oddly on mobile */
  .badge.rounded-pill{ white-space: nowrap; }
  .btn-outline-primary, .btn-outline-secondary{ color: #0b4ea2; }
  .btn-outline-secondary:hover{
    background-color: #f2f4f7;
    border-color: #cfd7e3;
    color: #0b4ea2;
  }
  .btn:focus-visible{ box-shadow: 0 0 0 .22rem rgba(106,166,255,.35); }
  
  /* ================================
     GRID CARD & TABLE (deduped)
  ================================ */
  .board-stage{
    background:
      radial-gradient(450px 100px at 10% 0%, rgba(106,166,255,.10), transparent 60%),
      radial-gradient(350px 110px at 90% 0%, rgba(123,227,255,.10), transparent 60%),
      #fff;
    border: 1px solid #e9edf3;
    border-radius: 14px;
  }
  .squares-table-ar thead th{
    background: #f7faff;
    color: #0f1a37;
    font-weight: 700;
  }
  .squares-table-ar td,
  .squares-table-ar th{
    box-shadow: inset 0 var(--line) 0 #e9edf3, inset var(--line) 0 0 #e9edf3; /* one value */
  }
  .square-content.handwritten-initials{
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
  /* Remove drop shadow from initials everywhere */
  .handwritten-initials,
  .square-content.handwritten-initials{
    text-shadow: none !important;
  }
  /* Ensure positioning context for overlays like the × affordance */
  .square-content{ position: relative; }
  /* Accessible, CSS-only tooltips for desktop (hover/focus) */
  .square-content[data-help]{
    position: relative;
    outline: none;
  }
  .square-content[data-help]{ cursor: help; }
  .square-content[data-help]::after{
    content: attr(data-help);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    background: rgba(17,24,39,.95);
    color: #fff;
    font-size: 12px;
    line-height: 1.2;
    padding: 6px 8px;
    border-radius: 6px;
    white-space: nowrap;
    box-shadow: 0 6px 18px rgba(0,0,0,.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease;
    z-index: 1000;
  }
  /* Remove triangle pointer to free ::before for other UI elements */
  /* make hover state obvious on own squares (delete-able) */
  .square-content.my-square[data-help]{ cursor: pointer; }
  
  .square-content[data-help]:focus-visible::after{
    opacity: 1;
    transform: translateX(-50%) translateY(-2px);
  }
  /* Show an X affordance only when the square is your own AND deletable */
  .square-content.my-square[hx-delete]::before{
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 28px;
    height: 28px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Ccircle cx='32' cy='32' r='30' fill='%23dc3545' stroke='%23ffffff' stroke-width='4'/%3E%3Cpath d='M20 20 L44 44 M44 20 L20 44' stroke='%23ffffff' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E");
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0,0,0,.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease;
    z-index: 3000;
  }
  .square-content.my-square[hx-delete]:hover::before,
  .square-content.my-square[hx-delete]:focus-visible::before{
    opacity: 1;
    transform: scale(1.02);
  }
  /* Ensure tooltip overlays above grid */
  .square-content[data-help]::after{ z-index: 2000; }
  /* Ensure projected overlay sits under tooltips and above background */
  td.winner-prov .square-content[data-help]::before{ z-index: 1001; }
  td.winner-prov .square-content[data-help]::after{ z-index: 2001; }
  /* Note: We allow tooltips on all devices; touch can ignore hover naturally */
  .left-label.team-name-heading{
    color: #0b4ea2;
    letter-spacing: .35px;
  }
  
  /* Spacing above grid */
  .section-title{ margin: .46rem 0 .28rem; }
  .squares-background-container{ padding-top: .46rem; }
  /* Matchup line sizing & truncation */
  .matchup-line{ max-width: 100%; overflow: hidden; padding-left: .5rem; padding-right: .5rem; }
  .matchup-line .team-name{ display:inline-flex; align-items:baseline; max-width: 40vw; }
  .matchup-line .team-city{ color:#334155; opacity:.9; font-weight:600; max-width: 20vw; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .matchup-line .team-mascot{ color:#0f172a; font-weight:700; white-space:nowrap; }
  @media (max-width: 768px){
    .matchup-line .team-name{ max-width: 32vw; }
    .matchup-line .team-city{ max-width: 16vw; }
  }
  
  /* ================================
     DROPDOWNS (single definition)
  ================================ */
  .dropdown-menu.small{
    border-radius: 12px;
    border: 1px solid #e9edf3;
    box-shadow: 0 8px 28px rgba(10,25,61,.08);
  }
  /* Ensure header dropdowns overlay the grid */
  .container .dropdown-menu{ z-index: 1040 !important; }
  .dropdown-menu .dropdown-item{ border-radius: .5rem; }
  .dropdown-menu .dropdown-item:active{ background: #eef5ff; }
  .dropdown-menu .dropdown-item.text-danger:hover{ background: #fee2e2; }
  .dropdown-menu .dropdown-item.text-warning:hover{ background: #fff7e6; }
  
  /* ================================
     MANAGE PLAYERS MODAL (kept)
  ================================ */
  @media (max-width: 576px){
    #managePlayersModal .modal-dialog{ margin: .5rem; }
    #managePlayersModal .table-responsive{ overflow-x: hidden; }
    #managePlayersModal table.table-modern thead{ display: none; }
    #managePlayersModal table.table-modern tbody tr{
      display: block; border-bottom: 1px solid #e9edf3; padding: .5rem 0;
    }
    #managePlayersModal table.table-modern tbody tr td{
      display: block; width: 100%; padding: .25rem 0; text-align: left !important;
    }
    #managePlayersModal table.table-modern tbody tr td:first-child{ font-weight: 700; }
    #managePlayersModal table.table-modern tbody tr td:nth-child(2)::before{
      content: '# Squares: '; color: #64748b; font-weight: 600; margin-right: .25rem;
    }
    #managePlayersModal .btn-group{ display: flex; flex-wrap: wrap; gap: .4rem; }
    #managePlayersModal .btn-group .btn{ flex: 1 1 calc(50% - .4rem); min-width: 0; }
    #managePlayersModal .modal-title{ font-size: 1.1rem; }
    #managePlayersModal td:first-child{ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  }

  /* ================================
     TOKEN-SPECIFIC SQUARE HIGHLIGHTING
  ================================ */
  .square-content.token-selected {
    border: none !important;
    /* subtle focus ring + gentle tint instead of hard border */
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.22) !important;
    background-color: rgba(37, 99, 235, 0.06) !important;
    position: relative;
  }
 

  /* Subtle corner dot to mark owned squares without clutter */
  .squares-table-ar .square-content.my-square::after{
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 2px #ffffff, 0 1px 2px rgba(0,0,0,.15);
    pointer-events: none;
    z-index: 3;
  }

  /* Remove old hover delete affordance bubble (X badge) completely */
  .square-content.my-square[hx-delete]::before,
  .square-content.my-square[hx-delete]:hover::before,
  .square-content.my-square[hx-delete]:focus-visible::before{ content: none !important; }

  /* Ensure pointer cursor instead of custom image cursor */
  .square-content.my-square{ cursor: pointer !important; }
  /* keep halo visible on hover without repainting background */
  .square-content.my-square:hover{ filter: brightness(0.99); }
  .square-content.token-selected:hover {
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.32) !important;
    background-color: rgba(37, 99, 235, 0.09) !important;
  }
  /* Ensure token highlighting works with existing square states */
  .square-content.token-selected.my-square::after,
  .square-content.token-selected.my-square-final::after {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, currentColor 85%, transparent),
                inset 0 0 0 6px rgba(37, 99, 235, 0.22),
                0 0 0 0 transparent; /* keep outside clear */
  }

  /* Mobile: increase hatch visibility on smaller squares */
  @media (max-width: 576px){
    .square-content.my-square::after{ inset: 0; border-radius: 9px; }
    .square-content.token-selected.my-square::after,
    .square-content.token-selected.my-square-final::after{
      box-shadow: inset 0 0 0 2px color-mix(in srgb, currentColor 85%, transparent),
                  inset 0 0 0 6px rgba(37, 99, 235, 0.28);
    }
  }

  /* Highlight toggle strengthens visualization for my squares without JS */
  #highlight-mine:checked ~ .board-grid-container .square-content.my-square{
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.35) !important;
    background-color: rgba(37, 99, 235, 0.08) !important;
  }
  #highlight-mine:checked ~ .board-grid-container .square-content.my-square::after{
    width: 10px; height: 10px; top: 3px; right: 3px;
    box-shadow: 0 0 0 2px #ffffff, 0 1px 3px rgba(0,0,0,.25);
  }

  /* SweetAlert2 theming to match site */
  .pms-swal{ border-radius: 16px !important; box-shadow: 0 10px 36px rgba(15,23,42,.14) !important; }
  .pms-swal-title{ font-weight: 800 !important; color: #0f172a !important; }
  .pms-swal-text{ color: #475569 !important; }

  /* ================================
     SQUARE NUMBER LABELS (Empty Squares Only)
  ================================ */
  .square-number {
    position: absolute;
    top: 3px;
    left: 4px;
    font-family: 'Inter', 'Arial', sans-serif;
    font-size: 0.6rem;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.5);
    line-height: 1;
    pointer-events: none;
    z-index: 1;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
    letter-spacing: -0.01em;
  }
  
  /* Ensure square content has relative positioning for absolute children */
  .squares-table-ar .square-content {
    position: relative;
  }
  /* Floating toggle button inside grid container, no extra vertical space */
  .board-grid-container{ position: relative; }
  /* Inline chip-style toggle sits with quarter chips (defined in partial) */
  .mine-toggle-chip{ white-space: nowrap; }
  
  /* Mobile adjustments for square numbers */
  @media (max-width: 576px) {
    .square-number {
      font-size: 0.55rem;
      top: 2px;
      left: 3px;
    }
  }

  /* ================================
     WINNER ICONS (replace border bars)
     Q1=top, Q2=right, Q3=bottom, FT=left
  ================================ */
  /* Reset and define per-quarter icon variables */
  .squares-table-ar .square-content{
    /* remove prior border-bar backgrounds */
    background-image: none;
    /* default: no quadrant fills */
    --q1-fill: none;
    --q2-fill: none;
    --q3-fill: none;
    --ft-fill: none;
  }

  /* ================================
     MATCHUP LEGEND & CURRENT SCORE FLASH
     ================================ */
  .matchup-legend{ display:flex; flex-wrap:wrap; justify-content:center; align-items:center; gap:.25rem .5rem; font-size:.85rem; }
  .matchup-legend .legend-swatch{
    display:inline-block; width:12px; height:12px; border-radius:3px; vertical-align:middle; margin-top:-2px;
    background-color:#ffffff; background-repeat:no-repeat; background-size:auto; background-position:0 0;
    border:1px solid #94a3b8; box-shadow: 0 1px 2px rgba(0,0,0,.08);
  }
  /* Quarter swatches mimic square winner shapes */
  .matchup-legend .legend-q1{ background-image: radial-gradient(circle at 0 0,
      rgba(13,110,253,0.85) 0, rgba(13,110,253,0.85) 60%,
      rgba(13,110,253,1) 60%, rgba(13,110,253,1) 62%,
      transparent 62%, transparent 100% ); }
  .matchup-legend .legend-q2{ background-image: radial-gradient(circle at 100% 0,
      rgba(25,135,84,0.85) 0, rgba(25,135,84,0.85) 60%,
      rgba(25,135,84,1) 60%, rgba(25,135,84,1) 62%,
      transparent 62%, transparent 100% ); }
  .matchup-legend .legend-q3{ background-image: radial-gradient(circle at 100% 100%,
      rgba(253,126,20,0.85) 0, rgba(253,126,20,0.85) 60%,
      rgba(253,126,20,1) 60%, rgba(253,126,20,1) 62%,
      transparent 62%, transparent 100% ); }
  .matchup-legend .legend-ft{ background-image: radial-gradient(circle at 0 100%,
      rgba(111,66,193,0.85) 0, rgba(111,66,193,0.85) 60%,
      rgba(111,66,193,1) 60%, rgba(111,66,193,1) 62%,
      transparent 62%, transparent 100% ); }
  .matchup-legend .legend-current{ display:inline-block; width:10px; height:10px; border-radius:50%; background:#dc3545; box-shadow:0 0 0 0 rgba(220,53,69,.45); animation: badgePulse 1.2s ease-in-out infinite; vertical-align:middle; }
  .matchup-legend .legend-pair{ display:inline-flex; align-items:center; gap:.35rem; white-space:nowrap; }
  /* Inline text link for Mine toggle */
  .legend-inline-link{ cursor:pointer; color:#1e40af; padding:.05rem .2rem; border-radius:.4rem; background:transparent; border:none; }
  .legend-inline-link:hover{ color:#0d6efd; text-decoration: underline; }
  .matchup-legend .me-3{ margin-right:.6rem !important; }

  /* Clamp the matchup line width so it doesn’t touch edges */
  .matchup-card.matchup-line{ max-width: clamp(320px, 88vw, 760px); margin-left:auto; margin-right:auto; flex-wrap: nowrap; gap: .35rem; }
  .matchup-card.matchup-line .team-name{ max-width: 26%; min-width: 0; overflow:hidden; text-overflow: ellipsis; white-space: nowrap; }
  .matchup-logo{ height:24px; width:auto; }
  @media (max-width: 576px){
    .matchup-card.matchup-line{ max-width: 94vw; }
    .matchup-card.matchup-line .team-name{ max-width: 34%; }
    .matchup-logo{ height:20px; }
  }

  /* Flashing badge for the current score next to team names */
  .score-badge-live{
    position: relative;
  }
  .score-badge-live::after{
    content:''; position:absolute; inset:-4px; border-radius:999px; box-shadow:0 0 0 0 rgba(220,53,69,.45);
    animation: badgePulse 1.4s ease-in-out infinite;
  }
  @keyframes badgePulse{
    0%{ box-shadow:0 0 0 0 rgba(220,53,69,.45); }
    70%{ box-shadow:0 0 0 10px rgba(220,53,69,0); }
    100%{ box-shadow:0 0 0 0 rgba(220,53,69,0); }
  }

  /* Layer up to four translucent quarter fills */
  .squares-table-ar td .square-content{
    background-image: var(--q1-fill), var(--q2-fill), var(--q3-fill), var(--ft-fill);
    background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
    background-size: auto, auto, auto, auto;
    background-position: 0 0, 0 0, 0 0, 0 0;
  }

  /* Q1 winner: quarter circle at top-left */
  .squares-table-ar td.winner-q1 .square-content{
    --q1-fill: radial-gradient(circle at 0 0,
      rgba(13,110,253,0.45) 0, rgba(13,110,253,0.45) 38%,
      rgba(13,110,253,0.95) 38%, rgba(13,110,253,0.95) 40%,
      transparent 40%, transparent 100%
    );
  }

  /* Q2 winner: quarter circle at top-right */
  .squares-table-ar td.winner-q2 .square-content{
    --q2-fill: radial-gradient(circle at 100% 0,
      rgba(25,135,84,0.45) 0, rgba(25,135,84,0.45) 38%,
      rgba(25,135,84,0.95) 38%, rgba(25,135,84,0.95) 40%,
      transparent 40%, transparent 100%
    );
  }

  /* Q3 winner: quarter circle at bottom-right */
  .squares-table-ar td.winner-q3 .square-content{
    --q3-fill: radial-gradient(circle at 100% 100%,
      rgba(253,126,20,0.45) 0, rgba(253,126,20,0.45) 38%,
      rgba(253,126,20,0.95) 38%, rgba(253,126,20,0.95) 40%,
      transparent 40%, transparent 100%
    );
  }

  /* Final winner: quarter circle at bottom-left */
  .squares-table-ar td.winner-ft .square-content{
    --ft-fill: radial-gradient(circle at 0 100%,
      rgba(111,66,193,0.45) 0, rgba(111,66,193,0.45) 38%,
      rgba(111,66,193,0.95) 38%, rgba(111,66,193,0.95) 40%,
      transparent 40%, transparent 100%
    );
  }

  /* ================================
     PROJECTED (PROVISIONAL) OVERLAY SIZE
     Make the pulsing indicator a centered circle at 50% size
  ================================ */
  td.winner-prov .square-content::before{
    /* cancel full-cover from base CSS and center the circle */
    inset: auto !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    width: 50% !important;
    height: 50% !important;
    transform: translate(-50%, -50%) !important;
    transform-origin: center center;
    border-radius: 50% !important;
    background: rgba(219, 39, 119, 0.18) !important;
    z-index: 3001 !important;
    pointer-events: none !important;
  }

  