:root {
  color-scheme: dark;
  --canvas: #03070d;
  --surface: #07111f;
  --surface-raised: #0b1b30;
  --header: #0e5ccd;
  --header-bright: #1675ee;
  --grid: #193654;
  --grid-strong: #2b537d;
  --text: #f7fbff;
  --muted: #93a9bf;
  --live: #ff5a36;
  --live-glow: rgba(255, 90, 54, 0.35);
  --success: #37d992;
  --warning: #ffbb38;
  --danger: #ff5a5f;
  --status-height: clamp(42px, 4.8vh, 50px);
  --footer-height: clamp(22px, 2.6vh, 30px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
}

body {
  color: var(--text);
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: var(--status-height) minmax(0, 1fr) var(--footer-height);
  width: 100vw;
  height: 100dvh;
  background:
    radial-gradient(circle at 50% 0%, rgba(21, 82, 150, 0.1), transparent 38%),
    var(--canvas);
}

.status-bar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  min-width: 0;
  padding: 0 clamp(14px, 2vw, 34px);
  background: var(--surface);
  border-bottom: 1px solid var(--grid-strong);
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.crest {
  display: grid;
  place-items: center;
  width: clamp(30px, 3.6vh, 38px);
  aspect-ratio: 1;
  flex: 0 0 auto;
  border: 1px solid #3977c2;
  color: #a9cdf8;
  font-size: clamp(10px, 1.3vh, 13px);
  font-weight: 800;
  letter-spacing: 0.12em;
}

.identity h1,
.identity p,
.sync-status strong,
.sync-status span {
  margin: 0;
}

.identity h1 {
  font-size: clamp(15px, 1.8vh, 20px);
  line-height: 1;
  letter-spacing: -0.02em;
}

.identity p {
  margin-top: 2px;
  color: var(--muted);
  font-size: clamp(9px, 1.05vh, 11px);
}

.sync-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 230px;
  text-align: left;
}

.sync-status > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sync-status strong {
  font-size: clamp(11px, 1.35vh, 14px);
}

.sync-status span:not(.status-dot) {
  color: var(--muted);
  font-size: clamp(9px, 1.05vh, 11px);
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 5px rgba(255, 187, 56, 0.1);
}

.status-dot.is-live {
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(55, 217, 146, 0.1);
}

.status-dot.is-error {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(255, 90, 95, 0.1);
}

.fullscreen-button {
  display: inline-flex;
  justify-self: end;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--grid-strong);
  border-radius: 7px;
  background: #0b1a2b;
  color: var(--text);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.fullscreen-button:hover,
.fullscreen-button:focus-visible {
  border-color: #4388dc;
  background: #102743;
  outline: none;
}

.fullscreen-button:active {
  transform: scale(0.97);
}

.fullscreen-button svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: square;
  stroke-width: 1.8;
}

.fullscreen-button span {
  font-size: 12px;
  font-weight: 700;
}

.board {
  --panel-count: 1;
  display: grid;
  grid-template-columns: repeat(var(--panel-count), minmax(0, 1fr));
  min-height: 0;
  gap: 2px;
  padding: 2px;
  background: var(--grid-strong);
  overflow: hidden;
}

.court-panel {
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

.court-table {
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.court-table thead {
  height: var(--table-header-height, 48px);
}

.court-table tbody tr {
  height: var(--table-row-height, 56px);
}

.court-table th,
.court-table td {
  padding: 0 clamp(6px, 0.8vw, 14px);
  text-align: center;
  border: 1px solid var(--grid);
  overflow: hidden;
  white-space: nowrap;
}

.court-table th {
  background: linear-gradient(180deg, var(--header-bright), var(--header));
  color: #fff;
  font-size: var(--header-font-size, 15px);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.court-table th:first-child,
.court-table td:first-child {
  width: 42%;
}

.court-number,
.serial-number {
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.court-number {
  color: var(--text);
  font-size: var(--court-font-size, 32px);
  font-weight: 800;
}

.serial-number {
  color: var(--live);
  font-size: var(--serial-font-size, 36px);
  font-weight: 900;
  letter-spacing: -0.02em;
  text-shadow: 0 0 18px var(--live-glow);
}

.serial-number.has-changed {
  animation: number-change 1.6s ease-out;
}

.empty-state,
.loading-state {
  grid-column: 1 / -1;
  display: grid;
  place-content: center;
  place-items: center;
  min-height: 100%;
  padding: 40px;
  background: var(--canvas);
  text-align: center;
}

.empty-state h2,
.loading-state h2 {
  margin: 18px 0 7px;
  font-size: clamp(24px, 4vw, 48px);
  letter-spacing: -0.03em;
}

.empty-state p,
.loading-state p {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(14px, 1.8vw, 20px);
  line-height: 1.5;
}

.empty-mark,
.loading-mark {
  display: block;
  width: 54px;
  height: 54px;
  border: 2px solid var(--grid-strong);
  border-radius: 50%;
}

.loading-mark {
  border-top-color: var(--header-bright);
  animation: spin 900ms linear infinite;
}

.empty-mark {
  position: relative;
}

.empty-mark::before,
.empty-mark::after {
  position: absolute;
  top: 24px;
  left: 13px;
  width: 26px;
  height: 2px;
  background: var(--muted);
  content: "";
}

.empty-mark::before {
  transform: rotate(45deg);
}

.empty-mark::after {
  transform: rotate(-45deg);
}

.source-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(12px, 1.8vw, 28px);
  background: #050d17;
  border-top: 1px solid var(--grid);
  color: #6f869c;
  font-size: clamp(9px, 1.15vh, 12px);
}

.source-credit {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  white-space: nowrap;
}

.creator-credit {
  color: #8198ae;
}

.creator-credit::before {
  margin-right: 12px;
  color: var(--grid-strong);
  content: "•";
}

.creator-credit strong {
  color: var(--muted);
  font-weight: 700;
}

#refresh-clock {
  flex: 0 0 auto;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: calc(var(--footer-height) + 16px);
  z-index: 20;
  max-width: min(440px, calc(100vw - 40px));
  padding: 13px 16px;
  border: 1px solid #79511e;
  border-radius: 8px;
  background: #22190e;
  color: #ffd691;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

:fullscreen .fullscreen-button span {
  display: none;
}

:fullscreen .fullscreen-button {
  width: 40px;
  padding: 0;
  justify-content: center;
  opacity: 0.35;
}

:fullscreen .fullscreen-button:hover,
:fullscreen .fullscreen-button:focus-visible {
  opacity: 1;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes number-change {
  0% {
    color: #fff;
    background: rgba(255, 90, 54, 0.42);
    text-shadow: 0 0 30px #ff927b;
  }
  100% {
    color: var(--live);
    background: transparent;
  }
}

@media (max-width: 700px) {
  :root {
    --status-height: 40px;
    --footer-height: 30px;
  }

  .status-bar {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding-inline: 8px;
  }

  .sync-status {
    position: absolute;
    left: 50%;
    min-width: 0;
    transform: translateX(-50%);
  }

  .sync-status > div,
  .identity p,
  .fullscreen-button span {
    display: none;
  }

  .fullscreen-button {
    width: 32px;
    min-height: 32px;
    padding: 0;
    justify-content: center;
  }

  .crest {
    width: 28px;
  }

  .identity {
    gap: 8px;
  }

  .identity h1 {
    font-size: 14px;
  }

  .source-strip {
    gap: 6px;
    padding-inline: 8px;
    font-size: 8px;
  }

  .source-credit {
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    line-height: 1.1;
  }

  .creator-credit::before {
    display: none;
  }
}

@media (max-width: 380px) {
  .crest {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
