:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #64717a;
  --line: #d8e0e4;
  --paper: #f7f9fa;
  --panel: #ffffff;
  --green: #8fc37c;
  --wall: #4c555d;
  --box: #a46b3f;
  --blue: #2e6eea;
  --red: #d74444;
  --gold: #d39c28;
  --focus: #167f6f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 0.62rem 0.78rem;
  cursor: pointer;
}

button:hover {
  border-color: var(--focus);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.4vw, 2.1rem);
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  letter-spacing: 0;
}

.topbar p,
.board-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.93rem;
}

.upload {
  display: grid;
  grid-template-columns: minmax(130px, 170px) minmax(140px, 180px) minmax(180px, 260px) auto;
  gap: 8px;
  align-items: center;
}

input,
select {
  width: 100%;
  min-height: 39px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0.52rem 0.62rem;
}

.layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 18px;
  padding-top: 18px;
}

.panel,
.board-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 14px;
}

.panel-head,
.board-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.slots {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.slot {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.slot strong {
  color: var(--muted);
  font-size: 0.9rem;
}

.settings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.settings span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.82rem;
}

.run {
  width: 100%;
  margin-top: 14px;
  border-color: #126f62;
  background: #167f6f;
  color: #fff;
  font-weight: 700;
}

.results {
  margin-top: 18px;
}

table {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 700;
}

.board-wrap {
  min-width: 0;
  padding: 14px;
}

.playback-wrap {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.playback {
  display: flex;
  gap: 8px;
}

.speed-control {
  display: grid;
  grid-template-columns: 42px minmax(120px, 180px);
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.speed-control input {
  min-height: 24px;
  padding: 0;
}

.replay-stage {
  display: grid;
  grid-template-columns: minmax(0, 650px) 240px;
  justify-content: center;
  align-items: stretch;
  gap: 0;
  margin: 16px auto 10px;
  width: min(100%, 890px);
}

#board {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  background: #a9d487;
}

.slider {
  display: block;
  width: min(100%, 760px);
  margin: 0 auto;
}

.agent-stats {
  display: block;
  min-height: 100%;
  border-radius: 0 8px 8px 0;
  background: #303840;
  color: #d7dce0;
  padding: 12px 10px;
  overflow: hidden;
}

.stat-card {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0 0 18px;
  min-width: 0;
}

.stat-card.dead {
  opacity: 1;
}

.stat-heading {
  margin: 0 0 18px;
  color: #f3f5f6;
  font-size: 1.24rem;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
}

.stat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 800;
  font-size: 0.98rem;
  color: #e6eaed;
}

.stat-dot {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  transform: rotate(45deg);
}

.stat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-grid {
  display: block;
  margin-top: 8px;
}

.stat-item span {
  display: none;
}

.stat-item strong {
  display: block;
  margin-top: 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: #c9cdd0;
}

.stat-item.status strong {
  color: #63d475;
  font-weight: 900;
}

.stat-card.dead .stat-item.status strong {
  color: #ff6666;
}

.stat-runtime {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.87rem;
}

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

.legend i {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.legend .grass {
  background: var(--green);
}

.legend .wall {
  background: var(--wall);
}

.legend .box {
  background: var(--box);
}

.legend .bomb {
  border-radius: 50%;
  background: #161819;
}

.legend .blast {
  background: var(--gold);
}

@media (max-width: 980px) {
  .topbar,
  .layout {
    grid-template-columns: 1fr;
    display: grid;
  }

  .upload {
    grid-template-columns: 1fr;
  }

  .settings {
    grid-template-columns: 1fr;
  }

  .replay-stage {
    grid-template-columns: minmax(0, 650px);
    width: min(100%, 650px);
  }

  #board {
    border-right: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
  }

  .agent-stats {
    border-radius: 0 0 8px 8px;
  }
}

@media (max-width: 560px) {
  .stat-heading {
    font-size: 1.1rem;
  }
}
