:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #171717;
  --muted: #6b7280;
  --panel: #ffffff;
  --line: #d8dde5;
  --strong-line: #29313d;
  --accent: #1f7a8c;
  --accent-dark: #14586a;
  --x: #648fff;
  --draw: #767c87;
  --o: #fe6100;
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow: hidden;
}

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

button {
  border: 1px solid var(--accent-dark);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 2.6rem;
  padding: 0.65rem 0.9rem;
}

button:not(.cell):hover:not(:disabled) {
  background: var(--accent-dark);
}

#play-best {
  background: rgb(0, 114, 237);
  border-color: rgb(0, 91, 190);
}

#play-best:hover:not(:disabled) {
  background: rgb(0, 96, 200);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.secondary {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

button.secondary:hover:not(:disabled) {
  background: #eef1f5;
}

.app {
  width: min(1060px, calc(100% - 40px));
  margin: 0 auto;
  padding: 36px 0;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(300px, 390px);
  gap: 0;
  align-items: center;
}

.play-area,
.posterior {
  background: var(--panel);
  min-width: 0;
}

.play-area {
  padding-right: 52px;
}

.topbar {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 22px;
}

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

h1 {
  font-size: 1.7rem;
  line-height: 1.15;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1.25rem;
  letter-spacing: -0.015em;
}

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

.compute-control {
  width: min(100%, 520px);
  margin: 0 auto 20px;
  padding: 12px 2px;
  display: grid;
  grid-template-columns: auto 1fr 5.4rem;
  gap: 12px;
  align-items: center;
}

.compute-control label,
.compute-control output {
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.compute-control output {
  color: var(--muted);
  text-align: right;
}

input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
}

.board {
  width: min(90%, 200px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 2px;
  margin: 0 auto;
  background: var(--strong-line);
}

.cell {
  appearance: none;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: 4rem;
  font-weight: 800;
  line-height: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
}

@media (hover: hover) {
  .board[data-player="X"] .cell:hover:not(:disabled)::after {
    color: var(--x);
    content: "X";
    opacity: 0.22;
  }

  .board[data-player="O"] .cell:hover:not(:disabled)::after {
    color: var(--o);
    content: "O";
    opacity: 0.22;
  }
}

.cell:disabled {
  cursor: default;
  opacity: 1;
}

.cell.win-line {
  background: #eef7f1;
}

.cell.mark-x {
  color: var(--x);
}

.cell.mark-o {
  color: var(--o);
}

.posterior {
  align-self: stretch;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 0 24px 52px;
}

.posterior-heading {
  margin-bottom: 22px;
}

.posterior-heading p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 5px;
}

.bars {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 4.2rem 1fr 3.2rem;
  gap: 10px;
  align-items: center;
  font-size: 0.9rem;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e7eaf0;
  overflow: hidden;
}

.bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  transition: width 120ms ease-out;
}

.bar.x-win {
  background: var(--x);
}

.bar.draw {
  background: var(--draw);
}

.bar.o-win {
  background: var(--o);
}

#simplex {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 26 / 21;
  background: #ffffff;
  display: block;
}

@media (min-width: 581px) and (max-width: 860px) {
  .app {
    grid-template-columns: minmax(290px, 1fr) minmax(230px, 300px);
    width: calc(100% - 20px);
    padding: 22px 0;
  }

  .play-area {
    padding-right: 24px;
  }

  .topbar {
    display: grid;
  }

  .actions {
    justify-content: start;
  }

  .cell {
    font-size: 3.1rem;
  }
}

@media (max-width: 580px) {
  .app {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 620px);
    padding: 22px 0;
    gap: 28px;
  }

  .play-area {
    padding-right: 0;
  }

  .posterior {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 28px 0 0;
  }

  .topbar {
    display: grid;
  }

  .actions {
    justify-content: start;
  }

  .compute-control {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .compute-control output {
    text-align: left;
  }

  .cell {
    font-size: 3.1rem;
  }
}

@media (max-width: 420px) {
  .posterior {
    padding: 24px 0 0;
  }

  .board {
    gap: 2px;
  }

  .cell {
    font-size: 2.65rem;
  }

}
