/* =================================================================
   Phuket Charity Boxing — Predictions
   Mobile-first dark palette. Cream replaces gold throughout.
   ================================================================= */

:root {
  --bg:        #0A0A0C;
  --panel:     #15151A;
  --panel-2:   #1F1F26;
  --line:      #2A2A33;
  --text:      #F4F4F4;
  --muted:     #8A8A95;
  --cream:     #F5F0E1;

  --red:       #B22222;
  --red-deep:  #7A1414;
  --blue:      #1E3A8A;
  --blue-deep: #0F1F4F;

  --success:   #4ADE80;
  --warning:   #F59E0B;
  --danger:    #EF4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--cream); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ HEADER ============ */
header.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(180deg, #15151A 0%, #0A0A0C 100%);
  border-bottom: 2px solid var(--cream);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;     /* allow row-2 wrap on narrow viewports */
  row-gap: 6px;
}

.brand {
  flex: 1;
  min-width: 0;
}
.brand h1 {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 1.1;
}
.brand .tagline {
  font-size: 9px;
  color: var(--cream);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-pool {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.summary-pool .label {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.summary-pool .value {
  font-size: 16px;
  font-weight: 900;
  color: var(--cream);
  line-height: 1.1;
}

.header-cta {
  background: var(--cream);
  color: #000;
  border: none;
  padding: 8px 12px;
  border-radius: 4px;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.header-cta:hover { opacity: 0.9; }
.header-cta.secondary {
  background: transparent;
  color: var(--cream);
  border: 1px solid var(--cream);
}

@media (min-width: 600px) {
  header.app-header { padding: 16px 24px; }
  .brand h1 { font-size: 22px; }
  .brand .tagline { font-size: 11px; }
  .summary-pool .value { font-size: 22px; }
}

/* ============ EVENT BANNER ============ */
.event-banner {
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.event-banner strong {
  color: var(--cream);
  font-weight: 700;
}

/* ============ MAIN ============ */
main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
}

/* ============ FIGHT GRID ============ */
.fight-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 24px;
}
@media (min-width: 600px) {
  .fight-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}

.fight-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fight-tile.closed { opacity: 0.7; }
.fight-tile.settled .corner.loser { opacity: 0.45; filter: grayscale(0.5); }
.fight-tile.settled .corner.winner {
  box-shadow: 0 0 0 2px var(--cream), 0 0 16px rgba(245, 240, 225, 0.35);
}

.fight-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.fight-num {
  font-size: 28px;
  font-weight: 900;
  color: var(--cream);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.fight-meta {
  flex: 1;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.status-badge {
  font-size: 9px;
  letter-spacing: 1.5px;
  padding: 3px 7px;
  border-radius: 3px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-OPEN    { background: #166534; color: #fff; }
.status-CLOSED  { background: #7A1414; color: #fff; }
.status-SETTLED { background: var(--cream); color: #000; }

.corners {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.corner {
  border-radius: 6px;
  padding: 12px 10px;
  cursor: pointer;
  border: none;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  transition: transform 0.15s ease;
}
.corner:active { transform: scale(0.98); }
.corner:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.corner.red {
  background: linear-gradient(135deg, var(--red) 0%, var(--red-deep) 100%);
}
.corner.blue {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-deep) 100%);
}

.corner-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.3;
  margin-bottom: 8px;
  min-height: 32px;
  text-transform: uppercase;
  color: #fff;
}

.corner-multiplier {
  font-size: 24px;
  font-weight: 900;
  color: var(--cream);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}
.corner-multiplier.placeholder {
  color: rgba(255,255,255,0.5);
  font-size: 18px;
}

.corner-pool {
  font-size: 10px;
  color: rgba(255,255,255,0.85);
  line-height: 1.3;
}
.corner-pool .paid-amt {
  font-weight: 700;
  font-size: 12px;
  color: #fff;
}
.corner-pool .ind-amt {
  color: rgba(255,255,255,0.6);
  font-style: italic;
}

.fight-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.5px;
}
.fight-footer .pred-count {
  color: var(--text);
  font-weight: 700;
}
.fight-footer a {
  color: var(--cream);
  font-size: 11px;
}

.winner-banner {
  text-align: center;
  font-size: 11px;
  color: var(--cream);
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 4px 0;
}

/* ============ RECENT ACTIVITY ============ */
.recent {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
}
.recent h2 {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cream);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.recent-list { list-style: none; }
.recent-list li {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  align-items: baseline;
}
.recent-list li:last-child { border-bottom: none; }
.recent-list .name { color: var(--text); font-weight: 600; }
.recent-list .fight { color: var(--muted); font-size: 11px; }
.recent-list .pick.RED  { color: #FF8888; font-weight: 700; }
.recent-list .pick.BLUE { color: #88AAFF; font-weight: 700; }
.recent-list .credits {
  color: var(--cream);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.recent-empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 12px 0;
}

/* ============ FOOTER ============ */
footer.app-footer {
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  padding: 16px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.5px;
}
footer.app-footer a {
  color: var(--cream);
  margin: 0 8px;
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #000;
  padding: 10px 20px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 200;
  pointer-events: none;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); color: #fff; }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 {
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cream);
  margin-bottom: 12px;
}
.modal p { color: var(--muted); font-size: 13px; line-height: 1.5; margin-bottom: 12px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.btn {
  background: var(--cream);
  color: #000;
  border: none;
  padding: 10px 16px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover { opacity: 0.9; }
.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.secondary:hover { border-color: var(--cream); color: var(--cream); }

/* ============ LOADING ============ */
.loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* v2: badge overlaid on the corner tile when the user has a prediction */
.corner { position: relative; }
.my-pred-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--cream);
  color: var(--cream);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  pointer-events: none;       /* badge is decorative; corner button handles taps */
}

/* ============ USER NAV TABS ============ */
/* Rendered by header.js into <div id="user-nav-slot"></div>.
   Sits directly beneath the app-header on /, /me, /disclaimer. */
.user-nav {
  display: flex;
  justify-content: center;
  gap: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: sticky;
  top: 50px;            /* sits below the sticky app-header */
  z-index: 40;
}
.user-nav-tab {
  display: inline-block;
  padding: 12px 20px;
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.user-nav-tab:hover {
  color: var(--cream);
  text-decoration: none;
}
.user-nav-tab.active {
  color: var(--cream);
  border-bottom-color: var(--cream);
}
@media (min-width: 600px) {
  .user-nav { top: 64px; }
  .user-nav-tab { padding: 14px 24px; font-size: 12px; }
}

/* ============ "ADD CREDITS" CTA + PENDING-TOPUP BANNER ============ */
/* Header CTA — cream pill, prominent next to the user menu. */
.header-cta.add-credits-cta {
  background: var(--cream);
  color: #000;
  font-weight: 800;
  letter-spacing: 1px;
}
.header-cta.add-credits-cta:hover { opacity: 0.85; }
@media (max-width: 480px) {
  /* On narrow phones, shrink to icon-style so it doesn't crowd the user menu. */
  .header-cta.add-credits-cta { padding: 8px 10px; font-size: 11px; }
}

/* Homepage pending banner (between event-banner and fight-grid). */
.pending-topup-banner {
  background: linear-gradient(90deg, rgba(245,158,11,0.18), rgba(245,158,11,0.08));
  border: 1px solid var(--warning);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 0 auto 12px;
  max-width: 1200px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s ease;
}
.pending-topup-banner:hover {
  background: linear-gradient(90deg, rgba(245,158,11,0.28), rgba(245,158,11,0.14));
  text-decoration: none;
}
.pending-topup-banner .left {
  display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0;
}
.pending-topup-banner .label {
  color: var(--warning);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 800;
  flex-shrink: 0;
}
.pending-topup-banner .amount {
  color: var(--cream);
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.pending-topup-banner .arrow {
  color: var(--cream);
  font-size: 18px;
  flex-shrink: 0;
}
.pending-topup-banner .hint {
  color: var(--muted);
  font-size: 11px;
}

/* /me page pending badge near the balance */
.pending-topup-badge {
  background: linear-gradient(90deg, rgba(245,158,11,0.18), rgba(245,158,11,0.08));
  border: 1px solid var(--warning);
  border-radius: 6px;
  padding: 10px 14px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.pending-topup-badge:hover { text-decoration: none; }
.pending-topup-badge .left {
  display: flex; flex-direction: column; gap: 2px;
}
.pending-topup-badge .label {
  color: var(--warning);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 800;
}
.pending-topup-badge .amount {
  color: var(--cream);
  font-weight: 800;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.pending-topup-badge .arrow {
  color: var(--cream);
  font-size: 18px;
}

/* =============================================================================
   MOBILE RENDERING FIXES (homepage + persistent header)
   ============================================================================= */

/* Bug 1: at narrow widths, "Fight Night Charity Challenge" can't sit on
   one row alongside the pool indicator + auth CTAs. Stack to two rows
   under 480px: row-1 = brand, row-2 = pool + auth slot. The header's
   flex-wrap (set above) lets these reflow naturally. */
@media (max-width: 480px) {
  header.app-header {
    padding: 10px 14px;
  }
  .brand {
    flex: 0 0 100%;       /* take the full first row */
    text-align: left;
    min-width: 0;
  }
  /* Title already has min-width:0 in flex; protect against very long
     charity names by wrapping the line if needed. */
  .brand h1 {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .summary-pool {
    flex: 0 0 auto;
    text-align: left;
  }
  /* The auth slot already wraps internally via flex; just keep it on
     the right of row 2. */
  .header-right {
    flex: 0 0 auto;
    margin-left: auto;
  }
}

/* Bug 2: sticky user-nav. The slot was a normal block-level wrapper;
   `position: sticky` on the nav inside it could only stick within the
   slot's own (tiny) height, so the nav scrolled away. `display: contents`
   removes the slot from the layout tree, so the nav becomes effectively
   a child of <body> and sticks against the page scroll. The top offset
   uses --header-height set by header.js (measures the live header so
   it stays correct when the header wraps to two rows on narrow widths). */
#user-nav-slot { display: contents; }

.user-nav {
  /* Override the hardcoded top values from the earlier rule below. */
  top: var(--header-height, 56px);
}
@media (min-width: 600px) {
  /* Drop the desktop-fixed top; the dynamic var handles all viewports. */
  .user-nav { top: var(--header-height, 64px); }
}

/* Bug 3: my-pred-badge — anchor to bottom-right of the corner tile
   so it stops overlapping the fighter name. Reserve right padding on
   .corner-pool so the credits-paid line doesn't run under the badge. */
.my-pred-badge {
  top: auto;            /* override the earlier top:6px */
  bottom: 4px;
  right: 4px;
}
.corner { padding-bottom: 4px; }   /* a hair of breathing room */
.corner-pool { padding-right: 64px; }
