:root {
  color-scheme: light;
  --bg: #eef1ea;
  --surface: #fbfcf8;
  --surface-2: #f1f5ed;
  --ink: #162017;
  --muted: #62705e;
  --line: #d5decf;
  --line-strong: #aebda7;
  --pitch: #266642;
  --pitch-dark: #1f5638;
  --pitch-line: rgba(255, 255, 255, 0.58);
  --own: #f9f6e8;
  --own-ink: #112018;
  --opp: #b94139;
  --opp-ink: #fff4ee;
  --accent: #d19624;
  --accent-2: #286e69;
  --risk: #a94335;
  --good: #2f7b4f;
  --shadow: 0 18px 50px rgba(31, 43, 28, 0.14);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(38, 102, 66, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(209, 150, 36, 0.14), transparent 30%),
    var(--bg);
}

button,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(260px, 0.8fr);
  gap: 16px;
  align-items: center;
  margin: 0 auto 18px;
  max-width: 1680px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(22, 32, 23, 0.16);
  border-radius: 8px;
  background: linear-gradient(145deg, #223c2d, #2f7b4f);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}

.brand-mark span {
  border-radius: 999px;
  background: #f6f1da;
}

.brand-mark span:nth-child(2) {
  background: var(--accent);
}

.brand-mark span:nth-child(3) {
  background: #c85b4f;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.15;
  letter-spacing: 0;
  text-transform: uppercase;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.18rem, 2vw, 1.65rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
  line-height: 1.18;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(96px, 1fr));
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.64);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(31, 43, 28, 0.08);
}

.view-tab,
.tool-button,
.small-button,
.icon-button,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: 7px;
  min-height: 38px;
  color: var(--ink);
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.view-tab {
  background: transparent;
  padding: 0 12px;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

.view-tab.is-active {
  background: var(--ink);
  color: #fffdf4;
}

.progress-strip {
  justify-self: end;
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, 1fr));
  gap: 8px;
  width: min(100%, 360px);
}

.progress-strip div {
  min-height: 52px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
  border-radius: var(--radius);
  padding: 8px 10px;
  box-shadow: 0 10px 28px rgba(31, 43, 28, 0.08);
}

.progress-strip strong {
  display: block;
  font-size: 1.05rem;
  line-height: 1.2;
}

.progress-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

main {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  max-width: 1680px;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: rgba(251, 252, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.side-panel {
  position: sticky;
  top: 18px;
  padding: 16px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line-strong);
  background: var(--ink);
  color: #fffdf4;
  font-size: 1.35rem;
  line-height: 1;
}

.icon-button:hover,
.primary-button:hover,
.secondary-button:hover,
.small-button:hover,
.tool-button:hover,
.view-tab:hover {
  transform: translateY(-1px);
}

.control-stack {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
}

label > span,
.textarea-label > span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffefa;
  color: var(--ink);
  outline: none;
}

select {
  min-height: 42px;
  padding: 0 10px;
  font-weight: 760;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
  min-height: 150px;
}

select:focus,
textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(40, 110, 105, 0.16);
}

.scenario-list {
  display: grid;
  gap: 8px;
}

.scenario-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fffefa;
  border-radius: 8px;
  padding: 11px;
  display: grid;
  gap: 8px;
  color: var(--ink);
}

.scenario-card.is-active {
  border-color: var(--accent-2);
  background: #edf6f1;
}

.scenario-card strong {
  display: block;
  font-size: 0.9rem;
  line-height: 1.25;
}

.scenario-card span {
  color: var(--muted);
  font-size: 0.77rem;
  line-height: 1.3;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid rgba(98, 112, 94, 0.24);
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.workspace {
  min-width: 0;
}

.view-pane {
  display: none;
}

.view-pane.is-active {
  display: block;
}

.scenario-brief {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: stretch;
  padding: 18px;
  margin-bottom: 18px;
}

.brief-main p:last-child {
  margin-bottom: 0;
  color: #344234;
  line-height: 1.5;
  max-width: 86ch;
}

.match-state {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 8px;
}

.match-state div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px;
  min-height: 70px;
}

.match-state span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.match-state strong {
  display: block;
  margin-top: 8px;
  font-size: 1rem;
  line-height: 1.1;
}

.lab-grid {
  display: grid;
  grid-template-columns: minmax(460px, 1.35fr) minmax(320px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.board-panel,
.solver-panel,
.evaluation-panel,
.model-lab,
.principle-library {
  padding: 16px;
}

.board-header {
  align-items: start;
}

.tool-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.tool-button,
.small-button,
.secondary-button {
  border: 1px solid var(--line);
  background: #fffefa;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 850;
}

.tool-button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fffdf4;
}

.tool-button.ghost,
.small-button {
  background: var(--surface-2);
}

.pitch-wrap {
  position: relative;
  width: min(100%, 48svh, 860px);
  aspect-ratio: 64 / 100;
  margin: 16px auto 18px;
  scroll-margin: 18px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(22, 32, 23, 0.22);
  background: var(--pitch);
}

#pitchSvg {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--pitch-dark);
  touch-action: manipulation;
}

.board-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 800;
}

.board-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.player.own {
  cursor: grab;
}

.player.own.is-selected circle {
  stroke: #d19624;
  stroke-width: 0.9;
}

.player.own.is-dragging {
  cursor: grabbing;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.dot.own {
  background: var(--own);
  border: 1px solid var(--ink);
}

.dot.opp {
  background: var(--opp);
}

.dot.ball {
  background: var(--accent);
  border: 1px solid rgba(22, 32, 23, 0.25);
}

.line {
  width: 22px;
  height: 3px;
  display: inline-block;
  border-radius: 999px;
}

.line.pass {
  background: #f4e9ba;
}

.line.run {
  background: #b9d9f0;
}

.line.cover {
  background: #6bc18a;
}

.principle-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.move-history {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  margin-bottom: 14px;
  padding: 10px;
}

.move-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

.move-history ol {
  margin: 8px 0 0;
  padding-left: 20px;
  color: #354233;
  line-height: 1.38;
  font-size: 0.86rem;
}

.move-history li + li {
  margin-top: 5px;
}

.move-history-empty {
  color: var(--muted);
}

.principle-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffefa;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 850;
}

.principle-chip.is-selected {
  color: #fffdf4;
  border-color: var(--accent-2);
  background: var(--accent-2);
}

.textarea-label {
  margin-bottom: 14px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.primary-button,
.secondary-button {
  padding: 0 14px;
  font-weight: 900;
}

.primary-button {
  background: var(--ink);
  color: #fffdf4;
  border: 1px solid var(--ink);
}

.primary-button.compact {
  min-height: 40px;
}

.secondary-button {
  background: #fffefa;
  border: 1px solid var(--line-strong);
}

.evaluation-panel {
  margin-top: 18px;
  min-height: 170px;
}

.empty-state {
  display: grid;
  place-items: start;
  align-content: center;
  min-height: 138px;
}

.empty-state p:last-child {
  color: var(--muted);
  max-width: 66ch;
  line-height: 1.45;
  margin-bottom: 0;
}

.eval-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.rating-ring {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background:
    conic-gradient(var(--accent-2) var(--score), rgba(40, 110, 105, 0.12) 0),
    #fffefa;
  border: 1px solid var(--line);
}

.rating-ring span {
  width: 54px;
  height: 54px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--surface);
  font-weight: 950;
}

.eval-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.eval-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffefa;
}

.eval-card h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 8px;
}

.eval-card ul {
  margin: 0;
  padding-left: 18px;
  color: #354233;
  line-height: 1.42;
}

.eval-card li + li {
  margin-top: 7px;
}

.eval-card.full {
  grid-column: 1 / -1;
}

.tag-good,
.tag-risk,
.tag-neutral {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.68rem;
  font-weight: 900;
}

.tag-good {
  color: #fff;
  background: var(--good);
}

.tag-risk {
  color: #fff;
  background: var(--risk);
}

.tag-neutral {
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.model-lab,
.principle-library,
.source-map {
  margin-bottom: 18px;
}

.model-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(260px, 0.42fr);
  gap: 16px;
  align-items: start;
}

.model-controls {
  display: grid;
  gap: 12px;
}

.library-count {
  color: var(--muted);
  font-weight: 850;
  font-size: 0.8rem;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

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

.library-card,
.source-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 13px;
  display: grid;
  gap: 8px;
}

.library-card p,
.source-card p {
  color: #405040;
  line-height: 1.42;
  margin-bottom: 0;
  font-size: 0.88rem;
}

.library-card .source,
.source-card .source {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.source-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.pending-point {
  animation: pulsePoint 1s ease-in-out infinite;
}

@keyframes pulsePoint {
  0%,
  100% {
    opacity: 0.38;
  }

  50% {
    opacity: 0.9;
  }
}

@media (max-width: 1240px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .view-tabs {
    width: 100%;
  }

  .progress-strip {
    justify-self: stretch;
    width: 100%;
  }

  main {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
    max-height: none;
  }

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

@media (max-width: 980px) {
  .scenario-brief,
  .lab-grid,
  .model-grid {
    grid-template-columns: 1fr;
  }

  .match-state {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .eval-grid,
  .library-grid,
  .source-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    gap: 10px;
  }

  .view-tabs {
    grid-template-columns: 1fr;
  }

  .progress-strip,
  .match-state,
  .scenario-list,
  .button-row {
    grid-template-columns: 1fr;
  }

  .panel {
    border-radius: 7px;
  }

  .scenario-brief,
  .board-panel,
  .solver-panel,
  .evaluation-panel,
  .model-lab,
  .principle-library,
  .side-panel {
    padding: 12px;
  }

  .eval-header {
    grid-template-columns: 1fr;
  }

  .tool-strip {
    justify-content: flex-start;
  }
}
