:root {
  color-scheme: light;
  --ink: #121714;
  --muted: #65706a;
  --line: #dce2de;
  --panel: #ffffff;
  --canvas: #eef1ef;
  --red: #d62631;
  --red-dark: #a81720;
  --green: #11845b;
  --amber: #b66a00;
  --gold: #ffd700;
  --silver: #e3e7ed;
  --bronze: #e69a55;
  --row-height: 72px;
  --page-gutter: max(clamp(40px, 10vw, 180px), calc((100vw - 1320px) / 2));
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
}

body {
  min-width: 320px;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.event-header {
  min-height: 94px;
  padding: 16px var(--page-gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: #2563eb;
  border-top: 6px solid #1d4ed8;
  color: #ffffff;
}

.brand-block,
.header-status,
.summary-actions {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
}

.brand-copy {
  min-width: 0;
}

h1 {
  margin: 0;
  color: #ffffff;
  font-size: 30px;
  line-height: 1.2;
  font-weight: 400;
  white-space: nowrap;
}

.event-hint {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 19px;
  line-height: 1.2;
  font-weight: 400;
}

.header-status {
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 26px;
}

.live-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
}

.live-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  border-radius: 50%;
  background: #34c98b;
  box-shadow: 0 0 0 4px rgba(52, 201, 139, 0.13);
}

#clock {
  min-width: 136px;
  font-family: "Segoe UI", monospace;
  font-size: 25px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.scoreboard-toolbar {
  min-height: 64px;
  padding: 0 var(--page-gutter);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.summary-actions {
  justify-content: flex-end;
}

#syncState.is-loading {
  color: #f0c56e;
}

#syncState.is-loading .live-dot {
  background: #f0b84b;
  box-shadow: 0 0 0 4px rgba(240, 184, 75, 0.13);
}

#syncState.is-error {
  color: #ff9298;
}

#syncState.is-error .live-dot {
  background: #ff5862;
  box-shadow: 0 0 0 4px rgba(255, 88, 98, 0.14);
}

.tool-button,
.icon-button {
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid #cbd4ce;
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 400;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.tool-button {
  padding: 0 14px;
}

.icon-button {
  width: 42px;
  padding: 0;
}

.tool-button svg,
.icon-button svg {
  width: 18px;
}

.tool-button:hover,
.icon-button:hover {
  border-color: #98a59d;
  background: #f1f4f2;
}

.tool-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.tool-button.primary {
  border-color: var(--red);
  background: var(--red);
  color: #ffffff;
}

.tool-button.primary:hover {
  border-color: var(--red-dark);
  background: var(--red-dark);
}

.leaderboard {
  min-height: 0;
  padding: 0 var(--page-gutter);
  background: var(--canvas);
}

.table-wrap {
  height: 100%;
  min-height: 300px;
  overflow: auto;
  background: #ffffff;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  outline: none;
  scroll-behavior: smooth;
}

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

thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #ffffff;
  color: #121714;
  border-bottom: 1px solid var(--line);
}

th {
  height: 48px;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 400;
  text-align: left;
}

tbody tr {
  height: var(--row-height);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 140ms ease;
}

tbody tr:hover,
tbody tr:focus-within {
  background: #f2f7f4;
}

td {
  padding: 10px 20px;
  overflow: hidden;
  color: #303934;
  font-size: 14px;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.rank-column { width: 8%; }
.draw-column { width: 8%; }
.team-column { width: 27%; }
.members-column { width: 37%; }
.score-column { width: 20%; }

.rank-column {
  text-align: center;
}

.draw-column {
  text-align: center;
}

.team-column,
.team-cell,
.members-column,
.members-cell,
.score-column,
.score-cell {
  text-align: center;
}

.rank-cell {
  text-align: center;
}

.rank-badge {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d3dad6;
  border-radius: 50%;
  background: #ffffff;
  color: #4e5953;
  font-family: "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.draw-cell {
  text-align: center;
  font-family: "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.team-name {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.members-list {
  overflow: hidden;
  color: #4f5a54;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-cell {
  text-align: center;
  white-space: nowrap;
}

.score-value {
  display: block;
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.score-note {
  display: block;
  margin-top: 2px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 400;
}

.score-empty {
  color: #9aa39e;
}

.status-pill {
  min-width: 68px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 9px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 400;
}

.status-finished {
  background: #dff4e9;
  color: #08734d;
}

.status-racing {
  background: #fff0d7;
  color: #945300;
}

.status-waiting {
  background: #edf0ee;
  color: #65706a;
}

.empty-state {
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
}

.empty-state[hidden] {
  display: none;
}

.empty-state svg {
  width: 34px;
  height: 34px;
}

.event-footer {
  min-height: 38px;
  padding: 0 clamp(20px, 3vw, 52px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #121714;
  color: #aeb8b2;
  font-size: 11px;
}

.event-footer span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.event-footer .live-dot {
  width: 6px;
  height: 6px;
  box-shadow: none;
}

.team-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 32px));
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(5, 12, 8, 0.35);
}

.team-dialog::backdrop {
  background: rgba(9, 14, 11, 0.66);
}

.dialog-header {
  min-height: 92px;
  padding: 19px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: #1b231e;
  color: #ffffff;
}

.dialog-header p {
  margin: 0 0 5px;
  color: #b9c4bd;
  font-size: 14px;
  font-weight: 400;
}

.dialog-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 400;
}

.icon-button.light {
  flex: 0 0 auto;
  border-color: #465149;
  background: #29332d;
  color: #ffffff;
}

.dialog-summary {
  padding: 20px 22px;
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--line);
}

.dialog-summary div {
  min-width: 0;
  padding: 0 18px;
  border-right: 1px solid var(--line);
}

.dialog-summary div:first-child {
  padding-left: 0;
}

.dialog-summary div:last-child {
  padding-right: 0;
  border-right: 0;
}

.dialog-summary span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.dialog-summary strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#dialogFinal {
  color: var(--red);
  font-family: "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.rounds-table-wrap {
  max-height: 390px;
  overflow: auto;
  padding: 16px 22px 24px;
}

.rounds-table {
  border: 1px solid var(--line);
}

.rounds-table thead {
  position: static;
  background: #f0f3f1;
  color: #4b5650;
}

.rounds-table th,
.rounds-table td {
  height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 400;
  text-align: right;
}

.rounds-table strong {
  font-weight: 400;
}

.rounds-table th:first-child,
.rounds-table td:first-child {
  text-align: left;
}

.rounds-table tbody tr {
  height: 48px;
  cursor: default;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 56px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 16px;
  transform: translateY(20px);
  border-radius: 6px;
  background: #18201b;
  color: #ffffff;
  box-shadow: 0 12px 36px rgba(7, 12, 9, 0.26);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.toast.error {
  background: #9f1b24;
}

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

@media (max-width: 1120px) {
  .button-label {
    display: none;
  }

  .tool-button {
    width: 42px;
    padding: 0;
  }

  .members-column,
  .members-cell {
    display: none;
  }

  .team-column {
    width: 34%;
  }
}

@media (max-width: 760px) {
  :root {
    --row-height: 66px;
    --page-gutter: 16px;
  }

  .app-shell {
    grid-template-rows: auto auto minmax(420px, 1fr) auto;
  }

  .event-header {
    min-height: 108px;
    padding: 14px 18px;
    border-top-width: 5px;
  }

  h1 {
    max-width: calc(100vw - 36px);
    font-size: 20px;
    line-height: 1.35;
    white-space: normal;
  }

  .event-hint {
    font-size: 15px;
  }

  .header-status {
    display: none;
  }

  .scoreboard-toolbar {
    min-height: 60px;
    margin: 0 12px;
    padding: 0;
  }

  .leaderboard {
    padding: 0 12px;
  }

  .table-wrap {
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
  }

  th,
  td {
    padding-right: 8px;
    padding-left: 8px;
  }

  .draw-column,
  .draw-cell,
  .members-column,
  .members-cell {
    display: none;
  }

  .rank-column {
    width: 60px;
  }

  .team-column {
    width: auto;
  }

  .score-column {
    width: 112px;
  }

  .score-column,
  .score-cell {
    text-align: right;
  }

  .rank-badge {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .team-name {
    font-size: 14px;
  }

  .score-value {
    font-size: 14px;
  }

  .event-footer {
    padding: 0 16px;
  }

  .event-footer span:last-child {
    display: none;
  }

  .dialog-summary {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .dialog-summary div {
    padding: 0;
    border-right: 0;
  }
}

@media (max-width: 390px) {
  h1 {
    max-width: calc(100vw - 36px);
  }
}

@media (max-width: 350px) {
  h1 {
    font-size: 18px;
  }

  .event-hint {
    font-size: 14px;
  }
}

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