/* ===================================
   五子棋 - 二次元风格样式表 v1.0
   设计理念：日系二次元 × 可爱圆润 × 清新明亮
   =================================== */

/* === 基础重置 === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* === 全局变量 - 二次元配色 === */
:root {
  /* 主色调 - 樱花粉紫渐变 */
  --bg-gradient-start: #ffb7d9;
  --bg-gradient-end: #c9a8ff;
  
  /* 棋盘色 - 樱花木纹主题 */
  --board-bg: #f5e6d3;
  --board-grid: #d4a574;
  --board-stars: #c98865;
  --board-border: #ffb7d9;
  
  /* 棋子色 - 二次元风格 */
  --stone-black-base: #4a3759;
  --stone-black-highlight: #7d5a94;
  --stone-black-shadow: #2d1f3d;
  --stone-white-base: #ffe5ec;
  --stone-white-highlight: #ffffff;
  --stone-white-shadow: #ffb6c1;
  
  /* UI 组件色 */
  --container-bg: #ffffff;
  --container-bg-alt: #fff5f8;
  --text-primary: #5a4a6e;
  --text-secondary: #8b7a9e;
  --text-hint: #a898b8;
  
  /* 状态色 */
  --status-bg-start: #fff5f8;
  --status-bg-end: #ffe5ec;
  --status-border: #ffb7d9;
  --status-text: #5a4a6e;
  --status-win-black: #7fdbb6;
  --status-win-white: #a8d4ff;
  --status-draw: #d4c4e8;
  
  /* 高亮色 */
  --highlight: #ff85c0;
  --success: #7fdbb6;
  --accent: #ffd700;
  
  /* 按钮色 */
  --btn-primary-start: #ff85c0;
  --btn-primary-end: #ff6eb4;
  --btn-secondary-start: #a8d4ff;
  --btn-secondary-end: #85c1ff;
  --btn-hover-offset: -3px;
  
  /* 信息区 */
  --info-bg: #f0f5ff;
  --info-border: #a8d4ff;
  
  /* 尺寸 */
  --board-size: 450px;
  --grid-spacing: 30px;
  --container-radius: 25px;
  --container-padding: 30px;
  --button-radius: 25px;
  
  /* 动效 */
  --transition-fast: 0.2s;
  --transition-normal: 0.3s;
  --transition-slow: 0.5s;
  
  /* 阴影 */
  --shadow-soft: 0 8px 32px rgba(157, 110, 255, 0.15);
  --shadow-medium: 0 12px 40px rgba(157, 110, 255, 0.25);
  --shadow-strong: 0 20px 60px rgba(157, 110, 255, 0.35);
  --shadow-btn: 0 4px 15px rgba(255, 133, 192, 0.4);
}

/* === 背景装饰 - 樱花飘落 === */
body {
  font-family: 'Quicksand', 'Nunito', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 15px;
  padding-top: 20px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  position: relative;
}

/* 樱花花瓣容器 */
.sakura-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.sakura-petal {
  position: absolute;
  background: linear-gradient(135deg, #ffb7d9 0%, #ff85c0 100%);
  border-radius: 50% 0 50% 0;
  opacity: 0.6;
  animation: sakuraFall linear infinite;
}

@keyframes sakuraFall {
  0% {
    transform: translateY(-10vh) rotate(0deg) translateX(0);
    opacity: 0;
  }
  10% {
    opacity: 0.6;
  }
  90% {
    opacity: 0.6;
  }
  100% {
    transform: translateY(110vh) rotate(360deg) translateX(50px);
    opacity: 0;
  }
}

/* 星光点缀 */
.star-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.star-point {
  position: absolute;
  background: white;
  border-radius: 50%;
  animation: starTwinkle ease-in-out infinite;
}

@keyframes starTwinkle {
  0%, 100% {
    opacity: 0.3;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* === 主容器 === */
.container {
  background: var(--container-bg);
  border-radius: var(--container-radius);
  padding: var(--container-padding);
  box-shadow: var(--shadow-strong);
  text-align: center;
  max-width: 600px;
  width: 100%;
  transition: box-shadow var(--transition-normal);
  position: relative;
  z-index: 1;
  border: 2px solid rgba(255, 183, 217, 0.3);
}

.container:hover {
  box-shadow: 0 25px 70px rgba(157, 110, 255, 0.4);
}

/* === 标题 === */
h1 {
  color: var(--text-primary);
  margin-bottom: 20px;
  font-size: 2em;
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 2px 2px 4px rgba(255, 133, 192, 0.2);
}

h1 .stone-icon {
  display: inline-block;
  animation: stoneFloat 3s ease-in-out infinite;
}

h1 .stone-icon.black {
  animation-delay: 0s;
}

h1 .stone-icon.white {
  animation-delay: 1.5s;
}

@keyframes stoneFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

/* === 状态栏 === */
#status {
  font-size: 1.5em;
  padding: 15px 30px;
  background: linear-gradient(135deg, var(--status-bg-start) 0%, var(--status-bg-end) 100%);
  border-radius: 20px;
  margin-bottom: 20px;
  display: inline-block;
  font-weight: 700;
  color: var(--status-text);
  transition: all var(--transition-normal);
  min-width: 220px;
  border: 2px solid var(--status-border);
  box-shadow: 0 4px 15px rgba(255, 183, 217, 0.3);
}

#status.win-black {
  background: linear-gradient(135deg, var(--status-win-black) 0%, #5fd49a 100%);
  color: white;
  border-color: #5fd49a;
  animation: victoryBounce 0.6s ease-in-out;
}

#status.win-white {
  background: linear-gradient(135deg, var(--status-win-white) 0%, #7ec0ff 100%);
  color: white;
  border-color: #7ec0ff;
  animation: victoryBounce 0.6s ease-in-out;
}

#status.draw {
  background: linear-gradient(135deg, var(--status-draw) 0%, #c4b4d8 100%);
  color: white;
  border-color: #c4b4d8;
}

#status.ai-thinking {
  background: linear-gradient(135deg, #fff9e6 0%, #fff3cd 100%);
  border-color: #ffd700;
  animation: thinkingPulse 1.5s ease-in-out infinite;
}

@keyframes victoryBounce {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes thinkingPulse {
  0%, 100% {
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
  }
  50% {
    box-shadow: 0 4px 25px rgba(255, 215, 0, 0.6);
  }
}

/* === 游戏区域 === */
.game-area {
  margin: 15px 0;
  display: flex;
  justify-content: center;
  box-shadow: var(--shadow-medium);
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--board-bg) 0%, #e8d5c4 100%);
  padding: 15px;
  max-width: 100%;
  border: 3px solid var(--board-border);
  position: relative;
}

.game-area::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
  animation: boardShine 3s linear infinite;
  pointer-events: none;
}

@keyframes boardShine {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

#board {
  display: block;
  cursor: pointer;
  touch-action: manipulation;
  border-radius: 8px;
  position: relative;
  z-index: 1;
}

/* === 控制按钮 === */
.controls-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px;
  background: var(--container-bg-alt);
  border-radius: 20px;
  margin-bottom: 15px;
  border: 2px solid rgba(255, 183, 217, 0.3);
}

.control-row {
  display: flex;
  gap: 15px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin: 10px 0;
}

.control-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.control-group label {
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  font-size: 0.95em;
}

button {
  padding: 12px 25px;
  font-size: 1em;
  border: none;
  border-radius: var(--button-radius);
  cursor: pointer;
  transition: all var(--transition-normal);
  background: linear-gradient(135deg, var(--btn-primary-start) 0%, var(--btn-primary-end) 100%);
  color: white;
  font-weight: 600;
  font-family: inherit;
  outline: none;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-btn);
}

button:hover {
  transform: translateY(var(--btn-hover-offset));
  box-shadow: 0 6px 20px rgba(255, 133, 192, 0.5);
}

button:active {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(255, 133, 192, 0.3);
}

button:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 133, 192, 0.5), var(--shadow-btn);
}

/* 按钮激活状态 */
button.active {
  background: linear-gradient(135deg, #ff6eb4 0%, #ff55a3 100%);
  box-shadow: 0 6px 20px rgba(255, 105, 163, 0.5);
}

/* 次级按钮（悔棋） */
.btn-undo {
  background: linear-gradient(135deg, var(--btn-secondary-start) 0%, var(--btn-secondary-end) 100%);
  box-shadow: 0 4px 15px rgba(168, 212, 255, 0.4);
}

.btn-undo:hover {
  box-shadow: 0 6px 20px rgba(168, 212, 255, 0.5);
}

/* 按钮点击波纹效果 */
button::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

button:active::after {
  width: 200px;
  height: 200px;
}

/* 选择器样式 */
.control-group select {
  padding: 10px 15px;
  font-size: 0.95em;
  border: 2px solid var(--status-border);
  border-radius: 15px;
  background: white;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
  color: var(--text-primary);
  font-weight: 600;
  outline: none;
}

.control-group select:hover {
  border-color: var(--btn-primary-start);
  box-shadow: 0 2px 8px rgba(255, 133, 192, 0.2);
}

.control-group select:focus {
  border-color: var(--btn-primary-start);
  box-shadow: 0 0 0 3px rgba(255, 133, 192, 0.2);
}

/* 行动按钮区 */
.action-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 15px;
}

.action-buttons button {
  min-width: 140px;
}

/* 音效控制按钮 */
.btn-sfx,
.btn-bgm {
  padding: 10px 20px;
  font-size: 0.95em;
  font-weight: 600;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
  color: white;
  background: linear-gradient(135deg, #a8d4ff 0%, #85c1ff 100%);
  box-shadow: 0 4px 15px rgba(168, 212, 255, 0.3);
  min-width: 80px;
}

.btn-sfx:hover,
.btn-bgm:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(168, 212, 255, 0.5);
}

.btn-sfx:active,
.btn-bgm:active {
  transform: translateY(0);
}

.btn-sfx.active,
.btn-bgm.active {
  background: linear-gradient(135deg, #7fdbb6 0%, #5dd496 100%);
  box-shadow: 0 4px 15px rgba(127, 219, 182, 0.4);
}

.btn-sfx.active:hover,
.btn-bgm.active:hover {
  box-shadow: 0 6px 20px rgba(127, 219, 182, 0.6);
}

/* === 信息区 === */
.info {
  margin-top: 20px;
  padding: 15px;
  background: var(--info-bg);
  border-radius: 15px;
  text-align: left;
  border-left: 4px solid var(--info-border);
  box-shadow: 0 2px 10px rgba(168, 212, 255, 0.2);
}

.info p {
  margin: 8px 0;
  color: var(--text-secondary);
  font-size: 0.95em;
  line-height: 1.6;
}

.info p:first-child {
  margin-top: 0;
}

.info p:last-child {
  margin-bottom: 0;
}

/* === 动效关键帧 === */

/* 棋子落子动画 - 二次元风格 */
@keyframes animeStoneDrop {
  0% {
    transform: scale(0) rotate(-180deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.15) rotate(10deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

.stone-drop {
  animation: animeStoneDrop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 胜利连线闪烁 */
@keyframes winPulse {
  0%, 100% {
    opacity: 1;
    stroke-width: 3;
    filter: drop-shadow(0 0 5px rgba(255, 133, 192, 0.8));
  }
  50% {
    opacity: 0.7;
    stroke-width: 5;
    filter: drop-shadow(0 0 15px rgba(255, 133, 192, 1));
  }
}

.win-line {
  animation: winPulse 1.5s ease-in-out infinite;
}

/* 页面加载淡入 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.container {
  animation: fadeIn 0.5s ease-out;
}

/* 庆祝彩带 */
.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  background: #ff85c0;
  animation: confettiFall 3s linear forwards;
  z-index: 100;
}

@keyframes confettiFall {
  0% {
    transform: translateY(-100vh) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* === 响应式设计 === */

/* 平板端 (769px - 1024px) */
@media (max-width: 1024px) {
  :root {
    --container-padding: 25px;
  }
  
  h1 {
    font-size: 1.8em;
  }
}

/* 移动端 (≤768px) */
@media (max-width: 768px) {
  :root {
    --container-padding: 15px;
    --container-radius: 20px;
    --button-radius: 20px;
  }
  
  body {
    padding: 10px;
    padding-top: 15px;
    align-items: flex-start;
  }
  
  .container {
    padding: var(--container-padding);
    max-width: 100%;
  }
  
  h1 {
    font-size: 1.5em;
    letter-spacing: 1px;
    margin-bottom: 12px;
  }
  
  #status {
    font-size: 1.1em;
    padding: 10px 15px;
    min-width: 140px;
    margin-bottom: 12px;
  }
  
  .controls-container {
    padding: 15px;
    margin-bottom: 12px;
  }
  
  .control-row {
    flex-direction: column;
    gap: 10px;
  }
  
  .control-group {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .game-area {
    padding: 10px;
    margin: 10px 0;
  }
  
  .action-buttons {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  .action-buttons button {
    flex: 1;
    min-width: 120px;
  }
  
  .info {
    padding: 12px;
    font-size: 0.85em;
    margin-top: 12px;
  }
  
  .info p {
    margin: 4px 0;
  }
  
  /* 移动端简化背景动效 */
  .sakura-petal,
  .star-point {
    display: none;
  }
}

/* iPhone 11 / 小屏手机 (≤375px) */
@media (max-width: 375px) {
  :root {
    --container-padding: 10px;
    --container-radius: 12px;
  }
  
  body {
    padding: 8px;
    padding-top: 12px;
  }
  
  .container {
    padding: var(--container-padding);
    max-width: 100%;
  }
  
  h1 {
    font-size: 1.3em;
    margin-bottom: 10px;
  }
  
  #status {
    font-size: 0.95em;
    padding: 8px 15px;
    min-width: 120px;
    margin-bottom: 10px;
  }
  
  .controls-container {
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 15px;
  }
  
  .control-row {
    flex-direction: column;
    gap: 8px;
  }
  
  .control-group {
    width: 100%;
    justify-content: center;
  }
  
  .control-group label {
    font-size: 13px;
  }
  
  .control-group select,
  .control-group button {
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 15px;
  }
  
  #mode-pvp,
  #mode-pve {
    flex: 1;
    min-width: 100px;
  }
  
  .game-area {
    padding: 8px;
    margin: 8px auto;
    border-radius: 10px;
  }
  
  .action-buttons {
    flex-direction: row;
    gap: 10px;
  }
  
  .action-buttons button {
    flex: 1;
    min-width: 100px;
    padding: 10px 15px;
    font-size: 14px;
    border-radius: 20px;
  }
}

/* 横屏模式优化 */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 10px;
    align-items: center;
  }
  
  .container {
    max-width: 95vw;
  }
  
  h1 {
    font-size: 1.3em;
    margin-bottom: 8px;
  }
  
  #status {
    font-size: 1em;
    padding: 6px 12px;
  }
  
  .controls-container {
    padding: 10px;
  }
  
  .game-area {
    padding: 8px;
  }
}

/* === 高 DPI 屏幕优化 === */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  #board {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* === 深色模式支持 === */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-gradient-start: #4a3759;
    --bg-gradient-end: #2d1f3d;
    --container-bg: #1a1a2e;
    --container-bg-alt: #252540;
    --text-primary: #e8dff5;
    --text-secondary: #c4b4d8;
    --text-hint: #a898b8;
    --info-bg: #16213e;
    --status-bg-start: #2d1f3d;
    --status-bg-end: #3d2a4d;
    --status-text: #e8dff5;
    --status-border: #7d5a94;
  }
  
  .container {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border-color: rgba(125, 90, 148, 0.3);
  }
  
  .controls-container {
    background: var(--container-bg-alt);
    border-color: rgba(125, 90, 148, 0.3);
  }
}

/* === 减少动效偏好 === */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .stone-drop,
  .win-line,
  #status.win-black,
  #status.win-white,
  #status.ai-thinking {
    animation: none;
  }
  
  .sakura-container,
  .star-container {
    display: none;
  }
}

/* === 打印样式 === */
@media print {
  body {
    background: white;
    padding: 0;
  }
  
  .container {
    box-shadow: none;
    padding: 0;
  }
  
  .controls,
  .info,
  .sakura-container,
  .star-container {
    display: none;
  }
  
  #status {
    background: none;
    color: black;
    border: 1px solid #ccc;
  }
}

/* === 无障碍增强 === */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 焦点可见性增强 */
:focus-visible {
  outline: 3px solid var(--btn-primary-start);
  outline-offset: 2px;
}

/* 高对比度模式 */
@media (forced-colors: active) {
  button {
    border: 2px solid currentColor;
  }
  
  #status {
    border: 2px solid currentColor;
  }
}

/* ===================================
   胜利特效样式
   =================================== */

/* 特效 Canvas 层 */
#effects-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* 胜利文字容器 - 备用方案 */
.victory-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9998;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  opacity: 0;
  animation: victoryFadeIn 0.5s ease-out forwards;
}

@keyframes victoryFadeIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.victory-main-text {
  font-size: 80px;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 
    0 0 20px rgba(255, 133, 192, 0.8),
    0 0 40px rgba(255, 133, 192, 0.6),
    0 0 60px rgba(255, 133, 192, 0.4);
  animation: victoryPulse 1s ease-in-out infinite;
  margin-bottom: 20px;
}

.victory-main-text.black-win {
  color: #2a2a2a;
  text-shadow: 
    0 0 20px rgba(42, 42, 42, 0.8),
    0 0 40px rgba(255, 255, 255, 0.6),
    0 0 60px rgba(255, 255, 255, 0.4);
}

.victory-main-text.white-win {
  color: #ffffff;
  text-shadow: 
    0 0 20px rgba(255, 255, 255, 0.8),
    0 0 40px rgba(168, 212, 255, 0.6),
    0 0 60px rgba(168, 212, 255, 0.4);
}

.victory-sub-text {
  font-size: 36px;
  color: #ff85c0;
  text-shadow: 
    0 0 15px rgba(255, 133, 192, 0.8),
    0 0 30px rgba(255, 133, 192, 0.6);
  animation: victoryFloat 2s ease-in-out infinite;
}

@keyframes victoryPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes victoryFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* 特效开关按钮 */
.effects-toggle {
  padding: 8px 16px;
  font-size: 0.85em;
  background: linear-gradient(135deg, #c9a8ff 0%, #a898ff 100%);
  box-shadow: 0 4px 12px rgba(201, 168, 255, 0.3);
}

.effects-toggle:hover {
  box-shadow: 0 6px 18px rgba(201, 168, 255, 0.5);
}

.effects-toggle.active {
  background: linear-gradient(135deg, #ffd700 0%, #ffc700 100%);
  box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
}

/* 移动端简化特效 */
@media (max-width: 768px) {
  .victory-main-text {
    font-size: 48px;
  }
  
  .victory-sub-text {
    font-size: 24px;
  }
}

@media (max-width: 375px) {
  .victory-main-text {
    font-size: 36px;
  }
  
  .victory-sub-text {
    font-size: 18px;
  }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  .victory-overlay,
  .victory-main-text,
  .victory-sub-text {
    animation: none;
  }
}
