/* =========================================================
   Design tokens
========================================================= */
:root {
  --bg: #0c0f14;            /* page background */
  --card: #121727;          /* card background */
  --muted: #a5b4fc;         /* accents */
  --text: #e5e7eb;          /* primary text */
  --text-dim: #cbd5e1;      /* secondary text */
  --border: #1f2a44;        /* borders */
  --brand: #7c3aed;         /* brand accent */
  --success: #10b981;
  --danger: #ef4444;
  --shadow: 0 10px 25px rgba(0,0,0,.25);
  --audio-h: 64px;          /* JS updates this to the real height */
}

/* =========================================================
   Base / reset
========================================================= */
* { box-sizing: border-box; }
html, body { height: 100%; }

body{
  margin:0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  color:var(--text);
  line-height:1.5;
  padding-top: var(--audio-h); /* keep content below fixed audio bar */

  /* Textured black background (punchier) */
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 700px at 18% -10%, rgba(255,255,255,0.06), transparent),
    radial-gradient(900px 550px at 82% 8%,   rgba(255,255,255,0.045), transparent),
    radial-gradient(800px 600px at 50% 120%, rgba(0,0,0,0.55),         transparent),
    radial-gradient(rgba(255,255,255,0.035) 1px, transparent 1px); /* dot grain */
  background-size: auto, auto, auto, 3px 3px;
  background-attachment: fixed, fixed, fixed, fixed;
}

/* Stronger micro-noise overlay (inline, no external file) */
body::after{
  content:"";
  position:fixed; inset:0; pointer-events:none;
  z-index:0;
  opacity:.10;                      /* 0.05–0.20 = subtle → strong */
  mix-blend-mode: normal;
  background-image: url('data:image/svg+xml;utf8,\
<svg xmlns="http://www.w3.org/2000/svg" width="160" height="160" viewBox="0 0 160 160">\
  <filter id="n">\
    <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="4" stitchTiles="stitch"/>\
    <feColorMatrix type="saturate" values="0"/>\
  </filter>\
  <rect width="160" height="160" filter="url(%23n)" />\
</svg>');
  background-size:160px 160px;      /* smaller = tighter grain */
}

/* Page container */
.container { width: min(1200px, 92vw); margin: 0 auto; }

/* =========================================================
   Audio bar (fixed, always on top)
========================================================= */
#audio-controls {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  backdrop-filter: saturate(160%) blur(6px);
  background: linear-gradient(180deg, rgba(11,15,25,.88), rgba(11,15,25,.70));
  border-bottom: 1px solid var(--border);
}
#audio-controls button {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
#audio-controls button:hover { border-color: var(--muted); color: #fff; }

/* =========================================================
   Layout (cards & stacks)
========================================================= */
.layout { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; padding: 24px 0 40px; }
@media (max-width: 900px){ .layout { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 24px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-header h2 { margin: 0; font-size: 18px; color: var(--text); }

/* =========================================================
   Roster grid (centered avatars with name underneath)
========================================================= */
.roster-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; padding: 16px; }
@media (max-width: 900px){ .roster-grid { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 520px){ .roster-grid { grid-template-columns: 1fr; } }

.roster-item {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px; padding: 14px;
  border: 1px solid var(--border); border-radius: 12px; background: rgba(255,255,255,.02);
}
.profile-img {
  width: 96px; height: 96px; border-radius: 12px; object-fit: cover;
  border: 1px solid var(--border); background: #0b0f19;
}
.wrestler-btn {
  border: 1px solid var(--border); background: #0e1424; color: var(--text);
  padding: 10px 12px; border-radius: 10px; font-weight: 600; cursor: pointer;
}
.wrestler-btn:hover { border-color: var(--muted); }

/* =========================================================
   Tables (Rankings + Match Log)
========================================================= */
.table-wrap { padding: 16px; }
.table-wrap table, #topRankings table, #matchLogContent table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.table-wrap thead th,
#topRankings thead th,
#matchLogContent thead th {
  text-align: left; font-weight: 600; color: var(--text);
  border-bottom: 1px solid var(--border); padding: 10px 8px;
}
.table-wrap tbody td,
#topRankings tbody td,
#matchLogContent tbody td {
  padding: 10px 8px; border-bottom: 1px solid rgba(255,255,255,.06); color: var(--text-dim);
}
#topRankings tbody tr:hover,
#matchLogContent tbody tr:hover { background: rgba(255,255,255,.03); }

/* --- Rankings table column sizing --- */
#topRankings table { table-layout: fixed; }
#topRankings thead th:nth-child(1),
#topRankings tbody td:nth-child(1) { width: 40%; }
#topRankings thead th:nth-child(2),
#topRankings tbody td:nth-child(2) { width: 40%; }
#topRankings thead th:nth-child(3),
#topRankings tbody td:nth-child(3) { width: 20%; }

/* prevent long names/chips from blowing columns */
#topRankings .tooltip { display: inline-block; max-width: 100%; vertical-align: bottom; }
#topRankings .tooltip > strong { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#topRankings .chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
#topRankings .chip .label { flex: 0 0 auto; }

@media (max-width: 520px){
  #topRankings thead th:nth-child(1),
  #topRankings tbody td:nth-child(1) { width: 56%; }
  #topRankings thead th:nth-child(2),
  #topRankings tbody td:nth-child(2),
  #topRankings thead th:nth-child(3),
  #topRankings tbody td:nth-child(3) { width: 22%; }
}

/* =========================================================
   Tooltip card (used in rankings for “last match”)
========================================================= */
.tooltip { position: relative; display: inline-block; }
.tooltipcard {
  position: absolute; left: 0; top: 100%; margin-top: 8px;
  min-width: 260px; max-width: 360px;
  padding: 12px;
  background: var(--card);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  pointer-events: none; opacity: 0; transform: translateY(4px);
  transition: opacity .15s ease, transform .15s ease;
  z-index: 900;
}
.tooltip:hover .tooltipcard { opacity: 1; pointer-events: auto; transform: translateY(0); }
.tip-title { font-weight: 700; color: var(--text); margin-bottom: 8px; }
.tip-grid { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; }
.tip-k { color: var(--text); opacity: .85; }
.tip-v.multiline { white-space: normal; }

/* =========================================================
   Modal (fixed size, lives below the audio bar)
========================================================= */
.modal {
  position: fixed; inset: 0;
  display: none; /* toggled by .open */
  align-items: flex-start;              /* start below bar */
  justify-content: center;
  padding: 16px;
  padding-top: calc(var(--audio-h) + 16px); /* keep clear of sound bar */
  background: rgba(0,0,0,.6);
  z-index: 950; /* below the audio bar which is 1000 */
}
.modal.open { display: flex; }

.modal-content {
  width: min(1100px, calc(100vw - 32px));
  height: calc(100vh - var(--audio-h) - 32px); /* fixed viewport-size panel */
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}
.close-button,
.modal-close {
  position: absolute; right: 12px; top: 12px;
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: rgba(255,255,255,.02);
  color: var(--text); font-weight: 700; cursor: pointer;
  display: grid; place-items: center;
  z-index: 1000;
}
.close-button:hover, .modal-close:hover { border-color: var(--muted); color: #fff; }

.modal-body {
  display: grid; grid-template-columns: 240px 1fr; gap: 18px;
  padding: 18px; overflow: auto;
}
@media (max-width: 800px){ .modal-body { grid-template-columns: 1fr; } }

.modal-image { display: grid; gap: 12px; align-content: start; }
.modal-image img {
  width: 100%; height: 220px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--border);
}

/* Accolades (fixed-size grid, no stretching) */
.profile-accolades {
  display: grid; grid-template-columns: repeat(6, 32px); gap: 8px;
}
@media (max-width: 800px){ .profile-accolades { grid-template-columns: repeat(5, 28px); } }
.accolade-icon { width: 32px; height: 32px; object-fit: contain; }

/* Right column text blocks */
.modal-text { color: var(--text-dim); }
#profileName { margin: 0 0 8px; color: var(--text); }
.catchphrase-title, .bio-title { margin: 12px 0 6px; color: var(--muted); font-weight: 600; }
.bio-text, .catchphrase-text { color: var(--text-dim); }

/* Stats */
.profile-stats { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-top: 12px; }
.profile-section, .credits {
  border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: rgba(255,255,255,.02);
}
.credits { grid-column: span 2; }
.section-title { margin: 0 0 6px 0; font-size: 14px; color: var(--text); }
.record { color: var(--muted); font-weight: 600; }
.winrate { color: var(--success); font-weight: 600; }
.credit.current { color: var(--text); font-weight: 600; }
.credit.previous { color: var(--danger); font-weight: 600; }

/* =========================================================
   Tabs (moved from JS so CSS is complete)
========================================================= */
.tabs-header{
  position: sticky; top: 0;
  background: var(--card); z-index: 1;
  display:flex; flex-wrap: wrap; gap:8px; padding:8px 0 0; border-bottom:1px solid var(--border);
}
.tab-btn{
  appearance:none; border:1px solid var(--border);
  background:rgba(255,255,255,.03); color:var(--text);
  padding:8px 10px; border-radius:10px 10px 0 0; font-weight:600; cursor:pointer;
}
.tab-btn.active{ background:#0e1424; border-bottom-color:#0e1424; }
.tab-panels{ padding:12px 0 0; }
.tab-panel{ display:none; }
.tab-panel.active{ display:block; }

.stats-grid{
  display:grid; grid-template-columns: repeat(2, minmax(0,1fr));
  gap:12px;
}
.stat-card{
  border:1px solid var(--border); border-radius:12px; padding:10px; background:rgba(255,255,255,.02);
}
.stat-title{ margin:0 0 6px 0; font-size:14px; color:var(--text); }
.stat-row{ color:var(--text-dim); }

.kv{ display:grid; grid-template-columns: 110px 1fr; gap:6px 10px; }
.kv .k{ color:var(--text); opacity:.85; font-weight:700; font-style:italic; }
.kv .v{ color:var(--text-dim); }

/* =========================================================
   Chips (badges used in rankings + overview)
========================================================= */
.chips{ display:flex; flex-wrap:wrap; gap:8px; margin:8px 0; }
.chip{
  display:inline-flex; align-items:center; gap:6px;
  font-size:12px; padding:6px 10px;
  border-radius:999px; border:1px solid var(--border);
  background:rgba(255,255,255,.03);
  white-space: nowrap; /* prevent wrapping */
  overflow: visible; /* allow overflow to show full text */
  text-overflow: clip; /* disable ellipsis */
  color: var(--text); /* ensure text color is visible */
  min-width: 40px; /* ensure enough width for arrow and number */
  justify-content: center;
}
.chip .label{ opacity:.7; margin-right:6px; font-weight:600; font-style:italic; }
.chip strong { color: inherit; } /* strong inherits chip color */
.chip.chip-brand{ border-color: var(--brand);  color: var(--brand); min-width: 60px; justify-content: center; }
.chip.chip-up   { border-color: var(--success); color: var(--success); min-width: 60px; justify-content: center; }
.chip.chip-down { border-color: var(--danger);  color: var(--danger); min-width: 60px; justify-content: center; }

/* =========================================================
   Rivals
========================================================= */
.rivals-grid{ display:grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap:12px; }
.rival-card{ display:flex; align-items:center; gap:10px; padding:10px; border:1px solid var(--border); border-radius:12px; background:rgba(255,255,255,.02); }
.rival-card img{ width:40px; height:40px; border-radius:8px; object-fit:cover; border:1px solid var(--border); background:#0b0f19; }

/* =========================================================
   Rival block (legacy + modern classes)
========================================================= */
.rival,
.rival-container {
  position: relative;
  width: 128px; height: 128px;
  margin: 0 auto 10px auto;
  display: flex; align-items: center; justify-content: center;
  background: url("Images/Profile/rivalboarder.png") no-repeat center / contain;
}
.rival img, .rival-image {
  width: 75px; height: 75px; border-radius: 8px; object-fit: cover;
}
.rival-name {
  position: absolute; bottom: -10px; left: 0; right: 0;
  text-align: center; font-size: 0.85rem; color: var(--text);
}

/* =========================================================
   Utility
========================================================= */
.win{ color: var(--success); }
.lose{ color: var(--danger); }
.hidden { display: none !important; }
