:root {
  --bg: #f4efe5;
  --bg-accent: #efe2cb;
  --surface: rgba(255, 252, 246, 0.94);
  --surface-strong: #fffdf8;
  --text: #1f2230;
  --muted: #596275;
  --line: rgba(48, 52, 63, 0.1);
  --brand: #a54218;
  --brand-dark: #7f3313;
  --success: #19735f;
  --shadow: 0 18px 40px rgba(47, 35, 17, 0.12);
  --shadow-soft: 0 10px 24px rgba(47, 35, 17, 0.08);
  --radius: 8px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(165, 66, 24, 0.16), transparent 24rem),
    radial-gradient(circle at right center, rgba(25, 115, 95, 0.14), transparent 28rem),
    linear-gradient(180deg, var(--bg) 0%, #f7f4ee 100%);
  min-height: 100vh;
}

body.modal-open {
  overflow: hidden;
}

.page-shell {
  width: min(1150px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding: 1.75rem 1.75rem 1.35rem;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: calc(var(--radius) + 2px);
  background:
    linear-gradient(135deg, rgba(255, 251, 244, 0.96), rgba(249, 240, 224, 0.88)),
    var(--surface);
  box-shadow: var(--shadow-soft);
}

.eyebrow,
.section-kicker {
  margin: 0 0 0.3rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--brand);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
  margin-bottom: 0.75rem;
}

h2 {
  font-size: 1.45rem;
  margin-top: 0.1rem;
}

.hero-copy {
  max-width: 40rem;
  color: var(--muted);
  line-height: 1.5;
}

.editable-line {
  display: flex;
  gap: 0.55rem;
  align-items: center;
}

.editable-line-top {
  align-items: flex-start;
}

.hero-badge {
  align-self: center;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.9rem 1.1rem;
  border-radius: 4px;
  background: rgba(165, 66, 24, 0.09);
  color: var(--brand-dark);
  font-weight: 600;
  text-align: center;
}

.layout {
  display: grid;
  gap: 1rem;
}

.tabs {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem;
  border-radius: var(--radius);
  background: rgba(255, 252, 246, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow-soft);
}

.tab-button {
  border: 0;
  border-radius: 4px;
  padding: 0.85rem 1.2rem;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.tab-button:hover {
  transform: translateY(-1px);
  color: var(--text);
}

.tab-button.active {
  background: var(--brand);
  color: white;
}

.panel {
  padding: 1.4rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid rgba(31, 34, 48, 0.08);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(8px);
}

.panel-wide {
  min-width: 0;
}

.tab-panel {
  display: none;
}

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

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.stack-form,
.participants-list,
.player-list {
  display: grid;
  gap: 0.9rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
  color: var(--text);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  padding: 0.82rem 0.95rem;
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(165, 66, 24, 0.22);
  border-color: rgba(165, 66, 24, 0.35);
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.button-row,
.participants-header {
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.filter-row {
  margin-bottom: 1rem;
}

.filter-field {
  max-width: 320px;
}

.button-primary,
.button-secondary,
.button-ghost {
  border: 0;
  border-radius: 4px;
  padding: 0.82rem 1.2rem;
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, opacity 140ms ease;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 0.82rem 1.2rem;
  background: rgba(31, 34, 48, 0.08);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  transition: transform 140ms ease, background-color 140ms ease;
}

.button-primary:hover,
.button-secondary:hover,
.button-ghost:hover,
.file-button:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: var(--brand);
  color: white;
  font-weight: 700;
}

.button-primary:hover {
  background: var(--brand-dark);
}

.button-secondary {
  background: rgba(31, 34, 48, 0.08);
  color: var(--text);
}

.button-ghost {
  background: rgba(165, 66, 24, 0.1);
  color: var(--brand-dark);
}

.field-title {
  font-weight: 700;
}

.icon-button {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 4px;
  background: rgba(31, 34, 48, 0.08);
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover {
  background: rgba(31, 34, 48, 0.14);
  color: var(--text);
}

.field-help,
.list-summary,
.muted-copy,
.match-meta,
.player-meta {
  color: var(--muted);
}

.list-summary {
  margin-bottom: 0.9rem;
}

.participant-row,
.match-card,
.player-card {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(31, 34, 48, 0.08);
  border-radius: var(--radius);
}

.participant-row {
  grid-template-columns: minmax(0, 1.8fr) minmax(110px, 1fr) minmax(110px, 1fr) auto;
  align-items: end;
}

.player-name {
  font-size: 1.06rem;
  font-weight: 700;
}

.player-actions,
.table-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.placement-stats {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.placement-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.24rem 0.55rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.88rem;
}

.placement-chip.gold {
  background: #f4d35e;
  color: #6b4f00;
}

.placement-chip.silver {
  background: #d9dee7;
  color: #445066;
}

.placement-chip.bronze {
  background: #d9a066;
  color: #5e3414;
}

.mini-button {
  border: 0;
  background: rgba(31, 34, 48, 0.08);
  border-radius: 4px;
  padding: 0.58rem 0.9rem;
  cursor: pointer;
}

.mini-button.danger {
  background: rgba(165, 24, 24, 0.12);
  color: #8f1f1f;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table th,
.results-table td,
.stats-table th,
.stats-table td {
  padding: 0.7rem 0.45rem;
  border-bottom: 1px solid rgba(31, 34, 48, 0.08);
  text-align: left;
}

.stats-table th:last-child,
.stats-table td:last-child {
  text-align: right;
}

.results-table th,
.stats-table th {
  font-size: 0.9rem;
  color: var(--muted);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.1rem;
  padding: 0.28rem 0.55rem;
  border-radius: 4px;
  background: rgba(25, 115, 95, 0.12);
  color: var(--success);
  font-weight: 700;
}

.empty-state {
  padding: 1rem 1.05rem;
  border-radius: var(--radius);
  background: rgba(31, 34, 48, 0.05);
  color: var(--muted);
}

.backup-panel {
  display: grid;
  gap: 0.9rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 24, 31, 0.45);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(760px, calc(100% - 1.5rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid rgba(31, 34, 48, 0.12);
  box-shadow: var(--shadow);
}

.modal-card-narrow {
  width: min(520px, calc(100% - 1.5rem));
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.stat-card {
  display: grid;
  gap: 0.35rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(31, 34, 48, 0.08);
}

.stat-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-value {
  font-size: 1.5rem;
  line-height: 1.1;
}

.table-wrap {
  overflow-x: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
}

.hidden {
  display: none !important;
}

@media (max-width: 930px) {
  .participant-row {
    grid-template-columns: 1fr;
  }

  .hero {
    flex-direction: column;
  }

  .hero-badge {
    align-self: flex-start;
  }

  .editable-line {
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 1rem, 1000px);
    padding-top: 0.75rem;
  }

  .hero,
  .panel {
    padding: 1rem;
  }

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

  .stats-summary {
    grid-template-columns: 1fr;
  }

  .tabs {
    gap: 0.5rem;
  }

  .tab-button {
    flex: 1 1 calc(50% - 0.5rem);
    text-align: center;
  }
}
