﻿:root {
  --square-size: min(16vmin, 90px);
  --light-square: #f4f0d6;
  --dark-square: #4f7b4f;
  --highlight-move: #b0b0b0;
  --highlight-selected: #ffcc33;
  --stone: #8b7f70;
  --stone-dark: #6b6055;
  --bg: #202320;
}

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

body {
  background: radial-gradient(circle at top, #343834 0%, #151615 60%);
  color: #fefefe;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0.8rem 0.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

/* HEADER */

#mainHeader {
  text-align: center;
}

#mainTitle {
  font-size: 2.3rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #f7e9b0;
  text-shadow: 0 3px 6px rgba(0, 0, 0, 0.8);
}

#subTitle {
  margin-top: 0.3rem;
  font-size: 0.9rem;
  color: #d2c8a0;
}

/* TABS */

#tabBar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.tab-button {
  flex: 1;
  max-width: 200px;
  padding: 0.5rem 0.3rem;
  border-radius: 999px;
  border: 1px solid rgba(247, 233, 176, 0.7);
  background: rgba(0, 0, 0, 0.3);
  color: #f7e9b0;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.tab-button.active {
  background: linear-gradient(135deg, #f7e9b0, #f7c65a);
  color: #2b251b;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.7);
}

.tab-button:hover {
  transform: translateY(-1px);
}

#gameArea {
  margin-top: 0.4rem;
  flex: 1;
  display: flex;
  justify-content: center;
}

/* GAME PANELS */

.game-panel {
  display: none;
  width: 100%;
}

.game-panel.active {
  display: flex;
  justify-content: center;
}

#classicContainer,
#chessyContainer {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* STONE BOARD FRAME */

.stone-border {
  background: radial-gradient(circle at top, #a59a8d 0%, #6b6055 60%, #3d362f 100%);
  padding: 1rem;
  border-radius: 24px;
  box-shadow:
    0 0 0 4px rgba(33, 27, 21, 0.8),
    0 18px 40px rgba(0, 0, 0, 0.8),
    inset 0 0 30px rgba(0, 0, 0, 0.4);
}

.board-row {
  display: flex;
  align-items: stretch;
}

/* BOARD & LABELS */

.board {
  display: grid;
  grid-template-columns: repeat(5, var(--square-size));
  grid-template-rows: repeat(5, var(--square-size));
  border-radius: 10px;
  overflow: visible;
  position: relative;
  box-shadow:
    inset 0 0 12px rgba(0, 0, 0, 0.6),
    0 0 0 4px #2b3a2b;
  background: #355335;
}

.square {
  position: relative;
  width: var(--square-size);
  height: var(--square-size);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.square.light {
  background: var(--light-square);
}

.square.dark {
  background: var(--dark-square);
}

.file-labels {
  display: flex;
  justify-content: center;
  gap: 0;
  margin: 0.1rem 0;
  font-size: 0.9rem;
  letter-spacing: 0.4rem;
  /* keep the spacing for letters usually */
  color: #f0e4c1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.file-labels span {
  display: inline-block;
  width: var(--square-size);
  text-align: center;
}

.file-labels.top {
  margin-bottom: 0.25rem;
}

.file-labels.bottom {
  margin-top: 0.25rem;
}

.rank-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /* Enforce symmetric width for both sides */
  width: 1.5rem;
  padding: 0.2rem 0;
  font-size: 0.9rem;
  color: #f0e4c1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  align-items: center;
  /* Center numbers horizontally in the strip */
}

/* Remove distinct side margins, rely on fixed width & centering */
.rank-labels.left {
  margin-right: 0.1rem;
}

.rank-labels.right {
  margin-left: 0.1rem;
}

.rank-labels span {
  height: var(--square-size);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* PIECES */

.piece {
  width: 80%;
  height: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  pointer-events: none;
  transition: transform 0.25s ease;
  position: relative;
  z-index: 1;
}

.piece.animating {
  z-index: 20;
}

.piece.promote-effect {
  animation: promoteFlash 0.35s ease-out;
}

.piece svg {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* HIGHLIGHTS */

.square.selected {
  box-shadow: inset 0 0 0 3px var(--highlight-selected),
    inset 0 0 0 6px rgba(0, 0, 0, 0.4);
}

.square.highlight-move {
  box-shadow: inset 0 0 0 3px var(--highlight-move),
    inset 0 0 0 6px rgba(0, 0, 0, 0.4);
}

.square.highlight-move::after {
  content: "";
  position: absolute;
  width: 20%;
  height: 20%;
  border-radius: 50%;
  background: rgba(160, 160, 160, 0.8);
  animation: pulse 1s infinite alternate;
}

/* check-escape suggestions */
/* check-escape suggestions: REMOVED as per request */
/* .square.king-escape.highlight-move { ... } */

/* King in check: continuous red flash loop */
.square.king-check-loop {
  animation: kingFlash 0.7s infinite;
}

/* Last move blue glow */
.square.last-move {
  box-shadow:
    inset 0 0 0 3px #00bfff,
    0 0 10px 3px rgba(0, 191, 255, 0.7);
}

/* BOTTOM CONTROLS */

.bottom-controls {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

.chessy-controls {
  margin-top: 0.4rem;
}

/* TRAYS (CHESSY) */

.tray {
  margin-top: 0.4rem;
  margin-bottom: 0.3rem;
  border-radius: 18px;
  padding: 0.2rem 0.4rem;
  background: radial-gradient(circle at top, #f7e9b0 0%, #b38b43 40%, #7d5a29 100%);
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.4),
    0 4px 12px rgba(0, 0, 0, 0.7);
}

.tray-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(18px, calc(var(--square-size) * 0.65)));
  gap: 0.16rem;
  justify-content: center;
  margin: 0.1rem 0;
}

.tray-slot {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  min-height: calc(var(--square-size) * 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow:
    inset 0 0 5px rgba(0, 0, 0, 0.4),
    0 1px 2px rgba(0, 0, 0, 0.5);
}

.reserve-piece {
  width: 80%;
  height: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.reserve-piece svg {
  width: 100%;
  height: 100%;
}

.reserve-piece.selected {
  /* Move up more and add green stroke effect */
  transform: translateY(-8px) scale(1.1);
  filter: drop-shadow(0 0 2px #00ff00) drop-shadow(0 0 1px #00ff00);
  box-shadow: none;
}

/* STATUS TEXT */

.status-text {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  color: #f0e4c1;
}

/* MODALS */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-visible {
  display: flex;
}

.modal-content {
  position: relative;
  background: #282c2b;
  border-radius: 16px;
  padding: 1.8rem 2.1rem;
  text-align: center;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.8),
    0 0 0 3px rgba(240, 228, 180, 0.3);
  max-width: 480px;
  width: 90%;
}

.modal-content h1 {
  margin-bottom: 0.9rem;
  font-size: 1.6rem;
}

.modal-content p {
  margin-bottom: 1rem;
  font-size: 0.98rem;
  color: #ddd5b6;
}

.modal-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
}

/* CONFIG MODAL SECTIONS */

.config-section {
  margin-top: 0.8rem;
  margin-bottom: 0.4rem;
}

.config-section h2 {
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
}

/* Modal close button */

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  background: transparent;
  border: none;
  color: #fefefe;
  font-size: 1.4rem;
  cursor: pointer;
}

/* HOW TO PLAY CONTENT */

.howto {
  text-align: left;
}

.howto-body {
  margin-top: 0.6rem;
  max-height: 60vh;
  overflow-y: auto;
}

.howto-body h2 {
  font-size: 1rem;
  margin: 0.6rem 0 0.3rem;
  color: #f7e9b0;
}

.howto-body ul {
  margin-left: 1.1rem;
  margin-bottom: 0.3rem;
}

.howto-body li {
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}

/* BUTTONS */

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.6rem;
  font-size: 1.05rem;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn.primary {
  background: linear-gradient(135deg, #f7e9b0, #f7c65a);
  color: #2b251b;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(0, 0, 0, 0.7);
}

.btn.secondary {
  background: linear-gradient(135deg, #4f7b4f, #86b686);
  color: #10140f;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(0, 0, 0, 0.7);
}

.btn:not(:disabled):hover {
  /* remove/ comment out movement */
  /* transform: translateY(-1px); */
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.9);
}



.btn:active {
  transform: translateY(1px);
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(0, 0, 0, 1);
}

/* ANIMATIONS */

@keyframes pulse {
  from {
    opacity: 0.4;
    transform: scale(0.6);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes kingFlash {

  0%,
  100% {
    box-shadow: inset 0 0 0 4px rgba(255, 0, 0, 0),
      0 0 0 0 rgba(255, 0, 0, 0);
  }

  50% {
    box-shadow:
      inset 0 0 0 4px rgba(255, 0, 0, 0.95),
      0 0 14px 4px rgba(255, 0, 0, 0.9);
  }
}

@keyframes promoteFlash {
  0% {
    transform: scale(1);
    filter: drop-shadow(0 0 0 rgba(255, 215, 0, 0));
  }

  50% {
    transform: scale(1.15);
    filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.9));
  }

  100% {
    transform: scale(1);
    filter: drop-shadow(0 0 0 rgba(255, 215, 0, 0));
  }
}

/* RESPONSIVE */

@media (max-width: 700px) {
  :root {
    /* Dynamic sizing for mobile: 5 squares * 17vw = 85vw. */
    --square-size: min(17vw, 75px);
  }

  #app {
    padding: 0.5rem 0.2rem 1rem;
    gap: 0.5rem;
  }

  #mainTitle {
    font-size: 1.8rem;
  }

  .file-labels {
    /* Critical fix: reduce side margins to prevent overflow */
    margin: 0.1rem 0.5rem;
    letter-spacing: 0.1rem;
  }

  .stone-border {
    padding: 0.8rem 0.4rem;
    border-radius: 16px;
  }

  /* Improve touch targets */
  .btn,
  .tab-button,
  .howto-circle-small {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .tab-button {
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
  }

  .modal-content {
    padding: 1.2rem 1rem;
    width: 95%;
  }

  .modal-buttons {
    flex-direction: column;
    width: 100%;
  }

  .modal-buttons .btn {
    width: 100%;
    margin: 0;
  }
}

@media (max-width: 380px) {
  :root {
    /* Tighter constraint for iPhone SE size */
    --square-size: 16.5vw;
  }

  #mainTitle {
    font-size: 1.5rem;
  }

  /* Eliminate side margins entirely on very small screens */
  .file-labels {
    margin: 0.1rem 0;
    font-size: 0.8rem;
    letter-spacing: 0;
  }

  .stone-border {
    padding: 0.6rem 0.2rem;
  }

  .rank-labels {
    font-size: 0.8rem;
    padding: 0.2rem 0;
  }

  .rank-labels.left {
    margin-right: 0.1rem;
  }

  .rank-labels.right {
    margin-left: 0.1rem;
  }

  .piece,
  .reserve-piece {
    width: 75%;
    height: 75%;
  }
}

/* Landscape mode on mobile adjustment */
@media (max-height: 600px) and (orientation: landscape) {
  #app {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: center;
  }

  #mainHeader {
    width: 100%;
    margin-bottom: 0.2rem;
  }

  #tabBar {
    width: 100%;
    margin-bottom: 0.2rem;
  }

  :root {
    --square-size: 13vh;
  }
}

/* Chessy board frame so how-to can sit on the right */
#chessyBoardFrame {
  position: relative;
}

/* Bounce animation for the Play button so it gets attention */
@keyframes playBounce {

  0%,
  100% {
    transform: translateY(0);
  }

  30% {
    transform: translateY(-4px);
  }

  60% {
    transform: translateY(-2px);
  }
}

.play-bounce {
  animation: playBounce 1.4s infinite ease-in-out;
}

/* Keep hover/active effects additive (optional) */
.play-bounce:hover {
  animation-play-state: paused;
  /* stops bouncing when pointer is over */
}

/* Chessy layout: board + right-side how-to button */
#chessyLayout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
}

/* USER REQUEST: Remove numbers/alphabets from Chessy board */
#game-chessy .file-labels,
#game-chessy .rank-labels {
  display: none !important;
}

/* Board frame must be relative so the Play button can center overlay */
#chessyBoardFrame {
  position: relative;
}

/* HEADER BUTTONS */
.header-btn {
  height: 36px;
  border-radius: 999px;
  /* Pill shape */
  border: none;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
  transition: transform 0.1s;
  text-decoration: none;
  gap: 0.5rem;
  color: #262016;
  position: relative;
  /* For tooltip positioning */
}

/* Tooltip implementation */
.header-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 125%;
  /* Above the button */
  left: 50%;
  transform: translateX(-50%) translateY(5px);
  background: rgba(40, 44, 43, 0.95);
  color: #f0e4c1;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.header-btn[data-tooltip]:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.header-btn:hover {
  transform: translateY(-1px);
}

.header-btn:active {
  transform: scale(0.95);
}

.header-btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.5;
}

/* Specific Variants */

/* How To Play: Default Yellow/Gold */
.header-btn.howto {
  background: radial-gradient(circle at top, #f7e9b0, #f7c65a);
  color: #262016;
}

/* Support: Green */
.header-btn.support {
  background: linear-gradient(135deg, #4f7b4f, #86b686);
  color: #ffffff;
  width: 42px;
  /* Circle-ish for icon only buttons */
  padding: 0;
  border-radius: 50%;
}

/* Feedback: Blue */
.header-btn.feedback {
  background: linear-gradient(135deg, #4da6ff, #0066cc);
  color: #ffffff;
  width: 42px;
  /* Circle-ish for icon only buttons */
  padding: 0;
  border-radius: 50%;
}

/* Play/Restart button in the CENTER of the Chessy board */
.chessy-play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  padding-inline: 2.4rem;
}

/* Bounce animation so user notices it */
@keyframes playBounce {

  0%,
  100% {
    transform: translate(-50%, -50%);
  }

  30% {
    transform: translate(-50%, calc(-50% - 2px));
  }

  60% {
    transform: translate(-50%, calc(-50% - 1px));
  }
}

.play-bounce {
  animation: playBounce 1.4s infinite ease-in-out;
}

/* Pause bounce while user is hovering it (desktop nicety) */
.play-bounce:hover {
  animation-play-state: paused;
}

/* Fix for Play button jumping on click */
.chessy-play-overlay:active {
  transform: translate(-50%, -50%) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.7) !important;
}

/* Classic (5×5) board frame so play button can anchor to it */
#classicBoardFrame {
  position: relative;
  display: inline-block;
}

/* Classic 5×5 stone-border gains positioning context */
.classic-stone {
  position: relative;
}

/* Play button centered under classic board */
.classic-play-bottom {
  position: absolute;
  left: 50%;
  bottom: -3rem;
  transform: translateX(-50%);
  z-index: 40;
}

@keyframes classicPlayButtonBounce {

  0%,
  100% {
    transform: translateX(-50%) translateY(0);
  }

  30% {
    transform: translateX(-50%) translateY(-4px);
  }

  60% {
    transform: translateX(-50%) translateY(-2px);
  }
}

.classic-play-bounce {
  animation: classicPlayButtonBounce 1.4s infinite ease-in-out;
}

.classic-play-bounce:hover {
  animation-play-state: paused;
}

/* Make the Chessy stone border a vertical stack:
   top tray ? top labels ? board ? bottom labels ? bottom tray */
#chessyBoardFrame .stone-border {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Default order: black tray at top, white tray at bottom */
#chessyBoardFrame .tray-top {
  order: 1;
}

#chessyBoardFrame .file-labels.top {
  order: 2;
}

#chessyBoardFrame .board-row {
  order: 3;
}

#chessyBoardFrame .file-labels.bottom {
  order: 4;
}

#chessyBoardFrame .tray-bottom {
  order: 5;
}

/* When playing black (frame has .flipped):
   swap the trays only — board & labels stay in correct orientation */
#chessyBoardFrame.flipped .tray-top {
  order: 5;
}

#chessyBoardFrame.flipped .tray-bottom {
  order: 1;
}



.chessy-restart-wrapper {
  margin-top: 0.6rem;
  display: flex;
  justify-content: center;

}

/* Back Arrow in Modals */
.modal-back-arrow {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-color);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: transform 0.2s ease, color 0.2s ease;
  z-index: 10;
}

.modal-back-arrow:hover {
  transform: translateX(-3px);
  color: var(--primary-color);
}