﻿:root {
  --app-base-width: 940px;
  --app-base-height: 780px;
  --paper: #fcf8eb;
  --ink: #1e2c42;
  --ink-soft: #4f6078;
  --line-blue: #b9d8ff;
  --line-red: #ffb9b9;
  --panel-top: #fffdf5ee;
  --panel-bottom: #f6fbffea;
  --chip: #eef6ff;
  --chip-active: #ffe9ae;
  --chip-border: #8bb2d8;
  --primary-a: #ffb45a;
  --primary-b: #ea8744;
  --secondary: #d7ebff;
  --x: #1e73ff;
  --o: #ff5e49;
  --board-line: rgba(106, 136, 172, 0.62);
  --board-cell: rgba(255, 255, 255, 0.94);
  --board-cell-hover: rgba(255, 240, 198, 0.65);
  --board-cell-last: rgba(255, 221, 129, 0.62);
  --board-cell-hint: rgba(146, 199, 255, 0.62);
  --win-line: #ff3c2f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Comic Sans MS", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 14px;
  touch-action: manipulation;
  user-select: none;
  background:
    radial-gradient(circle at 12% 18%, #ffe4a8 0, transparent 30%),
    radial-gradient(circle at 88% 78%, #d6f5d6 0, transparent 28%),
    linear-gradient(140deg, #f7fbff 0, #fff6e8 42%, #f7fffb 100%);
  background-color: var(--paper);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, transparent 62px, rgba(255, 164, 164, 0.42) 62px, rgba(255, 164, 164, 0.42) 64px, transparent 64px),
    repeating-linear-gradient(to bottom, transparent 0, transparent 31px, rgba(167, 205, 245, 0.47) 31px, rgba(167, 205, 245, 0.47) 32px);
  opacity: 0.7;
}

.app {
  width: var(--app-base-width);
  height: var(--app-base-height);
  position: fixed;
  left: 0;
  top: 0;
  transform-origin: top left;
  transform: translate(var(--app-x, 0px), var(--app-y, 0px)) scale(var(--app-scale, 1));
  will-change: transform;
  z-index: 1;
}

.screen {
  background: linear-gradient(175deg, var(--panel-top) 0%, var(--panel-bottom) 100%);
  border: 2px solid #97b7d8;
  border-radius: 26px;
  padding: 18px;
  min-height: 0;
  height: 100%;
  box-shadow:
    0 18px 42px rgba(30, 56, 90, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(2px);
  animation: pop-in 260ms ease;
}

.screen:not(.active) { display: none; }
#menu { text-align: center; display: flex; flex-direction: column; }
#menu:not(.active) { display: none; }
#game.active { display: flex; flex-direction: column; }
#game:not(.active) { display: none; }

h1, h2, p { margin: 0; }
h1 {
  font-size: clamp(2rem, 4.6vw, 2.7rem);
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(255,255,255,0.75);
}

#subtitle {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 1.02rem;
}

.options {
  margin-top: auto;
  width: 100%;
  background: rgba(255, 255, 255, 0.52);
  border: 1px dashed rgba(135, 171, 205, 0.8);
  border-radius: 14px;
  padding: 8px 10px 10px;
}

.option-label {
  font-size: 0.93rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.chip {
  flex: 1;
  border: 2px solid var(--chip-border);
  border-radius: 999px;
  padding: 7px 8px;
  background: var(--chip);
  color: var(--ink);
  font-weight: 700;
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

.chip:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(92, 128, 170, 0.18); }
.chip.active {
  background: linear-gradient(180deg, #fff1bf 0%, var(--chip-active) 100%);
  box-shadow: inset 0 -2px 0 rgba(200, 140, 63, 0.22);
}

.btn {
  margin-top: 10px;
  border: none;
  border-radius: 13px;
  padding: 9px 12px;
  font-size: 0.95rem;
  font-weight: 800;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(180deg, var(--primary-a) 0%, var(--primary-b) 100%);
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(220, 128, 58, 0.33);
  transition: transform 120ms ease, filter 120ms ease;
}

.btn:hover { filter: brightness(1.04); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }

.btn-secondary {
  margin-top: 0;
  color: var(--ink);
  background: linear-gradient(180deg, #eaf4ff 0%, var(--secondary) 100%);
  box-shadow: 0 5px 12px rgba(95, 138, 185, 0.2);
}

.other-game-btn {
  display: inline-grid;
  grid-template-rows: 88px auto;
  align-items: start;
  justify-content: center;
  gap: 6px;
  margin-top: 4px;
  padding: 4px 8px;
  animation: other-game-pulse 2.1s ease-in-out infinite;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  color: var(--ink);
  width: 100%;
}

.other-game-btn:hover,
.other-game-btn:active {
  filter: none;
  box-shadow: none;
}

.other-game-icon {
  width: 88px;
  height: 88px;
  border-radius: 12px;
  display: block;
  justify-self: center;
}

#other-game-label {
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  font-size: 0.95rem;
}

.hint {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 0.94rem;
}

#audio-options { margin-top: 10px; margin-bottom: 0; }

.audio-row {
  display: flex;
  gap: 6px;
  width: 100%;
  justify-content: space-between;
}

.audio-icon-btn {
  flex: 1;
  border: 2px solid var(--chip-border);
  border-radius: 12px;
  background: #f3f9ff;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.83rem;
  font-weight: 700;
  padding: 6px 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.audio-icon { font-size: 0.9rem; }
#sound-label, #music-label, #lang-toggle-label { white-space: nowrap; }

.audio-icon-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(100, 138, 179, 0.2); }
.audio-icon-btn.active { background: linear-gradient(180deg, #effff1 0%, #dff4e3 100%); }
.audio-icon-btn:not(.active) { background: #f1f1f1; opacity: 0.8; }

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.header-actions { display: flex; gap: 8px; }

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 6px;
}

.score-card {
  border: 2px dashed #9ec0e1;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 12px;
  padding: 8px 10px;
}

.score-name { color: var(--ink-soft); font-size: 0.88rem; }
.score-value { margin-top: 2px; font-size: 1.58rem; font-weight: 800; }
.match-info { color: var(--ink-soft); font-size: 0.91rem; margin-bottom: 10px; }

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 4px;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 234, 168, 0.36) 0, transparent 45%),
    radial-gradient(circle at 75% 82%, rgba(196, 232, 255, 0.32) 0, transparent 43%);
  border-radius: 16px;
}

.board {
  --size: 15;
  --line: var(--board-line);
  position: relative;
  width: min(100%, 640px);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
  gap: 1px;
  padding: 1px;
  border: 2px solid rgba(110, 140, 174, 0.66);
  border-radius: 10px;
  background: var(--line);
  box-shadow:
    0 6px 14px rgba(90, 120, 154, 0.14),
    inset 0 1px 0 rgba(255,255,255,0.96);
  overflow: hidden;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc((100% / var(--size)) - 1px),
    rgb(170 208 250 / 20%) calc((100% / var(--size)) - 1px),
    rgb(170 208 250 / 20%) calc(100% / var(--size))
  );
  z-index: 0;
}

.cell {
  border: 0;
  background: var(--board-cell);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: background-color 100ms ease;
  position: relative;
  z-index: 1;
}

.cell:hover { background: var(--board-cell-hover); }

.mark {
  width: 76%;
  height: 76%;
}

.mark path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  animation: draw-mark 320ms ease forwards;
}

.mark .stroke-main {
  stroke-width: 8;
  opacity: 0.95;
}

.mark .stroke-shadow {
  stroke-width: 5.3;
  opacity: 0.35;
  animation-delay: 55ms;
}

.mark .stroke-grain {
  stroke-width: 2.1;
  opacity: 0.22;
  stroke-dasharray: 8 10;
  animation-delay: 110ms;
}

.mark-x .stroke-main { stroke: var(--x); }
.mark-x .stroke-shadow { stroke: #1455be; }
.mark-x .stroke-grain { stroke: #5f9dff; }

.mark-o .stroke-main { stroke: var(--o); }
.mark-o .stroke-shadow { stroke: #c5493a; }
.mark-o .stroke-grain { stroke: #ff9d92; }
.cell.last-move { background: var(--board-cell-last); }
.cell.hint-move {
  background: var(--board-cell-hint);
  animation: hint-pulse 1s ease-in-out infinite;
}

.win-line {
  position: absolute;
  height: 6px;
  border-radius: 999px;
  background: var(--win-line);
  transform-origin: 0 50%;
  box-shadow: 0 0 10px rgba(255, 60, 47, 0.52);
  pointer-events: none;
  top: 0;
  left: 0;
  z-index: 3;
}

.confetti-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti {
  position: absolute;
  top: -10%;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: confetti-fall 1150ms ease-in forwards;
}

.match-overlay {
  position: absolute;
  inset: 0;
  border: 2px solid #9ec0e1;
  border-radius: 14px;
  background: rgba(255, 253, 245, 0.9);
  backdrop-filter: blur(3px);
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 18px 14px;
  z-index: 7;
}

.lang-toggle-btn {
  flex: 0 0 70px;
  padding: 6px 4px;
}

.match-overlay[hidden] { display: none !important; }
.overlay-title { font-size: 1.2rem; font-weight: 800; }
.overlay-score { margin-top: 4px; color: var(--ink-soft); font-size: 1.02rem; }
.overlay-timer { margin-top: 8px; color: var(--ink); font-weight: 700; }
.overlay-actions {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(100%, 380px);
}
.overlay-actions .btn { width: 100%; }
.overlay-actions[hidden] { display: none !important; }
.ad-btn {
  width: 100%;
  margin-top: 0;
  animation: cta-pulse 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 rgba(234, 135, 68, 0.4);
}

.board-wrap.overlay-active .board,
.board-wrap.overlay-active .win-line { filter: blur(2.5px) brightness(0.96); }

@keyframes confetti-fall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 0.95; }
  100% { transform: translateY(180px) rotate(420deg); opacity: 0; }
}

@keyframes draw-mark {
  to { stroke-dashoffset: 0; }
}

@keyframes hint-pulse {
  0%, 100% { box-shadow: inset 0 0 0 rgba(74, 133, 226, 0); }
  50% { box-shadow: inset 0 0 0 2px rgba(74, 133, 226, 0.45); }
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cta-pulse {
  0%, 100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 0 0 0 rgba(234, 135, 68, 0.42);
  }
  50% {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 0 0 9px rgba(234, 135, 68, 0);
  }
}

@keyframes other-game-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

@media (max-width: 700px) {
  .screen { padding: 14px; }
  .game-header { flex-direction: column; align-items: stretch; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; }
  .other-game-btn { width: 100%; }
}


