:root {
  --green-950: #243426;
  --green-900: #30472f;
  --green-800: #39543a;
  --green-700: #5d785f;
  --sage: #8ba38d;
  --sage-soft: #edf3ee;
  --mint: #dfe9e0;
  --gold: #c9a44f;
  --ink: #15231d;
  --muted: #65756e;
  --line: #dce5df;
  --paper: #f7faf7;
  --white: #ffffff;
  --danger: #b43b31;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  color: var(--white);
  background: linear-gradient(180deg, var(--green-950), var(--green-800));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.brand strong,
.brand span,
.judge-card strong,
.judge-card small {
  display: block;
}

.brand span,
.judge-card span,
.judge-card small,
.eyebrow {
  color: rgba(255, 255, 255, .72);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--white);
  background: rgba(255, 255, 255, .05);
  text-align: left;
  text-decoration: none;
  font-weight: 800;
  font: inherit;
  cursor: pointer;
}

.nav-link {
  display: flex;
  align-items: center;
}

.nav-item.is-active {
  color: var(--green-900);
  background: var(--mint);
}

.judge-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, .07);
}

.judge-card strong,
.judge-card small {
  margin-top: 6px;
}

.app-shell {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar .eyebrow,
.panel .eyebrow {
  color: var(--green-700);
  margin: 0 0 4px;
  font-weight: 900;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 20px;
}

.status-pill,
.sync-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  color: var(--green-800);
  background: var(--white);
  font-weight: 800;
  white-space: nowrap;
}

.status-pill span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #23b26d;
}

.sync-note {
  min-height: 30px;
  color: #755615;
  background: rgba(201, 164, 79, .16);
  border: 0;
  font-size: 12px;
  text-transform: uppercase;
}

.disconnect-action {
  width: 100%;
  min-height: 36px;
  margin-top: 12px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  color: var(--white);
  background: rgba(255, 255, 255, .08);
  font-weight: 850;
  cursor: pointer;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.hero-live {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 24px;
  margin-bottom: 18px;
  border-radius: 8px;
  color: var(--white);
  background: linear-gradient(135deg, var(--green-950), var(--green-700));
  box-shadow: 0 18px 45px rgba(15, 61, 46, .16);
}

.hero-live h2 {
  font-size: 30px;
  margin-bottom: 8px;
}

.hero-live p:not(.eyebrow) {
  margin: 0;
  max-width: 720px;
  color: rgba(255, 255, 255, .78);
  line-height: 1.5;
}

.live-total {
  min-width: 170px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  place-content: center;
  text-align: center;
  background: rgba(255, 255, 255, .08);
}

.live-total strong {
  font-size: 42px;
}

.live-total span {
  color: rgba(255, 255, 255, .78);
}

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 18px 45px rgba(15, 61, 46, .08);
}

.judge-login {
  display: grid;
  gap: 12px;
  max-width: 620px;
}

.judge-login label {
  color: var(--green-800);
  font-size: 13px;
  font-weight: 950;
  text-transform: uppercase;
}

.judge-login > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.admin-session-action {
  width: 100%;
  min-height: 44px;
}

.judge-login input {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  font: inherit;
  font-weight: 800;
}

.settings-panel {
  margin-bottom: 18px;
}

.competition-settings {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

.competition-settings label {
  display: grid;
  gap: 6px;
}

.competition-settings span {
  color: var(--green-800);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.formula-note {
  margin: 14px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--green-800);
  background: var(--sage-soft);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.45;
}

.prepared-list-info {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  margin: 0;
  border: 1px solid rgba(139, 163, 141, .46);
  border-radius: 999px;
  padding: 0 14px;
  color: var(--green-800);
  background: var(--sage-soft);
  font-size: 13px;
  font-weight: 950;
}

.prepared-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.prepared-list-info select {
  min-width: min(420px, 80vw);
  height: 36px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  font-weight: 950;
}

.prepared-list-info select:focus {
  outline: 0;
}

.prepare-list-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: 0 0 14px;
  border: 1px solid rgba(139, 163, 141, .56);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--green-800);
  background: var(--sage-soft);
  text-decoration: none;
  font-weight: 950;
}

.prepare-list-link:hover {
  border-color: var(--sage);
  background: var(--white);
}

.login-prepare-link {
  width: 100%;
  margin: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.is-run-view .topbar {
  display: none;
}

.is-group-view .topbar {
  justify-content: flex-end;
  margin-bottom: 10px;
}

.is-group-view .topbar > div:first-child {
  display: none;
}

.is-group-view .hero-live {
  align-items: center;
  padding: 10px 14px;
  margin-bottom: 10px;
}

.group-hero-title {
  font-size: 20px;
  font-weight: 950;
}

.is-group-view .live-total {
  min-width: 116px;
  padding: 8px 12px;
}

.is-group-view .live-total strong {
  font-size: 28px;
  line-height: 1;
}

.is-group-view .live-total span {
  font-size: 12px;
  font-weight: 850;
}

.is-group-view #groupView > .panel {
  padding: 12px;
  box-shadow: 0 10px 26px rgba(15, 61, 46, .05);
}

.is-group-view .settings-panel {
  margin-bottom: 10px;
}

.is-group-view .competition-settings {
  gap: 8px;
}

.is-group-view .competition-settings label {
  gap: 3px;
}

.is-group-view select,
.is-group-view input {
  height: 38px;
}

.is-group-view .formula-note {
  margin-top: 8px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.25;
}

.is-group-view .panel-head {
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}

.is-group-view .panel-head > div:empty {
  display: none;
}

.score-grid-test-head {
  display: grid;
  grid-template-columns: minmax(170px, .8fr) minmax(180px, 1fr) auto;
  align-items: end;
  margin-bottom: 12px;
}

.score-grid-test-head h2 {
  font-size: 20px;
}

.score-grid-test-head .status-pill {
  align-self: center;
}

select,
input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
  font-weight: 700;
}

input:focus,
select:focus {
  outline: 3px solid rgba(19, 86, 64, .14);
  border-color: var(--green-700);
}

button {
  font: inherit;
}

.primary-action,
.validated-action,
.secondary-action {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 950;
  cursor: pointer;
}

.primary-action {
  color: var(--white);
  border: 1px solid rgba(139, 163, 141, .52);
  background: linear-gradient(180deg, var(--green-800), var(--green-950));
  box-shadow: 0 6px 16px rgba(36, 52, 38, .16);
}

.validated-action {
  color: var(--green-800);
  background: rgba(19, 86, 64, .14);
  cursor: default;
}

.primary-action:disabled,
.validated-action:disabled,
.secondary-action:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.validated-action:disabled {
  opacity: 1;
  cursor: default;
}

.primary-action.compact {
  width: 150px;
}

.secondary-action {
  color: var(--green-800);
  background: var(--sage-soft);
}

.chrono-viewer-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  text-decoration: none;
}

.danger-action {
  color: var(--danger);
  background: rgba(180, 59, 49, .1);
}

.add-player {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.is-group-view .add-player {
  gap: 8px;
  margin-bottom: 8px;
}

.all-player-search {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(220px, 1fr) auto;
  align-items: stretch;
}

.is-group-view .all-player-search {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
}

.record-score-action {
  width: 100%;
  min-height: 54px;
  margin-top: 14px;
  font-size: 17px;
}

.send-now-action {
  width: 100%;
  min-height: 58px;
  margin-top: 16px;
  font-size: 18px;
}

.group-list,
.run-board,
.send-summary {
  display: grid;
  gap: 12px;
}

.is-group-view .group-list {
  gap: 6px;
}

.group-card,
.judge-run-card,
.summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfb;
}

.group-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.is-group-view .group-card {
  gap: 8px;
  min-height: 50px;
  padding: 7px 10px;
}

.is-group-view .group-card > div:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.is-group-view .group-card > div > strong,
.is-group-view .group-card > div > span {
  display: inline-flex;
  margin: 0;
  white-space: nowrap;
}

.is-group-view .group-card > div > strong {
  min-width: 0;
}

.is-group-view .group-card > div > span {
  font-size: 12px;
}

.group-card > div > strong,
.group-card > div > span {
  display: block;
}

.group-card span,
.summary-card span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.group-card strong,
.player-cell strong,
.summary-card strong {
  display: flex;
  align-items: center;
  gap: 8px;
}

.order-badge {
  width: 30px;
  height: 30px;
  display: inline-grid !important;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 999px;
  color: var(--white) !important;
  background: var(--green-800);
  font-size: 13px !important;
  font-weight: 950;
  margin: 0 !important;
}

.is-group-view .order-badge {
  width: 25px;
  height: 25px;
  font-size: 12px !important;
}

.group-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.is-group-view .group-actions {
  flex: 1 1 auto;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
}

.group-actions select {
  min-height: 42px;
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--white);
  font: inherit;
  font-weight: 800;
}

.is-group-view .group-actions select {
  width: min(34vw, 360px);
  min-width: 220px;
  min-height: 36px;
  height: 36px;
}

.icon-action {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--green-800);
  background: var(--white);
  font-size: 20px;
  font-weight: 950;
  cursor: pointer;
}

.is-group-view .icon-action {
  width: 36px;
  height: 36px;
  min-height: 36px;
  font-size: 18px;
}

.is-group-view .group-actions .secondary-action,
.is-group-view .panel-head .secondary-action,
.is-group-view .add-player .primary-action,
.is-group-view .all-player-search .secondary-action {
  min-height: 36px;
  padding: 0 12px;
}

.is-group-view .record-score-action {
  min-height: 44px;
  margin-top: 8px;
  font-size: 15px;
}

.icon-action:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.filters {
  display: flex;
  gap: 10px;
  min-width: min(520px, 60%);
}

.score-grid-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.score-grid-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.send-grid-action {
  min-width: 180px;
}

.score-block {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.score-block-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.score-block-head h3 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
}

.score-block-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.score-block.is-validated .score-grid-wrap {
  border-color: rgba(93, 120, 95, .38);
  box-shadow: inset 4px 0 0 rgba(93, 120, 95, .42);
}

.score-grid {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  table-layout: fixed;
}

.score-grid th,
.score-grid td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 6px;
  vertical-align: middle;
}

.score-grid th:last-child,
.score-grid td:last-child {
  border-right: 0;
}

.score-grid tbody tr:last-child th,
.score-grid tbody tr:last-child td {
  border-bottom: 0;
}

.score-grid thead th {
  height: 38px;
  color: var(--green-800);
  background: #f4f8f5;
  font-size: 12px;
  text-transform: uppercase;
}

.score-grid .name-col {
  width: 220px;
  text-align: left;
}

.score-grid tbody .name-col strong,
.score-grid tbody .name-col span {
  display: block;
}

.score-grid tbody .name-col strong {
  color: var(--ink);
  font-size: 13px;
}

.score-grid tbody .name-col span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.grid-cell-input,
.grid-score-cell,
.grid-final-cell {
  width: 100%;
  height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  background: #f9fbf9;
  text-align: center;
  font-weight: 950;
}

.grid-cell-input {
  padding: 0 6px;
}

.grid-cell-input::placeholder,
.grid-score-cell,
.grid-final-cell {
  color: #8a948e;
}

.grid-cell-input:focus,
.grid-score-cell:focus,
.grid-final-cell:focus {
  outline: 3px solid rgba(19, 86, 64, .16);
  border-color: var(--green-700);
  background: var(--white);
}

.grid-cell-input.has-draft {
  border-color: rgba(201, 164, 79, .28);
  color: var(--ink);
  background: rgba(201, 164, 79, .14);
}

.grid-cell-input.is-chrono-target {
  border-color: rgba(217, 119, 6, .62);
  color: var(--ink);
  background: #fff3d6;
  box-shadow: inset 0 0 0 2px rgba(217, 119, 6, .18);
}

.grid-cell-input.is-filled,
.grid-score-cell.is-filled {
  border-color: rgba(93, 120, 95, .28);
  color: var(--ink);
  background: #b7d8ac;
}

.grid-final-cell.is-ready {
  border-color: rgba(201, 164, 79, .34);
  color: var(--green-950);
  background: rgba(201, 164, 79, .18);
}

.grid-final-cell.is-sending {
  border-color: rgba(201, 164, 79, .34);
  color: #755615;
  background: rgba(201, 164, 79, .18);
}

.grid-final-cell.is-error {
  border-color: rgba(180, 59, 49, .36);
  color: var(--danger);
  background: rgba(180, 59, 49, .1);
}

.grid-final-cell.is-sent {
  border-color: rgba(93, 120, 95, .28);
  color: var(--ink);
  background: #b7d8ac;
}

.grid-final-cell:disabled {
  opacity: 1;
  cursor: default;
}

.judge-run-card {
  display: grid;
  grid-template-columns: minmax(190px, .8fr) repeat(3, minmax(160px, 1fr)) minmax(170px, .7fr);
  gap: 12px;
  align-items: stretch;
}

.player-cell > span {
  display: block;
}

.player-cell span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.run-cell {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--white);
}

.run-cell header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 900;
}

.run-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.run-cell button {
  width: 100%;
  margin-top: 8px;
}

.run-cell.is-valid {
  border-color: rgba(19, 86, 64, .32);
  background: rgba(19, 86, 64, .06);
}

.run-cell.has-error {
  border-color: rgba(180, 59, 49, .55);
  background: rgba(180, 59, 49, .05);
}

.run-feedback {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.run-cell.has-error .run-feedback {
  color: var(--danger);
}

.reset-live-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.reset-live-panel span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.run-pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 950;
}

.run-pill.pending {
  color: #755615;
  background: rgba(201, 164, 79, .15);
}

.run-pill.ready,
.badge.ready {
  color: var(--green-800);
  background: rgba(19, 86, 64, .12);
}

.badge.waiting {
  color: var(--muted);
  background: #e8eee9;
}

.badge.error {
  color: var(--danger);
  background: rgba(180, 59, 49, .1);
}

.history-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.retry-action,
.retry-all-action,
.live-toggle-action {
  min-height: 36px;
}

.live-toggle-action {
  min-width: 82px;
  padding: 0 10px;
}

.score-cell {
  display: grid;
  gap: 8px;
  align-content: center;
}

.score-cell b {
  color: var(--green-800);
  font-size: 30px;
}

.score-cell button {
  width: 100%;
}

.summary-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 160px;
  gap: 12px;
  align-items: center;
}

.summary-card b {
  color: var(--green-800);
  font-size: 24px;
  text-align: right;
}

.hint {
  color: var(--muted);
  margin: 14px 0 0;
  line-height: 1.45;
}

@media (max-width: 1120px) {
  .judge-run-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    padding: 14px;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .brand {
    display: none;
  }

  .judge-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px 10px;
    margin-top: 10px;
    padding: 10px 12px;
  }

  .judge-card span,
  .judge-card small {
    display: none;
  }

  .judge-card strong {
    margin-top: 0;
    font-size: 13px;
    line-height: 1.2;
  }

  .judge-card .disconnect-action {
    width: auto;
    min-height: 32px;
    margin-top: 0;
    padding: 0 12px;
    font-size: 12px;
    white-space: nowrap;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
    padding: 0 8px;
    font-size: 13px;
  }

  .app-shell {
    padding: 18px;
  }

  .topbar,
  .hero-live,
  .panel-head,
  .add-player,
  .filters,
  .group-card,
  .summary-card {
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .topbar,
  .hero-live,
  .panel-head,
  .group-card {
    align-items: stretch;
  }

  .filters {
    min-width: 0;
  }

  .primary-action.compact {
    width: 100%;
  }

  .judge-login > div {
    grid-template-columns: 1fr;
  }

  .competition-settings {
    grid-template-columns: 1fr;
  }

  .is-group-view .hero-live {
    flex-direction: row;
    align-items: center;
  }

  .is-group-view .group-card > div:first-child {
    display: block;
  }

  .is-group-view .group-card > div > strong,
  .is-group-view .group-card > div > span {
    display: flex;
    white-space: normal;
  }

  .is-group-view .all-player-search {
    grid-template-columns: 1fr;
  }

  .prepared-row {
    align-items: stretch;
    flex-direction: column;
  }

  .group-actions select {
    grid-column: 1 / -1;
    width: 100%;
  }

  .group-actions {
    display: grid;
    grid-template-columns: 42px 42px minmax(0, 1fr);
    justify-content: stretch;
    width: 100%;
  }

  .group-actions .icon-action {
    width: 42px;
    min-width: 42px;
  }

  .group-actions .secondary-action {
    justify-self: end;
    min-height: 42px;
    width: auto;
    min-width: 96px;
  }

  .reset-live-panel {
    align-items: stretch;
    flex-direction: column;
  }
}
