* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #dff3f5;
  --text: #0f172a;
  --muted: #6b7280;
  --player: #2ab3e6;
  --bot: #ff4d4d;
  --grid: #dbe4ff;
  --dot: #1f2937;
  --shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
  --menu-accent: #ff4d4d;
  --menu-accent-2: #2ab3e6;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow-x: hidden;
  overflow-y: auto;
}

body::-webkit-scrollbar {
  width: 10px;
}

body::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.06);
}

body::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.22);
  border-radius: 999px;
}

body::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 23, 42, 0.32);
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom) + 84px);
}

.menu-screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 20;
  padding: 24px;
}

body.menu-visible .menu-screen {
  display: flex;
}

body.menu-visible .game-screen {
  filter: blur(6px);
  pointer-events: none;
  user-select: none;
}

.menu-card {
  background: #ffffff;
  border-radius: 24px;
  padding: 28px 28px 32px;
  width: min(460px, 92vw);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}

.menu-title {
  font-size: 2.1rem;
  font-weight: 800;
  color: var(--menu-accent);
  letter-spacing: 2px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.menu-title-icon {
  color: var(--menu-accent-2);
  font-size: 1.6rem;
  margin-top: 2px;
}

.menu-title-sub {
  color: #3f4a5c;
  font-size: 1.6rem;
  margin-top: 2px;
}

.menu-title-line {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--menu-accent-2), #ffffff, var(--menu-accent-2));
  position: relative;
}

.menu-title-line::after {
  content: "";
  position: absolute;
  inset: 2px 40px;
  border-radius: 999px;
  background: var(--menu-accent-2);
  opacity: 0.6;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
  color: #3f4a5c;
}

.menu-label {
  font-size: 0.95rem;
}

.menu-pill {
  background: var(--menu-accent-2);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 16px;
  min-width: 64px;
  text-align: center;
}

.menu-toggle {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.menu-subscribe-btn {
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, #2ab3e6, #4b7cff);
  box-shadow: 0 12px 22px rgba(42, 179, 230, 0.25);
  cursor: pointer;
}

.menu-subscribe-btn:active {
  transform: scale(0.99);
}

.menu-btn {
  border: 2px solid #d7e7ec;
  background: #f5fbfc;
  color: #3f4a5c;
  padding: 8px 14px;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.menu-btn.active {
  background: var(--menu-accent);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(255, 77, 77, 0.35);
}

.menu-play {
  margin-top: 6px;
  padding: 14px 18px;
  border-radius: 18px;
  border: none;
  background: var(--menu-accent);
  color: #ffffff;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 2px;
  box-shadow: 0 14px 0 rgba(255, 77, 77, 0.35);
  cursor: pointer;
}

.menu-play:active {
  transform: translateY(2px);
  box-shadow: 0 10px 0 rgba(255, 77, 77, 0.35);
}

.menu-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.menu-action-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: #ffffff;
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.15);
  cursor: pointer;
  font-size: 1.1rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.menu-action-btn:active {
  transform: scale(0.96);
}

.menu-action-btn.is-off {
  opacity: 0.6;
}

.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 6px;
}

.hud-side {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-side.right {
  justify-content: flex-end;
}

.hud-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #2ab3e6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 10px 18px rgba(42, 179, 230, 0.3);
  font-size: 1.2rem;
}

.hud-avatar.bot {
  background: #ff4d4d;
  box-shadow: 0 10px 18px rgba(255, 77, 77, 0.3);
}

.hud-score {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #cfe8ee;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.hud-score.player {
  color: #2ab3e6;
}

.hud-score.bot {
  color: #ff4d4d;
}

.hud-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.turn-chip {
  padding: 8px 16px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #cfe8ee;
  font-weight: 600;
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.game-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding-bottom: 6px;
  flex-wrap: wrap;
}

.game-subscribe-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.game-subscribe-btn {
  width: auto;
  min-width: 220px;
  max-width: 92vw;
  margin: 8px auto 0;
  border: 2px solid rgba(75, 124, 255, 0.35);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #1d4ed8;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  letter-spacing: 0.2px;
}

.game-subscribe-btn:active {
  transform: scale(0.98);
}

.game-subscribe-btn:hover {
  background: rgba(255, 255, 255, 0.95);
}

.action-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: #ffffff;
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.18);
  cursor: pointer;
  font-size: 1.2rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.subscribe-heart-btn {
  background: linear-gradient(135deg, #ff4d4d, #ff7a7a);
  color: #ffffff;
  box-shadow: 0 12px 20px rgba(255, 77, 77, 0.35);
  font-size: 1.35rem;
  line-height: 1;
}

.subscribe-heart-btn:active {
  transform: scale(0.96);
}

.subscribe-heart-btn:hover {
  box-shadow: 0 14px 24px rgba(255, 77, 77, 0.42);
}

.btn-home {
  background: linear-gradient(135deg, #4b7cff, #2ab3e6);
  color: #ffffff;
  box-shadow: 0 12px 20px rgba(42, 179, 230, 0.32);
}

.btn-restart {
  background: linear-gradient(135deg, #22c55e, #34d399);
  color: #ffffff;
  box-shadow: 0 12px 20px rgba(34, 197, 94, 0.28);
}

.btn-music {
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  color: #ffffff;
  box-shadow: 0 12px 20px rgba(124, 58, 237, 0.28);
}

.btn-notify {
  background: linear-gradient(135deg, #f59e0b, #f97316);
  color: #ffffff;
  box-shadow: 0 12px 20px rgba(245, 158, 11, 0.28);
}

.btn-recommend {
  background: linear-gradient(135deg, #0ea5e9, #38bdf8);
  color: #ffffff;
  box-shadow: 0 12px 20px rgba(14, 165, 233, 0.28);
}

.action-btn.text-btn {
  width: auto;
  height: 46px;
  padding: 0 16px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.action-btn:active {
  transform: scale(0.96);
}

.action-btn.is-off {
  opacity: 0.6;
}

.help-text {
  text-align: left;
  line-height: 1.5;
}

.board {
  display: grid;
  gap: 0;
  padding: 18px;
  background: #ffffff;
  border-radius: 24px;
  border: 1px solid #e2e8f0;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.dot {
  width: calc(var(--cell) * 0.28);
  height: calc(var(--cell) * 0.28);
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #d7e7ec;
  box-shadow: 0 4px 8px rgba(15, 23, 42, 0.25);
  animation: pulse 2.2s ease-in-out infinite;
}

.edge {
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.edge.horizontal {
  width: 100%;
  height: calc(var(--cell) * 0.24);
}

.edge.vertical {
  width: calc(var(--cell) * 0.24);
  height: 100%;
}

.edge:not(.disabled):hover {
  background: rgba(42, 179, 230, 0.2);
  transform: scale(1.08);
}

.edge.player {
  background: linear-gradient(135deg, rgba(42, 179, 230, 0.9), rgba(88, 212, 244, 0.9));
  box-shadow: 0 0 10px rgba(42, 179, 230, 0.4);
}

.edge.bot {
  background: linear-gradient(135deg, rgba(255, 77, 77, 0.9), rgba(255, 120, 120, 0.9));
  box-shadow: 0 0 10px rgba(255, 77, 77, 0.35);
}

.edge.just-played {
  animation: edgeFlash 0.35s ease;
}

.edge.disabled {
  cursor: default;
}

.box {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  transition: transform 0.2s ease;
}

.box.player {
  background: linear-gradient(135deg, rgba(42, 179, 230, 0.32), rgba(88, 212, 244, 0.32));
}

.box.bot {
  background: linear-gradient(135deg, rgba(255, 77, 77, 0.32), rgba(255, 140, 140, 0.35));
}

.box.just-captured {
  animation: pop 0.35s ease;
}

.box-marker {
  width: calc(var(--cell) * 0.22);
  height: calc(var(--cell) * 0.22);
  border-radius: 6px;
  margin: auto;
  opacity: 0.9;
}

.box-marker.player {
  background: var(--menu-accent-2);
}

.box-marker.bot {
  background: var(--menu-accent);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay.fullscreen {
  align-items: stretch;
  justify-content: stretch;
}

.overlay-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: var(--shadow);
}

.overlay.fullscreen .overlay-card {
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  padding: 28px 22px calc(env(safe-area-inset-bottom, 0px) + 24px);
  overflow-y: auto;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.overlay-title {
  font-size: 1.4rem;
  margin-bottom: 12px;
}

.overlay-text {
  color: var(--text);
  margin-bottom: 10px;
  font-weight: 600;
}

.overlay-meta {
  color: var(--muted);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.overlay-card .primary-btn {
  width: 100%;
}

.primary-btn {
  border: none;
  border-radius: 16px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, #2ab3e6, #4b7cff);
  box-shadow: 0 12px 22px rgba(42, 179, 230, 0.25);
  cursor: pointer;
  transition: transform 0.2s ease;
}

.primary-btn:active {
  transform: translateY(2px);
}

.hidden {
  display: none !important;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.08); opacity: 1; }
}

@keyframes edgeFlash {
  0% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

@keyframes pop {
  0% { transform: scale(0.7); }
  100% { transform: scale(1); }
}

@media (max-width: 720px) {
  .app {
    padding: 12px;
    gap: 12px;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-btn {
    width: 100%;
  }

  .menu-card {
    padding: 22px 20px 26px;
  }

  .menu-title {
    font-size: 1.6rem;
    letter-spacing: 1px;
  }

  .menu-title-icon {
    font-size: 1.2rem;
  }

  .menu-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .menu-toggle {
    width: 100%;
    justify-content: flex-start;
  }

  .board-wrap {
    margin-top: 100px;
    padding-bottom: 0;
  }

  .game-actions {
    margin-top: 6px;
    padding-bottom: 6px;
  }

  .hud-avatar {
    width: 46px;
    height: 46px;
  }

  .hud-score {
    width: 38px;
    height: 38px;
  }
}
