/* ==========================================================================
   teams-page-theme.css  -  dynamic page colour for teams.html
   Load AFTER style.css and team-detail.css.

   teams-page-theme.js copies the colour palette of the team card that is in
   the middle of the screen (or of the open team's detail page) into the
   --pg-* variables below. Everything that used to be a hard-coded brown /
   gold "frame" colour on the Teams page reads from these variables instead,
   so the whole page re-tints as you scroll from one card to the next.

   With no themed card (emoji-only crest, nothing loaded yet) the variables
   fall back to the original brown / gold look.
   ========================================================================== */

/* Registered as <color> so changes animate smoothly (Chrome, Safari, Firefox 128+).
   Browsers without @property still work - the colour simply switches instantly. */
@property --pg-top    { syntax: '<color>'; inherits: true; initial-value: #2d241b; }
@property --pg-bot    { syntax: '<color>'; inherits: true; initial-value: #1a1410; }
@property --pg-edge   { syntax: '<color>'; inherits: true; initial-value: #5a4a3a; }
@property --pg-line   { syntax: '<color>'; inherits: true; initial-value: #3a2a1a; }
@property --pg-glow   { syntax: '<color>'; inherits: true; initial-value: rgba(245, 200, 66, 0); }
@property --pg-accent { syntax: '<color>'; inherits: true; initial-value: #f5c842; }
@property --pg-muted  { syntax: '<color>'; inherits: true; initial-value: #8a7a68; }
@property --pg-text   { syntax: '<color>'; inherits: true; initial-value: #d6c3ab; }
@property --pg-track  { syntax: '<color>'; inherits: true; initial-value: #241a12; }

body.teams-body {
  /* defaults (the original brown theme); JS overrides these inline */
  --pg-top:    #2d241b;
  --pg-bot:    #1a1410;
  --pg-edge:   #5a4a3a;
  --pg-line:   #3a2a1a;
  --pg-glow:   rgba(245, 200, 66, 0);
  --pg-accent: #f5c842;
  --pg-muted:  #8a7a68;
  --pg-text:   #d6c3ab;
  --pg-track:  #241a12;

  background-color: var(--pg-bot);
  background-image:
    radial-gradient(120% 55% at 50% 0%, var(--pg-glow), transparent 70%),
    linear-gradient(145deg, var(--pg-bot), var(--pg-top));
  background-attachment: fixed;

  transition: --pg-top .5s ease, --pg-bot .5s ease, --pg-edge .5s ease, --pg-line .5s ease,
              --pg-glow .5s ease, --pg-accent .5s ease, --pg-muted .5s ease,
              --pg-text .5s ease, --pg-track .5s ease;
}
@media (prefers-reduced-motion: reduce) { body.teams-body { transition: none; } }

/* ---------- page text, titles, notes ---------- */
body.teams-body .teams-page            { color: var(--pg-text); }
body.teams-body .teams-panel-title     { color: var(--pg-accent); }
body.teams-body .teams-panel-note,
body.teams-body .teams-empty           { color: var(--pg-muted); }
body.teams-body .teams-empty a         { color: var(--pg-accent); }
body.teams-body .profile-bar-text,
body.teams-body .general-rules-list li,
body.teams-body .filter-check          { color: var(--pg-text); }
body.teams-body .filter-field          { color: var(--pg-muted); }

/* ---------- toolbar (Discover Teams / search / sort / filter) ---------- */
body.teams-body .teams-toolbar         { border-bottom-color: var(--pg-line); }
body.teams-body .tb-search,
body.teams-body .tb-sort,
body.teams-body .tb-btn,
body.teams-body .filter-field input,
body.teams-body .filter-field select   { background: var(--pg-track); border-color: var(--pg-line); }
body.teams-body .tb-btn:hover          { background: #2a2018; background: color-mix(in srgb, var(--pg-track) 88%, #fff); }
body.teams-body .tb-btn.active         { border-color: var(--pg-accent); color: var(--pg-accent); }
body.teams-body .tb-badge              { background: var(--pg-accent); }

/* ---------- panels (profile, rules, create team, status note) ---------- */
body.teams-body .teams-panel,
body.teams-body .profile-bar,
body.teams-body #teamSettingsForm      { background: var(--pg-bot); border-color: var(--pg-line); }
body.teams-body .teams-status-note {
  background: #1e1712;
  background: linear-gradient(180deg, color-mix(in srgb, var(--pg-top) 35%, var(--pg-bot)), var(--pg-bot));
  border-color: var(--pg-line);
  border-left-color: var(--pg-accent);
}
body.teams-body .teams-status-note .teams-panel-note         { color: var(--pg-text); }
body.teams-body .teams-status-note .teams-panel-note strong,
body.teams-body .teams-status-note .teams-status-cta         { color: var(--pg-accent); }

/* ---------- floating menu button + menu ---------- */
body.teams-body .floating-menu-btn        { background: var(--pg-bot); border-color: var(--pg-edge); }
body.teams-body .floating-menu-btn:hover  { border-color: var(--pg-accent); }
body.teams-body .floating-menu-btn span   { background: var(--pg-accent); }
body.teams-body .floating-menu-panel      { background: var(--pg-bot); border-color: var(--pg-edge); }
body.teams-body .floating-menu-header     { border-bottom-color: var(--pg-line); }
body.teams-body .floating-menu-header h3  { color: var(--pg-accent); }
body.teams-body .floating-menu-nav .menu-item       { color: var(--pg-text); }
body.teams-body .floating-menu-nav .menu-item:hover { background: #2a2018; background: color-mix(in srgb, var(--pg-track) 88%, #fff); color: var(--pg-accent); }

/* ---------- modals (rules, filter) + toast + close buttons ---------- */
body.teams-body .rules-modal              { background: var(--pg-bot); border-color: var(--pg-edge); color: var(--pg-text); }
body.teams-body .rules-modal-header h2    { color: var(--pg-accent); }
body.teams-body .team-detail-close        { border-color: var(--pg-line); color: var(--pg-text); }
body.teams-body .team-detail-close:hover  { border-color: var(--pg-accent); color: var(--pg-accent); }
body.teams-body #comingSoonBanner         { background: var(--pg-bot); border-color: var(--pg-accent); color: var(--pg-accent); }

/* ---------- secondary buttons (menu close, Reset, Edit Profile ...) ---------- */
body.teams-body .btn-secondary {
  background: #3a2a1a;
  background: color-mix(in srgb, var(--pg-edge) 35%, var(--pg-bot));
  border-color: var(--pg-edge);
  color: var(--pg-text);
}
body.teams-body .btn-secondary:hover {
  background: #5a4a3a;
  background: color-mix(in srgb, var(--pg-edge) 60%, var(--pg-bot));
}

/* ---------- landscape shelf pager dots ---------- */
body.teams-body .teams-panels-dots button         { background: var(--pg-line); }
body.teams-body .teams-panels-dots button.active  { background: var(--pg-accent); }

/* ---------- team cards: same border + glow as the crest on the team detail page ----------
   (detail crest = 2px solid var(--t-edge) with a soft glow). Your own team's card no longer
   has a forced gold border - it uses its theme colour like every other card; the
   "YOUR TEAM" badge still marks it. */
body.teams-body .team-card.crest-themed,
body.teams-body .team-card.crest-themed.team-card-mine {
  border: 2px solid var(--t-edge) !important;
  box-shadow: 0 0 22px var(--t-glow), 0 6px 14px rgba(0, 0, 0, .45);
}

/* ---------- Wider team cards on phone landscape: room for name + country ---------- */
@media (max-width: 1099px) and (max-height: 700px) and (orientation: landscape) {

  /* Card: 58vw -> ~86vw (next card still peeks in at the edge) */
  body.teams-body #teamsListScreen .teams-grid .team-card {
    flex: 0 0 86vw;
    max-width: 760px;
  }

  /* Crest panel keeps a similar size, so the text side gets the extra width */
  body.teams-body .team-card-banner { flex: 0 0 32%; }

  /* More breathing room in the text side */
  body.teams-body .team-card-body {
    padding: 1.1rem 1.4rem;
    column-gap: 1.25rem;
    row-gap: 0.55rem;
  }

  /* Name: wrap if needed, never cut off with "..." */
  body.teams-body .team-card-name,
  body.teams-body .team-card-name.name-long,
  body.teams-body .team-card-name.name-xl {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
    line-height: 1.2;
    font-size: 1.25rem;
  }

  /* Country: full name, no ellipsis */
  body.teams-body .team-card-country span:last-child {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
}

/* =====================================================================
   DESKTOP / TABLET: one swipeable row of wide cards (same idea as phone
   landscape) instead of a stacked grid. Applies to every screen that is
   NOT the phone-landscape layout above.
   ===================================================================== */
@media (min-width: 1100px), (min-width: 700px) and (min-height: 701px) {

  /* --- the row --- */
  body.teams-body #teamsListScreen .teams-grid {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 1.5rem;
    grid-template-columns: none;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scroll-padding-left: 1.5rem;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem 1.5rem 1.25rem;
    margin-bottom: 5rem;               /* breathing room below (footer goes here) */
    scrollbar-width: thin;             /* mouse users need a visible bar */
    scrollbar-color: var(--pg-line, #3a2a1a) transparent;
  }
  body.teams-body #teamsListScreen .teams-grid::-webkit-scrollbar { display: block; height: 8px; }
  body.teams-body #teamsListScreen .teams-grid::-webkit-scrollbar-thumb {
    background: var(--pg-line, #3a2a1a); border-radius: 4px;
  }
  body.teams-body #teamsListScreen .teams-grid .teams-empty { flex: 1 0 100%; }

  /* --- the card: wide, horizontal, fixed height --- */
  body.teams-body #teamsListScreen .teams-grid .team-card {
    flex: 0 0 min(780px, 80vw);
    flex-direction: row;
    align-items: stretch;
    height: clamp(26rem, calc(100vh - 17rem), 34rem);
    height: clamp(26rem, calc(100dvh - 17rem), 34rem);
    scroll-snap-align: start;
  }
  body.teams-body #teamsListScreen .teams-grid .team-card:hover,
  body.teams-body #teamsListScreen .teams-grid .team-card:focus-visible { transform: none; }

  /* --- crest panel on the left --- */
  body.teams-body .team-card-banner {
    flex: 0 0 36%;
    height: auto;
    min-height: 0;
    overflow: hidden;
    border-bottom: 0;
    border-right: 1px solid #3a2a1a;
  }
  body.teams-body .team-card-banner::after { display: none; }
  body.teams-body .team-card-crest {
    position: absolute; inset: 0; width: 100%; height: 100%; filter: none;
  }
  body.teams-body .team-card-crest img {
    width: 100% !important; height: 100% !important;
    object-fit: cover; border-radius: 0 !important; filter: none;
  }
  body.teams-body .team-card-crest > span { font-size: 7rem !important; }
  body.teams-body .team-card-mine-badge { top: 0.75rem; left: 0.75rem; font-size: 0.7rem; padding: 0.2rem 0.6rem; }

  /* --- details on the right --- */
  body.teams-body .team-card-body {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name    rank"
      "country rank"
      "league  form"
      "records records"
      "members members"
      "join    join";
    grid-template-rows: auto auto auto auto auto 1fr;
    column-gap: 1.5rem;
    row-gap: 0.7rem;
    padding: 1.5rem 1.75rem;
    align-items: center;
    align-content: stretch;
    text-align: left;
  }
  body.teams-body .team-card-name {
    grid-area: name; margin: 0;
    font-size: 1.6rem; line-height: 1.2;
    white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere;
  }
  body.teams-body .team-card-name.name-long,
  body.teams-body .team-card-name.name-xl { font-size: 1.6rem; white-space: normal; }
  body.teams-body .team-card-country {
    grid-area: country; justify-content: flex-start; margin: 0; font-size: 1.05rem;
  }
  body.teams-body .team-card-country span:last-child {
    white-space: normal; overflow: visible; text-overflow: clip;
  }
  body.teams-body .team-card-league  { grid-area: league; margin: 0; font-size: 0.8rem; overflow: visible; text-overflow: clip; }
  body.teams-body .team-card-rank    { grid-area: rank; margin: 0; align-self: center; }
  body.teams-body .team-card-form    { grid-area: form; justify-self: end; margin: 0; }
  body.teams-body .form-dot          { width: 1.3rem; height: 1.3rem; font-size: 0.65rem; }
  body.teams-body .tr-card           { grid-area: records; margin-top: 0.4rem; align-self: start; width: 100%; }
  body.teams-body .team-card-members { grid-area: members; justify-self: stretch; margin: 0; white-space: normal; font-size: 0.9rem; }
  body.teams-body .tcm-text          { font-size: 0.95rem; }
  body.teams-body .tcm-fans          { font-size: 0.95rem; }
  body.teams-body .team-card-actions { grid-area: join; align-self: end; margin: 0; }

  /* --- records table: a bit larger to match the bigger card --- */
  body.teams-body .tr-head,
  body.teams-body .tr-row { grid-template-columns: minmax(0, 1fr) repeat(4, 2.4rem); }
  body.teams-body .tr-label { font-size: 0.9rem; }
  body.teams-body .tr-n     { font-size: 1.1rem; }
  body.teams-body .tr-empty { font-size: 0.85rem; }
  body.teams-body .tr-head span { font-size: 0.7rem; }
}
