:root {
  --bg: #071018;
  --panel: #0f1a24;
  --panel-2: #132230;
  --line: #1e3344;
  --text: #e8f1f6;
  --muted: #8aa0b3;
  --home: #1d6feb;
  --away: #e23b3b;
  --accent: #3ad07a;
  --gold: #e2c15a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 92px 1fr 280px;
  grid-template-rows: 72px 1fr;
  grid-template-areas:
    "top top top"
    "tools stage side";
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: linear-gradient(180deg, #102131, #0c1a26);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background:
    radial-gradient(circle at 30% 30%, #fff 0 8%, transparent 9%),
    radial-gradient(circle at 70% 35%, #fff 0 7%, transparent 8%),
    radial-gradient(circle at 50% 72%, #fff 0 8%, transparent 9%),
    linear-gradient(135deg, #1f8f4d, #0e5c32);
  box-shadow: 0 0 0 2px #2bd67a, 0 8px 18px rgba(0,0,0,.35);
}
.brand h1 { font-size: 18px; letter-spacing: .04em; }
.brand p { font-size: 12px; color: var(--muted); }

.match-meta { display: flex; align-items: center; gap: 10px; }
.team-input {
  width: 140px; height: 36px; border-radius: 8px;
  border: 1px solid var(--line); background: #0b1722;
  color: var(--text); text-align: center; font-weight: 700;
}
.team-input.home { box-shadow: inset 0 0 0 1px rgba(29,111,235,.5); }
.team-input.away { box-shadow: inset 0 0 0 1px rgba(226,59,59,.5); }
.vs { color: var(--gold); font-weight: 800; font-size: 13px; }

.top-actions, .danger-row { display: flex; gap: 8px; }
button {
  border: 0; cursor: pointer; font: inherit; color: inherit;
}
.ghost, .primary, .chip {
  height: 36px; padding: 0 14px; border-radius: 8px;
}
.ghost { background: #173044; color: var(--text); }
.ghost:hover { background: #1d3c52; }
.primary { background: var(--accent); color: #052013; font-weight: 700; }
.danger { color: #ff8d8d; }

.toolbar {
  grid-area: tools;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px 8px;
  overflow: auto;
}
.tool-group { margin-bottom: 18px; display: flex; flex-direction: column; gap: 6px; }
.group-label, h2 {
  font-size: 11px; color: var(--muted); letter-spacing: .12em; text-transform: uppercase;
}
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px; border-radius: 10px; background: transparent; font-size: 11px; color: var(--muted);
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool.active, .tool:hover { background: #173044; color: var(--text); }

.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 6px; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; margin: 0 auto;
}
.swatch.active { border-color: #fff; }
.slider-row, .toggle {
  display: flex; flex-direction: column; gap: 6px; font-size: 11px; color: var(--muted); padding: 0 6px;
}
.toggle { flex-direction: row; align-items: center; gap: 8px; }

.stage {
  grid-area: stage;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(ellipse at center, #123049 0%, #071018 70%);
}
.board {
  width: min(100%, 1100px);
  aspect-ratio: 105 / 68;
  position: relative;
}
.pitch, .grass, .markings, #drawLayer, .tokens {
  position: absolute; inset: 0;
}
.pitch {
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,.45), 0 0 0 3px #0b3a22;
}
.grass {
  background:
    repeating-linear-gradient(
      90deg,
      #1f7a43 0 70px,
      #176536 70px 140px
    );
}
.markings { width: 100%; height: 100%; pointer-events: none; }
#drawLayer { width: 100%; height: 100%; cursor: crosshair; }
.tokens { pointer-events: none; }

.token, .ball {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  user-select: none;
  cursor: grab;
}
.token:active, .ball:active { cursor: grabbing; }
.token .shirt {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: #fff;
  box-shadow: 0 6px 14px rgba(0,0,0,.35), inset 0 0 0 2px rgba(255,255,255,.25);
}
.token.home .shirt { background: radial-gradient(circle at 30% 25%, #6aa4ff, var(--home)); }
.token.away .shirt { background: radial-gradient(circle at 30% 25%, #ff7a7a, var(--away)); }
.token .name {
  margin-top: 4px; text-align: center; font-size: 11px; font-weight: 700;
  text-shadow: 0 1px 3px #000; white-space: nowrap; max-width: 72px; overflow: hidden;
}
.token.selected .shirt { outline: 3px solid var(--gold); }
.ball {
  width: 22px; height: 22px; border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, #fff 0 18%, #111 19% 28%, #fff 29% 55%, #111 56%);
  box-shadow: 0 4px 10px rgba(0,0,0,.4);
}

.sidebar {
  grid-area: side;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.format-switch { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.format-btn {
  height: 36px; border-radius: 8px; background: var(--panel-2); font-weight: 700; font-size: 13px;
}
.format-btn.active { background: #1f4d32; color: var(--accent); }
.formation-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.formation-btn {
  height: 36px; border-radius: 8px; background: var(--panel-2); font-weight: 700; font-size: 13px;
}
.formation-btn.active { background: #1f4d32; color: var(--accent); }
.side-switch { display: flex; gap: 8px; margin-top: 10px; }
.chip { background: var(--panel-2); flex: 1; }
.chip.active.home, #applyHome.active { background: var(--home); }
.chip.active, #applyAway.active { background: #5a1d1d; }
#applyAway.active { background: var(--away); }

.roster { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.roster-item {
  display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: center;
}
.num {
  height: 28px; border-radius: 6px; display: grid; place-items: center; font-weight: 800; font-size: 12px;
}
.num.home { background: var(--home); }
.num.away { background: var(--away); }
.roster-item input {
  height: 28px; border: 1px solid var(--line); border-radius: 6px;
  background: #0b1722; color: var(--text); padding: 0 8px;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
      "top"
      "tools"
      "stage"
      "side";
  }
  .toolbar { display: flex; gap: 12px; overflow-x: auto; }
  .tool-group { flex-direction: row; align-items: center; margin: 0; }
}
