:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-strong: #f8fafb;
  --text: #17212b;
  --muted: #66727f;
  --line: #d9e0e6;
  --accent: #146c68;
  --accent-dark: #0f504d;
  --warning: #b45b22;
  --danger: #a23a3a;
  --shadow: 0 18px 45px rgba(28, 39, 49, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.import-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    transform 0.15s ease;
}

button:hover,
.import-btn:hover {
  border-color: #9fb0bd;
  background: var(--surface-strong);
}

button:active,
.import-btn:active {
  transform: translateY(1px);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 40px;
  padding: 8px 10px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(20, 108, 104, 0.18);
  border-color: var(--accent);
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: grid;
  grid-template-columns: auto auto auto minmax(260px, 1fr);
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: #f7f9fa;
  padding: 14px 24px;
}

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

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #d9ebe8;
  border: 1px solid #b8d9d4;
}

.brand-mark span {
  /*position: relative;
  width: 27px;
  height: 4px;
  background: var(--accent);
  border-radius: 999px;*/
}

.brand-mark span::before,
.brand-mark span::after {
  /*position: absolute;
  content: "";
  top: -8px;
  width: 12px;
  height: 20px;
  border-radius: 100% 100% 2px 2px;
  background: var(--accent);*/
}

.brand-mark span::before {
  left: 5px;
  transform: rotate(-58deg);
}

.brand-mark span::after {
  right: 5px;
  transform: rotate(58deg);
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.panel p {
  margin: 0;
}

.brand h1 {
  font-size: 1.15rem;
  letter-spacing: 0;
}

.brand p,
.eyebrow,
.result-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.print-results-header {
  display: none;
}

.primary-action {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-action:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.danger-action {
  color: var(--danger);
  border-color: #e2b7b7;
}

.danger-action:hover {
  background: #fff4f4;
  border-color: var(--danger);
}

.competition-list {
  display: flex;
  grid-column: 4;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

body[data-view="entry"] .competition-list,
body[data-view="results"] .competition-list {
  grid-column: 3 / -1;
}

.main-nav {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.main-nav a,
.public-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  text-decoration: none;
  font-weight: 800;
}

.main-nav a.active,
.main-nav a:hover,
.public-link:hover {
  border-color: var(--accent);
  background: #e7f2f0;
}

.competition-item {
  display: grid;
  gap: 4px;
  flex: 0 0 min(260px, 72vw);
  text-align: left;
  min-height: 48px;
}

.competition-item.active {
  border-color: var(--accent);
  background: #e7f2f0;
}

.competition-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.competition-item span {
  color: var(--muted);
  font-size: 0.78rem;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 24px;
}

.topbar,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h2 {
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  line-height: 1.15;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.logout-form {
  display: contents;
}

.import-btn {
  display: inline-grid;
  place-items: center;
  position: relative;
}

.import-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.competition-form {
  display: grid;
  grid-template-columns: 1.5fr 1fr repeat(4, minmax(130px, 0.55fr));
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(420px, 1.4fr);
  gap: 18px;
  align-items: start;
}

body[data-view="entry"] .content-grid {
  grid-template-columns: 1fr;
}

body[data-view="setup"] .content-grid {
  grid-template-columns: minmax(420px, 1fr) minmax(360px, 0.9fr);
}

body[data-view="results"] .content-grid,
body[data-view="results"] .competition-form {
  display: none;
}

[hidden] {
  display: none !important;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel h3 {
  font-size: 1.05rem;
}

.entry-form {
  display: grid;
  grid-template-columns: minmax(140px, 1.1fr) minmax(130px, 0.8fr) minmax(110px, 0.8fr) auto;
  gap: 8px;
  margin: 16px 0;
}

.available-pilot-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(130px, 0.8fr) minmax(110px, 0.8fr) auto;
  gap: 8px;
  margin: 16px 0;
}

.available-pilots-list {
  display: grid;
  gap: 8px;
}

.available-pilot-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.1fr) minmax(130px, 0.8fr) minmax(110px, 0.8fr) auto;
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  padding: 10px;
}

.available-pilot-row .delete-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.table-wrap.wide {
  margin-top: 16px;
}

.station-groups {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.station-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  overflow: hidden;
}

.station-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.station-group-header h4 {
  margin: 0;
  font-size: 0.95rem;
}

.station-group-header span,
.station-empty,
.station-pilot-main span {
  color: var(--muted);
  font-size: 0.8rem;
}

.station-pilot-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.station-pilot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(96px, max-content) minmax(88px, max-content) auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 10px;
}

.station-pilot > label {
  min-width: 0;
}

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

.station-pilot-main div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.station-pilot-main strong,
.station-pilot-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.station-order-badge {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #e7f2f0;
  color: var(--accent-dark);
  font-weight: 900;
}

.station-empty {
  padding: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

#scoresTable {
  min-width: 860px;
}

.results-panel table {
  min-width: 960px;
}

.round-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.round-tab {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  font-weight: 800;
}

.round-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.score-input {
  width: 92px;
  max-width: none;
  min-width: 92px;
  min-height: 34px;
  padding: 6px 8px;
}

.time-input {
  width: 84px;
  min-width: 84px;
}

.station-input {
  width: 100%;
  min-width: 72px;
  max-width: 96px;
  min-height: 34px;
  padding: 6px 8px;
}

.rank {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eef1f4;
  font-weight: 800;
}

.rank.gold {
  background: #f4cf60;
}

.rank.silver {
  background: #d7dde3;
}

.rank.bronze {
  background: #c99462;
  color: #fff;
}

.delete-btn {
  min-height: 32px;
  padding: 0 10px;
  color: var(--danger);
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

.muted {
  color: var(--muted);
}

.score-list {
  white-space: nowrap;
}

.dropped-score {
  color: var(--warning);
  font-weight: 700;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.dropped {
  color: var(--warning);
  font-weight: 700;
}

.pin-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.pin-card {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.pin-brand {
  align-items: flex-start;
}

.pin-form {
  display: grid;
  gap: 14px;
}

.pin-note {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .app-header {
    grid-template-columns: 1fr auto;
  }

  .main-nav,
  .competition-list {
    grid-column: 1 / -1;
  }

  .competition-list {
    overflow-x: auto;
  }

  .competition-form,
  .content-grid {
    grid-template-columns: 1fr 1fr;
  }

  .scores-panel,
  .results-panel {
    grid-column: 1 / -1;
  }

  body[data-view="setup"] .content-grid {
    grid-template-columns: 1fr;
  }

  .entry-form,
  .available-pilot-form,
  .available-pilot-row {
    grid-template-columns: 1fr 1fr;
  }

  .entry-form button,
  .available-pilot-form button,
  .available-pilot-row .delete-btn {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .station-pilot {
    grid-template-columns: minmax(110px, 1fr) minmax(96px, 1fr) auto;
  }

  .station-pilot-main {
    grid-column: 1 / -1;
  }

  .station-pilot .delete-btn {
    min-width: 82px;
  }
}

@media (max-width: 680px) {
  .workspace,
  .app-header {
    padding: 16px;
  }

  .app-header,
  .topbar,
  .panel-header {
    align-items: stretch;
  }

  .app-header {
    grid-template-columns: 1fr;
  }

  .main-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .topbar,
  .panel-header {
    flex-direction: column;
  }

  .toolbar,
  .panel-header button {
    width: 100%;
  }

  .toolbar button,
  .toolbar .import-btn,
  .panel-header button {
    flex: 1;
  }

  .competition-form,
  .content-grid,
  .entry-form,
  .available-pilot-form,
  .available-pilot-row {
    grid-template-columns: 1fr;
  }

  .station-pilot {
    grid-template-columns: 1fr 1fr;
  }

  .station-pilot-main {
    grid-column: 1 / -1;
  }

  .station-pilot .delete-btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  table {
    min-width: 620px;
  }
}
@media print {
  @page {
    margin: 12mm;
    size: A4 landscape;
  }

  body {
    background: #fff;
    color: #000;
  }

  .app-header,
  .topbar,
  .competition-form,
  .content-grid,
  .results-panel .panel-header,
  .result-actions,
  #emptyStateTemplate {
    display: none !important;
  }

  .app-shell,
  .workspace {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .results-panel {
    display: block !important;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
  }

  .print-results-header {
    display: block;
    margin-bottom: 14px;
  }

  .print-results-header h1 {
    margin: 0 0 4px;
    font-size: 22px;
  }

  .print-results-header p {
    margin: 0;
    color: #444;
    font-size: 12px;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
  }

  .results-panel table {
    min-width: 0;
    font-size: 11px;
  }

  th,
  td {
    padding: 6px 7px;
  }

  button,
  .import-btn {
    display: none !important;
  }
}
