:root {
  --color-x: #4f7cff;
  --color-o: #ff5c8a;
  --color-bg-1: #6a5cff;
  --color-bg-2: #ff6fa5;
  --color-surface: #ffffff;
  --color-text: #2b2b3c;
  --color-muted: #8a8aa3;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  /* В Telegram Mini App высоту окна задаёт SDK — 100vh там не совпадает с видимой областью. */
  min-height: var(--tg-viewport-stable-height, 100vh);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--color-bg-1), var(--color-bg-2));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--color-text);
}

.app {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  text-align: center;
}

h1 {
  margin: 0 0 24px;
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--color-x), var(--color-o));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 {
  font-size: 18px;
  margin: 0 0 12px;
}

.screen.hidden {
  display: none;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

/* Двойной тап по кнопке или клетке на телефоне не должен зумить страницу. */
.btn,
.cell {
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-x), var(--color-o));
  color: white;
  box-shadow: 0 8px 20px rgba(79, 124, 255, 0.35);
}

.btn-secondary {
  background: #f0f1fb;
  color: var(--color-text);
}

.btn-small {
  width: auto;
  padding: 10px 14px;
  background: #f0f1fb;
  color: var(--color-text);
  white-space: nowrap;
}

.btn-text {
  background: transparent;
  color: var(--color-muted);
  box-shadow: none;
  font-weight: 500;
}

.online-box {
  text-align: left;
  margin-bottom: 12px;
}

.online-box.hidden {
  display: none;
}

.copy-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.copy-row input,
.copy-row textarea {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e0e0ee;
  font-size: 14px;
  font-family: inherit;
  resize: none;
}

.room-code {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  padding: 14px 0;
  margin-bottom: 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(79, 124, 255, 0.12), rgba(255, 92, 138, 0.12));
  border: 2px dashed rgba(106, 92, 255, 0.35);
  color: var(--color-text);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--color-muted);
  margin: 4px 0 16px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-x);
  flex-shrink: 0;
  animation: blink 1.2s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.15); }
}

.hidden {
  display: none !important;
}

.scoreboard {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.score {
  flex: 1;
  background: #f6f6fb;
  border-radius: 12px;
  padding: 10px 0;
}

.score .label {
  display: block;
  font-size: 12px;
  color: var(--color-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.score .value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  margin-top: 2px;
}

.score-x .value { color: var(--color-x); }
.score-o .value { color: var(--color-o); }

.turn-indicator {
  font-weight: 600;
  min-height: 22px;
  margin: 0 0 16px;
}

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  aspect-ratio: 1 / 1;
}

.board-wrap.size-5 {
  max-width: 340px;
}

.board.size-5 {
  gap: 6px;
}

.board.size-5 .cell {
  font-size: clamp(18px, 6vw, 28px);
}

.cell {
  background: #f6f6fb;
  border-radius: 12px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
  user-select: none;
}

.cell:hover:not(:disabled) {
  background: #ececfa;
}

.cell:disabled {
  cursor: default;
}

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

.cell.pop {
  animation: pop 0.2s ease;
}

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

.cell.win {
  background: #fff2d6;
  animation: pulse 0.8s ease infinite alternate;
}

@keyframes pulse {
  from { box-shadow: 0 0 0 rgba(255, 193, 7, 0.4); }
  to { box-shadow: 0 0 0 10px rgba(255, 193, 7, 0); }
}

.win-line {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.win-line line {
  stroke: #ffb300;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: var(--line-length, 300);
  stroke-dashoffset: var(--line-length, 300);
  transition: stroke-dashoffset 0.35s ease;
}

.win-line.show line {
  stroke-dashoffset: 0;
}

.win-line.pulse line {
  animation: win-line-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes win-line-pulse {
  from { stroke-width: 8; filter: drop-shadow(0 0 0 rgba(255, 179, 0, 0)); }
  to   { stroke-width: 11; filter: drop-shadow(0 0 6px rgba(255, 179, 0, 0.85)); }
}

.game-actions {
  margin-top: 20px;
}

.congrats {
  position: relative;
  overflow: hidden;
}

.salute {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--spark-color, #ffb300);
  opacity: 0;
  animation: spark-burst 0.9s ease-out forwards;
}

@keyframes spark-burst {
  0% { transform: translate(0, 0) scale(0.6); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, 0)) scale(0.2); opacity: 0; }
}
