:root {
  --c-bg: #fff7e6;
  --c-bg-2: #ffe9c2;
  --c-ink: #2a1a08;
  --c-muted: #7a6650;
  --c-card: #ffffff;
  --c-border: #f0d9b0;
  --c-red: #e63946;
  --c-orange: #f4801f;
  --c-yellow: #ffcb2b;
  --c-green: #2ec27e;
  --c-blue: #2271ff;
  --c-purple: #7a4dff;
  --shadow: 0 4px 0 rgba(42,26,8,.1), 0 12px 30px rgba(42,26,8,.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background:
    radial-gradient(circle at 10% 0%, #ffd56b22, transparent 40%),
    radial-gradient(circle at 90% 10%, #2271ff1c, transparent 35%),
    radial-gradient(circle at 50% 100%, #2ec27e1f, transparent 45%),
    var(--c-bg);
  color: var(--c-ink);
  min-height: 100vh;
  line-height: 1.5;
}

.site-header {
  text-align: center;
  padding: 2.4rem 1rem 1.4rem;
}
.site-header h1 {
  font-family: 'Bungee', system-ui, sans-serif;
  font-size: clamp(2rem, 6vw, 3.4rem);
  margin: .2rem 0;
  letter-spacing: .02em;
  text-shadow: 3px 3px 0 var(--c-yellow);
}
.site-header .accent { color: var(--c-red); }
.site-header .tagline { color: var(--c-muted); margin: 0; font-size: 1rem; }

.logo {
  position: relative;
  width: 110px; height: 40px;
  margin: 0 auto 6px;
}
.logo .ball, .logo .cochonnet {
  position: absolute;
  border-radius: 50%;
  bottom: 0;
  box-shadow: inset -3px -4px 6px rgba(0,0,0,.25), 0 2px 0 rgba(0,0,0,.12);
}
.logo .ball { width: 28px; height: 28px; }
.logo .b1 { background: linear-gradient(145deg, #ff9b3d, var(--c-orange)); left: 0; }
.logo .b2 { background: linear-gradient(145deg, #6aa1ff, var(--c-blue)); left: 26px; }
.logo .b3 { background: linear-gradient(145deg, #4be3a4, var(--c-green)); left: 52px; }
.logo .cochonnet {
  width: 14px; height: 14px;
  background: linear-gradient(145deg, #fff39a, var(--c-yellow));
  right: 4px; bottom: 4px;
}

main { max-width: 960px; margin: 0 auto; padding: 0 1rem 4rem; }

.card {
  background: var(--c-card);
  border: 2px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow);
}
.card h2 {
  font-family: 'Bungee', system-ui, sans-serif;
  font-size: 1.2rem;
  margin: 0 0 1rem;
  color: var(--c-ink);
}

form label { display: block; margin-bottom: .8rem; font-weight: 500; }
input[type=text], input[type=number], input:not([type]) {
  width: 100%;
  padding: .6rem .8rem;
  margin-top: .25rem;
  border: 2px solid var(--c-border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fffdf6;
  color: var(--c-ink);
  font-family: inherit;
}
input:focus { outline: none; border-color: var(--c-orange); box-shadow: 0 0 0 4px #f4801f33; }

.format-picker {
  border: none; padding: 0; margin: 0 0 1rem;
  display: flex; gap: .6rem; flex-wrap: wrap;
}
.format-picker legend { font-weight: 500; padding-bottom: .25rem; }
.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .9rem;
  border: 2px solid var(--c-border);
  border-radius: 999px;
  cursor: pointer;
  background: #fffdf6;
  font-weight: 500;
  transition: transform .12s, background .12s, border-color .12s;
}
.pill input { display: none; }
.pill:hover { transform: translateY(-1px); }
.pill:has(input:checked) {
  background: var(--c-yellow);
  border-color: var(--c-orange);
}

button { font-family: inherit; cursor: pointer; }
.btn-primary, .btn-danger, .btn-ghost {
  border: none;
  border-radius: 10px;
  padding: .65rem 1.1rem;
  font-weight: 700;
  font-size: 1rem;
  transition: transform .1s, filter .1s, box-shadow .1s;
}
.btn-primary {
  background: linear-gradient(180deg, var(--c-orange), #d96a13);
  color: #fff;
  box-shadow: 0 3px 0 #a44d05;
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #a44d05; }
.btn-danger {
  background: #fff;
  color: var(--c-red);
  border: 2px solid var(--c-red);
}
.btn-danger:hover { background: var(--c-red); color: #fff; }
.btn-ghost {
  background: transparent; color: var(--c-ink); border: 2px solid var(--c-border);
}
.btn-ghost:hover { background: var(--c-bg-2); }

.tournament-list { list-style: none; padding: 0; margin: 0; }
.tournament-list .empty { color: var(--c-muted); font-style: italic; }
.tournament-list a {
  display: flex; justify-content: space-between; align-items: center;
  padding: .8rem 1rem;
  border: 2px solid var(--c-border);
  border-radius: 12px;
  margin-bottom: .6rem;
  text-decoration: none;
  color: var(--c-ink);
  background: #fffdf6;
  transition: transform .12s, border-color .12s;
}
.tournament-list a:hover { transform: translateX(2px); border-color: var(--c-orange); }
.tournament-list .t-name { font-weight: 700; }
.tournament-list .t-info { color: var(--c-muted); font-size: .9rem; }

.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  background: var(--c-yellow);
  color: var(--c-ink);
}
.badge.muted { background: var(--c-bg-2); color: var(--c-muted); }
.badge.green { background: var(--c-green); color: #fff; }
.badge.blue { background: var(--c-blue); color: #fff; }
.badge.red { background: var(--c-red); color: #fff; }

.back-link {
  display: inline-block; margin-bottom: 1rem;
  color: var(--c-blue); text-decoration: none; font-weight: 600;
}
.back-link:hover { text-decoration: underline; }

.tournament-header { display: grid; gap: .6rem; }
.tournament-header h2 { margin: 0; }
.tournament-header .meta { display: flex; gap: .4rem; flex-wrap: wrap; }
.tournament-header .actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .4rem; }

.tabs { display: flex; gap: .4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab {
  border: 2px solid var(--c-border);
  background: #fffdf6;
  padding: .55rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  color: var(--c-ink);
  transition: background .12s, border-color .12s;
}
.tab:hover { background: var(--c-bg-2); }
.tab.active { background: var(--c-blue); color: #fff; border-color: var(--c-blue); }

.roster-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.4rem;
}
@media (max-width: 720px) { .roster-grid { grid-template-columns: 1fr; } }

.roster-col {
  background: #fffdf6;
  border: 2px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1rem;
}
.roster-title {
  font-family: 'Bungee', system-ui, sans-serif;
  font-size: 1rem;
  margin: 0 0 .8rem;
  color: var(--c-orange);
}
.roster-col:nth-child(2) .roster-title { color: var(--c-blue); }

.single-input {
  display: grid; grid-template-columns: 1fr auto; gap: .5rem; margin-bottom: .8rem;
}
.single-input input { margin-top: 0; }
.single-input button { font-size: 1.4rem; padding: 0 1rem; }

.player-list { list-style: none; padding: 0; margin: 0; max-height: 360px; overflow-y: auto; }
.player-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .8rem;
  border: 2px solid var(--c-border);
  border-radius: 10px;
  margin-bottom: .4rem;
  background: #fff;
}
.player-list li.assigned { opacity: .55; background: var(--c-bg-2); }
.player-list .p-meta { font-size: .8rem; color: var(--c-muted); margin-left: .4rem; }
.player-list .remove {
  background: transparent; border: none; color: var(--c-red); font-size: 1.1rem;
  cursor: pointer; padding: 0 .3rem;
}
.player-list .remove:hover { transform: scale(1.2); }
.player-list .empty {
  color: var(--c-muted); font-style: italic; text-align: center;
  padding: .8rem; background: transparent; border: 2px dashed var(--c-border);
}

.team-builder {
  display: grid; gap: .6rem; margin-bottom: 1rem;
  padding-bottom: .8rem; border-bottom: 2px dashed var(--c-border);
}
.team-builder input { margin-top: 0; }

.player-picker {
  display: flex; flex-wrap: wrap; gap: .35rem;
  max-height: 200px; overflow-y: auto;
  padding: .4rem; border: 2px dashed var(--c-border); border-radius: 10px;
  background: #fffdf6;
  min-height: 50px;
  align-content: flex-start;
}
.player-picker .chip {
  display: inline-flex; align-items: center;
  padding: .35rem .7rem;
  border-radius: 999px;
  background: #fff;
  border: 2px solid var(--c-border);
  font-weight: 500;
  font-size: .9rem;
  cursor: pointer;
  user-select: none;
  transition: transform .12s, background .12s, border-color .12s;
}
.player-picker .chip:hover { transform: translateY(-1px); }
.player-picker .chip input { display: none; }
.player-picker .chip:has(input:checked) {
  background: linear-gradient(180deg, var(--c-green), #25a268);
  color: #fff;
  border-color: #25a268;
}
.player-picker .empty {
  color: var(--c-muted); font-style: italic; font-size: .85rem;
  padding: .5rem; text-align: center; width: 100%;
}

.team-list { list-style: none; padding: 0; margin: 0; }
.team-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem;
  border: 2px solid var(--c-border);
  border-radius: 12px;
  margin-bottom: .5rem;
  background: #fff;
}
.team-list .t-info { display: flex; flex-direction: column; gap: .15rem; }
.team-list .t-meta { color: var(--c-muted); font-size: .85rem; }
.team-list .remove {
  background: transparent; border: none; color: var(--c-red); font-size: 1.2rem;
  cursor: pointer; padding: 0 .4rem;
}
.team-list .remove:hover { transform: scale(1.2); }

.round-block { margin-bottom: 1.4rem; }
.round-block h3 {
  font-family: 'Bungee', system-ui, sans-serif;
  font-size: 1rem;
  margin: 0 0 .6rem;
  color: var(--c-purple);
}
.match {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .4rem;
  padding: .7rem .9rem;
  border: 2px solid var(--c-border);
  border-radius: 12px;
  background: #fffdf6;
  margin-bottom: .5rem;
}
.match.done { background: linear-gradient(180deg, #fffdf6, #f0fff5); border-color: #b6e9cf; }
.match .side { display: flex; align-items: center; gap: .5rem; }
.match .side.b { justify-content: flex-end; text-align: right; }
.match .name { font-weight: 600; }
.match .name.winner { color: var(--c-green); }
.match .name.tbd { color: var(--c-muted); font-style: italic; }
.match .score-input {
  width: 3.2rem;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  padding: .35rem;
  margin: 0;
}
.match .vs { font-family: 'Bungee'; font-size: .9rem; color: var(--c-muted); }
.match .submit {
  background: var(--c-green); color: #fff; border: none;
  padding: .35rem .6rem; border-radius: 8px; font-weight: 700;
  margin-left: .4rem;
}
.match .submit:disabled { opacity: .35; cursor: not-allowed; }
.match .final {
  font-family: 'Bungee'; font-size: 1.05rem;
  display: inline-block; padding: .2rem .6rem; border-radius: 8px;
  background: var(--c-yellow); color: var(--c-ink);
}

.standings {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fffdf6;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--c-border);
}
.standings th, .standings td {
  padding: .65rem .8rem;
  text-align: center;
  border-bottom: 1px solid var(--c-border);
}
.standings th {
  background: var(--c-blue); color: #fff;
  font-family: 'Bungee'; font-size: .85rem;
}
.standings td:nth-child(2) { text-align: left; font-weight: 600; }
.standings tbody tr:last-child td { border-bottom: none; }
.standings tbody tr:nth-child(1) td:first-child { background: var(--c-yellow); font-weight: 700; }
.standings tbody tr:nth-child(2) td:first-child { background: #d8d8d8; font-weight: 700; }
.standings tbody tr:nth-child(3) td:first-child { background: #f4a06a; font-weight: 700; }
.standings .pts { font-weight: 700; color: var(--c-orange); }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--c-ink); color: #fff;
  padding: .7rem 1.2rem; border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 600;
  z-index: 100;
}
.toast.error { background: var(--c-red); }
.toast.success { background: var(--c-green); }

.empty-state {
  text-align: center; padding: 2rem 1rem;
  color: var(--c-muted);
}
