@font-face {
  font-family: "Tajawal";
  src: url("/fonts/Tajawal-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Tajawal";
  src: url("/fonts/Tajawal-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

/* The scoreboard look the hall's wall board has, dark by default. */
:root {
  --bg: #0b0f17;
  --surface: #141a26;
  --surface-2: #1b2333;
  --line: #263046;
  --text: #e8edf5;
  --muted: #8b97ab;
  --accent: #2dd4bf;
  --accent-ink: #062b27;
  --gold: #f5c542;
  --silver: #c3cad4;
  --bronze: #d08a4e;
  --live: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 14px;
  --gutter: 16px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --line: #dde3ec;
    --text: #111827;
    --muted: #5b6577;
    --accent: #0d9488;
    --accent-ink: #ffffff;
    --gold: #b7860b;
    --silver: #6b7685;
    --bronze: #a35f25;
    --live: #dc2626;
    --ok: #059669;
    --warn: #b45309;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; }
button { font: inherit; color: inherit; }
img { display: block; }

.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* -- the bar along the top -------------------------------------------------- */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px var(--gutter);
  padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.hall-link {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
}
.hall-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cup { width: 22px; height: 22px; fill: var(--gold); flex: none; }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; flex: none; }

.lang {
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}

main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px var(--gutter) 32px;
}

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px var(--gutter);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--line);
}
.brand { letter-spacing: 0.04em; display: inline-flex; align-items: center; gap: 6px; }
.brand img { border-radius: 4px; }

.loading, .message {
  text-align: center;
  color: var(--muted);
  padding: 48px 0;
}
.message strong { display: block; color: var(--text); font-size: 1.15rem; margin-bottom: 6px; }

.stale {
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

/* -- pills -------------------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.pill.ACTIVE { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.pill.ACTIVE::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}
.pill.COMPLETED { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, transparent); }
.pill.live { color: var(--live); border-color: color-mix(in srgb, var(--live) 50%, transparent); }

@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .pill.ACTIVE::before { animation: none; } }

/* -- the hall's list -------------------------------------------------------------- */

.page-title { font-size: 1.5rem; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 18px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--accent); }
.card:active { transform: scale(0.99); }
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.card h2 { font-size: 1.15rem; margin: 0 0 4px; }
.card .meta { color: var(--muted); font-size: 0.88rem; }
.card .champion { margin-top: 10px; color: var(--gold); font-weight: 700; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 12px;
}
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.bar-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8rem; margin-top: 6px; }

/* -- one competition -------------------------------------------------------------- */

.back {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 10px;
}
.back:hover { color: var(--text); }

.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.hero h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 6px; }
.hero .meta { color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.prize { margin-top: 12px; display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--gold); }
.prize img { width: 34px; height: 34px; object-fit: contain; }

.champion-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, color-mix(in srgb, var(--gold) 22%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent);
}
.champion-banner .label { color: var(--gold); font-size: 0.85rem; font-weight: 700; }
.champion-banner .name { font-size: 1.3rem; font-weight: 700; }

/* -- on now and next ---------------------------------------------------------------- */

.section-title { font-size: 1rem; margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }

.live-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.live {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--live) 40%, var(--line));
  border-radius: var(--radius);
  padding: 12px 14px;
}
.live .where { color: var(--live); font-weight: 700; font-size: 0.85rem; margin-bottom: 8px; }
.live.next { border-color: var(--line); }
.live.next .where { color: var(--muted); }

.versus {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.versus .side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.versus .side.away { flex-direction: row-reverse; text-align: end; }
.versus .side span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.versus .vs { color: var(--muted); font-size: 0.8rem; }

/* -- tabs ------------------------------------------------------------------------------ */

.tabs {
  display: flex;
  gap: 6px;
  margin: 18px 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--muted);
}
.tab[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* -- avatars ------------------------------------------------------------------------------ */

.avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
}
.avatar.large { width: 64px; height: 64px; font-size: 1.4rem; }

/* -- the table ------------------------------------------------------------------------------ */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 14px;
}
.table-wrap h3 { margin: 0; padding: 12px 14px 0; font-size: 0.95rem; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 10px 8px; text-align: center; white-space: nowrap; }
th { color: var(--muted); font-weight: 700; font-size: 0.78rem; border-bottom: 1px solid var(--line); }
td { border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
tr:last-child td { border-bottom: 0; }
td.who { text-align: start; width: 100%; }
td.who > div { display: flex; align-items: center; gap: 8px; }
td.pos { width: 2.4em; font-weight: 700; }
td.pts { font-weight: 700; color: var(--accent); }
tr.p1 td.pos { color: var(--gold); }
tr.p2 td.pos { color: var(--silver); }
tr.p3 td.pos { color: var(--bronze); }

@media (max-width: 520px) {
  .wide { display: none; }
  th, td { padding: 9px 5px; }
}

/* -- matches ------------------------------------------------------------------------------ */

.round { margin-bottom: 16px; }
.round h3 { font-size: 0.9rem; color: var(--muted); margin: 0 0 8px; }

.match {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 6px;
}
.match .side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.match .side.away { flex-direction: row-reverse; text-align: end; }
.match .side span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match .won { font-weight: 700; }
.match .lost { color: var(--muted); }
.score {
  min-width: 74px;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
}
.score .when { font-size: 0.8rem; font-weight: 400; color: var(--muted); display: block; }
.score .tag { font-size: 0.72rem; font-weight: 700; color: var(--warn); display: block; }
.match.bye { opacity: 0.6; }
.match.on { border-color: color-mix(in srgb, var(--live) 50%, var(--line)); }

/* -- the bracket: first round on the reader's start, rounds towards the cup -- */

.bracket-wrap {
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.bracket { display: flex; gap: 22px; min-width: min-content; align-items: stretch; }
.column { display: flex; flex-direction: column; min-width: 190px; }
.column h3 { font-size: 0.82rem; color: var(--muted); margin: 0 0 8px; text-align: center; }
.column .ties { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }

.tie {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.tie .line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  min-height: 38px;
}
.tie .line + .line { border-top: 1px solid var(--line); }
.tie .line span.name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tie .line.won { font-weight: 700; }
.tie .line.won .goals { color: var(--accent); }
.tie .line.lost { color: var(--muted); }
.tie .line.empty { color: var(--muted); font-style: italic; }
.tie .goals { font-weight: 700; min-width: 1.5em; text-align: center; }
.tie.on { border-color: color-mix(in srgb, var(--live) 55%, var(--line)); }

.trophy {
  align-self: center;
  min-width: 170px;
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent);
  background: linear-gradient(180deg, color-mix(in srgb, var(--gold) 16%, var(--surface)), var(--surface));
}
.trophy svg { width: 56px; height: 56px; fill: var(--gold); }
.trophy img { width: 80px; height: 80px; object-fit: contain; margin: 0 auto; }
.trophy .who { font-weight: 700; font-size: 1.1rem; margin-top: 6px; }
.trophy .what { color: var(--muted); font-size: 0.85rem; }

/* -- players ------------------------------------------------------------------------------ */

.players {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.player {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.player .name { font-weight: 700; word-break: break-word; }
.player .meta { color: var(--muted); font-size: 0.82rem; }
.player .members { color: var(--muted); font-size: 0.82rem; }
.player.out { opacity: 0.55; }
