:root {
  --ink: #17231d;
  --muted: #637169;
  --paper: #f5f3ec;
  --surface: #fffef9;
  --line: #dcd8ca;
  --green: #195c43;
  --green-soft: #e1efe7;
  --gold: #c7902d;
  --red: #a63d3d;
  --shadow: 0 18px 50px rgba(31, 48, 39, .10);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 5%, rgba(199, 144, 45, .13), transparent 24rem),
    linear-gradient(180deg, #eeece3 0, var(--paper) 18rem);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 2rem;
  padding: 2rem max(4vw, 1.25rem) 1.5rem;
  color: white;
  background: var(--green);
  border-bottom: 5px solid var(--gold);
}
.eyebrow { margin: 0 0 .45rem; color: #c6e0d1; font-size: .78rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 4vw, 3.7rem); line-height: .96; font-weight: 600; }
.topbar > p { max-width: 33rem; margin: 0; color: #dcebe3; line-height: 1.55; }
.tournament-tabs { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: 1.15rem; }
.tournament-tabs button {
  display: grid; grid-template-columns: auto 1fr; gap: .45rem; align-items: center; min-height: 2.6rem; padding: .38rem .7rem;
  color: #dcebe3; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .24); border-radius: 11px;
}
.tournament-tabs button:hover { background: rgba(255, 255, 255, .14); }
.tournament-tabs button.active { color: var(--ink); background: var(--gold); border-color: var(--gold); }
.tournament-tabs b { font-size: .82rem; }
.tournament-tabs span { font-size: .78rem; font-weight: 700; }

main { width: min(1500px, calc(100% - 2rem)); margin: 1.5rem auto 4rem; }
.workspace { display: grid; grid-template-columns: minmax(620px, 1.45fr) minmax(300px, .55fr); gap: 1.25rem; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--line); }
.panel-head h2, .results-head h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; }
.panel-head p { margin: .2rem 0 0; color: var(--muted); font-size: .88rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.button, .file-button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 2.5rem; padding: .55rem .85rem;
  border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; font-weight: 750;
}
.button:hover, .file-button:hover { border-color: var(--green); }
.button.primary { color: white; background: var(--green); border-color: var(--green); }
.button.primary:hover { background: #104a35; }
.file-button input { display: none; }

.table-wrap { max-height: 66vh; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 0; z-index: 1; padding: .65rem .55rem; color: var(--muted); background: #f2f0e8; font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; text-align: left; }
td { padding: .34rem .42rem; border-top: 1px solid #ece9df; }
td.index { width: 2.5rem; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
td:nth-child(3), td:nth-child(4) { width: 6.3rem; }
input, select { width: 100%; min-height: 2.25rem; padding: .4rem .55rem; color: var(--ink); background: white; border: 1px solid #d8d4c7; border-radius: 8px; }
input:focus, select:focus { outline: 3px solid rgba(25, 92, 67, .15); border-color: var(--green); }

.control-panel { position: sticky; top: 1rem; padding-bottom: 1.2rem; }
.control-panel .panel-head { display: block; }
.rules { display: grid; gap: .72rem; margin: 1rem 1.25rem; padding: 0; list-style: none; }
.rules li { display: grid; grid-template-columns: 2rem 1fr; gap: .65rem; align-items: center; color: #3d4b43; line-height: 1.35; }
.rules span { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; color: var(--green); background: var(--green-soft); font-weight: 900; }
.seed-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; margin: 1.1rem 1.25rem .7rem; }
.seed-row label { grid-column: 1 / -1; color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
.generate { width: calc(100% - 2.5rem); margin: .35rem 1.25rem; min-height: 3.2rem; font-size: 1.03rem; }
.message { margin: .9rem 1.25rem 0; padding: .8rem .9rem; white-space: pre-line; border-radius: 10px; font-size: .9rem; line-height: 1.4; }
.message.success { color: #0b5035; background: #dff2e7; }
.message.error { color: #792323; background: #f8e2e0; }
.message.info, .message.working { color: #55431e; background: #f5ebd3; }

.results { margin-top: 1.4rem; }
.results-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.2rem 1.3rem; border-bottom: 1px solid var(--line); }
.checks { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7rem; padding: 1.1rem 1.25rem; margin: 0; list-style: none; background: #f7f5ee; }
.checks li { display: grid; grid-template-columns: 1.7rem 1fr; align-items: center; min-height: 3.3rem; padding: .65rem; background: white; border: 1px solid var(--line); border-radius: 11px; font-size: .82rem; font-weight: 700; }
.checks li span { color: var(--green); font-size: 1.15rem; }
.checks li.preference span { color: #ad6a00; }
.checks li small { grid-column: 2; color: var(--muted); font-weight: 500; }
.rounds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; padding: 1.25rem; }
.round-card { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.round-card h3 { margin: 0; padding: .7rem .8rem; color: white; background: var(--green); font-size: 1rem; }
.fixture { display: grid; grid-template-columns: 1fr auto 1fr; gap: .4rem; align-items: center; padding: .42rem .6rem; border-top: 1px solid #ece9df; font-size: .8rem; }
.fixture span:first-child { text-align: right; }
.fixture b { color: var(--gold); }
.team-view { margin: 0 1.25rem 1.25rem; padding: 1rem; border: 1px solid var(--line); border-radius: 13px; background: #f7f5ee; }
.team-view-head { display: flex; gap: 1rem; justify-content: space-between; align-items: center; }
.team-view h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; }
.team-view select { max-width: 22rem; }
.team-schedule { display: grid; grid-template-columns: repeat(4, 1fr); gap: .55rem; margin-top: .9rem; }
.team-game { display: grid; grid-template-columns: 1.8rem 2rem 1fr; column-gap: .45rem; align-items: center; padding: .65rem; background: white; border: 1px solid var(--line); border-radius: 9px; }
.team-game small { grid-column: 3; color: var(--muted); }
.round-number { display: grid; place-items: center; width: 1.65rem; height: 1.65rem; color: white; background: var(--ink); border-radius: 50%; font-weight: 800; }
.venue { font-size: .72rem; font-weight: 900; }
.venue.home { color: var(--green); }
.venue.away { color: var(--gold); }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 1fr; }
  .control-panel { position: static; }
  .checks, .rounds, .team-schedule { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 650px) {
  .topbar { align-items: start; flex-direction: column; }
  main { width: min(100% - 1rem, 1500px); }
  .panel-head, .results-head, .team-view-head { align-items: stretch; flex-direction: column; }
  .actions { justify-content: start; }
  .checks, .rounds, .team-schedule { grid-template-columns: 1fr; }
  .table-wrap { max-height: 58vh; }
}
