:root {
  --bg-1: #0f0c29;
  --bg-2: #302b63;
  --bg-3: #24243e;
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --accent-x: #ff5f6d;
  --accent-o: #4facfe;
  --accent-x-glow: rgba(255, 95, 109, 0.55);
  --accent-o-glow: rgba(79, 172, 254, 0.55);
  --text-main: #f5f5fb;
  --text-dim: #b3b0c9;
  --success: #34d399;
  --draw: #fbbf24;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-1), var(--bg-2), var(--bg-3));
  background-size: 300% 300%;
  animation: bgShift 18s ease infinite;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes bgShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.app {
  width: 100%;
  max-width: 480px;
  padding: 20px;
  position: relative;
}

.screen {
  display: none;
  animation: fadeIn 0.4s ease;
}
.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 32px 28px;
  backdrop-filter: blur(18px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  text-align: center;
}

.title {
  font-size: 2.1rem;
  margin: 0 0 4px;
  font-weight: 800;
  letter-spacing: 1px;
}
.title .dot {
  color: var(--accent-o);
}
.subtitle {
  color: var(--text-dim);
  margin: 0 0 28px;
  font-size: 0.95rem;
}

.option-group {
  margin-bottom: 22px;
  text-align: right;
}
.option-group h2 {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pill-group {
  display: flex;
  gap: 8px;
  background: rgba(0,0,0,0.25);
  padding: 5px;
  border-radius: 14px;
}

.pill {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  font-family: inherit;
}
.pill:hover {
  color: var(--text-main);
}
.pill.active {
  background: linear-gradient(135deg, var(--accent-x), var(--accent-o));
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

.primary-btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-x), var(--accent-o));
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
}
.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(79,172,254,0.35);
}
.primary-btn:active {
  transform: translateY(0);
}

.secondary-btn {
  padding: 12px 18px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}
.secondary-btn:hover {
  background: rgba(255,255,255,0.14);
}

.sound-toggle {
  margin-top: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255,255,255,0.15);
  border-radius: 24px;
  transition: 0.3s;
}
.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.switch input:checked + .slider {
  background: linear-gradient(135deg, var(--accent-x), var(--accent-o));
}
.switch input:checked + .slider::before {
  transform: translateX(-18px);
}

/* ---------- GAME SCREEN ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 10px;
}

.score-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 10px 16px;
  text-align: center;
  min-width: 80px;
  transition: box-shadow 0.3s ease, transform 0.2s ease;
}
.score-box.pulse {
  transform: scale(1.08);
}
.player-score { box-shadow: inset 0 0 0 1px var(--accent-x-glow); }
.computer-score { box-shadow: inset 0 0 0 1px var(--accent-o-glow); }

.score-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-weight: 600;
}
.score-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 800;
}
.player-score .score-value { color: var(--accent-x); }
.computer-score .score-value { color: var(--accent-o); }

.mid-hud {
  text-align: center;
  flex: 1;
}
.round-indicator {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.status {
  font-size: 0.95rem;
  font-weight: 700;
  min-height: 1.3em;
}

.board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  width: min(90vw, 340px);
  height: min(90vw, 340px);
  background: rgba(0,0,0,0.25);
  padding: 8px;
  border-radius: 20px;
  border: 1px solid var(--card-border);
}

.cell {
  background: rgba(255,255,255,0.05);
  border: none;
  border-radius: 12px;
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.1s ease;
  position: relative;
  font-family: inherit;
}
.cell:hover:not(:disabled) {
  background: rgba(255,255,255,0.12);
}
.cell:disabled {
  cursor: default;
}
.cell.x { color: var(--accent-x); text-shadow: 0 0 18px var(--accent-x-glow); }
.cell.o { color: var(--accent-o); text-shadow: 0 0 18px var(--accent-o-glow); }

.cell.pop {
  animation: popIn 0.28s ease;
}
@keyframes popIn {
  0% { transform: scale(0.3); opacity: 0; }
  70% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

.cell.win-cell {
  background: rgba(52, 211, 153, 0.18);
  animation: winPulse 0.9s ease infinite;
}
@keyframes winPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(52,211,153,0); }
}

.win-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.win-line line {
  stroke: var(--success);
  stroke-width: 8;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--success));
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ---------- ROUND OVERLAY ---------- */
.round-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 30, 0.55);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 50;
}
.round-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.round-overlay-content {
  background: linear-gradient(135deg, rgba(255,95,109,0.9), rgba(79,172,254,0.9));
  padding: 26px 48px;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  transform: scale(0.7);
  transition: transform 0.35s cubic-bezier(.34,1.56,.64,1);
}
.round-overlay.show .round-overlay-content {
  transform: scale(1);
}
.round-overlay-text {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  text-align: center;
  white-space: nowrap;
}

/* ---------- SERIES END ---------- */
.series-score-labels {
  direction: ltr;
  unicode-bidi: isolate;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  margin: 4px 0 0;
  letter-spacing: 1px;
}

.series-final-score {
  font-size: 2.4rem;
  font-weight: 800;
  margin: 10px 0 26px;
  background: linear-gradient(135deg, var(--accent-x), var(--accent-o));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  direction: ltr; /* מונע היפוך ויזואלי של "1 : 0" ע"י אלגוריתם ה-bidi בעמוד RTL */
  unicode-bidi: isolate;
}
#series-end-screen .secondary-btn {
  width: 100%;
  margin-top: 10px;
}

@media (max-width: 400px) {
  .title { font-size: 1.7rem; }
  .cell { font-size: 2.1rem; }
  .score-value { font-size: 1.3rem; }
}
