:root, :host {
  --bg: #0f1216;
  --panel: #171b21;
  --panel2: #1e242c;
  --panel3: #12161c;
  --line: #2a323d;
  --text: #e8ecf1;
  --mute: #95a0b0;
  --accent: #f2a33a;
  --accent-ink: #1a1205;
  --accent2: #3aa0f2;
  --good: #3ecf8e;
  --good-bg: #133424;
  --bad: #ef5b5b;
  --bad-bg: #3b1919;
  --warn-bg: #3b2c10;
  --warn-text: #ffd894;
  --info-bg: #162a3d;
  --info-text: #8ccbff;
  --red: #d9483b;
  --red-bg: rgba(217, 72, 59, 0.14);
  --green: #2f9e5b;
  --green-bg: rgba(47, 158, 91, 0.14);
  --radius: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

:host {      /* F-65: the organizer's /boutboard draws the widgets in a shadow root holding this stylesheet */
  display: block;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.app {
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 12px 18px;
  background: rgba(15, 18, 22, 0.96);
  border-bottom: 1px solid var(--line);
}

.topbar-main {
  min-width: 0;
  flex: 1 1 260px;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 3px;
}

.brand-icon {
  display: block;
  border-radius: 5px;
  flex: none;
}

.brand-name {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.brand-name b {
  color: var(--accent);
}

.brand-role {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--mute);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.event-title {
  margin: 0;
  font-size: clamp(18px, 2.2vw, 26px);
  line-height: 1.18;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.event-meta {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--mute);
  overflow-wrap: anywhere;
}

.topbar-actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- buttons & badges ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: var(--mute);
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-pri {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 8px;
}

.badge, .pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel2);
  color: var(--mute);
  white-space: nowrap;
  flex: none;
}

.pill-live {
  background: var(--bad-bg);
  color: #ff9494;
  border: 1px solid rgba(239, 91, 91, 0.45);
}

.pill-good {
  background: var(--good-bg);
  color: var(--good);
}

.pill-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.pill-bad {
  background: var(--bad-bg);
  color: #ff9c9c;
}

.pill-info {
  background: var(--info-bg);
  color: var(--info-text);
}

/* ---------- banners ---------- */
.banners {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 18px 0;
}

.banners:empty {
  display: none;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 14px;
}

.banner-warn {
  background: var(--warn-bg);
  border-color: var(--accent);
  color: var(--warn-text);
}

.banner-err {
  background: var(--bad-bg);
  border-color: var(--bad);
  color: #ffd0d0;
}

.banner-info {
  background: var(--info-bg);
  border-color: #2f5b85;
  color: #d7ecff;
}

.banner-text {
  flex: 1 1 220px;
  min-width: 0;
}

.banner-text strong {
  display: block;
  margin-bottom: 2px;
}

.banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- mat filter bar ---------- */
.mat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 18px 0;
}

.mat-bar-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--mute);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
}

.chip {
  min-height: 38px;
  padding: 6px 13px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--mute);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--mute);
  color: var(--text);
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---------- main content & grid (F-65) ----------
   boutboard.js picks the columns, the cell size and the widget font (--cols, --cell-w, --cell-h, --card-f) from
   the space left under the header and bars; every cell is the same size, the last row included. Inside a
   widget everything is in em of that font, so text grows with the cell. Before the script has measured
   (or without layout APIs) a plain auto-fill grid is used. */
.content {
  flex: 1;
  padding: 14px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.mat-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  align-items: stretch;
  font-size: 16px;
}

.mat-grid.laid {
  grid-template-columns: repeat(var(--cols), var(--cell-w));
  grid-auto-rows: var(--cell-h);
  justify-content: center;
  font-size: var(--card-f);
}

.mat-grid.measuring {
  grid-auto-rows: auto !important;
  align-items: start !important;
  font-size: 100px !important;
}

/* ---------- mat widget ---------- */
.mat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.7em;
  padding: 0.45em 0.55em;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  min-width: 0;
  min-height: 0;
  line-height: 1.2;
}

.mat-card.is-live {
  border-color: var(--bad);
  box-shadow: 0 0 0 1px rgba(239, 91, 91, 0.25);
}

.mat-head {
  flex: none;
  height: 2.3em;
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.mat-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75em;
  height: 1.75em;
  padding: 0 0.35em;
  border-radius: 0.4em;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.1em;
  font-weight: 900;
  line-height: 1;
  flex: none;
}

.mat-title-wrap {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.mat-name {
  margin: 0;
  font-size: 1.15em;
  font-weight: 800;
  line-height: 1.15;
}

.mat-sub {
  font-size: 0.85em;
  line-height: 1.2;
  color: var(--mute);
}

.mat-head > .pill {
  font-size: 0.85em;
}

.mat-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}

.col-now {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

.col-queue {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}

.lay-wide .mat-body {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  align-items: stretch;
}

.lay-wide .col-queue {
  justify-content: space-between;
}

/* ---------- sections: current bout, On deck, In the hole ---------- */
.slot {
  min-width: 0;
  border-radius: 0.5em;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.slot-now {
  flex: 1 0 auto;
  padding: 0.35em 0.4em;
  gap: 0.25em;
  background: var(--panel2);
}

.slot-now > .ath-pair,
.slot-now > .slot-body {
  margin: auto 0;
}

.slot-now.is-live {
  border-color: rgba(239, 91, 91, 0.65);
}

.slot-q {
  flex: none;
  padding: 0.25em 0.4em;
  gap: 0.15em;
  background: var(--panel3);
}

.slot-q.on-deck {
  border-color: rgba(242, 163, 58, 0.55);
}

.slot-head {
  flex: none;
  height: 1.5em;
  display: flex;
  align-items: center;
  gap: 0.45em;
  min-width: 0;
  white-space: nowrap;
}

.slot-q .slot-head {
  height: 1.35em;
}

.slot-pill {
  font-size: 0.85em;
  padding: 0.15em 0.6em;
}

.bout-num {
  flex: none;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.bout-weight {
  flex: none;
  font-weight: 800;
  font-size: 0.95em;
}

.bout-round {
  flex: 1 1 auto;
  font-size: 0.85em;
  color: var(--mute);
}

.slot-body {
  position: relative;
}

.ath-pair.ghost {
  visibility: hidden;
}

.slot-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--line);
  border-radius: 0.4em;
  color: var(--mute);
  font-size: 0.9em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

/* ---------- athlete blocks: name line, school line below, side colour on the left ---------- */
.ath-pair {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.25em;
}

.slot-q .ath-pair {
  gap: 0.15em;
}

.ath {
  display: flex;
  align-items: center;
  gap: 0.4em;
  min-width: 0;
  padding: 0.2em 0.45em;
  border-radius: 0.4em;
  border-left: 0.3em solid transparent;
  background: var(--panel3);
}

.slot-q .ath {
  padding: 0.05em 0.4em;
  border-left-width: 0.22em;
  background: transparent;
}

.ath.red {
  border-left-color: var(--red);
}

.ath.green {
  border-left-color: var(--green);
}

.slot-now .ath.red {
  background: linear-gradient(90deg, var(--red-bg) 0%, var(--panel3) 45%);
}

.slot-now .ath.green {
  background: linear-gradient(90deg, var(--green-bg) 0%, var(--panel3) 45%);
}

.ath-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.ath-name {
  font-size: 1.4em;
  font-weight: 800;
  line-height: 1.15;
}

.slot-q .ath-name {
  font-size: 1.08em;
  font-weight: 750;
}

.ath-name.tbd {
  color: var(--mute);
  font-weight: 600;
}

.ath-team {
  font-size: 0.9em;
  line-height: 1.2;
  font-weight: 600;
  color: #c3ccd8;
}

.slot-q .ath-team {
  font-size: 0.85em;
  color: var(--mute);
}

.side-score {
  font-size: 1.8em;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  min-width: 1.2em;
  text-align: right;
  flex: none;
}

.ath.red .side-score {
  color: #ff8e83;
}

.ath.green .side-score {
  color: #6ce09b;
}

/* ---------- live period and clock (only after a WebSocket live snapshot) ---------- */
.live-strip {
  flex: none;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.05em 0.4em;
  border-radius: 0.35em;
  background: rgba(239, 91, 91, 0.14);
  border: 1px solid rgba(239, 91, 91, 0.38);
  font-variant-numeric: tabular-nums;
}

.live-period {
  font-size: 0.85em;
  font-weight: 800;
  color: var(--warn-text);
}

.live-clock {
  font-size: 1.05em;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- fixed one-line slots and the full-text reveal ---------- */
.fit {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ath-name.tight {
  font-size: 1.18em;
  letter-spacing: -0.01em;
}

.slot-q .ath-name.tight {
  font-size: 0.95em;
}

.ath-name.tight.tighter {
  font-size: 1.12em;
  letter-spacing: -0.015em;
}

.slot-q .ath-name.tight.tighter {
  font-size: 0.88em;
}

[data-reveal] {
  position: relative;
}

.has-clip {
  cursor: pointer;
}

.has-clip:focus {
  outline: 2px solid var(--accent2);
  outline-offset: 1px;
}

.reveal-pop {
  display: none;
  position: absolute;
  z-index: 6;
  left: 0;
  right: 0;
  top: 0;
  min-height: 100%;
  padding: 0.25em 0.5em;
  border-radius: 0.4em;
  border: 1px solid var(--accent2);
  background: #0b0e12;
  color: var(--text);
  font-size: 0.95em;
  font-weight: 700;
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: anywhere;
  box-shadow: 0 0.3em 1em rgba(0, 0, 0, 0.55);
}

.reveal-pop > div + div {
  color: #c3ccd8;
  font-weight: 600;
}

.has-clip.revealed > .reveal-pop {
  display: block;
}

/* ---------- state cards ---------- */
.state-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 560px;
  width: 100%;
  margin: 18px auto;
}

.state-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.state-note {
  margin: 0;
  font-size: 14px;
  color: var(--mute);
  max-width: 46ch;
}

/* ---------- footer ---------- */
.footer {
  padding: 10px 18px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 12.5px;
  color: var(--mute);
}

.footer a {
  color: var(--accent2);
  font-weight: 600;
}

.footer a:hover {
  text-decoration: underline;
}

/* ---------- web-app shell update bar (F-14) ---------- */
.ob-update-host:empty {
  display: none;
}

.ob-update-host {
  padding: 12px 18px 0;
}

.ob-update-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--warn-bg);
  border: 1px solid var(--accent);
  color: var(--text);
}

.ob-update-text {
  min-width: 0;
  flex: 1 1 200px;
}

.ob-update-msg {
  display: block;
  font-size: 14px;
  color: var(--warn-text);
}

.ob-update-note {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.ob-hidden {
  display: none !important;
}

.ob-update-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.ob-update-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.ob-update-pri {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.ob-update-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- narrow mobile screens ---------- */
@media (max-width: 640px) {
  .topbar {
    padding: 10px 12px;
  }
  .ob-update-host,
  .banners {
    padding: 10px 12px 0;
  }
  .mat-bar {
    padding: 8px 12px 0;
  }
  .content {
    padding: 12px 12px 16px;
  }
  .footer {
    padding: 10px 12px 14px;
  }
  .mat-grid {
    gap: 12px;
  }
}
