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

body {
  min-height: 100vh;
  background: linear-gradient(135deg, #2b2320 0%, #3a2f28 60%, #241d19 100%);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: #e8dcc8;
  display: flex;
  justify-content: center;
  padding: 24px 16px;
  touch-action: manipulation;
}

.info-duo {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mobile-top,
.settings-btn {
  display: none;
}

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s;
}

body.sheet-open .sheet-mask {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 151;
  background: #2a221c;
  border-top: 1px solid rgba(255, 220, 160, 0.18);
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(105%);
  visibility: hidden;
  transition: transform 0.26s cubic-bezier(0.3, 0.9, 0.4, 1), visibility 0.26s;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

body.sheet-open .sheet {
  transform: translateY(0);
  visibility: visible;
}

.sheet-title {
  font-size: 16px;
  color: #f0e2c8;
  letter-spacing: 2px;
  text-align: center;
}

.sheet-done {
  padding: 12px 0;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #c9a04a, #a37c2e);
  color: #241d15;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}

.wrap {
  width: 100%;
  max-width: 1080px;
}

header {
  text-align: center;
  margin-bottom: 20px;
}

header h1 {
  font-size: 30px;
  letter-spacing: 10px;
  color: #f0e2c8;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

main {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

.board-holder {
  overflow: visible;
  flex: none;
}

.board-frame {
  background: #1c1613;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 220, 160, 0.08);
  transform-origin: top left;
}

#board {
  position: relative;
  width: 640px;
  user-select: none;
  cursor: pointer;
  touch-action: none;
}

.board-bg {
  display: block;
  width: 100%;
  border-radius: 6px;
}

.piece {
  position: absolute;
  width: 58px;
  height: 58px;
  margin: 3px;
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
  z-index: 2;
  transition: transform 0.28s cubic-bezier(0.25, 0.9, 0.3, 1.05);
  will-change: transform;
}

.piece.moving {
  z-index: 6;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.55));
}

.piece.dragging {
  z-index: 8;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.6)) brightness(1.05);
  cursor: grabbing;
}

.piece.in-check {
  animation: checkPulse 0.9s ease-in-out infinite;
}

.fx {
  position: absolute;
  width: 58px;
  height: 58px;
  margin: 3px;
  pointer-events: none;
  z-index: 2;
}

.fx.captured {
  animation: capturePop 0.38s ease-in forwards;
}

.fx.ripple {
  border-radius: 50%;
  z-index: 1;
  animation: rippleOut 0.65s ease-out forwards;
}

@keyframes capturePop {
  0% {
    transform: scale(1);
    opacity: 0.95;
  }
  40% {
    transform: scale(1.18);
    opacity: 0.9;
  }
  100% {
    transform: scale(0.2) rotate(14deg);
    opacity: 0;
  }
}

@keyframes rippleOut {
  0% {
    box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.55);
    border: 2px solid rgba(241, 196, 15, 0.7);
  }
  100% {
    box-shadow: 0 0 0 34px rgba(241, 196, 15, 0);
    border-color: rgba(241, 196, 15, 0);
  }
}

@keyframes checkPulse {
  0%,
  100% {
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(231, 76, 60, 0.95)) brightness(1.12);
  }
}

.dot {
  position: absolute;
  width: 58px;
  height: 58px;
  margin: 3px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
  animation: fadeIn 0.15s ease;
}

.dot::after {
  content: "";
  position: absolute;
  inset: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(46, 204, 113, 0.85);
  box-shadow: 0 0 6px rgba(46, 204, 113, 0.6);
}

.dot.cap::after {
  width: 46px;
  height: 46px;
  background: transparent;
  border: 3px solid rgba(231, 76, 60, 0.9);
  box-shadow: 0 0 8px rgba(231, 76, 60, 0.5);
  animation: capSpin 1.4s linear infinite;
}

@keyframes capSpin {
  0%,
  100% {
    box-shadow: 0 0 6px rgba(231, 76, 60, 0.4);
  }
  50% {
    box-shadow: 0 0 14px rgba(231, 76, 60, 0.85);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sel {
  position: absolute;
  width: 58px;
  height: 58px;
  margin: 3px;
  border-radius: 50%;
  border: 3px solid #f1c40f;
  box-shadow: 0 0 12px rgba(241, 196, 15, 0.8);
  pointer-events: none;
  z-index: 4;
  animation: selPulse 1.1s ease-in-out infinite;
}

@keyframes selPulse {
  0%,
  100% {
    box-shadow: 0 0 10px rgba(241, 196, 15, 0.55);
  }
  50% {
    box-shadow: 0 0 20px rgba(241, 196, 15, 0.95);
  }
}

.lastmove {
  position: absolute;
  width: 58px;
  height: 58px;
  margin: 3px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
}

.lastmove.from {
  border: 2px dashed rgba(241, 196, 15, 0.75);
  animation: fadeIn 0.3s ease;
}

.lastmove.to {
  border: 3px solid rgba(243, 200, 66, 0.95);
  box-shadow: 0 0 14px rgba(241, 196, 15, 0.55), inset 0 0 12px rgba(241, 196, 15, 0.35);
  animation: toPulse 1.4s ease-in-out infinite;
}

@keyframes toPulse {
  0%,
  100% {
    box-shadow: 0 0 8px rgba(241, 196, 15, 0.35), inset 0 0 8px rgba(241, 196, 15, 0.25);
  }
  50% {
    box-shadow: 0 0 20px rgba(241, 196, 15, 0.85), inset 0 0 16px rgba(241, 196, 15, 0.5);
  }
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translate(-50%, -14px);
  background: rgba(40, 32, 26, 0.95);
  border: 1px solid rgba(241, 196, 15, 0.5);
  color: #f5e9cf;
  font-size: 15px;
  padding: 10px 26px;
  border-radius: 999px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.sound-btn {
  width: 100%;
  padding: 8px 0;
  border: 1px solid rgba(255, 220, 160, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #cbbfa8;
  font-size: 13px;
  cursor: pointer;
  transition: filter 0.15s;
}

.sound-btn:hover {
  filter: brightness(1.3);
}

.panel {
  width: 320px;
  max-width: calc(100vw - 52px);
  background: rgba(28, 22, 19, 0.92);
  border: 1px solid rgba(255, 220, 160, 0.1);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.status {
  background: rgba(241, 196, 15, 0.1);
  border: 1px solid rgba(241, 196, 15, 0.3);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  min-height: 42px;
  display: flex;
  align-items: center;
}

.status.thinking::after {
  content: "";
  margin-left: 8px;
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid rgba(241, 196, 15, 0.35);
  border-top-color: #f1c40f;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: #cbbfa8;
}

.row select {
  background: #2e2620;
  color: #f0e2c8;
  border: 1px solid rgba(255, 220, 160, 0.2);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  outline: none;
  cursor: pointer;
}

.btns {
  display: flex;
  gap: 10px;
}

.btns button {
  flex: 1;
  padding: 9px 0;
  border: 1px solid rgba(255, 220, 160, 0.25);
  border-radius: 8px;
  background: linear-gradient(180deg, #4a3c30, #3a2e24);
  color: #f0e2c8;
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}

.btns button:hover {
  filter: brightness(1.2);
}

.btns button:active {
  transform: scale(0.97);
}

.btns button.danger {
  border-color: rgba(231, 76, 60, 0.5);
  background: linear-gradient(180deg, #6b3028, #52241e);
}

.captures-box h3,
.history-box h3,
.tips summary {
  font-size: 14px;
  color: #cbbfa8;
  margin-bottom: 8px;
  letter-spacing: 2px;
}

.tips summary {
  cursor: pointer;
  list-style: none;
}

.tips summary::-webkit-details-marker {
  display: none;
}

.tips summary::after {
  content: " ▾";
  color: #8a7d68;
}

.cap-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.cap-side {
  flex: none;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.cap-side.red {
  color: #f0b9a8;
}

.cap-side.blk {
  color: #b9c4d8;
}

.cap-list {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 28px;
  align-items: center;
}

.cap-list img {
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.cap-list .none {
  color: #6f6452;
  font-size: 13px;
}

#history {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.9;
  color: #d8cbb2;
}

#history::-webkit-scrollbar {
  width: 6px;
}

#history::-webkit-scrollbar-thumb {
  background: rgba(255, 220, 160, 0.2);
  border-radius: 3px;
}

#history .no {
  color: #8a7d68;
  margin-right: 6px;
  font-size: 12px;
}

#history .side {
  display: inline-block;
  font-size: 11px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
  margin: 0 6px 0 2px;
}

#history .side.red {
  color: #f2c7b4;
  background: rgba(231, 76, 60, 0.18);
}

#history .side.blk {
  color: #c3cde0;
  background: rgba(93, 120, 160, 0.22);
}

.tips p {
  font-size: 12.5px;
  line-height: 1.8;
  color: #9a8d78;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: #2e2620;
  border: 1px solid rgba(255, 220, 160, 0.25);
  border-radius: 14px;
  padding: 36px 48px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  animation: popIn 0.32s cubic-bezier(0.3, 1.4, 0.5, 1);
}

@keyframes popIn {
  from {
    transform: scale(0.72);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

#overlay-text {
  font-size: 22px;
  color: #f0e2c8;
  margin-bottom: 22px;
}

#btn-again {
  padding: 10px 34px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(180deg, #c9a04a, #a37c2e);
  color: #241d15;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}

#btn-again:hover {
  filter: brightness(1.1);
}

@media (max-width: 720px) {
  body {
    padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
    align-items: flex-start;
  }

  body.sheet-open {
    overflow: hidden;
  }

  header {
    margin-bottom: 8px;
  }

  header h1 {
    font-size: 20px;
    letter-spacing: 5px;
  }

  header .sub {
    font-size: 11px;
    margin-top: 3px;
  }

  main {
    gap: 8px;
  }

  .board-holder {
    margin: 0 auto;
  }

  .mobile-top {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  .mobile-top .status {
    font-size: 13.5px;
    padding: 9px 12px;
    min-height: 40px;
  }

  .mobile-top .btns {
    flex: 1 1 auto;
    gap: 8px;
  }

  .mobile-top .btns button {
    padding: 11px 0;
    font-size: 15px;
  }

  .settings-btn {
    display: block;
  }

  .panel {
    width: 100%;
    padding: 10px;
    gap: 9px;
  }

  .info-duo {
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
  }

  .captures-box {
    flex: 1 1 40%;
    min-width: 0;
  }

  .history-box {
    flex: 1 1 55%;
    min-width: 0;
  }

  .captures-box h3,
  .history-box h3,
  .tips summary {
    margin-bottom: 6px;
  }

  .cap-row {
    margin-bottom: 4px;
    gap: 6px;
  }

  .cap-list img {
    width: 20px;
    height: 20px;
  }

  #history {
    max-height: 128px;
    font-size: 12px;
    padding: 6px 8px;
    line-height: 1.7;
  }

  .sheet .row {
    justify-content: space-between;
    font-size: 14px;
  }

  .sheet .row select {
    background: #2e2620;
    color: #f0e2c8;
    border: 1px solid rgba(255, 220, 160, 0.2);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 14px;
    max-width: 62%;
  }

  .sheet .sound-btn {
    padding: 11px 0;
    font-size: 14px;
  }

  .sheet .tips summary {
    margin-bottom: 4px;
  }

  .tips p {
    font-size: 12px;
  }

  .toast {
    top: auto;
    bottom: calc(20px + env(safe-area-inset-bottom));
    font-size: 13px;
    padding: 8px 18px;
    max-width: 92vw;
    white-space: normal;
    text-align: center;
  }

  .overlay-card {
    padding: 26px 30px;
  }

  #overlay-text {
    font-size: 18px;
  }
}


@media (prefers-reduced-motion: reduce) {
  .piece,
  .fx.captured,
  .fx.ripple,
  .piece.in-check,
  .sel,
  .lastmove.to,
  .dot.cap::after,
  .overlay-card {
    animation: none !important;
  }
}
