/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #4a90e2 0%, #5c6bc0 100%);
  min-height: 100vh;
  color: #333;
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Header styles */
header {
  text-align: center;
  margin-bottom: 30px;
  color: white;
}

header h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.game-description {
  font-size: 1.1rem;
  opacity: 0.9;
  margin-bottom: 20px;
}

/* Game status area */
.game-status {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-bottom: 30px;
  background: rgba(38, 50, 56, 0.9);
  padding: 18px;
  border-radius: 10px;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-item {
  text-align: center;
}

.status-item .label {
  display: block;
  font-size: 1rem;
  color: #b0bec5;
  margin-bottom: 8px;
  font-weight: 500;
}

.status-item .value {
  font-size: 1.5rem;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.status-item .total {
  color: #90a4ae;
  font-size: 1.2rem;
}

/* Game board container */
.game-board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
}

/* Board controls */
.board-controls {
  margin-top: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Auto random container */
.auto-random-container {
  display: flex;
  align-items: center;
  margin-left: 10px;
}

.auto-random-container input[type='checkbox'] {
  margin-right: 5px;
}

/* 5x5 Game board grid */
.game-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 4px;
  background: #263238;
  padding: 12px;
  border-radius: 12px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
  width: 350px;
  height: 350px;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

/* Individual game board cells */
.game-cell {
  background: #eceff1;
  border: 2px solid #b0bec5;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  /* 無障礙改進 */
  outline: none;
  min-height: 44px; /* WCAG 最小觸控目標尺寸 */
  min-width: 44px;
}

/* 鍵盤焦點樣式 */
.game-cell:focus {
  outline: 3px solid #2196f3;
  outline-offset: 2px;
  z-index: 10;
}

/* 高對比度模式支持 */
@media (prefers-contrast: high) {
  .game-cell {
    border-width: 3px;
    border-color: #000;
  }

  .game-cell.player {
    background: #0000ff;
    border-color: #000;
  }

  .game-cell.computer {
    background: #ff0000;
    border-color: #000;
  }
}

/* Cell hover effect */
.game-cell:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  border-color: #90a4ae;
}

/* Empty cell state */
.game-cell.empty {
  background: #eceff1;
  border-color: #b0bec5;
}

.game-cell.empty:hover {
  background: #cfd8dc;
  border-color: #90a4ae;
}

/* Player selected cell state */
.game-cell.player {
  background: linear-gradient(135deg, #2196f3, #0d47a1);
  border-color: #0d47a1;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  box-shadow: 0 2px 5px rgba(13, 71, 161, 0.4);
}

.game-cell.player::before {
  content: 'P';
  font-size: 1.8rem;
  font-weight: bold;
}

/* Computer selected cell state */
.game-cell.computer {
  background: linear-gradient(135deg, #f44336, #b71c1c);
  border-color: #b71c1c;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  box-shadow: 0 2px 5px rgba(183, 28, 28, 0.4);
}

.game-cell.computer::before {
  content: 'C';
  font-size: 1.8rem;
  font-weight: bold;
}

/* Enhanced suggestion highlight with confidence levels - Improved */
.game-cell.suggested {
  border-width: 4px;
  animation: pulse-suggestion 1.5s infinite;
  position: relative;
  z-index: 5;
  transition: all 0.3s ease;
  transform-origin: center;
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
  overflow: visible;
}

/* Confidence-based suggestion colors with improved gradients */
.game-cell.suggested.confidence-very-high {
  background: radial-gradient(circle, #4caf50, #2e7d32) !important;
  border-color: #1b5e20;
  box-shadow:
    0 0 30px rgba(76, 175, 80, 0.9),
    inset 0 0 15px rgba(255, 255, 255, 0.4);
  animation: pulse-suggestion-very-high 1.5s infinite;
}

.game-cell.suggested.confidence-high {
  background: radial-gradient(circle, #2196f3, #1565c0) !important;
  border-color: #0d47a1;
  box-shadow:
    0 0 30px rgba(33, 150, 243, 0.9),
    inset 0 0 15px rgba(255, 255, 255, 0.4);
  animation: pulse-suggestion-high 1.5s infinite;
}

.game-cell.suggested.confidence-medium {
  background: radial-gradient(circle, #ff9800, #e65100) !important;
  border-color: #bf360c;
  box-shadow:
    0 0 30px rgba(255, 152, 0, 0.9),
    inset 0 0 15px rgba(255, 255, 255, 0.4);
  animation: pulse-suggestion-medium 1.5s infinite;
}

.game-cell.suggested.confidence-low {
  background: radial-gradient(circle, #f44336, #c62828) !important;
  border-color: #b71c1c;
  box-shadow:
    0 0 30px rgba(244, 67, 54, 0.9),
    inset 0 0 15px rgba(255, 255, 255, 0.4);
  animation: pulse-suggestion-low 1.5s infinite;
}

/* Default suggestion (fallback) with improved gradient */
.game-cell.suggested:not(.confidence-very-high):not(.confidence-high):not(
    .confidence-medium
  ):not(.confidence-low) {
  background: radial-gradient(circle, #ffeb3b, #ffc107) !important;
  border-color: #ff6f00;
  box-shadow:
    0 0 30px rgba(255, 193, 7, 0.9),
    inset 0 0 15px rgba(255, 255, 255, 0.4);
}

/* Enhanced pulse animations with confidence variations */
@keyframes pulse-suggestion {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.08);
    opacity: 0.9;
  }
}

@keyframes pulse-suggestion-very-high {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 0 30px rgba(76, 175, 80, 0.9),
      inset 0 0 15px rgba(255, 255, 255, 0.4);
  }
  50% {
    transform: scale(1.1);
    box-shadow:
      0 0 40px rgba(76, 175, 80, 1),
      inset 0 0 20px rgba(255, 255, 255, 0.6);
  }
}

@keyframes pulse-suggestion-high {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 0 30px rgba(33, 150, 243, 0.9),
      inset 0 0 15px rgba(255, 255, 255, 0.4);
  }
  50% {
    transform: scale(1.09);
    box-shadow:
      0 0 40px rgba(33, 150, 243, 1),
      inset 0 0 20px rgba(255, 255, 255, 0.6);
  }
}

@keyframes pulse-suggestion-medium {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 0 30px rgba(255, 152, 0, 0.9),
      inset 0 0 15px rgba(255, 255, 255, 0.4);
  }
  50% {
    transform: scale(1.08);
    box-shadow:
      0 0 40px rgba(255, 152, 0, 1),
      inset 0 0 20px rgba(255, 255, 255, 0.6);
  }
}

@keyframes pulse-suggestion-low {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 0 30px rgba(244, 67, 54, 0.9),
      inset 0 0 15px rgba(255, 255, 255, 0.4);
  }
  50% {
    transform: scale(1.07);
    box-shadow:
      0 0 40px rgba(244, 67, 54, 1),
      inset 0 0 20px rgba(255, 255, 255, 0.6);
  }
}

/* Alternative suggestion highlighting - Improved */
.game-cell.alternative-suggestion {
  border: 2px dashed #9e9e9e;
  position: relative;
  z-index: 3;
  overflow: visible;
}

.game-cell.alternative-suggestion[data-alt-rank='2'] {
  background: rgba(33, 150, 243, 0.15) !important;
  border-color: rgba(33, 150, 243, 0.5);
  animation: fade-alternative-2 2s infinite;
}

.game-cell.alternative-suggestion[data-alt-rank='3'] {
  background: rgba(255, 152, 0, 0.15) !important;
  border-color: rgba(255, 152, 0, 0.5);
  animation: fade-alternative-3 2s infinite;
}

.game-cell.alternative-suggestion[data-alt-rank='4'] {
  background: rgba(244, 67, 54, 0.15) !important;
  border-color: rgba(244, 67, 54, 0.5);
  animation: fade-alternative-4 2s infinite;
}

@keyframes fade-alternative-2 {
  0%,
  100% {
    opacity: 0.7;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
  }
  50% {
    opacity: 0.9;
    box-shadow: 0 0 15px rgba(33, 150, 243, 0.5);
  }
}

@keyframes fade-alternative-3 {
  0%,
  100% {
    opacity: 0.6;
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.3);
  }
  50% {
    opacity: 0.8;
    box-shadow: 0 0 12px rgba(255, 152, 0, 0.5);
  }
}

@keyframes fade-alternative-4 {
  0%,
  100% {
    opacity: 0.5;
    box-shadow: 0 0 6px rgba(244, 67, 54, 0.3);
  }
  50% {
    opacity: 0.7;
    box-shadow: 0 0 10px rgba(244, 67, 54, 0.5);
  }
}

/* Value indicator overlay - Improved */
.game-cell.suggested::after {
  content: attr(data-value);
  position: absolute;
  top: -10px;
  right: -10px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  font-size: 0.8rem;
  font-weight: bold;
  padding: 3px 8px;
  border-radius: 12px;
  min-width: 24px;
  text-align: center;
  z-index: 10;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  animation: value-appear 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Alternative suggestion value indicator */
.game-cell.alternative-suggestion::after {
  content: attr(data-alt-value);
  position: absolute;
  top: -8px;
  right: -8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  animation: alt-value-appear 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

@keyframes value-appear {
  0% {
    opacity: 0;
    transform: scale(0.5) translateY(10px);
  }
  70% {
    transform: scale(1.1) translateY(-2px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes alt-value-appear {
  0% {
    opacity: 0;
    transform: scale(0.5) translateY(5px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Confidence indicator icon - Improved */
.game-cell.suggested::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  z-index: 10;
  animation: confidence-pulse 1.2s infinite;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.game-cell.suggested.confidence-very-high::before {
  background: radial-gradient(circle, #4caf50, #1b5e20);
  box-shadow: 0 0 10px rgba(27, 94, 32, 0.8);
}

.game-cell.suggested.confidence-high::before {
  background: radial-gradient(circle, #2196f3, #0d47a1);
  box-shadow: 0 0 10px rgba(13, 71, 161, 0.8);
}

.game-cell.suggested.confidence-medium::before {
  background: radial-gradient(circle, #ff9800, #e65100);
  box-shadow: 0 0 10px rgba(230, 81, 0, 0.8);
}

.game-cell.suggested.confidence-low::before {
  background: radial-gradient(circle, #f44336, #b71c1c);
  box-shadow: 0 0 10px rgba(183, 28, 28, 0.8);
}

@keyframes confidence-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.3);
    opacity: 0.8;
  }
}

/* Rank indicator for alternative suggestions */
.game-cell.alternative-suggestion::before {
  content: attr(data-alt-rank);
  position: absolute;
  top: 4px;
  left: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 0.7rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Line completion highlight */
.game-cell.line-completed {
  animation: line-flash 2s ease-in-out;
}

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

/* 統一的連線顯示方式 - 使用多重背景圖像 */
.game-cell.line-completed {
  position: relative;
  z-index: 5;
  box-shadow: 0 0 15px rgba(76, 175, 80, 0.8);
}

/* 基本線條樣式 - 所有線條都使用相同的綠色 */
.game-cell.horizontal-line,
.game-cell.vertical-line,
.game-cell.diagonal-line,
.game-cell.anti-diagonal-line {
  background-repeat: no-repeat;
  background-position: center center;
  position: relative;
}

/* 為連線添加偽元素覆蓋層，確保在所有背景之上顯示 */
.game-cell.line-completed::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 1;
}

/* 水平線 */
.game-cell.line-completed.horizontal-line::after {
  background-image: linear-gradient(
    to right,
    transparent 10%,
    #4caf50 10%,
    #4caf50 90%,
    transparent 90%
  ) !important;
  background-size: 100% 6px !important;
  background-repeat: no-repeat !important;
  background-position: center center !important;
}

/* 垂直線 */
.game-cell.line-completed.vertical-line::after {
  background-image: linear-gradient(
    to bottom,
    transparent 10%,
    #4caf50 10%,
    #4caf50 90%,
    transparent 90%
  ) !important;
  background-size: 6px 100% !important;
  background-repeat: no-repeat !important;
  background-position: center center !important;
}

/* 主對角線（左上到右下）*/
.game-cell.line-completed.diagonal-line::after {
  background-image: linear-gradient(
    45deg,
    transparent 47%,
    #4caf50 47%,
    #4caf50 53%,
    transparent 53%
  ) !important;
  background-repeat: no-repeat !important;
  background-position: center center !important;
}

/* 反對角線（右上到左下）*/
.game-cell.line-completed.anti-diagonal-line::after {
  background-image: linear-gradient(
    -45deg,
    transparent 47%,
    #4caf50 47%,
    #4caf50 53%,
    transparent 53%
  ) !important;
  background-repeat: no-repeat !important;
  background-position: center center !important;
}

/* 水平線 + 垂直線 = 十字 */
.game-cell.horizontal-line.vertical-line::after {
  background-image:
    linear-gradient(
      to right,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      to bottom,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    );
  background-size:
    100% 6px,
    6px 100%;
  background-repeat: no-repeat, no-repeat;
  background-position:
    center center,
    center center;
}

/* 水平線 + 主對角線 */
.game-cell.horizontal-line.diagonal-line {
  background-image:
    linear-gradient(
      to right,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    100% 6px,
    100% 100%;
}

/* 水平線 + 反對角線 */
.game-cell.horizontal-line.anti-diagonal-line {
  background-image:
    linear-gradient(
      to right,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      -45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    100% 6px,
    100% 100%;
}

/* 垂直線 + 主對角線 */
.game-cell.vertical-line.diagonal-line {
  background-image:
    linear-gradient(
      to bottom,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    6px 100%,
    100% 100%;
}

/* 垂直線 + 反對角線 */
.game-cell.vertical-line.anti-diagonal-line {
  background-image:
    linear-gradient(
      to bottom,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      -45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    6px 100%,
    100% 100%;
}

/* 主對角線 + 反對角線 = X */
.game-cell.diagonal-line.anti-diagonal-line {
  background-image:
    linear-gradient(
      45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    ),
    linear-gradient(
      -45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
}

/* 水平線 + 垂直線 + 主對角線 */
.game-cell.horizontal-line.vertical-line.diagonal-line {
  background-image:
    linear-gradient(
      to right,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      to bottom,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    100% 6px,
    6px 100%,
    100% 100%;
}

/* 水平線 + 垂直線 + 反對角線 */
.game-cell.horizontal-line.vertical-line.anti-diagonal-line {
  background-image:
    linear-gradient(
      to right,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      to bottom,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      -45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    100% 6px,
    6px 100%,
    100% 100%;
}

/* 水平線 + 主對角線 + 反對角線 */
.game-cell.horizontal-line.diagonal-line.anti-diagonal-line {
  background-image:
    linear-gradient(
      to right,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    ),
    linear-gradient(
      -45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    100% 6px,
    100% 100%,
    100% 100%;
}

/* 垂直線 + 主對角線 + 反對角線 */
.game-cell.vertical-line.diagonal-line.anti-diagonal-line {
  background-image:
    linear-gradient(
      to bottom,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    ),
    linear-gradient(
      -45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    6px 100%,
    100% 100%,
    100% 100%;
}

/* 所有四種線條 */
.game-cell.horizontal-line.vertical-line.diagonal-line.anti-diagonal-line {
  background-image:
    linear-gradient(
      to right,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      to bottom,
      transparent 10%,
      #4caf50 10%,
      #4caf50 90%,
      transparent 90%
    ),
    linear-gradient(
      45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    ),
    linear-gradient(
      -45deg,
      transparent 47%,
      #4caf50 47%,
      #4caf50 53%,
      transparent 53%
    );
  background-size:
    100% 6px,
    6px 100%,
    100% 100%,
    100% 100%;
}

/* 鍵盤焦點樣式 */
.game-cell.keyboard-focus {
  outline: 3px solid #ffd700;
  outline-offset: 2px;
  z-index: 15;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* 減少動畫偏好支持 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .game-cell {
    transition: none;
  }

  .game-cell.suggested {
    animation: none;
  }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #e0e0e0;
  }

  .game-cell.empty {
    background: #2d2d2d;
    border-color: #555;
    color: #e0e0e0;
  }

  .control-panel,
  .instructions {
    background: rgba(45, 45, 45, 0.95);
    color: #e0e0e0;
  }

  .suggestion-display {
    background: linear-gradient(to right, #2d3748, #4a5568);
    color: #e0e0e0;
  }
}

/* 強制深色模式類別 */
.dark-mode {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #e0e0e0;
}

.dark-mode .game-cell.empty {
  background: #2d2d2d;
  border-color: #555;
  color: #e0e0e0;
}

.dark-mode .control-panel,
.dark-mode .instructions {
  background: rgba(45, 45, 45, 0.95);
  color: #e0e0e0;
}

/* 高對比度模式類別 */
.high-contrast .game-cell {
  border-width: 3px;
}

.high-contrast .game-cell.player {
  background: #0000ff !important;
  color: #ffffff !important;
}

.high-contrast .game-cell.computer {
  background: #ff0000 !important;
  color: #ffffff !important;
}

/* 減少動畫類別 */
.reduce-motion * {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* 螢幕閱讀器專用樣式 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 跳過連結 */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  z-index: 1000;
  border-radius: 4px;
}

.skip-link:focus {
  top: 6px;
}

/* 改善焦點可見性 */
*:focus {
  outline: 2px solid #4a90e2;
  outline-offset: 2px;
}

/* 確保文字對比度符合 WCAG AA 標準 */
.game-description {
  color: #ffffff;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

/* 錯誤和警告訊息的高對比度 */
.error-message {
  color: #d32f2f;
  font-weight: 600;
}

.warning-message {
  color: #f57c00;
  font-weight: 600;
}

.success-message {
  color: #388e3c;
  font-weight: 600;
}

/* 確保按鈕在所有狀態下都有足夠的對比度 */
button:disabled {
  background: #bdbdbd !important;
  color: #757575 !important;
  border-color: #9e9e9e !important;
}

/* 改善表單元素的可訪問性 */
input[type='checkbox'] {
  width: 18px;
  height: 18px;
  margin-right: 8px;
}

label {
  cursor: pointer;
  user-select: none;
}

/* 確保載入狀態對螢幕閱讀器友好 */
.loading::after {
  content: '載入中...';
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* 性能模式樣式 */
.performance-mode * {
  animation-duration: 0.1s !important;
  transition-duration: 0.1s !important;
}

.performance-mode .game-cell {
  transition: none !important;
  animation: none !important;
}

.performance-mode .suggested {
  animation-duration: 0.5s !important;
}

/* 優化渲染樣式 */
.optimized-rendering .game-cell {
  contain: layout style paint;
  will-change: transform;
}

.optimized-rendering .suggestion-display {
  contain: layout style;
}

/* 觸控優化 */
.game-cell {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;
}

/* 增強的載入狀態 */
.global-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(74, 144, 226, 0.95) 0%,
    rgba(92, 107, 192, 0.95) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(10px);
}

.global-loading.hidden {
  display: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid #ffffff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

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

.loading-text {
  color: white;
  font-size: 1.1rem;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* 增強的錯誤通知樣式 */
.error-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  background: linear-gradient(135deg, #ff4444, #cc3333);
  color: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.3),
    0 4px 8px rgba(255, 68, 68, 0.2);
  z-index: 10000;
  max-width: 420px;
  min-width: 300px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  animation: slideInFromRight 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideInFromRight {
  0% {
    transform: translateX(100%);
    opacity: 0;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

/* 無障礙控制面板 */
.accessibility-controls {
  position: fixed;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 8px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.9);
  padding: 8px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.accessibility-btn {
  padding: 6px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  color: #333;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.accessibility-btn:hover {
  background: #f0f0f0;
  border-color: #bbb;
}

.accessibility-btn[aria-pressed='true'] {
  background: #4a90e2;
  color: white;
  border-color: #4a90e2;
}

/* 跳過連結樣式 */
.skip-links {
  position: absolute;
  top: -40px;
  left: 6px;
  z-index: 1000;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  z-index: 1000;
  border-radius: 4px;
  font-size: 0.9rem;
}

.skip-link:focus {
  top: 6px;
}

/* 鍵盤快捷鍵模態框 */
.keyboard-shortcuts-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
}

.keyboard-shortcuts-modal .modal-content {
  background: white;
  padding: 30px;
  border-radius: 12px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}

.shortcuts-list {
  margin: 20px 0;
}

.shortcut-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

.shortcut-item:last-child {
  border-bottom: none;
}

.shortcut-item kbd {
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 4px 8px;
  font-family: monospace;
  font-size: 0.9rem;
  min-width: 80px;
  text-align: center;
}

.shortcut-item span {
  flex: 1;
  color: #555;
}

.modal-close-btn {
  background: #4a90e2;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  margin-top: 20px;
}

.modal-close-btn:hover {
  background: #357abd;
}

/* 語音控制 */
.voice-controls {
  margin-left: 8px;
}

/* 增強的建議顯示 - 基礎樣式已在 suggestion-enhancements.js 中定義 */

/* 響應式無障礙改進 */
@media (max-width: 768px) {
  .accessibility-controls {
    position: relative;
    top: auto;
    left: auto;
    margin-bottom: 10px;
    justify-content: center;
  }

  .skip-links {
    display: none; /* 在移動設備上隱藏跳過連結 */
  }

  .error-notification {
    left: 10px;
    right: 10px;
    max-width: none;
    min-width: auto;
  }
}

/* 打印樣式 */
@media print {
  .accessibility-controls,
  .skip-links,
  .error-notification,
  .global-loading {
    display: none !important;
  }

  .game-board {
    break-inside: avoid;
  }
}

/* 調試面板樣式 */
.debug-panel {
  background: rgba(255, 235, 59, 0.1);
  border: 2px solid #ffc107;
  border-radius: 8px;
  padding: 15px;
  margin-top: 20px;
  position: relative;
}

.debug-panel h3 {
  color: #f57c00;
  margin-bottom: 15px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.debug-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 15px;
}

.debug-btn {
  background: #ff9800;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background-color 0.2s ease;
}

.debug-btn:hover {
  background: #f57c00;
}

.debug-btn:active {
  background: #e65100;
}

.debug-info {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 4px;
  padding: 10px;
  font-size: 0.9rem;
  color: #333;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid #ffe0b2;
}

.debug-info p {
  margin: 5px 0;
  line-height: 1.4;
}

.debug-info .debug-success {
  color: #2e7d32;
  font-weight: bold;
}

.debug-info .debug-error {
  color: #c62828;
  font-weight: bold;
}

.debug-info .debug-warning {
  color: #f57c00;
  font-weight: bold;
}

/* 調試模式下的特殊樣式 */
.debug-mode .game-cell {
  position: relative;
}

.debug-mode .game-cell::before {
  content: attr(data-row) ',' attr(data-col);
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 0.6rem;
  color: rgba(0, 0, 0, 0.5);
  background: rgba(255, 255, 255, 0.8);
  padding: 1px 3px;
  border-radius: 2px;
  z-index: 10;
}

/* 調試提示樣式 */
.debug-hint {
  background: rgba(255, 193, 7, 0.1);
  border: 1px solid #ffc107;
  border-radius: 6px;
  padding: 8px 12px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: #f57c00;
  text-align: center;
}

.debug-hint kbd {
  background: #333;
  color: white;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.8rem;
  font-family: monospace;
}

.debug-hint code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.8rem;
}

/* Control panel */
.control-panel {
  background: rgba(255, 255, 255, 0.95);
  padding: 25px;
  border-radius: 10px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
  margin-bottom: 20px;
  border: 1px solid rgba(207, 216, 220, 0.5);
}

.control-panel h3 {
  color: #1565c0;
  margin-bottom: 15px;
  font-size: 1.3rem;
  border-bottom: 2px solid #e3f2fd;
  padding-bottom: 8px;
}

/* Enhanced suggestion area - Improved */
.suggestion-area {
  margin-bottom: 25px;
  position: relative;
}

.suggestion-display {
  background: linear-gradient(to right, #e3f2fd, #bbdefb);
  padding: 22px;
  border-radius: 12px;
  font-size: 1.1rem;
  box-shadow: 0 6px 12px rgba(33, 150, 243, 0.2);
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1px solid rgba(33, 150, 243, 0.3);
}

.suggestion-display::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #2196f3, #42a5f5, #2196f3);
  background-size: 200% 100%;
  animation: suggestion-loading 2s linear infinite;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.suggestion-display.loading::before {
  opacity: 1;
}

/* Confidence-based suggestion display styling */
.suggestion-display.confidence-very-high {
  background: linear-gradient(to right, #e8f5e9, #c8e6c9);
  border-left: 6px solid #4caf50;
  border-color: rgba(76, 175, 80, 0.3);
  box-shadow: 0 6px 12px rgba(76, 175, 80, 0.2);
}

.suggestion-display.confidence-high {
  background: linear-gradient(to right, #e3f2fd, #bbdefb);
  border-left: 6px solid #2196f3;
  border-color: rgba(33, 150, 243, 0.3);
  box-shadow: 0 6px 12px rgba(33, 150, 243, 0.2);
}

.suggestion-display.confidence-medium {
  background: linear-gradient(to right, #fff3e0, #ffe0b2);
  border-left: 6px solid #ff9800;
  border-color: rgba(255, 152, 0, 0.3);
  box-shadow: 0 6px 12px rgba(255, 152, 0, 0.2);
}

.suggestion-display.confidence-low {
  background: linear-gradient(to right, #ffebee, #ffcdd2);
  border-left: 6px solid #f44336;
  border-color: rgba(244, 67, 54, 0.3);
  box-shadow: 0 6px 12px rgba(244, 67, 54, 0.2);
}

@keyframes suggestion-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

#suggestion-text {
  color: #0d47a1;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.suggestion-display.confidence-very-high #suggestion-text {
  color: #2e7d32;
}

.suggestion-display.confidence-high #suggestion-text {
  color: #0d47a1;
}

.suggestion-display.confidence-medium #suggestion-text {
  color: #e65100;
}

.suggestion-display.confidence-low #suggestion-text {
  color: #c62828;
}

/* Confidence indicator in suggestion text - Improved */
.confidence-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 8px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: bold;
  text-transform: uppercase;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  animation: confidence-indicator-pulse 2s infinite;
}

.confidence-indicator.very-high {
  background: linear-gradient(
    to right,
    rgba(76, 175, 80, 0.2),
    rgba(76, 175, 80, 0.3)
  );
  color: #2e7d32;
  border: 1px solid rgba(76, 175, 80, 0.4);
}

.confidence-indicator.high {
  background: linear-gradient(
    to right,
    rgba(33, 150, 243, 0.2),
    rgba(33, 150, 243, 0.3)
  );
  color: #1565c0;
  border: 1px solid rgba(33, 150, 243, 0.4);
}

.confidence-indicator.medium {
  background: linear-gradient(
    to right,
    rgba(255, 152, 0, 0.2),
    rgba(255, 152, 0, 0.3)
  );
  color: #e65100;
  border: 1px solid rgba(255, 152, 0, 0.4);
}

.confidence-indicator.low {
  background: linear-gradient(
    to right,
    rgba(244, 67, 54, 0.2),
    rgba(244, 67, 54, 0.3)
  );
  color: #c62828;
  border: 1px solid rgba(244, 67, 54, 0.4);
}

@keyframes confidence-indicator-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.03);
  }
}

/* Value explanation - Improved */
.value-explanation {
  font-size: 0.95rem;
  color: #37474f;
  margin-top: 12px;
  padding: 12px 15px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  border-left: 4px solid #42a5f5;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  position: relative;
  animation: value-explanation-appear 0.5s ease-out;
}

.suggestion-display.confidence-very-high .value-explanation {
  border-left: 4px solid #4caf50;
}

.suggestion-display.confidence-medium .value-explanation {
  border-left: 4px solid #ff9800;
}

.suggestion-display.confidence-low .value-explanation {
  border-left: 4px solid #f44336;
}

@keyframes value-explanation-appear {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Value highlight */
.value-highlight {
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 4px;
  margin: 0 2px;
  display: inline-block;
}

.value-highlight.very-high {
  background-color: rgba(76, 175, 80, 0.2);
  color: #2e7d32;
}

.value-highlight.high {
  background-color: rgba(33, 150, 243, 0.2);
  color: #1565c0;
}

.value-highlight.medium {
  background-color: rgba(255, 152, 0, 0.2);
  color: #e65100;
}

.value-highlight.low {
  background-color: rgba(244, 67, 54, 0.2);
  color: #c62828;
}

/* Alternative suggestions display - Improved */
.alternatives-container {
  margin-top: 18px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  border: 1px solid rgba(33, 150, 243, 0.2);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
  animation: alternatives-appear 0.6s ease-out;
}

@keyframes alternatives-appear {
  0% {
    opacity: 0;
    transform: translateY(15px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.alternatives-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1565c0;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(33, 150, 243, 0.1);
}

.alternatives-title::before {
  content: '💡';
  font-size: 0.9rem;
}

.alternatives-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.alternative-item {
  background: rgba(158, 158, 158, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  color: #455a64;
  border: 1px solid rgba(158, 158, 158, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.alternative-item:hover {
  background: rgba(33, 150, 243, 0.1);
  border-color: rgba(33, 150, 243, 0.4);
  color: #1565c0;
  transform: translateY(-2px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
}

.alternative-item:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.alternative-item::before {
  content: attr(data-rank);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: bold;
}

.alternative-item[data-rank='2']::before {
  background: rgba(33, 150, 243, 0.2);
  color: #1565c0;
}

.alternative-item[data-rank='3']::before {
  background: rgba(255, 152, 0, 0.2);
  color: #e65100;
}

.alternative-item[data-rank='4']::before {
  background: rgba(244, 67, 54, 0.2);
  color: #c62828;
}

.alternative-value {
  font-weight: bold;
  margin-left: 3px;
}

/* Suggestion animation effects - Improved */
.suggestion-appear {
  animation: suggestion-slide-in 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes suggestion-slide-in {
  0% {
    opacity: 0;
    transform: translateY(-15px) scale(0.95);
  }
  70% {
    transform: translateY(5px) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.suggestion-update {
  animation: suggestion-update-flash 0.6s ease-out;
}

@keyframes suggestion-update-flash {
  0% {
    box-shadow: 0 0 30px rgba(33, 150, 243, 0.6);
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 6px 12px rgba(33, 150, 243, 0.2);
    transform: scale(1);
  }
}

/* Confidence-specific update animations */
.suggestion-display.confidence-very-high.suggestion-update {
  animation: suggestion-update-flash-very-high 0.6s ease-out;
}

.suggestion-display.confidence-medium.suggestion-update {
  animation: suggestion-update-flash-medium 0.6s ease-out;
}

.suggestion-display.confidence-low.suggestion-update {
  animation: suggestion-update-flash-low 0.6s ease-out;
}

@keyframes suggestion-update-flash-very-high {
  0% {
    box-shadow: 0 0 30px rgba(76, 175, 80, 0.6);
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 6px 12px rgba(76, 175, 80, 0.2);
    transform: scale(1);
  }
}

@keyframes suggestion-update-flash-medium {
  0% {
    box-shadow: 0 0 30px rgba(255, 152, 0, 0.6);
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 6px 12px rgba(255, 152, 0, 0.2);
    transform: scale(1);
  }
}

@keyframes suggestion-update-flash-low {
  0% {
    box-shadow: 0 0 30px rgba(244, 67, 54, 0.6);
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 6px 12px rgba(244, 67, 54, 0.2);
    transform: scale(1);
  }
}

/* Computer input area */
.input-area {
  margin-bottom: 25px;
}

.computer-input {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.computer-input label {
  font-weight: 500;
  color: #2c3e50;
}

.computer-input input {
  width: 60px;
  padding: 8px;
  border: 2px solid #bdc3c7;
  border-radius: 5px;
  text-align: center;
  font-size: 1rem;
}

.computer-input input:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

.computer-input input:disabled {
  background: #ecf0f1;
  color: #7f8c8d;
}

/* Buttons */
button {
  padding: 14px 28px;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  letter-spacing: 0.5px;

  /* 無障礙改進 */
  min-height: 44px; /* WCAG 最小觸控目標尺寸 */
  outline: none;
}

/* 鍵盤焦點樣式 */
button:focus {
  outline: 3px solid #ffd700;
  outline-offset: 2px;
}

/* 高對比度模式支持 */
@media (prefers-contrast: high) {
  button {
    border: 2px solid #000;
  }

  .primary-btn {
    background: #0000ff;
    color: #ffffff;
  }

  .secondary-btn {
    background: #808080;
    color: #ffffff;
  }
}

.primary-btn {
  background: linear-gradient(135deg, #2196f3, #1976d2);
  color: white;
  border: 1px solid #1565c0;
}

.primary-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #1976d2, #0d47a1);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.secondary-btn {
  background: linear-gradient(135deg, #78909c, #546e7a);
  color: white;
  border: 1px solid #455a64;
}

.secondary-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #546e7a, #37474f);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

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

/* Instructions area */
.instructions {
  background: rgba(255, 255, 255, 0.95);
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
  margin-bottom: 20px;
  border: 1px solid rgba(207, 216, 220, 0.5);
}

.instructions h3 {
  color: #1565c0;
  margin-bottom: 12px;
  font-size: 1.3rem;
  border-bottom: 2px solid #e3f2fd;
  padding-bottom: 8px;
}

.instruction-text {
  color: #37474f;
  font-size: 1.1rem;
  line-height: 1.6;
  background: #f5f5f5;
  padding: 15px;
  border-radius: 8px;
  border-left: 4px solid #42a5f5;
}

/* Game results panel */
.hidden {
  display: none !important;
}

.result-panel {
  background: #e3f2fd;
  padding: 20px;
  border-radius: 10px;
  border-left: 6px solid #2196f3;
  margin-bottom: 20px;
  text-align: center;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.result-panel h3 {
  color: #1565c0;
  margin-bottom: 15px;
  font-size: 1.5rem;
  border-bottom: 2px solid #bbdefb;
  padding-bottom: 8px;
}

.final-stats {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
  padding: 15px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.stat-item {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: bold;
  color: #1565c0;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  color: #2c3e50;
}

.completed-lines-display {
  margin-bottom: 25px;
}

.completed-lines-display h3 {
  color: #2c3e50;
  margin-bottom: 15px;
}

.lines-list {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.line-item {
  background: #e9ecef;
  padding: 8px 12px;
  border-radius: 5px;
  font-size: 0.9rem;
  color: #495057;
  display: flex;
  align-items: center;
  gap: 8px;
}

.line-type-header {
  background: #3498db;
  color: white;
  padding: 10px 15px;
  border-radius: 8px;
  font-weight: bold;
  margin: 10px 0 5px 0;
  font-size: 1rem;
}

.line-number {
  font-weight: bold;
  color: #2c3e50;
  min-width: 20px;
}

.line-cells {
  color: #495057;
}

.lines-summary {
  margin-top: 15px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid #27ae60;
}

.summary-item {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.summary-item:last-child {
  margin-bottom: 0;
}

.line-item.no-lines {
  background: #fff3cd;
  border: 1px solid #ffeaa7;
  padding: 20px;
  text-align: center;
}

.no-lines-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.no-lines-icon {
  font-size: 2rem;
}

.no-lines-text {
  font-weight: bold;
  color: #856404;
  font-size: 1.1rem;
}

.no-lines-tip {
  color: #856404;
  font-size: 0.9rem;
  font-style: italic;
}

/* Game Analysis Styles */
.game-analysis {
  margin: 20px 0;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 10px;
  border-left: 4px solid #3498db;
}

.game-analysis h3 {
  color: #2c3e50;
  margin-bottom: 15px;
  font-size: 1.2rem;
}

.analysis-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.analysis-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #e9ecef;
}

.analysis-item:last-child {
  border-bottom: none;
}

.analysis-label {
  font-weight: 500;
  color: #495057;
  min-width: 100px;
}

.analysis-value {
  font-weight: bold;
  text-align: right;
}

/* Grade-based colors for cooperation score */
.analysis-value.a\+ {
  color: #27ae60;
}

.analysis-value.a {
  color: #2ecc71;
}

.analysis-value.b {
  color: #f39c12;
}

.analysis-value.c {
  color: #e67e22;
}

.analysis-value.d {
  color: #e74c3c;
}

.analysis-value.f {
  color: #c0392b;
}

/* Responsive design */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  header h1 {
    font-size: 2rem;
  }

  .game-status {
    flex-direction: column;
    gap: 15px;
    text-align: center;
  }

  .game-board {
    width: 300px;
    height: 300px;
  }

  .game-cell {
    font-size: 1rem;
  }

  .game-cell.player::before,
  .game-cell.computer::before {
    font-size: 1.2rem;
  }

  .control-panel {
    padding: 20px;
  }

  .computer-input {
    justify-content: center;
  }

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

  .final-stats {
    flex-direction: column;
    gap: 15px;
  }

  .results-content {
    padding: 30px 20px;
  }
}

@media (max-width: 480px) {
  .game-board {
    width: 250px;
    height: 250px;
    gap: 2px;
    padding: 8px;
  }

  .game-cell {
    font-size: 0.9rem;
    border-radius: 5px;
  }

  .game-cell.player::before,
  .game-cell.computer::before {
    font-size: 1rem;
  }

  .computer-input {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .computer-input input {
    width: 80px;
  }

  button {
    padding: 10px 20px;
    font-size: 0.9rem;
  }
}

/* Mobile Touch Optimization Styles */
.touch-device .touch-optimized {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.touch-active {
  transform: scale(0.95);
  opacity: 0.8;
  transition:
    transform 0.1s ease,
    opacity 0.1s ease;
}

.touch-feedback {
  animation: touchPulse 0.3s ease-out;
}

@keyframes touchPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(52, 152, 219, 0.7);
  }
  70% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(52, 152, 219, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(52, 152, 219, 0);
  }
}

/* Enhanced touch targets for mobile */
.touch-device .game-cell {
  min-width: 50px;
  min-height: 50px;
  margin: 2px;
  position: relative;
}

.touch-device .game-cell::after {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
  z-index: -1;
}

.touch-device button {
  min-height: 44px;
  padding: 12px 20px;
  font-size: 16px; /* 防止 iOS 縮放 */
}

.touch-device .algorithm-option {
  min-height: 60px;
  padding: 16px;
  margin: 4px 0;
}

/* Mobile gesture feedback */
.swipe-feedback {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 12px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.swipe-feedback.show {
  opacity: 1;
}

.swipe-feedback.swipe-left::before {
  content: '← ';
}

.swipe-feedback.swipe-right::before {
  content: '→ ';
}

.swipe-feedback.swipe-up::before {
  content: '↑ ';
}

.swipe-feedback.swipe-down::before {
  content: '↓ ';
}

/* Mobile stats panel */
.mobile-stats-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  min-width: 200px;
}

.mobile-stats-panel.show {
  transform: translateX(0);
}

.mobile-stats-panel h3 {
  margin: 0 0 12px 0;
  color: #2c3e50;
  font-size: 16px;
}

.mobile-stats-panel .stat-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
}

.mobile-stats-panel .label {
  color: #666;
}

.mobile-stats-panel .value {
  font-weight: bold;
  color: #2c3e50;
}

/* Cell info tooltip */
.cell-info-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  z-index: 10000;
  opacity: 0;
  transform: translateX(-50%) translateY(-100%);
  transition: opacity 0.3s ease;
  pointer-events: none;
  max-width: 200px;
}

.cell-info-tooltip.show {
  opacity: 1;
}

.cell-info-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.9);
}

/* Performance optimization for mobile */
.touch-device .game-board {
  will-change: transform;
  transform: translateZ(0);
}

.touch-device .game-cell,
.touch-device button,
.touch-device .algorithm-option {
  will-change: transform, opacity;
  backface-visibility: hidden;
}

/* Reduce animations on low performance */
.reduce-animations * {
  animation-duration: 0.1s !important;
  transition-duration: 0.1s !important;
}

/* PWA Install Banner */
.pwa-install-banner {
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 10000;
  max-width: 400px;
  margin: 0 auto;
}

.pwa-install-banner.show {
  transform: translateY(0);
}

.install-content {
  display: flex;
  align-items: center;
  padding: 16px;
  gap: 12px;
}

.install-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.install-text {
  flex: 1;
}

.install-text h3 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 600;
}

.install-text p {
  margin: 0;
  font-size: 14px;
  opacity: 0.9;
}

.install-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.install-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.install-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.dismiss-btn {
  background: transparent;
  border: none;
  color: white;
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.dismiss-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* PWA Update Banner */
.pwa-update-banner {
  position: fixed;
  top: 20px;
  left: 20px;
  right: 20px;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transform: translateY(-100%);
  transition: transform 0.3s ease;
  z-index: 10000;
  max-width: 400px;
  margin: 0 auto;
}

.pwa-update-banner.show {
  transform: translateY(0);
}

.update-content {
  display: flex;
  align-items: center;
  padding: 16px;
  gap: 12px;
}

.update-icon {
  font-size: 24px;
  flex-shrink: 0;
  animation: rotate 2s linear infinite;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.update-text {
  flex: 1;
}

.update-text h3 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 600;
}

.update-text p {
  margin: 0;
  font-size: 14px;
  opacity: 0.9;
}

.update-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.update-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.update-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* PWA Success Message */
.pwa-success-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 10000;
  min-width: 280px;
}

.pwa-success-message.show {
  opacity: 1;
}

.success-content {
  display: flex;
  align-items: center;
  padding: 20px;
  gap: 16px;
}

.success-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.success-text h3 {
  margin: 0 0 4px 0;
  font-size: 18px;
  font-weight: 600;
}

.success-text p {
  margin: 0;
  font-size: 14px;
  opacity: 0.9;
}

/* Connection Status Banner */
.connection-status {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
  z-index: 10000;
}

.connection-status.show {
  transform: translateY(0);
}

.connection-status.offline {
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
  color: white;
}

.connection-status.online {
  background: linear-gradient(135deg, #51cf66 0%, #40c057 100%);
  color: white;
}

.status-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.status-icon {
  font-size: 16px;
}

/* Floating Install Button */
.floating-install-btn {
  position: fixed;
  bottom: 80px;
  right: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
  z-index: 1000;
}

.floating-install-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.floating-install-btn:active {
  transform: translateY(0);
}

/* PWA Installed State */
.pwa-installed .floating-install-btn {
  display: none !important;
}

.pwa-installed .pwa-install-banner {
  display: none !important;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Input validation and error handling styles */
.input-error {
  border-color: #e74c3c !important;
  background-color: #fdf2f2 !important;
  box-shadow: 0 0 5px rgba(231, 76, 60, 0.3) !important;
}

.input-error-container {
  margin-top: 10px;
  padding: 10px;
  background: #fdf2f2;
  border: 1px solid #e74c3c;
  border-radius: 5px;
  display: none;
}

.input-error-message {
  color: #c0392b;
  font-size: 0.9rem;
  margin-bottom: 5px;
}

.input-error-message:last-child {
  margin-bottom: 0;
}

/* Success message styles */
.success-message {
  margin-top: 15px;
  padding: 12px;
  background: #d5f4e6;
  border: 1px solid #27ae60;
  border-radius: 5px;
  color: #1e8449;
  font-size: 0.95rem;
  display: none;
  animation: fadeInSuccess 0.3s ease-in;
}

@keyframes fadeInSuccess {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Enhanced error modal styles */
.error-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.error-content {
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 400px;
  width: 90%;
  border-left: 5px solid #e74c3c;
}

.error-message {
  color: #c0392b;
  font-size: 1.1rem;
  margin-bottom: 20px;
  line-height: 1.4;
}

.error-close-btn {
  background: #e74c3c;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s ease;
}

.error-close-btn:hover {
  background: #c0392b;
}

/* Input focus and interaction improvements */
.computer-input input:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 8px rgba(52, 152, 219, 0.4);
  background-color: #ffffff;
}

.computer-input input:invalid {
  border-color: #e67e22;
  background-color: #fef9e7;
}

/* Enhanced button states */
#confirm-computer-move {
  background: linear-gradient(135deg, #27ae60, #229954);
  color: white;
  margin-left: 10px;
  transition: all 0.3s ease;
}

#confirm-computer-move:hover:not(:disabled) {
  background: linear-gradient(135deg, #229954, #1e8449);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#confirm-computer-move:disabled {
  background: #bdc3c7;
  color: #7f8c8d;
}

/* Loading state for buttons */
.button-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.button-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  border-top-color: transparent;
  animation: button-spin 1s linear infinite;
}

@keyframes button-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Loading overlay for game board */
.game-board-loading {
  position: relative;
  pointer-events: none;
}

.game-board-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  z-index: 10;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.3s ease-in;
}

.game-board-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 4px solid #3498db;
  border-radius: 50%;
  border-top-color: transparent;
  animation: board-spin 1s linear infinite;
  z-index: 11;
}

@keyframes board-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Global loading overlay */
.global-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(102, 126, 234, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(5px);
  animation: fadeIn 0.3s ease-in;
}

.global-loading.hidden {
  display: none;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 6px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

.loading-text {
  color: white;
  font-size: 1.2rem;
  font-weight: 500;
  text-align: center;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* Skeleton loading for components */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1rem;
  border-radius: 4px;
  margin-bottom: 8px;
}

.skeleton-text.large {
  height: 1.5rem;
}

.skeleton-text.small {
  height: 0.8rem;
  width: 60%;
}

/* Progressive loading states */
.component-loading {
  opacity: 0.6;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.component-loaded {
  opacity: 1;
  animation: slideInUp 0.4s ease-out;
}

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

/* Smooth transitions for game state changes */
.game-status {
  transition: all 0.3s ease;
}

.status-item .value {
  transition: all 0.2s ease;
}

.status-item .value.updating {
  transform: scale(1.1);
  color: #3498db;
}

/* Enhanced cell animations */
.game-cell {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform, background-color, box-shadow;
}

.game-cell.placing {
  animation: cell-place 0.4s ease-out;
}

@keyframes cell-place {
  0% {
    transform: scale(0.8);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.game-cell.suggestion-appear {
  animation: suggestion-appear 0.5s ease-out;
}

@keyframes suggestion-appear {
  0% {
    transform: scale(0.9);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Hover effects for suggested cells */
.game-cell.suggested:hover {
  transform: scale(1.1);
  z-index: 15;
}

.game-cell.alternative-suggestion:hover {
  transform: scale(1.05);
  border-style: solid;
  border-width: 2px;
  background: rgba(33, 150, 243, 0.3) !important;
}

/* Smooth transitions for suggestion updates */
.game-cell.suggested {
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.game-cell.alternative-suggestion {
  transition: all 0.3s ease;
}

/* Enhanced value indicator positioning */
.game-cell.alternative-suggestion::after {
  content: attr(data-alt-value);
  position: absolute;
  top: -6px;
  right: -6px;
  background: rgba(158, 158, 158, 0.9);
  color: white;
  font-size: 0.6rem;
  font-weight: bold;
  padding: 1px 4px;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
  z-index: 10;
}

/* Rank indicator for alternatives */
.game-cell.alternative-suggestion::before {
  content: attr(data-alt-rank);
  position: absolute;
  top: 2px;
  left: 2px;
  background: rgba(158, 158, 158, 0.8);
  color: white;
  font-size: 0.6rem;
  font-weight: bold;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* Performance optimizations */
.game-board {
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform;
  contain: layout style paint;
}

.game-cell {
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform, background-color, box-shadow;
  contain: layout style paint;
}

/* GPU acceleration for animations */
.game-cell.suggested,
.game-cell.line-completed,
.game-cell.placing {
  transform: translateZ(0);
  will-change: transform, opacity, background-color;
}

/* Optimize repaints */
.game-status,
.control-panel,
.instructions {
  contain: layout style;
}

/* Reduce layout thrashing */
.status-item .value.updating {
  will-change: transform, color;
}

/* Fade transitions for UI elements */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

.fade-out {
  animation: fadeOut 0.3s ease-out;
}

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

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* Enhanced instruction area */
.instruction-text {
  color: #34495e;
  font-size: 1rem;
  line-height: 1.5;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid #3498db;
  transition: all 0.3s ease;
}

.instruction-text.warning {
  border-left-color: #f39c12;
  background: #fef9e7;
  color: #d68910;
}

.instruction-text.error {
  border-left-color: #e74c3c;
  background: #fdf2f2;
  color: #c0392b;
}

.instruction-text.success {
  border-left-color: #27ae60;
  background: #d5f4e6;
  color: #1e8449;
}

/* Input group styling */
.input-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.input-group label {
  min-width: 80px;
  font-weight: 500;
  color: #2c3e50;
}

/* Tooltip for input help */
.input-tooltip {
  position: relative;
  display: inline-block;
}

.input-tooltip .tooltip-text {
  visibility: hidden;
  width: 200px;
  background-color: #2c3e50;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 8px;
  position: absolute;
  z-index: 1;
  bottom: 125%;
  left: 50%;
  margin-left: -100px;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity 0.3s;
}

.input-tooltip:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .game-cell.empty {
    border-width: 3px;
  }

  .game-cell.player {
    background: #0066cc;
    border-color: #004499;
  }

  .game-cell.computer {
    background: #cc0000;
    border-color: #990000;
  }

  .game-cell.suggested {
    background: #ff6600;
    border-color: #cc3300;
  }

  .input-error {
    border-width: 3px !important;
  }

  .success-message {
    border-width: 2px;
  }
}

/* Cross-browser compatibility fixes */
/* Firefox specific fixes */
@-moz-document url-prefix() {
  .game-board {
    -moz-user-select: none;
  }

  .game-cell {
    -moz-user-select: none;
  }
}

/* Safari specific fixes */
@supports (-webkit-appearance: none) {
  .game-cell {
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .game-board {
    -webkit-user-select: none;
  }

  /* Fix for Safari backdrop-filter */
  .global-loading::before {
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
  }
}

/* Internet Explorer and Edge legacy support */
@supports not (display: grid) {
  .game-board {
    display: table;
    border-collapse: separate;
    border-spacing: 3px;
  }

  .game-cell {
    display: table-cell;
    width: 60px;
    height: 60px;
    vertical-align: middle;
    text-align: center;
  }
}

/* Fallback for older browsers without CSS custom properties */
.no-css-variables .game-cell.player {
  background: #3498db;
}

.no-css-variables .game-cell.computer {
  background: #e74c3c;
}

.no-css-variables .game-cell.suggested {
  background: #f39c12;
}

/* Print styles */
@media print {
  .global-loading,
  .error-modal,
  .game-results {
    display: none !important;
  }

  .game-board {
    break-inside: avoid;
  }

  .control-panel,
  .instructions {
    break-inside: avoid;
  }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .game-cell {
    transition: none !important;
  }

  .loading-spinner {
    animation: none !important;
  }

  .skeleton {
    animation: none !important;
    background: #f0f0f0 !important;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, #1a237e 0%, #303f9f 100%);
    color: #eceff1;
  }

  .game-status {
    background: rgba(38, 50, 56, 0.95);
    color: #eceff1;
    border: 1px solid rgba(66, 165, 245, 0.2);
  }

  .control-panel,
  .instructions,
  .algorithm-selector {
    background: rgba(38, 50, 56, 0.95);
    color: #eceff1;
    border: 1px solid rgba(66, 165, 245, 0.2);
  }

  .control-panel h3,
  .instructions h3 {
    color: #90caf9;
    border-bottom: 2px solid #1e88e5;
  }

  .game-cell.empty {
    background: #37474f;
    border-color: #546e7a;
    color: #eceff1;
  }

  .game-cell.empty:hover {
    background: #263238;
    border-color: #78909c;
  }

  .suggestion-display {
    background: #1a237e;
    color: #e3f2fd;
    border-left: 6px solid #42a5f5;
  }

  #suggestion-text {
    color: #bbdefb;
  }

  .results-content,
  .result-panel {
    background: #263238;
    color: #eceff1;
    border: 1px solid rgba(66, 165, 245, 0.3);
  }

  .result-panel h3 {
    color: #90caf9;
    border-bottom: 2px solid rgba(66, 165, 245, 0.5);
  }

  .final-stats,
  .lines-list {
    background: #37474f;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  }

  .stat-label {
    color: #b0bec5;
  }

  .stat-value {
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }

  .line-item {
    background: #263238;
    color: #eceff1;
  }

  .instruction-text {
    background: #263238;
    color: #eceff1;
    border-left: 4px solid #42a5f5;
  }

  /* Ensure buttons are visible in dark mode */
  .primary-btn {
    background: linear-gradient(135deg, #2196f3, #1976d2);
    border: 1px solid #1565c0;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  }

  .primary-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #42a5f5, #1e88e5);
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .game-cell {
    min-height: 44px; /* iOS accessibility guideline */
    min-width: 44px;
  }

  button {
    min-height: 44px;
    padding: 12px 20px;
  }

  .game-cell:hover {
    transform: none; /* Disable hover effects on touch devices */
  }

  .algorithm-option:hover {
    background-color: transparent;
    border-color: #ddd;
  }
}

/* High DPI display support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .game-cell {
    border-width: 0.5px;
  }

  .game-board {
    gap: 2px;
  }
}

/* Landscape orientation on mobile */
@media screen and (orientation: landscape) and (max-height: 500px) {
  .container {
    padding: 10px;
  }

  header h1 {
    font-size: 1.8rem;
    margin-bottom: 5px;
  }

  .game-status {
    flex-direction: row;
    gap: 20px;
    margin-bottom: 15px;
    padding: 10px;
  }

  .game-board {
    width: 280px;
    height: 280px;
  }
}

/* Focus management for accessibility */
.game-cell:focus {
  outline: 3px solid #3498db;
  outline-offset: 2px;
  z-index: 1;
}

button:focus {
  outline: 3px solid #3498db;
  outline-offset: 2px;
}

/* Screen reader support */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Loading state improvements */
.loading-shimmer {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Error state improvements */
.error-shake {
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Success state improvements */
.success-bounce {
  animation: bounce 0.6s ease-in-out;
}

@keyframes bounce {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
} /* Addi
tional styles for enhanced suggestion visualization */

/* Value detail styling */
.value-detail {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.4;
}

/* Alternatives hint */
.alternatives-hint {
  margin-top: 10px;
  font-size: 0.8rem;
  color: #78909c;
  font-style: italic;
  text-align: center;
}

/* Suggestion position styling */
.suggestion-position {
  margin-bottom: 8px;
  font-size: 1.1rem;
}

.suggestion-position strong {
  color: inherit;
  font-weight: 600;
}

/* Alternative position styling */
.alternative-position {
  font-size: 0.9rem;
}

/* Ripple effect for alternative items */
.ripple-effect {
  position: absolute;
  border-radius: 50%;
  background-color: rgba(33, 150, 243, 0.3);
  transform: scale(0);
  animation: ripple 0.6s linear;
  pointer-events: none;
}

@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* Enhanced suggestion display transitions */
.suggestion-display {
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Improved focus styles for accessibility */
.game-cell:focus {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(33, 150, 243, 0.5),
    0 0 10px rgba(33, 150, 243, 0.3);
  z-index: 10;
}

.game-cell.suggested:focus {
  box-shadow:
    0 0 0 3px rgba(76, 175, 80, 0.5),
    0 0 20px rgba(76, 175, 80, 0.4);
}

/* Tooltip for value explanation */
.value-tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  max-width: 200px;
  z-index: 100;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.game-cell.suggested:hover .value-tooltip {
  opacity: 1;
}

/* Improved alternative suggestion appearance */
.game-cell.alternative-suggestion:hover::after {
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
} /* AI Lea
rning System Styles */
.ai-learning-status {
  background: rgba(255, 255, 255, 0.95);
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.ai-learning-status h3 {
  color: #2c3e50;
  margin-bottom: 15px;
  font-size: 1.2rem;
  text-align: center;
}

.ai-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
}

.ai-stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid #3498db;
}

.ai-stat-item .label {
  font-weight: 600;
  color: #2c3e50;
}

.ai-stat-item .value {
  font-weight: bold;
  color: #3498db;
}

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

.ai-controls button {
  padding: 8px 16px;
  font-size: 0.9rem;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.ai-controls .secondary-btn {
  background-color: #95a5a6;
  color: white;
}

.ai-controls .secondary-btn:hover {
  background-color: #7f8c8d;
  transform: translateY(-2px);
}

/* Algorithm option for AI learning */
.algorithm-option[data-algorithm='ai-learning'] {
  border-color: #9b59b6;
}

.algorithm-option[data-algorithm='ai-learning']:hover {
  border-color: #8e44ad;
  background-color: #f4f1f8;
}

.algorithm-option[data-algorithm='ai-learning'].selected {
  border-color: #8e44ad;
  background-color: #f4f1f8;
  box-shadow: 0 2px 4px rgba(142, 68, 173, 0.2);
}

/* AI suggestion enhancement */
.suggestion-display.ai-enhanced {
  border-left: 4px solid #9b59b6;
  background: linear-gradient(135deg, #f4f1f8 0%, #ffffff 100%);
}

.suggestion-display.ai-enhanced::before {
  content: '🤖 AI建議: ';
  font-weight: bold;
  color: #8e44ad;
}

/* Learning progress indicator */
.learning-progress {
  margin-top: 10px;
  padding: 10px;
  background: #ecf0f1;
  border-radius: 5px;
  font-size: 0.9rem;
}

.learning-progress .progress-bar {
  width: 100%;
  height: 8px;
  background: #bdc3c7;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 5px;
}

.learning-progress .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3498db, #9b59b6);
  transition: width 0.3s ease;
}

/* Responsive design for AI components */
@media (max-width: 768px) {
  .ai-stats {
    grid-template-columns: 1fr;
  }

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

  .ai-controls button {
    width: 100%;
    max-width: 200px;
  }
}

/* Hidden class */
.hidden {
  display: none !important;
}
/* 
Security and Error Handling Styles */
.error-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #e74c3c;
  color: white;
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  max-width: 400px;
  font-family: Arial, sans-serif;
  animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.error-notification-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.error-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.error-message {
  flex: 1;
  margin-bottom: 12px;
}

.error-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.error-retry-btn,
.error-dismiss-btn,
.error-report-btn {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background-color 0.2s;
}

.error-retry-btn:hover,
.error-dismiss-btn:hover,
.error-report-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.error-page {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  font-family: Arial, sans-serif;
}

.error-page-content {
  background: white;
  padding: 40px;
  border-radius: 12px;
  text-align: center;
  max-width: 500px;
  margin: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.error-page-content h1 {
  color: #e74c3c;
  margin-bottom: 20px;
}

.error-details {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  margin: 20px 0;
  text-align: left;
}

.error-details p {
  margin-bottom: 8px;
}

.error-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 20px;
}

.reload-btn,
.report-btn {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.2s;
}

.reload-btn {
  background: #3498db;
  color: white;
}

.reload-btn:hover {
  background: #2980b9;
}

.report-btn {
  background: #95a5a6;
  color: white;
}

.report-btn:hover {
  background: #7f8c8d;
}

.error-report-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25000;
}

.dialog-content {
  background: white;
  padding: 30px;
  border-radius: 10px;
  max-width: 500px;
  width: 90%;
  margin: 20px;
}

.dialog-content h3 {
  margin-bottom: 20px;
  color: #2c3e50;
}

.error-description {
  width: 100%;
  height: 100px;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
  resize: vertical;
  font-family: inherit;
  margin-bottom: 20px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.send-report-btn,
.cancel-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
}

.send-report-btn {
  background: #27ae60;
  color: white;
}

.send-report-btn:hover {
  background: #229954;
}

.cancel-btn {
  background: #95a5a6;
  color: white;
}

.cancel-btn:hover {
  background: #7f8c8d;
}

/* Offline Mode Styles */
.offline-mode {
  filter: grayscale(20%);
}

.offline-notice {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: #ff9800;
  color: white;
  text-align: center;
  padding: 8px;
  z-index: 15000;
  font-weight: 500;
}

/* Security Validation Styles */
.input-error {
  border: 2px solid #e74c3c !important;
  background-color: #fdf2f2 !important;
}

.input-error-message {
  color: #e74c3c;
  font-size: 12px;
  margin-top: 4px;
  display: block;
}

.security-warning {
  background: #fff3cd;
  border: 1px solid #ffeaa7;
  color: #856404;
  padding: 12px;
  border-radius: 6px;
  margin: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.security-warning::before {
  content: '⚠️';
  font-size: 18px;
}

/* Rate Limiting Styles */
.rate-limit-warning {
  background: #f8d7da;
  border: 1px solid #f5c6cb;
  color: #721c24;
  padding: 12px;
  border-radius: 6px;
  margin: 10px 0;
  text-align: center;
}

/* Keyboard Navigation Styles */
.keyboard-focus {
  outline: 3px solid #3498db !important;
  outline-offset: 2px;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.3) !important;
}

/* Screen Reader Only Content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* High Contrast Mode */
.high-contrast {
  filter: contrast(150%);
}

.high-contrast .game-cell {
  border-width: 3px;
}

.high-contrast .game-cell.player {
  background: #000 !important;
  color: #fff !important;
}

.high-contrast .game-cell.computer {
  background: #fff !important;
  color: #000 !important;
  border-color: #000 !important;
}

/* Reduced Motion */
.reduce-motion * {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* Dark Mode Support */
.dark-mode {
  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
}

.dark-mode .game-status {
  background: rgba(52, 73, 94, 0.9);
}

.dark-mode .game-cell {
  background: #34495e;
  border-color: #5d6d7e;
  color: #ecf0f1;
}

.dark-mode .game-cell:hover {
  background: #4a5f7a;
}

/* Loading States for Security Operations */
.security-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.security-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #3498db;
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Success Messages */
.success-message {
  background: #d4edda;
  border: 1px solid #c3e6cb;
  color: #155724;
  padding: 12px;
  border-radius: 6px;
  margin: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.success-message::before {
  content: '✅';
  font-size: 18px;
}

/* Warning Messages */
.warning-message {
  background: #fff3cd;
  border: 1px solid #ffeaa7;
  color: #856404;
  padding: 12px;
  border-radius: 6px;
  margin: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.warning-message::before {
  content: '⚠️';
  font-size: 18px;
}

/* Mobile Security Enhancements */
@media (max-width: 768px) {
  .error-notification {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }

  .error-page-content {
    padding: 30px 20px;
    margin: 10px;
  }

  .dialog-content {
    padding: 20px;
    margin: 10px;
  }

  .error-actions,
  .dialog-actions {
    flex-direction: column;
  }

  .error-retry-btn,
  .error-dismiss-btn,
  .error-report-btn,
  .send-report-btn,
  .cancel-btn {
    width: 100%;
    margin-bottom: 8px;
  }
}

/* Print Styles for Error Reports */
@media print {
  .error-notification,
  .error-page,
  .error-report-dialog,
  .offline-notice {
    display: none !important;
  }
}
