/* ============================================================
   Стабилизация реактора — оформление панели научной установки
   ============================================================ */


:root {
  --bg-deep: #060a12;
  --panel: #0f1a2c;
  --panel-2: #16233a;
  --panel-3: #1d2c47;
  --line: #24344f;
  --text: #e6eefc;
  --muted: #93a4c0;
  --accent: #38bdf8;
  --accent-2: #2563eb;
  --green: #22c55e;
  --red: #ef4444;

  --pad: clamp(0.75rem, 4vw, 1.5rem);
  --board-max: 420px;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: var(--pad);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -10%, #14243d 0%, #0a1120 45%, var(--bg-deep) 100%) fixed;
}

/* ====== Каркас ====== */

#game {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
}

.title {
  margin: 0;
  text-align: center;
  font-size: clamp(1.25rem, 5.4vw, 1.8rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow: 0 0 24px rgba(56, 189, 248, 0.25);
}

.title span {
  color: var(--accent);
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
}

.lead {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  letter-spacing: 0.03em;
}

/* ====== Правила ====== */

.rules {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: inset 0 0 30px rgba(56, 189, 248, 0.05);
}

.rules__title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.rules__list {
  margin: 0;
  padding-left: 1.1rem;
}

.rules__list li {
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.rules__list li:last-child {
  margin-bottom: 0;
}

.rules b {
  color: var(--text);
}

.sym {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 0.25em;
  border-radius: 6px;
  font-weight: 800;
  text-align: center;
  line-height: 1.4;
}

.sym--ok {
  color: #b8f5d0;
  background: rgba(34, 197, 94, 0.18);
  border: 1px solid rgba(34, 197, 94, 0.5);
}

.sym--bad {
  color: #ffd0d3;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.5);
}

/* ====== Кнопки ====== */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0.7rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:hover {
  background: var(--panel-3);
  border-color: #3a4d70;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  background: linear-gradient(180deg, #2563eb, #1e40af);
  border-color: #3b82f6;
  color: #ffffff;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.28);
}

.btn--primary:hover {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  border-color: #60a5fa;
}

/* ====== Панель показателей ====== */

.hud {
  width: 100%;
  max-width: var(--board-max);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.stat {
  min-width: 0;
  padding: 0.45rem 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.stat__label {
  font-size: 0.66rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat__value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ====== Игровое поле ====== */

.board {
  --size: 3;
  width: 100%;
  max-width: var(--board-max);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  gap: clamp(4px, 1.6vw, 10px);
  padding: clamp(6px, 2vw, 12px);
  background: linear-gradient(180deg, #0e1728, #0a111e);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    inset 0 0 44px rgba(56, 189, 248, 0.06),
    0 18px 40px rgba(0, 0, 0, 0.5);
}

.cell {
  appearance: none;
  margin: 0;
  padding: 0;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-size: calc(min(calc(100vw - 2 * var(--pad)), var(--board-max)) / var(--size) * 0.4);
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell:disabled {
  cursor: default;
}

/* Зелёная (стабильная) ячейка */
.cell--stable {
  background: radial-gradient(circle at 50% 32%, #1c7a4a, #0b3320 78%);
  border-color: #2ea36a;
  color: #b8f5d0;
  box-shadow:
    0 0 14px rgba(34, 197, 94, 0.35),
    inset 0 0 14px rgba(34, 197, 94, 0.22);
  animation: flip-stable 0.24s ease;
}

/* Красная (нестабильная) ячейка */
.cell--unstable {
  background: radial-gradient(circle at 50% 32%, #8c1f2b, #3a0f16 78%);
  border-color: #e0484f;
  color: #ffd0d3;
  box-shadow:
    0 0 14px rgba(239, 68, 68, 0.42),
    inset 0 0 14px rgba(239, 68, 68, 0.24);
  animation: flip-unstable 0.24s ease;
}

.board--locked .cell {
  opacity: 0.92;
}

@keyframes flip-stable {
  0%   { transform: scale(0.86); }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes flip-unstable {
  0%   { transform: scale(0.86); }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ====== Сообщение о завершении ====== */

.status {
  width: 100%;
  max-width: var(--board-max);
  margin: 0 auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  text-align: center;
  background: linear-gradient(180deg, rgba(34, 197, 94, 0.16), rgba(34, 197, 94, 0.05));
  border: 1px solid rgba(46, 163, 106, 0.75);
  border-radius: var(--radius);
  box-shadow: 0 0 26px rgba(34, 197, 94, 0.16);
}

.status__text {
  margin: 0;
  font-weight: 700;
  color: #d6ffe6;
}

/* ====== Нижние кнопки ====== */

.controls {
  width: 100%;
  max-width: var(--board-max);
  margin: 0 auto;
  display: flex;
}

.controls .btn {
  flex: 1 1 auto;
}

/* ====== Доступность: меньше движения ====== */

@media (prefers-reduced-motion: reduce) {
  .cell,
  .btn {
    animation: none !important;
    transition: none !important;
  }
}