:root {
  --bg: #fff8ea;
  --panel: rgba(255, 255, 255, .82);
  --panel-soft: #f5ead5;
  --ink: #001e32;
  --muted: #617080;
  --line: rgba(16, 32, 51, .14);
  --accent: #de9e05;
  --accent-dark: #c58a00;
  --navy: #001e32;
  --gold: #de9e05;
  --gold-2: #f0bd36;
  --danger: #9c2f2f;
  --ok: #001e32;
  --warn: #9b6a10;
  --shadow: 0 18px 55px rgba(7, 35, 63, .16);
  --font-display: "Barlow Condensed", sans-serif;
  --font-body: "Inter", sans-serif;
  font-family: var(--font-body);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(0, 30, 50, .08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(0, 30, 50, .06) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, .55), transparent 72%);
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, .72);
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  border-color: #aeb6bd;
}

button.primary {
  border-color: var(--gold);
  color: #111b25;
  background: var(--gold);
  text-transform: uppercase;
}

button.primary:hover {
  background: var(--gold-2);
}

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

button.small-button {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 12px;
}

.icon-button {
  width: 46px;
  min-height: 46px;
  padding: 0;
  border: 2px solid var(--navy);
  color: var(--navy);
  background: rgba(255, 255, 255, .62);
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--gold);
  background: var(--gold);
}

textarea,
input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, .88);
  line-height: 1.45;
}

textarea {
  min-height: 180px;
  resize: vertical;
}

select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 18px clamp(16px, 4vw, 56px);
  border-bottom: 1px solid rgba(0, 30, 50, .1);
  background: rgba(255, 248, 234, .9);
  backdrop-filter: blur(14px);
}

.app-header h1,
.panel h2 {
  margin: 0;
}

.app-header h1 {
  color: var(--navy);
  font-family: var(--font-display);
  font-size: clamp(38px, 6vw, 68px);
  line-height: .96;
  text-transform: uppercase;
}

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

.eyebrow {
  margin: 0 0 10px;
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.engine-status {
  max-width: 460px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
}

.engine-status.ok {
  border-color: rgba(40, 112, 75, .35);
  color: var(--ok);
}

.engine-status.fail {
  border-color: rgba(156, 47, 47, .35);
  color: var(--danger);
}

.menu-wrap {
  position: relative;
}

.menu-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  width: min(300px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgba(255, 248, 234, .96);
  box-shadow: var(--shadow);
}

.menu-panel[hidden],
[hidden] {
  display: none !important;
}

.menu-panel .primary {
  width: 100%;
  margin-top: 8px;
}

.menu-status {
  margin: 0 0 10px;
  color: var(--ok);
  font-weight: 700;
}

.menu-panel button:not(.primary) {
  width: 100%;
}

.tabs {
  display: flex;
  gap: 8px;
  width: min(1180px, calc(100% - 32px));
  margin: 22px auto 0;
}

.tab-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
}

.tab-button.active {
  border-color: var(--gold);
  color: #111b25;
  background: var(--gold);
}

.app-shell {
  display: grid;
  gap: 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 14px auto 70px;
}

.tab-panel {
  display: none;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  gap: 18px;
}

.tab-panel.active {
  display: grid;
}

#roundsTab,
#startlistTab {
  grid-template-columns: 1fr;
}

.panel {
  min-width: 0;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(0, 30, 50, .08);
}

.admin-panel {
  border-left: 8px solid var(--gold);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
}

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

.panel h2,
.round-block h3 {
  color: var(--navy);
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0;
}

.panel h2 {
  font-size: clamp(34px, 4vw, 48px);
  line-height: 1.02;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tool-row,
.admin-actions {
  margin-bottom: 12px;
}

.field-label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 0;
  color: var(--muted);
  background: var(--panel-soft);
}

.pairing-table,
.round-table,
.standings-table,
.start-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.pairing-table th,
.pairing-table td,
.round-table th,
.round-table td,
.standings-table th,
.standings-table td,
.start-table th,
.start-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(0, 30, 50, .12);
  text-align: left;
  vertical-align: middle;
}

.pairing-table th,
.round-table th,
.standings-table th,
.start-table th {
  color: var(--muted);
  background: rgba(245, 234, 213, .8);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.pairing-table tbody tr:nth-child(even),
.round-table tbody tr:nth-child(even),
.standings-table tbody tr:nth-child(even),
.start-table tbody tr:nth-child(even) {
  background: rgba(245, 234, 213, .42);
}

.pairing-table tbody tr:hover,
.round-table tbody tr:hover,
.standings-table tbody tr:hover,
.start-table tbody tr:hover {
  background: rgba(240, 189, 54, .16);
}

.pairing-table td:first-child,
.round-table td:first-child,
.standings-table td:first-child,
.start-table td:first-child {
  width: 52px;
  color: var(--muted);
}

.result-cell {
  width: 130px;
}

.round-block {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .62);
  box-shadow: 0 10px 26px rgba(0, 30, 50, .07);
}

.round-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: 0 0 8px;
}

.round-block h3 {
  margin: 0;
  font-size: clamp(26px, 3vw, 34px);
  line-height: 1;
}

dialog {
  width: min(760px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(19, 32, 44, .34);
}

.dialog-body {
  display: grid;
  gap: 12px;
}

.dialog-body h2 {
  margin: 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 12px;
  border-radius: 0;
  color: #fff;
  background: var(--ink);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}

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

.toast.error {
  background: var(--danger);
}

.toast.warn {
  background: var(--warn);
}

@media (max-width: 980px) {
  .app-header,
  .header-actions,
  .panel-heading {
    display: grid;
  }

  .tab-panel,
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell,
  .tabs {
    width: min(100% - 20px, 1440px);
  }

  .tabs {
    overflow-x: auto;
  }

  .round-heading {
    display: grid;
  }

  .pairing-table,
  .round-table,
  .standings-table,
  .start-table {
    font-size: 13px;
  }
}
