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

:root {
  --bg-color: #FFF8DC;
  --bg-gradient: linear-gradient(135deg, #FFF8DC 0%, #FAF0C0 50%, #F5E6B0 100%);
  --board-color: #D2B48C;
  --board-border: #8B7355;
  --board-border-dark: #6B5344;
  --cell-bg: #F5DEB3;
  --cell-hover: #FFE4B5;
  --cell-highlight: rgba(74, 144, 217, 0.2);
  --human-color: #4A90D9;
  --human-dark: #2563EB;
  --human-light: #7AB8F5;
  --ai-color: #E74C3C;
  --ai-dark: #DC2626;
  --ai-light: #F58779;
  --text-color: #5D4E37;
  --text-light: #8B7355;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);

  --board-size: min(40vh, 40vw, 340px);
  --piece-area-width: calc(var(--board-size) * 0.55);
  --piece-small: calc(var(--board-size) * 0.12);
  --piece-medium: calc(var(--board-size) * 0.17);
  --piece-large: calc(var(--board-size) * 0.22);
  --panel-padding: calc(var(--board-size) * 0.05);
  --panel-gap: calc(var(--board-size) * 0.05);
}

html, body {
  height: 100%;
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-color);
  overflow: hidden;
}

.game-container {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
}

.game-header {
  text-align: center;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.game-title {
  font-size: clamp(1.1rem, 3.2vh, 1.8rem);
  font-weight: 700;
  color: var(--text-color);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
  margin-bottom: 4px;
  letter-spacing: 3px;
  white-space: nowrap;
}

.game-status {
  font-size: clamp(0.8rem, 1.6vh, 0.95rem);
  color: var(--text-light);
  font-weight: 500;
  transition: opacity 0.3s ease;
}

.game-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: 1;
  width: 100%;
  max-width: 100%;
}

.game-panel {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: #D2B48C;
  border-radius: 16px;
  padding: var(--panel-padding);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  border: 4px solid var(--board-border);
  gap: var(--panel-gap);
}

.piece-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.pieces {
  position: relative;
  background: var(--board-border);
  border-radius: 12px;
  width: var(--piece-area-width);
  height: var(--board-size);
  box-sizing: border-box;
  border: 3px solid var(--board-border-dark);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2);
  overflow: visible;
}

.piece {
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: absolute;
  user-select: none;
  z-index: 1;
}

.piece:hover {
  transform: scale(1.08);
  z-index: 10;
}

.piece.held {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  transform: translate(-50%, -50%) scale(1.25);
}

.piece.human {
  background: radial-gradient(circle at 30% 30%, var(--human-light), var(--human-color) 60%, var(--human-dark));
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25), inset 0 -3px 6px rgba(0, 0, 0, 0.15), inset 0 3px 6px rgba(255, 255, 255, 0.3);
}

.piece.ai {
  background: radial-gradient(circle at 30% 30%, var(--ai-light), var(--ai-color) 60%, var(--ai-dark));
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25), inset 0 -3px 6px rgba(0, 0, 0, 0.15), inset 0 3px 6px rgba(255, 255, 255, 0.3);
}

.piece.small {
  width: var(--piece-small);
  height: var(--piece-small);
}

.piece.medium {
  width: var(--piece-medium);
  height: var(--piece-medium);
}

.piece.large {
  width: var(--piece-large);
  height: var(--piece-large);
}

.piece.ai-animate {
  transition: transform 0.3s ease, top 0.4s ease-in-out, left 0.4s ease-in-out;
  z-index: 100;
}

.piece.ai-pickup {
  animation: aiPickup 0.3s ease;
}

@keyframes aiPickup {
  0% { transform: scale(1); }
  50% { transform: scale(1.15) translateY(-8px); }
  100% { transform: scale(1.1); }
}

.piece.ai-drop {
  animation: aiDrop 0.3s ease;
}

@keyframes aiDrop {
  0% { transform: scale(1.1); }
  50% { transform: scale(1.15) translateY(4px); }
  100% { transform: scale(1); }
}

.board-section {
  flex-shrink: 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
  background: var(--board-border);
  padding: 10px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg), inset 0 2px 8px rgba(0, 0, 0, 0.1);
  width: var(--board-size);
  height: var(--board-size);
}

.cell {
  background: var(--cell-bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.2s ease;
  cursor: pointer;
  overflow: visible;
}

.cell:hover {
  background: var(--cell-hover);
}

.cell.highlight {
  background: var(--cell-highlight);
}

.cell .piece {
  position: absolute;
  cursor: default;
}

.cell .piece:hover {
  transform: none;
}

.cell .piece.drop-animation {
  animation: dropBounce 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes dropBounce {
  0% {
    transform: translateY(-30px) scale(0.8);
    opacity: 0;
  }
  60% {
    transform: translateY(5px) scale(1.05);
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.cell .piece.eaten {
  animation: eatAnimation 0.35s ease forwards;
}

@keyframes eatAnimation {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}

.cell.winning {
  animation: winningGlow 1s ease-in-out infinite;
}

@keyframes winningGlow {
  0%, 100% {
    box-shadow: inset 0 0 15px rgba(255, 215, 0, 0.5);
  }
  50% {
    box-shadow: inset 0 0 25px rgba(255, 215, 0, 0.8);
  }
}

.cell.winning .piece {
  animation: winningPulse 1s ease-in-out infinite;
}

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

.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--board-border);
  border-radius: 12px;
  padding: 10px 16px;
  border: 3px solid var(--board-border-dark);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  min-width: min(calc(var(--board-size) * 1.5), 90vw);
}

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

.control-label {
  font-size: clamp(0.8rem, 1.5vh, 0.9rem);
  color: #F5DEB3;
  font-weight: 500;
  white-space: nowrap;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.control-select {
  padding: 6px 28px 6px 10px;
  font-size: clamp(0.8rem, 1.5vh, 0.9rem);
  background: #D2B48C;
  color: var(--text-color);
  border: 2px solid var(--board-border-dark);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235D4E37' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.control-select:hover {
  border-color: #5D4E37;
}

.control-select:focus {
  outline: none;
  border-color: #5D4E37;
  box-shadow: 0 0 0 2px rgba(93, 78, 55, 0.2);
}

.control-select option {
  background: #F5DEB3;
  color: var(--text-color);
}

.wood-btn {
  padding: 8px 20px;
  font-size: clamp(0.8rem, 1.5vh, 0.9rem);
  font-weight: 600;
  color: #FFF8DC;
  background: linear-gradient(180deg, #A08060 0%, #8B7355 50%, #6B5344 100%);
  border: 2px solid #5D4E37;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25), inset 0 1px 2px rgba(255, 255, 255, 0.2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  letter-spacing: 1px;
  font-family: inherit;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}

.wood-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.3), inset 0 1px 2px rgba(255, 255, 255, 0.25);
}

.wood-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2), inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 26px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, #A08060 0%, #8B7355 50%, #6B5344 100%);
  border: 2px solid #5D4E37;
  border-radius: 8px;
  transition: background 0.2s ease;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

.toggle-slider::before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 2px;
  top: 2px;
  background: #F5DEB3;
  border-radius: 4px;
  transition: transform 0.25s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

.rules-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.rules-content {
  background: linear-gradient(180deg, #D2B48C 0%, #C4A67A 50%, #B8956A 100%);
  border: 4px solid #5D4E37;
  border-radius: 16px;
  padding: 24px 28px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.rules-content h2 {
  color: #5D4E37;
  font-size: 1.3rem;
  margin-bottom: 16px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.rules-text {
  color: #3D2E17;
  font-size: 0.9rem;
  line-height: 1.6;
  text-align: left;
  margin-bottom: 20px;
}

.rules-text p {
  margin-bottom: 8px;
}

.rules-text strong {
  color: #5D4E37;
}

.piece-tooltip {
  position: fixed;
  padding: 8px 16px;
  background: rgba(93, 78, 55, 0.95);
  color: #FFF8DC;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  pointer-events: none;
  z-index: 3000;
  transform: translate(-50%, -100%);
  margin-top: -15px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  animation: tooltipFade 1.2s ease forwards;
}

@keyframes tooltipFade {
  0% { opacity: 0; transform: translate(-50%, -100%) translateY(10px); }
  20% { opacity: 1; transform: translate(-50%, -100%) translateY(0); }
  80% { opacity: 1; transform: translate(-50%, -100%) translateY(0); }
  100% { opacity: 0; transform: translate(-50%, -100%) translateY(-10px); }
}

.game-over-modal {
  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: 2000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.modal-content {
  background: var(--bg-color);
  padding: 28px 36px;
  border-radius: 16px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: scale(0.9);
  transition: transform 0.3s ease;
  max-width: 90%;
  border: 3px solid var(--board-border);
}

.game-over-modal.show .modal-content {
  transform: scale(1);
}

.modal-content h2 {
  font-size: clamp(1.3rem, 2.8vh, 1.8rem);
  margin-bottom: 8px;
  color: var(--text-color);
}

.modal-content p {
  font-size: clamp(0.85rem, 1.8vh, 1rem);
  color: var(--text-light);
  margin-bottom: 18px;
}

@media (max-width: 768px), (max-aspect-ratio: 4/3) {
  :root {
    --board-size: min(40vw, 40vh, 260px);
    --piece-area-width: calc(var(--board-size) * 0.45);
    --piece-small: calc(var(--board-size) * 0.14);
    --piece-medium: calc(var(--board-size) * 0.2);
    --piece-large: calc(var(--board-size) * 0.26);
  }

  .game-container {
    padding: 6px;
    min-height: 100vh;
    justify-content: center;
  }

  .game-header {
    margin-bottom: 6px;
  }

  .game-title {
    font-size: 1.2rem;
    margin-bottom: 2px;
  }

  .game-status {
    font-size: 0.9rem;
  }

  .game-main {
    gap: 6px;
  }

  .game-panel {
    flex-direction: row;
    width: auto;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    border-width: 4px;
    border-radius: 14px;
  }

  .piece-area {
    width: var(--piece-area-width);
  }

  .pieces {
    width: var(--piece-area-width);
    height: var(--board-size);
    border-width: 2px;
    border-radius: 8px;
  }

  .board-section {
    width: auto;
  }

  .rules-modal {
    padding: 10px;
    align-items: center;
  }

  .rules-content {
    max-width: 340px;
    padding: 16px 18px;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: 12px;
    margin-top: 0;
  }

  .rules-content h2 {
    font-size: 1.1rem;
    margin-bottom: 10px;
  }

  .rules-text {
    font-size: 0.82rem;
    line-height: 1.55;
    margin-bottom: 14px;
  }
}

@media (max-width: 480px) {
  :root {
    --board-size: min(34vw, 34vh, 190px);
    --piece-area-width: calc(var(--board-size) * 0.45);
    --piece-small: calc(var(--board-size) * 0.14);
    --piece-medium: calc(var(--board-size) * 0.2);
    --piece-large: calc(var(--board-size) * 0.26);
  }

  .game-container {
    padding: 4px;
  }

  .game-title {
    font-size: 1rem;
    letter-spacing: 0.5px;
  }

  .game-status {
    font-size: 0.8rem;
  }

  .game-panel {
    gap: 4px;
    padding: 6px;
    border-width: 3px;
    border-radius: 12px;
  }

  .pieces {
    border-radius: 6px;
    border-width: 2px;
  }

  .rules-modal {
    padding: 8px;
    align-items: flex-start;
  }

  .rules-content {
    padding: 12px 14px;
    max-width: 92vw;
    max-height: 88vh;
    overflow-y: auto;
    border-width: 3px;
    border-radius: 10px;
    margin-top: 4vh;
  }

  .rules-content h2 {
    font-size: 0.95rem;
    margin-bottom: 6px;
  }

  .rules-text {
    font-size: 0.75rem;
    line-height: 1.45;
    margin-bottom: 10px;
  }

  .rules-text p {
    margin-bottom: 5px;
  }
}
