:root {
  color-scheme: light;
  --page: #f4f1e8;
  --ink: #18201b;
  --muted: #637167;
  --line: #d9d1bd;
  --panel: #fffdf7;
  --pitch: #1f7a4d;
  --pitch-dark: #16603d;
  --pitch-line: rgba(255, 255, 255, 0.7);
  --accent: #c83b31;
  --accent-dark: #9e2821;
  --gold: #d99a2b;
  --shadow: 0 16px 40px rgba(31, 42, 32, 0.13);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  font-family:
    "Inter",
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    sans-serif;
  font-size: 16px;
  letter-spacing: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(24, 32, 27, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(24, 32, 27, 0.04) 1px, transparent 1px),
    var(--page);
  background-size: 36px 36px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  max-width: 100vw;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.88);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar > div {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.icon-button,
.formation-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.primary-button {
  padding: 0 18px;
  color: #fffdf7;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.ghost-button {
  padding: 0 16px;
  color: var(--ink);
  background: #fffdf7;
  border-color: var(--line);
}

.ghost-button:hover,
.icon-button:hover,
.formation-button:hover {
  border-color: #b9ab8d;
}

.icon-button {
  width: 44px;
  flex: 0 0 44px;
  color: var(--ink);
  background: #fffdf7;
  border-color: var(--line);
  font-size: 1.2rem;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(420px, 1fr) minmax(280px, 360px);
  gap: 18px;
  padding: 18px;
  align-items: start;
}

.control-panel,
.lineup-panel {
  min-width: 0;
  max-width: 100%;
  background: rgba(255, 253, 247, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.control-panel section + section {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.control-panel h2,
.lineup-panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  line-height: 1.25;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.formation-button {
  padding: 0 10px;
  color: var(--ink);
  background: #fffdf7;
  border-color: var(--line);
  font-weight: 700;
}

.formation-button.is-active {
  color: #fffdf7;
  background: var(--pitch-dark);
  border-color: var(--pitch-dark);
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

select,
input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  padding: 0 10px;
}

select:focus,
input:focus,
button:focus-visible {
  outline: 3px solid rgba(200, 59, 49, 0.25);
  outline-offset: 2px;
}

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 12px;
  color: var(--ink);
  line-height: 1.35;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.seed-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.seed-row input {
  min-width: 0;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.rules-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.rules-list div {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
}

.rules-list dt {
  color: var(--muted);
}

.rules-list dd {
  margin: 0;
  line-height: 1.35;
}

.pitch-stage {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.score-strip > div {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.94);
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.2;
}

.score-strip strong {
  display: block;
  margin-top: 5px;
  font-size: 1.45rem;
  line-height: 1.1;
}

.pitch {
  position: relative;
  display: grid;
  grid-template-rows: repeat(4, minmax(120px, 1fr));
  gap: 14px;
  min-height: 700px;
  overflow: hidden;
  padding: 22px;
  border-radius: 8px;
  border: 1px solid #0d4d30;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 50%, rgba(0, 0, 0, 0.04) 50%),
    linear-gradient(180deg, var(--pitch), var(--pitch-dark));
  background-size: 160px 100%, 100% 100%;
  box-shadow: var(--shadow);
}

.pitch::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 2px solid var(--pitch-line);
  border-radius: 6px;
  pointer-events: none;
}

.pitch::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 154px;
  height: 154px;
  border: 2px solid var(--pitch-line);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.pitch-row {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
}

.player-tile {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 7px;
  flex: 1 1 118px;
  width: min(152px, 100%);
  max-width: 152px;
  min-width: 0;
  min-height: 116px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 253, 247, 0.7);
  background: rgba(255, 253, 247, 0.92);
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(13, 77, 48, 0.25);
}

.tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
}

.slot-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 24px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--ink);
  color: #fffdf7;
  font-size: 0.76rem;
  font-weight: 800;
}

.overall-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 28px;
  border-radius: 6px;
  background: var(--gold);
  color: #1f1606;
  font-weight: 900;
}

.overall-badge.is-estimated {
  background: #d7cfc0;
  color: #3b352c;
}

.player-name {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.18;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.player-meta,
.player-value {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.lineup-panel {
  padding: 16px;
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.panel-header h2 {
  margin: 0;
}

.panel-header span {
  color: var(--muted);
  font-size: 0.86rem;
}

.lineup-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.lineup-list li {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
}

.mini-position {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  border-radius: 6px;
  background: #e9e1cf;
  font-weight: 800;
  font-size: 0.78rem;
}

.list-name {
  margin: 0;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.list-meta {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.list-rating {
  display: grid;
  justify-items: end;
  gap: 2px;
  min-width: 44px;
}

.list-rating strong {
  font-size: 1.05rem;
}

.list-rating span {
  color: var(--muted);
  font-size: 0.72rem;
}

.status-line {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.status-line.is-error {
  color: var(--accent-dark);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 290px minmax(420px, 1fr);
  }

  .lineup-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions button {
    min-width: 0;
    flex: 1 1 160px;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
    padding: 12px;
  }

  .score-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pitch {
    min-height: 620px;
    padding: 16px 10px;
    gap: 10px;
  }

  .pitch-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .player-tile {
    flex-basis: 96px;
    min-height: 106px;
    padding: 8px;
  }

  .player-name {
    font-size: 0.84rem;
  }

  .player-meta,
  .player-value {
    font-size: 0.72rem;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 15px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .top-actions button {
    width: 100%;
    flex: 0 1 auto;
  }

  .control-panel,
  .lineup-panel,
  .pitch-stage {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
  }

  .segmented-control,
  .score-strip {
    grid-template-columns: 1fr;
  }

  .pitch {
    min-height: 760px;
  }

  .pitch-row {
    align-items: stretch;
  }

  .player-tile {
    width: 100%;
    min-width: 0;
  }

  .slot-label {
    min-width: 32px;
    padding: 0 5px;
  }

  .overall-badge {
    min-width: 30px;
  }
}
