/* ==========================================================
   Church Table Tennis Cup
   Palette taken from the game: table blue, white lines,
   orange ball, navy ink on a cool paper background.
   ========================================================== */
:root {
  --ink: #10233f;
  --ink-soft: #3b4d66;
  --muted: #5d6d83;
  --paper: #f2f5f9;
  --surface: #ffffff;
  --line: #d6dee8;
  --table: #1b5aa3;
  --table-deep: #13457f;
  --ball: #ff7a1a;
  --ball-deep: #d95f06;
  --good: #1d7f48;
  --good-bg: #e5f4ea;
  --bad: #b92f28;
  --bad-bg: #fbe9e7;
  --warn-bg: #fff3e0;
  --info-bg: #e7f0fb;
  --display: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 35, 63, .08), 0 4px 14px rgba(16, 35, 63, .05);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--table); text-underline-offset: 2px; }
a:hover { color: var(--table-deep); }
:focus-visible { outline: 3px solid var(--ball); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.1; letter-spacing: .01em; margin: 0 0 .5em; }
h1 { font-size: 2.6rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.3rem; }
p { margin: 0 0 1em; max-width: 70ch; }
.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.main { flex: 1; padding-top: 28px; padding-bottom: 60px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; }

/* ---------- Header ---------- */
.site-header { background: var(--ink); color: #fff; border-bottom: 4px solid var(--table); }
.header-inner { display: flex; align-items: center; gap: 20px; min-height: 68px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; margin-right: auto; }
.brand:hover { color: #fff; }
.brand-ball { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffb07a, var(--ball) 55%, var(--ball-deep)); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: var(--display); font-size: 1.45rem; letter-spacing: .02em; }
.brand-text small { color: #a9b8cc; font-size: .82rem; }
.site-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.site-nav a, .site-nav .link-button { color: #d7e1ee; text-decoration: none; padding: 8px 12px; border-radius: var(--radius); font-weight: 600; font-size: .98rem; }
.site-nav a:hover, .site-nav .link-button:hover { color: #fff; background: rgba(255,255,255,.08); }
.site-nav a.active { color: #fff; box-shadow: inset 0 -3px 0 var(--ball); border-radius: 0; }
.site-nav a.nav-cta { background: var(--ball); color: var(--ink); margin-left: 6px; }
.site-nav a.nav-cta:hover { background: #ff9447; color: var(--ink); }
.nav-form { margin: 0; }
.nav-toggle { display: none; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: var(--radius); padding: 6px 12px; font: inherit; font-weight: 600; cursor: pointer; }

@media (max-width: 820px) {
  .nav-toggle { display: block; }
  .site-nav { display: none; position: absolute; left: 0; right: 0; top: 72px; background: var(--ink); flex-direction: column; align-items: stretch; padding: 8px 20px 16px; z-index: 5; }
  .nav-open .site-nav { display: flex; }
  .site-header { position: relative; }
  .site-nav a.active { box-shadow: inset 3px 0 0 var(--ball); }
  .site-nav a.nav-cta { margin: 6px 0 0; text-align: center; }
  h1 { font-size: 2.1rem; }
}

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 1rem/1.2 var(--body); padding: 11px 18px; border-radius: var(--radius);
  border: 2px solid transparent; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--table); color: #fff; }
.btn-primary:hover { background: var(--table-deep); color: #fff; }
.btn-light { background: #fff; color: var(--table-deep); }
.btn-light:hover { background: #e9f0f9; }
.btn-ghost { background: transparent; color: var(--table); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--table); color: var(--table-deep); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { background: #962520; color: #fff; }
.btn-small { padding: 7px 12px; font-size: .92rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--table); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-button.danger { color: var(--bad); }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }

label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .95rem; color: var(--ink-soft); }
input, select, textarea {
  font: 400 1rem/1.4 var(--body); color: var(--ink); background: #fff;
  border: 1px solid #b9c6d6; border-radius: var(--radius); padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--table); box-shadow: 0 0 0 3px rgba(27, 90, 163, .18); }
.optional { font-weight: 400; color: var(--muted); font-size: .85rem; }
.hint { color: var(--muted); font-size: .92rem; margin: -4px 0 4px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .row-2 { grid-template-columns: 1fr; } }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 8px 0 0; padding: 18px 0 0; display: flex; flex-direction: column; gap: 16px; }
legend { font-family: var(--display); font-weight: 700; font-size: 1.3rem; padding-right: 10px; }
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .choice-row { grid-template-columns: 1fr; } }
.choice { flex-direction: row; align-items: flex-start; gap: 10px; border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; font-weight: 400; }
.choice:has(input:checked) { border-color: var(--table); background: var(--info-bg); }
.choice input { width: auto; margin-top: 4px; }
.choice strong { display: block; color: var(--ink); }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }
.inline-fields { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; }
.inline-fields label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.inline-fields input, .inline-fields select { width: auto; padding: 6px 8px; font-size: .92rem; }
.inline-fields input.narrow { width: 64px; }
.inline-fields input[name="set_scores"] { width: 150px; }
.form-actions { display: flex; gap: 10px; padding-top: 8px; }
.form-wide { max-width: 760px; }

/* ---------- Flash ---------- */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 12px; border-left: 5px solid; font-weight: 600; transition: opacity .6s; }
.flash-success { background: var(--good-bg); border-color: var(--good); color: #145a33; }
.flash-error { background: var(--bad-bg); border-color: var(--bad); color: #7d1f1a; }
.flash-warning { background: var(--warn-bg); border-color: var(--ball); color: #7a3d05; }
.flash-info { background: var(--info-bg); border-color: var(--table); color: var(--table-deep); }
.flash.fade { opacity: 0; }

/* ---------- Hero: a table-tennis table seen from above ---------- */
.hero {
  position: relative; overflow: hidden;
  background: var(--table);
  border: 10px solid #fff; outline: 1px solid var(--line);
  border-radius: 4px; color: #fff; margin-bottom: 40px;
  padding: 56px 48px 60px;
  min-height: 340px; display: flex; align-items: center;
}
/* white centre line along the length of the table */
.hero::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 3px; background: rgba(255,255,255,.85); transform: translateY(-50%); }
/* the net across the middle */
.hero::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 62%; width: 8px;
  background: repeating-linear-gradient(0deg, rgba(16,35,63,.85) 0 3px, rgba(255,255,255,.7) 3px 6px);
  box-shadow: 0 0 0 2px rgba(255,255,255,.9);
}
.hero-copy { position: relative; z-index: 1; max-width: 560px; background: var(--table); padding: 8px 12px 8px 0; }
.hero h1 { font-size: clamp(2.6rem, 6vw, 4.4rem); line-height: .98; text-transform: none; margin-bottom: 18px; }
.hero p { font-size: 1.15rem; color: #e3ecf8; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.hero .btn-primary { background: var(--ball); color: var(--ink); }
.hero .btn-primary:hover { background: #ff9447; }
.hero-ball {
  position: absolute; z-index: 1; width: 46px; height: 46px; border-radius: 50%;
  left: 80%; top: 24%;
  background: radial-gradient(circle at 34% 32%, #ffc79e, var(--ball) 52%, var(--ball-deep));
  box-shadow: 18px 26px 0 -6px rgba(8, 25, 50, .35);
  animation: rally 2.8s ease-in-out infinite alternate;
}
@keyframes rally {
  0%   { transform: translate(0, 0); }
  50%  { transform: translate(-140px, 60px); }
  100% { transform: translate(-40px, 150px); }
}
@media (prefers-reduced-motion: reduce) { .hero-ball { animation: none; } }
@media (max-width: 820px) {
  .hero { padding: 36px 24px 40px; }
  .hero::after { left: auto; right: 18%; }
  .hero-ball { left: auto; right: 6%; top: 12%; }
}

/* ---------- Sections & cards ---------- */
.section { margin-top: 44px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.page-head { margin-bottom: 24px; }
.page-head p { color: var(--muted); }
.page-head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.crumbs { margin: 0 0 4px; font-size: .92rem; }
.empty { color: var(--muted); background: var(--surface); border: 1px dashed #b9c6d6; border-radius: var(--radius); padding: 22px; }
td.empty { border: 0; text-align: center; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }
.comp-card { background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--table); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.comp-card h3 { font-size: 1.6rem; margin: 0; }
.comp-card h3 a { color: var(--ink); text-decoration: none; }
.comp-card h3 a:hover { color: var(--table); }
.comp-card .btn { align-self: flex-start; margin-top: auto; }
.comp-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }

.facts { margin: 0; display: grid; gap: 6px; }
.facts div { display: grid; grid-template-columns: 90px 1fr; gap: 10px; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; font-weight: 600; }
.facts-stacked div { grid-template-columns: 1fr; gap: 0; padding-bottom: 10px; border-bottom: 1px solid var(--line); }

.tag, .status { display: inline-block; font-size: .8rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.tag-single { background: var(--info-bg); color: var(--table-deep); }
.tag-double { background: #ebe6fb; color: #4b2f9c; }
.status-registration { background: var(--good-bg); color: var(--good); }
.status-closed { background: #eceff3; color: var(--ink-soft); }
.status-active { background: var(--warn-bg); color: #9a4a06; }
.status-completed { background: var(--ink); color: #fff; }
.joined-note { color: var(--good); font-weight: 700; margin: 0; }
.joined-note::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--good); margin-right: 8px; }

.step-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; counter-reset: step; }
.step-list li { counter-increment: step; border-top: 3px solid var(--ink); padding-top: 14px; display: flex; flex-direction: column; gap: 4px; }
.step-list li::before { content: counter(step); font-family: var(--display); font-weight: 700; font-size: 2.4rem; line-height: 1; color: var(--table); }
.step-list span { color: var(--muted); }
@media (max-width: 760px) { .step-list { grid-template-columns: 1fr; } }

.next-matches { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.next-matches a { display: flex; gap: 16px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--ball); padding: 12px 16px; border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.next-matches a:hover { border-color: var(--table); border-left-color: var(--ball); }
.next-matches span { color: var(--muted); }

/* ---------- Auth ---------- */
.auth-card { max-width: 480px; margin: 20px auto; background: var(--surface); border: 1px solid var(--line); border-top: 6px solid var(--table); border-radius: var(--radius); padding: 30px; box-shadow: var(--shadow); }
.auth-card .lead { color: var(--muted); }
.auth-switch { margin: 18px 0 0; text-align: center; color: var(--muted); }

/* ---------- Competition page ---------- */
.comp-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.comp-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.meta-text { color: var(--muted); font-size: .95rem; }
.comp-layout { display: grid; grid-template-columns: 290px 1fr; gap: 28px; align-items: start; }
@media (max-width: 960px) { .comp-layout { grid-template-columns: 1fr; } }
.comp-info { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.description { color: var(--ink-soft); font-size: .96rem; }
.join-box { border-top: 1px solid var(--line); padding-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.join-box .btn { width: 100%; }
.comp-main { min-width: 0; }

.champion {
  display: flex; align-items: center; gap: 16px; margin-bottom: 24px;
  background: var(--ink); color: #fff; border-radius: var(--radius); padding: 18px 22px;
  border-left: 8px solid var(--ball);
}
.champion small { display: block; color: #a9b8cc; font-size: .9rem; }
.champion strong { font-family: var(--display); font-size: 2.2rem; line-height: 1; }
.champion-ball { width: 40px; height: 40px; border-radius: 50%; flex: none; background: radial-gradient(circle at 34% 32%, #ffc79e, var(--ball) 52%, var(--ball-deep)); }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 20px; }
.tabs button { background: none; border: 0; font: 700 1.25rem/1 var(--display); letter-spacing: .02em; color: var(--muted); padding: 12px 16px; cursor: pointer; margin-bottom: -2px; border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ball); }
.tab-panel { margin-bottom: 28px; }
.day-title { margin-top: 24px; }
.player-list { columns: 3 200px; margin: 0; padding-left: 20px; }
.player-list li { padding: 3px 0; break-inside: avoid; }

/* ---------- Bracket (World Cup style draw) ---------- */
.bracket-scroll { overflow-x: auto; padding-bottom: 12px; }
.bracket { display: flex; gap: 36px; min-width: max-content; align-items: stretch; }
.round { display: flex; flex-direction: column; width: 210px; }
.round-title { font-size: 1.15rem; color: var(--muted); text-align: center; margin: 0 0 10px; }
.round:last-child .round-title { color: var(--ball-deep); }
.round-matches { flex: 1; display: flex; flex-direction: column; }
.slot { flex: 1; display: flex; align-items: center; position: relative; padding: 8px 0; }
/* connector lines: each pair of matches joins into the next round */
.round:not(:last-child) .slot::after { content: ""; position: absolute; right: -18px; width: 18px; border-right: 2px solid #aebdd0; }
.round:not(:last-child) .slot:nth-child(odd)::after { top: 50%; height: 50%; border-top: 2px solid #aebdd0; }
.round:not(:last-child) .slot:nth-child(even)::after { bottom: 50%; height: 50%; border-bottom: 2px solid #aebdd0; }
.round:not(:first-child) .slot::before { content: ""; position: absolute; left: -18px; width: 18px; top: 50%; border-top: 2px solid #aebdd0; }

.match { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; position: relative; z-index: 1; }
.match.is-bye { opacity: .6; box-shadow: none; }
.match.is-mine { border-color: var(--ball); box-shadow: 0 0 0 2px rgba(255,122,26,.35); }
.match.is-target { animation: pulse 1.6s ease-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,122,26,.7); } 100% { box-shadow: 0 0 0 14px rgba(255,122,26,0); } }
.side { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: .95rem; }
.side-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-name em { color: var(--muted); font-style: normal; }
.side-score { font-family: var(--display); font-weight: 700; font-size: 1.2rem; min-width: 1ch; text-align: right; color: var(--muted); }
.side.won { font-weight: 700; }
.side.won .side-score { color: var(--ink); }
.side.won .side-name::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ball); margin-right: 7px; vertical-align: 1px; }
.side.you .side-name { color: var(--table-deep); text-decoration: underline; text-decoration-color: var(--ball); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.match-when { font-size: .8rem; color: var(--muted); padding: 5px 10px; background: #f7f9fc; }
.round:last-child .match { border: 2px solid var(--ink); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 2px solid var(--line); background: #f7f9fc; white-space: nowrap; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.is-mine td { background: #fff4ea; }
table.data tr.row-done td { background: #fafcfe; }
table.data tr.row-disabled td { opacity: .6; }
.vs { color: var(--muted); font-size: .85rem; padding: 0 4px; }
.winner { font-weight: 700; }
.winner::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ball); margin-right: 6px; vertical-align: 1px; }
.actions { white-space: nowrap; }
.actions a, .actions form { display: inline-block; margin-right: 10px; }
.actions form { margin: 0 10px 0 0; }
.reset-form { margin-top: 6px; font-size: .88rem; }
.admin-matches td { vertical-align: middle; }
.match-names { min-width: 200px; }

.step-panels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
.step-panels .panel p { color: var(--ink-soft); font-size: .95rem; }
.step-panels form { margin: 0; }
@media (max-width: 960px) { .step-panels { grid-template-columns: 1fr; } }

.danger-zone { max-width: 760px; margin-top: 28px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; border: 1px solid #e5b4b0; background: var(--bad-bg); border-radius: var(--radius); padding: 18px 22px; }
.danger-zone h2 { font-size: 1.3rem; margin: 0; }
.danger-zone p { margin: 0; color: #7d1f1a; }

/* ---------- Super admin ---------- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
@media (max-width: 760px) { .stat-row { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat strong { display: block; font-family: var(--display); font-size: 2rem; line-height: 1; }
.stat span { color: var(--muted); font-size: .9rem; }
.stat-warn { border-color: var(--bad); }
.stat-warn strong { color: var(--bad); }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; align-items: end; margin-bottom: 14px; }
.filters input, .filters select { padding: 7px 9px; font-size: .92rem; }
.filter-actions { display: flex; gap: 8px; }
.result-count { color: var(--muted); font-size: .92rem; margin: 8px 0; }
table.audit { font-size: .88rem; }
.url-cell { word-break: break-all; min-width: 220px; }
.method { font-weight: 700; font-size: .75rem; background: #eceff3; padding: 1px 5px; border-radius: 3px; }
.event { font-weight: 700; font-size: .8rem; padding: 2px 7px; border-radius: 3px; white-space: nowrap; }
.ev-nav { background: #eceff3; color: var(--ink-soft); }
.ev-auth { background: var(--info-bg); color: var(--table-deep); }
.ev-action { background: var(--warn-bg); color: #8a4105; }
.ev-bad { background: var(--bad-bg); color: var(--bad); }
.desc { color: var(--ink-soft); }
.small-link { font-size: .82rem; }
.search-row { display: flex; gap: 8px; max-width: 520px; margin-bottom: 10px; }

.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.pagination .page { padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-decoration: none; }
.pagination .current { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Errors & footer ---------- */
.error-page { text-align: center; padding: 60px 20px; }
.error-page p { margin-left: auto; margin-right: auto; color: var(--muted); }
.site-footer { background: var(--ink); color: #a9b8cc; padding: 22px 0; font-size: .92rem; }
.site-footer p { margin: 0; }
