:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #cbd5e1;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top left, #e0e7ff, transparent 28rem), var(--bg);
  color: var(--ink);
}

a { color: var(--primary); }

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto;
  display: grid;
  grid-template-columns: minmax(320px, 560px) minmax(300px, 1fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
}

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

h1, h2 { margin: 0 0 8px; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
h2 { font-size: 1.1rem; }
.muted { margin: 0; color: var(--muted); line-height: 1.5; }

.api-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.api-status span {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--warn);
  display: inline-block;
}

.api-status.ok span { background: var(--ok); }
.api-status.bad span { background: var(--danger); }

.board {
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  background: var(--ink);
  gap: 6px;
  border: 6px solid var(--ink);
  border-radius: 22px;
  overflow: hidden;
}

.cell {
  border: 0;
  background: #ffffff;
  color: var(--ink);
  font-size: clamp(3rem, 12vw, 6.5rem);
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  line-height: 1;
  appearance: none;
  transition: background 0.15s ease, transform 0.12s ease, color 0.15s ease;
}

.cell:not(:disabled):hover,
.cell:not(:disabled):focus-visible {
  background: var(--primary-soft);
  outline: none;
  transform: scale(0.985);
}

.cell:disabled { cursor: default; }
.cell.is-x { color: #0f172a; }
.cell.is-o { color: var(--primary); }
.cell.is-win { background: #fee2e2; color: var(--danger); }
.cell.is-last { box-shadow: inset 0 0 0 6px rgba(79, 70, 229, 0.18); }

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-top: 18px;
}

.button {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.button.secondary {
  background: #e2e8f0;
  color: var(--ink);
}

.side-column {
  display: grid;
  gap: 20px;
}

.trace-panel,
.history-panel,
.help-panel {
  line-height: 1.55;
}

.trace-step {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-top: 12px;
  background: #f8fafc;
}

.trace-step:first-child { margin-top: 0; }
.trace-step strong { display: block; margin-bottom: 6px; }

.evaluations {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.evaluation {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #ffffff;
  font-size: 0.95rem;
}

.evaluation.selected {
  background: var(--primary-soft);
  border-color: #a5b4fc;
}

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

.history-list li {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #ffffff;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .panel-header { flex-direction: column; }
}
