@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600;700&display=swap');

:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #f0f3f1;
  --border: #e1e6e3;
  --text: #16241d;
  --text-dim: #5c6b63;
  --text-faint: #8a978f;
  --accent: #0f8a5f;
  --accent-dark: #0b6e4b;
  --accent-soft: #e3f5ec;
  --live: #e0472c;
  --live-soft: #fdeae6;
  --gold: #c9971f;
  --gold-soft: #fbf1dd;
  --danger: #d13c3c;
  --danger-soft: #fbe8e8;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 4px 16px rgba(20, 40, 30, .05);
  --font-display: 'Oswald', 'Arial Narrow', sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0 0 4px; letter-spacing: .01em; }
a { color: var(--accent-dark); }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------------- layout shell ---------------- */
#kourtio-root { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-size: 20px; font-weight: 700; color: var(--accent-dark); white-space: nowrap; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.tourn-select { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); }
.tourn-select select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.topbar-spacer { flex: 1; }

.demo-switcher { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px dashed var(--border); padding: 4px; border-radius: 999px; }
.demo-switcher .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 0 6px; }
.pill-btn { border: none; background: transparent; padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--text-dim); cursor: pointer; white-space: nowrap; }
.pill-btn.active { background: var(--accent); color: #fff; }
.pill-btn:hover:not(.active) { background: #e5e9e6; }

nav.tabs { display: flex; gap: 4px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
nav.tabs button { border: none; background: transparent; padding: 12px 14px; font-weight: 600; font-size: 13.5px; color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
nav.tabs button.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
nav.tabs button:hover:not(.active) { color: var(--text); }

main#view { padding: 18px; max-width: 1180px; margin: 0 auto; width: 100%; flex: 1; }
.role-banner { padding: 8px 18px; font-size: 12.5px; font-weight: 600; text-align: center; color: #fff; }
.role-banner.admin { background: var(--accent-dark); }
.role-banner.master { background: #4a3a8c; }
.role-banner.scorer { background: var(--live); }

/* ---------------- generic components ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.badge.live { background: var(--live-soft); color: var(--live); }
.badge.live .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--live); animation: pulse 1.4s infinite; }
.badge.done { background: var(--accent-soft); color: var(--accent-dark); }
.badge.upcoming { background: var(--surface-2); color: var(--text-dim); }
.badge.manual { background: var(--gold-soft); color: var(--gold); }
.badge.auto { background: var(--surface-2); color: var(--text-faint); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: var(--danger-soft); border-color: var(--danger-soft); color: var(--danger); }
.btn.danger:hover { background: #f7d3d3; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.field input, .field select, .field textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.field textarea { resize: vertical; min-height: 60px; }
.hint { font-size: 11.5px; color: var(--text-faint); }

.table-wrap { overflow-x: auto; }
table.simple { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.simple th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); padding: 6px 10px; border-bottom: 1px solid var(--border); }
table.simple td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.simple tr:last-child td { border-bottom: none; }
table.simple tr.clickable { cursor: pointer; }
table.simple tr.clickable:hover { background: var(--surface-2); }
table.simple tr.selected { background: var(--accent-soft); }

.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-title h2 { font-size: 18px; }
.section-title .sub { font-size: 12.5px; color: var(--text-faint); }

.empty { text-align: center; padding: 30px 10px; color: var(--text-faint); font-size: 13.5px; }

/* -------------- list + detail pane (one-item-at-a-time editing) -------------- */
.list-detail { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
@media (max-width: 800px) { .list-detail { grid-template-columns: 1fr; } }
.item-list { display: flex; flex-direction: column; gap: 6px; max-height: 620px; overflow-y: auto; }
.item-row { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.item-row:hover { border-color: var(--accent); }
.item-row.selected { border-color: var(--accent); background: var(--accent-soft); }
.item-row .title { font-weight: 700; font-size: 13.5px; }
.item-row .meta { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

/* ---------------- live score views ---------------- */
.match-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; box-shadow: var(--shadow); }
.match-card .mc-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }
.mc-teams { display: flex; flex-direction: column; gap: 6px; }
.mc-team-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; }
.mc-team-row .name { font-weight: 600; font-size: 14.5px; }
.mc-team-row.winner .name { color: var(--accent-dark); }
.mc-sets { display: flex; gap: 6px; font-family: var(--font-mono); font-weight: 600; }
.mc-sets .set { min-width: 22px; text-align: center; color: var(--text-dim); }
.mc-sets .set.current { color: var(--live); }
.mc-point { font-family: var(--font-mono); font-weight: 700; font-size: 18px; min-width: 34px; text-align: center; background: var(--surface-2); border-radius: 6px; padding: 2px 6px; }
.mc-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 8px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- scorer console ---------------- */
.pin-screen { max-width: 380px; margin: 60px auto; text-align: center; }
.pin-screen .pin-input { font-family: var(--font-mono); font-size: 26px; letter-spacing: .3em; text-align: center; padding: 14px; text-transform: uppercase; }
.court-console { max-width: 640px; margin: 0 auto; }
.score-panel { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--border); }
.score-side { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 16px 18px; }
.score-side.a { border-bottom: 1px solid var(--border); }
.score-side .team-name { font-weight: 700; font-size: 17px; }
.score-side .sub { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.score-side .scores { display: flex; align-items: center; gap: 12px; }
.score-side .games { font-family: var(--font-mono); font-size: 22px; font-weight: 700; color: var(--text-dim); min-width: 28px; text-align: center; }
.score-side .point-big { font-family: var(--font-mono); font-size: 40px; font-weight: 700; min-width: 76px; text-align: center; background: var(--surface-2); border-radius: 10px; padding: 4px 8px; }
.score-side.serving .point-big { background: var(--accent-soft); color: var(--accent-dark); }
.score-controls { display: flex; gap: 10px; padding: 14px 18px; background: var(--surface-2); }
.score-controls .btn-point { flex: 1; padding: 16px; font-size: 15px; font-weight: 700; border-radius: 10px; }
.score-format-bar { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 18px; font-size: 11.5px; }
.completed-sets-strip { display: flex; gap: 8px; padding: 10px 18px 0; font-family: var(--font-mono); font-size: 13px; color: var(--text-dim); }

/* ---------------- bracket ---------------- */
.bracket-wrap { position: relative; overflow-x: auto; padding-bottom: 10px; }
.bracket-lines { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 0; }
.bracket-lines path { fill: none; stroke: #b7c2bc; stroke-width: 2; }
.bracket { position: relative; z-index: 1; display: flex; gap: 46px; align-items: stretch; min-width: 640px; }
.bracket-round { display: flex; flex-direction: column; min-width: 220px; }
.bracket-round .round-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); text-align: center; margin-bottom: 10px; font-weight: 700; }
.round-matches { display: flex; flex-direction: column; justify-content: space-around; gap: 26px; flex: 1; }
.bmatch { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.bmatch-meta { font-size: 10.5px; color: var(--text-faint); padding: 5px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.bmatch .brow { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; font-size: 12.5px; }
.bmatch .brow:first-child { border-bottom: 1px solid var(--border); }
.bmatch .brow.winner { font-weight: 700; background: var(--accent-soft); color: var(--accent-dark); border-left: 3px solid var(--accent); padding-left: 7px; }
.bmatch .brow.bye { color: var(--text-faint); font-style: italic; }
.bmatch .bscore { font-family: var(--font-mono); color: var(--text-dim); }
.bmatch-f3 { border-style: dashed; max-width: 320px; }
.bracket-footnote { font-size: 11.5px; color: var(--text-faint); margin-top: 12px; }

.f3-section { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--border); }
.f3-title { font-size: 13px; color: var(--text-dim); }
.f3-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-dim); cursor: pointer; }
.f3-toggle input { width: auto; }
.f3-box-wrap { max-width: 320px; margin-top: 8px; }

/* ---------------- standings ---------------- */
.standings-group-title { font-weight: 700; font-size: 13.5px; margin: 14px 0 6px; }
.standings-table th:not(:first-child):not(:nth-child(2)), .standings-table td:not(:first-child):not(:nth-child(2)) { text-align: center; }
.standings-table tr.qualify-row { background: var(--accent-soft); }
.standings-table tr.qualify-row td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.standings-pts { font-weight: 700; color: var(--accent-dark); }

/* ---------------- ranking ---------------- */
.rank-row-num { font-family: var(--font-mono); font-weight: 700; color: var(--text-faint); width: 28px; display: inline-block; }
.rank-total { font-family: var(--font-mono); font-weight: 700; color: var(--accent-dark); }

/* ---------------- announcements ---------------- */
.ann-item { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; }
.ann-item.pinned { border-left-color: var(--gold); }
.ann-item .ann-title { font-weight: 700; font-size: 14px; }
.ann-item .ann-date { font-size: 11px; color: var(--text-faint); }
.ann-item .ann-body { font-size: 13.5px; color: var(--text-dim); margin-top: 3px; }

/* ---------------- tournament banner ---------------- */
.tournament-banner-wrap { width: 100%; aspect-ratio: 4 / 1; border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 16px; background: var(--surface-2); box-shadow: var(--shadow); }
.tournament-banner-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.banner-admin { margin-bottom: 12px; }
.banner-preview-wrap { width: 100%; aspect-ratio: 4 / 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); margin: 8px 0; border: 1px solid var(--border); }
.banner-preview-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------------- login ---------------- */
.login-box { max-width: 360px; margin: 60px auto; }
.login-box .btn.block { margin-top: 6px; }

/* ---------------- modal ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,30,25,.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 20px; max-width: 420px; width: 100%; box-shadow: var(--shadow); }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 600; z-index: 200; box-shadow: var(--shadow); }

.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.gap-6 { gap: 6px; }
.gap-10 { gap: 10px; }
.muted { color: var(--text-faint); }
.small { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.mt-14 { margin-top: 14px; }
