/* ═══════════════════════════════════════════════════════
   Gomoku — Premium UI Styles
   Dark Glassmorphism + Non-linear Animations
   ═══════════════════════════════════════════════════════ */

/* ── Reset & Variables ──────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Palette */
  --bg-deep: #08060c;
  --bg-mid: #110d18;
  --bg-surface: rgba(22, 17, 31, 0.65);
  --bg-glass: rgba(30, 22, 45, 0.4);
  --border-glass: rgba(140, 100, 200, 0.15);
  --border-active: rgba(167, 139, 250, 0.5);
  --text-primary: #f0eef6;
  --text-secondary: #a99fc4;
  --text-muted: #6b6480;
  --accent: #a78bfa;
  --accent-glow: rgba(167, 139, 250, 0.4);
  --accent-2: #ec4899;
  --accent-3: #06b6d4;
  --success: #34d399;
  --danger: #f43f5e;

  /* Easing — non-linear curves */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-back: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-bounce: cubic-bezier(0.87, 0, 0.13, 1);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px var(--accent-glow);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* ── Animated Mesh Gradient Background ───────────────── */
.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: var(--bg-deep);
  overflow: hidden;
}

.bg-mesh::before,
.bg-mesh::after {
  content: '';
  position: absolute;
  width: 60vmax;
  height: 60vmax;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.3;
  animation: float-blob 20s ease-in-out infinite;
}

.bg-mesh::before {
  background: radial-gradient(circle, rgba(167, 139, 250, 0.4), transparent 70%);
  top: -10%;
  left: -10%;
}

.bg-mesh::after {
  background: radial-gradient(circle, rgba(236, 72, 153, 0.25), transparent 70%);
  bottom: -15%;
  right: -10%;
  animation-delay: -10s;
}

.bg-orb {
  position: fixed;
  width: 40vmax;
  height: 40vmax;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.15), transparent 70%);
  filter: blur(60px);
  top: 30%;
  left: 40%;
  z-index: -2;
  animation: float-blob 25s ease-in-out infinite reverse;
}

@keyframes float-blob {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(8vw, -5vh) scale(1.1); }
  66% { transform: translate(-5vw, 8vh) scale(0.9); }
}

/* Subtle noise texture overlay */
.bg-noise {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.015;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.9' /%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' /%3E%3C/svg%3E");
}

/* ── Layout ──────────────────────────────────────────── */
.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  opacity: 0;
  animation: fade-down 0.8s var(--ease-expo) 0.1s forwards;
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 4px 20px rgba(167, 139, 250, 0.4);
  position: relative;
  overflow: hidden;
}

.logo-mark::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.2) 50%, transparent 60%);
  animation: shine 4s ease-in-out infinite;
}

@keyframes shine {
  0%, 100% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
}

.logo-text h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #f0eef6, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-text p {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 2px;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: 100px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Main Grid ──────────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 28px;
  align-items: start;
  flex: 1;
}

/* ── Board Area ─────────────────────────────────────── */
.board-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 0;
  animation: fade-up 0.8s var(--ease-expo) 0.3s forwards;
}

.board-wrap {
  position: relative;
  aspect-ratio: 1;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-lg), 0 0 80px rgba(167, 139, 250, 0.1);
}

.board-wrap canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
}

#overlay {
  cursor: crosshair;
  z-index: 2;
}

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 0;
  animation: fade-left 0.8s var(--ease-expo) 0.5s forwards;
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-glass);
  border-radius: 18px;
  padding: 20px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.3s var(--ease-smooth), box-shadow 0.3s var(--ease-smooth);
}

.panel:hover {
  border-color: rgba(167, 139, 250, 0.25);
  box-shadow: var(--shadow-md), 0 0 30px rgba(167, 139, 250, 0.08);
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

/* ── Status Card ────────────────────────────────────── */
.status-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  transition: background 0.4s var(--ease-smooth);
}

.status-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0;
  animation: pulse-ring 2s ease-out infinite;
}

.status-dot.black { background: #2a2a30; color: #555; }
.status-dot.white { background: #e8e8ec; color: #ccc; }
.status-dot.thinking { background: var(--accent); color: var(--accent); }
.status-dot.thinking::after { opacity: 1; }
.status-dot.win { background: var(--success); color: var(--success); }
.status-dot.lose { background: var(--danger); color: var(--danger); }
.status-dot.draw { background: var(--text-muted); color: var(--text-muted); }

@keyframes pulse-ring {
  0% { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(1.8); opacity: 0; }
}

.status-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}

/* ── Buttons ────────────────────────────────────────── */
.btn-group {
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  background: var(--bg-glass);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s var(--ease-spring);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  opacity: 0;
  transition: opacity 0.3s var(--ease-smooth);
  z-index: -1;
}

.btn:hover {
  border-color: var(--border-active);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(167, 139, 250, 0.2);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 16px rgba(167, 139, 250, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 8px 30px rgba(167, 139, 250, 0.4);
  filter: brightness(1.1);
}

/* ── Segmented Control ──────────────────────────────── */
.segment {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  border: 1px solid var(--border-glass);
}

.seg-btn {
  flex: 1;
  padding: 9px 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.35s var(--ease-spring);
  font-family: inherit;
}

.seg-btn.active {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.25), rgba(236, 72, 153, 0.15));
  color: var(--text-primary);
  box-shadow: 0 2px 12px rgba(167, 139, 250, 0.2);
}

.seg-btn:hover:not(.active) {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

/* ── Stats Row ──────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 12px;
}

.stat-item {
  flex: 1;
  text-align: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Result Modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 6, 12, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s var(--ease-smooth), visibility 0.4s;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-mid);
  border: 1px solid var(--border-glass);
  border-radius: 24px;
  padding: 40px 48px;
  text-align: center;
  max-width: 380px;
  transform: scale(0.8) translateY(20px);
  transition: transform 0.5s var(--ease-spring);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(167, 139, 250, 0.15);
}

.modal-overlay.show .modal {
  transform: scale(1) translateY(0);
}

.result-icon {
  width: 80px;
  height: 80px;
  border-radius: 24px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 32px rgba(167, 139, 250, 0.3);
  animation: icon-pop 0.6s var(--ease-spring) 0.2s both;
}

@keyframes icon-pop {
  0% { transform: scale(0) rotate(-180deg); }
  100% { transform: scale(1) rotate(0); }
}

.result-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #f0eef6, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ── Footer ─────────────────────────────────────────── */
.footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 16px;
  opacity: 0;
  animation: fade-up 0.8s var(--ease-expo) 0.7s forwards;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

.footer a:hover {
  color: var(--accent-2);
}

/* ── Entrance Animations ────────────────────────────── */
@keyframes fade-down {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-left {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 960px) {
  .app {
    padding: 16px;
  }

  .main {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: -1;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .panel {
    flex: 1;
    min-width: 200px;
  }
}

@media (max-width: 600px) {
  .header {
    flex-direction: column;
    gap: 12px;
  }

  .sidebar {
    flex-direction: column;
  }

  .modal {
    padding: 32px 24px;
    margin: 20px;
  }
}

/* ── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(167, 139, 250, 0.2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(167, 139, 250, 0.4);
}

/* ── Selection ──────────────────────────────────────── */
::selection {
  background: rgba(167, 139, 250, 0.3);
  color: #fff;
}
