:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-strong: #f9faf7;
  --ink: #20251f;
  --muted: #677067;
  --line: #d7dbd2;
  --line-strong: #bbc4b8;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #dff4ef;
  --warn: #9f5b0b;
  --danger: #b42318;
  --danger-soft: #ffe4df;
  --shadow: 0 14px 36px rgba(31, 42, 31, 0.08);
  --radius: 8px;
  --sidebar: 284px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(37, 63, 53, 0.045) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  position: relative;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
}

.brand-mark span {
  position: absolute;
  width: 31px;
  height: 40px;
  border: 2px solid #20251f;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 6px 0 rgba(15, 118, 110, 0.18);
}

.brand-mark span:first-child {
  left: 3px;
  top: 3px;
  rotate: -8deg;
}

.brand-mark span:last-child {
  right: 3px;
  bottom: 3px;
  rotate: 9deg;
}

.brand h1,
.topbar h2,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 1.08rem;
  line-height: 1.25;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-tabs {
  display: grid;
  gap: 7px;
}

.nav-tab,
.ghost-button,
.danger-button,
.primary-button,
.secondary-button,
.text-button,
.icon-button,
.segment {
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.nav-tab {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  min-height: 44px;
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-tab:hover,
.nav-tab.is-active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--accent);
  font-weight: 800;
}

.quick-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.quick-panel div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.quick-panel strong {
  color: var(--ink);
}

.sidebar-actions,
.topbar-actions,
.action-row,
.round-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sidebar-actions {
  margin-top: auto;
}

.main {
  min-width: 0;
  padding: 24px;
}

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

.topbar h2 {
  font-size: clamp(1.55rem, 3vw, 2.4rem);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 13px;
  white-space: nowrap;
}

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

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.ghost-button,
.text-button,
.icon-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button:hover,
.ghost-button:hover,
.text-button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-strong);
}

.danger-button {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

.danger-button:hover {
  border-color: #f7b4aa;
}

.text-button {
  min-height: 34px;
  padding: 7px 10px;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 1.3rem;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.screen {
  display: none;
}

.screen.is-active {
  display: grid;
  gap: 18px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 94px;
  padding: 17px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(1.42rem, 4vw, 2.15rem);
  line-height: 1;
}

.panel {
  min-width: 0;
  padding: 16px;
}

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

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

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.share-url {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.share-url span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.share-url code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 12px;
}

.qr-card {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.qr-card-header {
  display: grid;
  gap: 3px;
}

.qr-card-header strong,
.qr-card-header span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qr-card-header span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.qr-box {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.qr-box svg {
  width: min(160px, 100%);
  height: auto;
}

.match-qr {
  display: grid;
  justify-items: end;
  gap: 4px;
  width: 88px;
}

.match-qr .qr-box {
  min-height: 74px;
  width: 74px;
}

.match-qr .qr-box svg {
  width: 68px;
}

.match-qr a,
.qr-card a {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 900;
  text-decoration: none;
}

.entry-form,
.settings-grid {
  display: grid;
  gap: 12px;
}

.entry-form {
  grid-template-columns: minmax(180px, 1.2fr) minmax(180px, 1fr) auto;
  align-items: end;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
}

input[type="text"]:focus,
input[type="number"]:focus {
  outline: 3px solid rgba(15, 118, 110, 0.16);
  border-color: var(--accent);
}

input[readonly] {
  background: var(--surface-strong);
  color: var(--muted);
}

.check-row {
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  min-height: 42px;
  color: var(--ink);
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.segmented {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.segment {
  min-height: 30px;
  padding: 5px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
}

.segment.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(31, 42, 31, 0.08);
}

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

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}

.compact-table table {
  min-width: 500px;
}

.regulation-table table {
  min-width: 720px;
}

.result-template-table table {
  min-width: 680px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 0.9rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.table-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

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

.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
}

.mini-button.warn {
  color: var(--warn);
}

.mini-button.danger {
  color: var(--danger);
}

.match-list {
  display: grid;
  gap: 10px;
}

.match-card {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.table-number {
  display: grid;
  place-items: center;
  height: 52px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 900;
}

.match-players {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.player-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.player-line strong,
.player-line span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-line span {
  color: var(--muted);
  font-size: 0.82rem;
}

.result-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 360px;
}

.result-controls button {
  min-width: 54px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
}

.result-controls button.is-selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.bye-card .table-number {
  background: #fff3d9;
  color: var(--warn);
}

.empty-state:empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.58);
}

.match-list > .empty-copy {
  min-height: 180px;
  display: grid;
  place-content: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.58);
}

.empty-copy {
  display: grid;
  gap: 6px;
  text-align: center;
  color: var(--muted);
}

.empty-copy strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #20251f;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

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

.mobile-body {
  display: grid;
  min-height: 100vh;
  background: var(--bg);
}

.mobile-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 18px;
}

.mobile-card {
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.mobile-card h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0;
}

.mobile-content {
  display: grid;
  gap: 16px;
}

.mobile-player,
.mobile-match {
  display: grid;
  gap: 10px;
}

.mobile-player,
.mobile-match div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.mobile-player span,
.mobile-match span,
.mobile-player small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.mobile-player strong,
.mobile-match strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.mobile-main-button {
  width: 100%;
  min-height: 52px;
}

.mobile-result-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mobile-result-button {
  min-height: 52px;
}

.mobile-status {
  min-height: 28px;
  color: var(--accent-strong);
  font-weight: 900;
}

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

.badge-active,
.badge-dropped,
.badge-bye {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 900;
}

.badge-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge-dropped {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-bye {
  background: #fff3d9;
  color: var(--warn);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

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

  .nav-tab {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 58px;
    padding: 7px;
    text-align: center;
    font-size: 0.78rem;
  }

  .quick-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sidebar-actions {
    margin-top: 0;
  }

  .main {
    padding: 16px;
  }

  .metrics-grid,
  .two-column {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions > * {
    flex: 1;
  }

  .metrics-grid,
  .two-column,
  .entry-form,
  .settings-grid,
  .quick-panel {
    grid-template-columns: 1fr;
  }

  .match-card {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .result-controls {
    grid-column: 1 / -1;
    justify-content: flex-start;
    max-width: none;
  }

  .match-qr {
    justify-items: start;
    width: 100%;
  }

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

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .action-row,
  .result-controls,
  .toast {
    display: none !important;
  }

  .app-shell,
  .main,
  .screen.is-active {
    display: block;
  }

  .main {
    padding: 0;
  }

  .panel {
    box-shadow: none;
    border: 0;
  }
}
