:root {
  --bg: #eef1f6;
  --board-bg: #dcc9a6;
  --board-line: #a8916a;
  --board-edge: #8a7147;
  --ink: #1a1d23;
  --muted: #5d6472;
  --x-color: #101215;
  --o-color: #16306b;
  --win: #d81f27;
  --panel: #ffffff;
  --shadow: 0 8px 28px rgba(20, 26, 40, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 24px 16px 40px;
  background: radial-gradient(circle at 50% 0%, #f7f9fc, var(--bg));
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.app {
  width: 100%;
  max-width: 1040px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Доска с управлением — слева, панель анализа — справа. На узком экране
   (или когда анализ выключен) панель уезжает вниз / исчезает, а доска
   остаётся по центру и не растягивается шире 660px. */
.stage {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-start;
  justify-content: center;
}

.stage-main {
  flex: 1 1 460px;
  min-width: 0;
  max-width: 660px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.stage .analysis {
  flex: 1 1 280px;
  max-width: 340px;
}

.head { text-align: center; }

.title {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status {
  margin: 6px 0 0;
  min-height: 24px;
  color: var(--muted);
  font-size: 16px;
}

.status.win { color: var(--win); font-weight: 600; }
.status.lose { color: var(--o-color); font-weight: 600; }

/* Поле */

.board-wrap {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  background: var(--board-bg);
  border: 3px solid var(--board-edge);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 1px;
  background: var(--board-line);
}

.cell {
  padding: 0;
  border: 0;
  background: var(--board-bg);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background-color 0.12s ease;
}

.cell:disabled { cursor: default; }

.board:not(.locked) .cell:not(.taken):hover,
.board:not(.locked) .cell:not(.taken):focus-visible {
  background: #ecdcbc;
  outline: none;
}

.cell.last { background: #e6d3ad; }

/* Режим анализа: тепловая карта оценок */

.heat {
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  pointer-events: none;
  text-shadow: 0 1px 1.5px rgba(0, 0, 0, 0.55);
}

/* Нейтральная тёмная рамка — читается и на зелёной, и на синей карте */
.cell.heat-best { box-shadow: inset 0 0 0 2px #2b3040; }
.cell.heat-win { box-shadow: inset 0 0 0 2px var(--win); }
.cell.heat-block { box-shadow: inset 0 0 0 2px #e07c14; }

/* Клетка, которую компьютер выбрал и вот-вот займёт — заметный пульс */
.cell.heat-planned {
  z-index: 1;
  animation: planned-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes planned-pulse {
  from { box-shadow: inset 0 0 0 2px var(--o-color); }
  to { box-shadow: inset 0 0 0 4px var(--o-color); }
}

.mark {
  width: 68%;
  height: 68%;
  display: block;
  animation: pop 0.14s ease-out;
}

@keyframes pop {
  from { transform: scale(0.55); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.mark-x { stroke: var(--x-color); stroke-width: 2.6; stroke-linecap: round; fill: none; }
.mark-o { stroke: var(--o-color); stroke-width: 2.4; fill: none; }

.cell.winning .mark-x,
.cell.winning .mark-o { stroke: var(--win); }

/* Красная черта поверх выигрышной пятёрки */

.strike {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.strike line {
  stroke: var(--win);
  stroke-width: 0.13;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
  stroke-dasharray: 22;
  stroke-dashoffset: 22;
  animation: draw 0.4s 0.1s ease-out forwards;
}

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

/* Панель */

.panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  padding: 9px 15px;
  border: 1px solid #d3d8e2;
  border-radius: 8px;
  background: #f6f8fb;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) { background: #eceff5; }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--o-color);
  border-color: var(--o-color);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: #1d3d85; }

.level {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.level select {
  padding: 8px 10px;
  border: 1px solid #d3d8e2;
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.toggle input { cursor: pointer; }

/* `display: flex` выше перебил бы штатный [hidden] — прячем явно.
   То же и для кнопки: скрываем «Отменить ход» на сложном уровне. */
.toggle[hidden],
.btn[hidden] { display: none; }

.score {
  display: flex;
  gap: 20px;
  margin: 0;
}

.score-item { text-align: center; }

.score dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.score dd {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Панель анализа */

.analysis {
  padding: 14px 18px 16px;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.analysis-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.analysis-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.seg {
  display: inline-flex;
  border: 1px solid #d3d8e2;
  border-radius: 8px;
  overflow: hidden;
}

.seg-btn {
  padding: 6px 12px;
  border: 0;
  background: #f6f8fb;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.seg-btn + .seg-btn { border-left: 1px solid #d3d8e2; }

.seg-btn.is-active {
  background: var(--o-color);
  color: #fff;
}

.analysis-list {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.analysis-list li::marker { color: var(--muted); }
.analysis-list b { font-variant-numeric: tabular-nums; }

.analysis-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.chip {
  display: inline-block;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 4px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.chip-win { background: var(--win); }
.chip-block { background: #e07c14; }

@media (max-width: 560px) {
  .title { font-size: 24px; }
  .panel { justify-content: center; }
  .score { gap: 16px; }
}
