/* My Bracket live viewer — 7.0 renderer spike
   Brand tokens mirror BracketApp/Classes/Common/Constants.h + design/share-sheet-mockup.html */

:root {
  --purple: #5116E2;
  --gold: #FFD964;
  --gold-start: #FFCE64;
  --light-purple: #F6F2FF;
  --med-purple: #E3D8FF;
  --dark: #333536;
  --live-green: #2ECC40;
  --page-bg: #FAF9FE;
  --card-bg: #FFFFFF;
  --font: 'Jost', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--page-bg);
  color: var(--dark);
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Top bar ---------- */

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--med-purple);
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.name-block { min-width: 0; display: flex; align-items: center; gap: 12px; width: 100%; justify-content: space-between; }

/* The name is the page's primary context — wrap up to 2 lines before
   ellipsizing; never one-line-truncate it */
#bracket-name {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.status-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.updated-ago { font-size: 10.5px; color: #999; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--light-purple);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--purple);
  flex-shrink: 0;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live-green);
  animation: pulse 2s ease-in-out infinite;
}

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

.status.offline { color: #888; }
.status.offline .live-dot { background: #bbb; animation: none; }
/* champion decided: brand-purple dot, no pulse */
.status.complete .live-dot { background: var(--purple); animation: none; }

/* ---------- Stage ---------- */

.stage {
  flex: 1;
  padding: 20px 0 28px;
}

.stage-inner {
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- Report link (UGC insurance, live mode only) ---------- */

.report-line { text-align: center; padding: 6px 20px 14px; }
.report-line a { color: #9a93ac; font-size: 14px; text-decoration: underline; cursor: pointer; }

/* ---------- Install CTA bar ---------- */

.cta-bar {
  background: var(--card-bg);
  border-top: 1px solid var(--med-purple);
  position: sticky;
  bottom: 0;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}

.cta-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.cta-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
}

.cta-copy { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.cta-copy strong { font-size: 15px; font-weight: 700; }
.cta-copy span { font-size: 12.5px; color: #777; }

/* iPhone: big gold branded button — they can install right now */
.cta-btn {
  background: linear-gradient(var(--gold-start), var(--gold));
  color: var(--dark);
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(255, 217, 100, .5);
  flex-shrink: 0;
}

/* Everyone else: official Apple badge — never restyle/recolor
   (marketing guidelines); min height 40px, we use 44 */
.badge-link { flex-shrink: 0; display: inline-flex; }
.badge-link img { height: 44px; width: auto; display: block; }

/* ---------- Fixture picker (spike-only dev harness) ---------- */

.fixture-bar {
  background: var(--dark);
  color: #fff;
  padding: 6px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.fixture-bar select { font-size: 12px; padding: 2px 4px; border-radius: 6px; }
.fixture-bar-label { opacity: .7; }
.fixture-bar-build { margin-left: auto; opacity: .55; font-weight: 700; letter-spacing: .05em; }

/* ---------- Bracket panels ---------- */

.bracket-panel { margin: 0 0 8px; min-width: 0; }

.panel-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--purple);
  padding: 10px 20px 6px;
}

.bracket-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 12px 12px;
}

.bracket-canvas {
  position: relative;
  display: flex;
  gap: 28px;
  width: max-content;
  padding: 0 8px;
}

.connector-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.connector-layer path {
  fill: none;
  stroke: var(--med-purple);
  stroke-width: 2;
}

.round-col { position: relative; width: 158px; flex-shrink: 0; }

.round-head {
  height: 28px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.round-body { display: flex; flex-direction: column; }

.game-cell {
  display: flex;
  align-items: center;
  min-height: 60px;
}

.gf-body { justify-content: center; gap: 18px; }
.gf-cell { height: auto; }

/* ---------- Game cards ---------- */

.game-box { position: relative; width: 100%; }

/* FINAL overline pinned just above the final matchup card */
.card-overline {
  position: absolute;
  bottom: 100%;
  left: 2px;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.4px;
  color: #9C90D6;
}

.game-card {
  background: var(--card-bg);
  border: 1px solid var(--med-purple);
  border-radius: 10px;
  overflow: hidden;
  width: 100%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}

/* W/L notes hang below the card so team rows stay centered on the connector.
   Compact one-line chip; truncated chips get a chevron and tap-expand. */
/* the note attaches to its matchup: card bottom squares off, chip carries
   the bottom radius — reads as one unit */
.game-box.has-note .game-card {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.game-note.hanging-note {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  padding: 3px 8px 4px;
  border-radius: 0 0 10px 10px;
  border: 1px solid var(--med-purple);
  border-top: none;
  display: flex;
  align-items: center;
  gap: 5px;
}

.game-note.hanging-note .note-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

/* truncation = right-edge fade (Apple-style), no glyphs wasted */
.game-note.hanging-note.expandable { cursor: pointer; }
.game-note.hanging-note.expandable .note-text {
  -webkit-mask-image: linear-gradient(90deg, #000 70%, transparent 99%);
  mask-image: linear-gradient(90deg, #000 70%, transparent 99%);
}
.game-note.hanging-note.expanded {
  z-index: 5;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
/* The cell owning an expanded note has to come forward as a unit: .acc-cell is
   transformed (its own stacking context), so the note's z-index alone can't
   clear the cards below it. .game-cell is static, so it needs positioning to
   take a z-index at all. */
.acc-cell.note-open { z-index: 10; }
.game-cell.note-open { position: relative; z-index: 10; }
.game-note.hanging-note.expanded .note-text {
  white-space: normal;
  -webkit-mask-image: none;
  mask-image: none;
}

/* ---------- Round pager (big brackets) ---------- */

.pager-wrap { min-width: 0; scroll-margin-top: 76px; }

.pager-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 20px 10px;
  -webkit-overflow-scrolling: touch;
}

.pager-tab {
  border: 1px solid var(--med-purple);
  background: var(--card-bg);
  color: var(--purple);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  flex-shrink: 0;
  cursor: pointer;
}

.pager-tab.active {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff;
}
/* accordion canvas: columns morph between rail and full width; passed
   rounds compress against the left edge */
/* overflow-x:auto alone implicitly makes overflow-y:auto too (CSS spec) —
   that nested vertical scroller was Tom's dead-space oblivion. Never again. */
.acc-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 4px 12px 12px;
}

/* NO height/width transition: iOS Safari pauses CSS transitions during
   touch scrolling, freezing the canvas mid-collapse — the layout box must
   always snap to its true size (Tom's phantom void) */
.acc-canvas {
  position: relative;
}

.acc-canvas .connector-layer { transition: opacity .15s ease; }

.acc-col {
  position: absolute;
  top: 0;
  bottom: 0;
  transition: left .28s ease, width .28s ease;
}

.acc-cell {
  position: absolute;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  transition: top .28s ease, opacity .2s ease;
}

.acc-cell.acc-hidden { opacity: 0; pointer-events: none; }

.acc-col.rail { overflow: hidden; }

.team-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  font-size: 13px;
  min-height: 30px;
}

.team-row + .team-row { border-top: 1px solid var(--light-purple); }

.team-row.winner { background: rgba(255, 217, 100, .38); font-weight: 700; }
.team-row.loser .team-name { color: #999; }
.team-row.bye .team-name { color: #b9b9bd; font-style: italic; }
.team-row.tbd .team-name { color: #c5c5ca; }

.seed-chip {
  background: var(--light-purple);
  border: 1px solid var(--med-purple);
  color: var(--purple);
  font-size: 10px;
  font-weight: 700;
  border-radius: 5px;
  min-width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  flex-shrink: 0;
}

.team-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  /* overflow fades out over the last 14px — no ellipsis, matches the app
     cells (Tom, Jul 26). Short names never reach the fade zone. */
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 14px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 14px), transparent);
}

.team-score {
  font-weight: 700;
  font-size: 13px;
  color: var(--dark);
  flex-shrink: 0;
}

.game-note {
  font-size: 11px;
  line-height: 1.35;
  color: #7466ad;
  background: var(--light-purple);
  padding: 4px 9px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.game-sublabel {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--purple);
  padding: 4px 9px 5px;
  background: var(--light-purple);
}

/* ---------- Champion / messages ---------- */

.champion-banner {
  margin: 4px 20px 12px;
  background: linear-gradient(var(--gold-start), var(--gold));
  border-radius: 14px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 0 10px rgba(255, 217, 100, .5);
}

.champion-trophy { width: 24px; height: 24px; color: rgba(51, 53, 54, .8); flex-shrink: 0; }
.champion-name {
  font-weight: 700;
  font-size: 17px;
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.champion-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: rgba(51, 53, 54, .65); }

.message-card {
  margin: 16px 20px;
  background: var(--card-bg);
  border: 1px solid var(--med-purple);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
}

.message-card h2 { font-size: 16px; margin-bottom: 6px; }
.message-card p { font-size: 13.5px; color: #777; }

.offline-note {
  margin: 4px 20px 12px;
  background: #FFF6E5;
  border: 1px solid #F0DCA8;
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13px;
}

/* ---------- Round robin ---------- */

.rr-wrap { padding: 0 20px; display: flex; flex-direction: column; gap: 14px; max-width: 560px; margin: 0 auto; width: 100%; }

.rr-card {
  background: var(--card-bg);
  border: 1px solid var(--med-purple);
  border-radius: 14px;
  overflow: hidden;
}

.rr-card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--purple);
  padding: 12px 16px 8px;
}

/* fixed layout: numeric columns get set widths, team column takes the rest
   and clamps at 2 lines — never collapses, never widens the table */
.rr-table { width: 100%; border-collapse: collapse; font-size: 13.5px; table-layout: fixed; }
.rr-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #999;
  padding: 4px 10px 8px;
}
.rr-table td { padding: 8px 10px; border-top: 1px solid var(--light-purple); }
.rr-table th:first-child, .rr-table td:first-child { padding-left: 16px; width: 44px; }
.rr-table th:nth-child(n+3), .rr-table td:nth-child(n+3) { text-align: center; width: 44px; }
.rr-rank { color: #999; font-weight: 700; }
.rr-team {
  font-weight: 500;
  display: -webkit-box;
  /* 2 clipped a third line mid-glyph on a phone (Tom, Jul 28) — the table row
     grows to fit, so allow the full three lines. */
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.rr-diff { color: #777; }

.rr-games { display: flex; flex-direction: column; }

.rr-game { padding: 9px 16px 9px 12px; border-top: 1px solid var(--light-purple); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.rr-letter {
  background: var(--light-purple);
  border: 1px solid var(--med-purple);
  color: var(--purple);
  font-size: 10px;
  font-weight: 700;
  border-radius: 5px;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.rr-match { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 13.5px; }

.rr-side {
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.rr-side:last-child { text-align: right; }
.rr-side.winner { font-weight: 700; }
.rr-side.winner .rr-side-name { border-bottom: 2px solid var(--gold); }

.rr-score {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 12.5px;
  background: var(--light-purple);
  border-radius: 7px;
  padding: 3px 8px;
  color: var(--dark);
}
.rr-score.unplayed { color: #aaa; font-weight: 500; }

.rr-game .game-note { flex-basis: 100%; border-radius: 7px; }

