/* ==========================================
   3zee - Main Unified Stylesheet
   Player green tile in grid = #0d9488
   CPU red tile in grid = #e11d48
   ========================================== */

/* Resets & Base Layout */
* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #ffffff; /* #f8fafc; */
  color: #0f172a;
  margin: 0;
  padding: 16px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;

  /* Lock body to the viewport instead of growing with content.
     100dvh accounts for mobile browser chrome (address bar etc). */
  height: 100dvh;
  overflow: hidden;
}

a { text-decoration: none; }

.app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 500px; /* Constrains total app width for clean mobile alignment */

  /* Take up all available vertical space inside body's padding,
     so children (esp. the board) can be told to share it. */
  height: 100%;
  min-height: 0;
  background-color: #ffffff;
}

/* ==========================================
   Header Section
   ========================================== */
.header-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  flex-shrink: 0;
}

.header-row {
  display: flex;
  align-items: center;
  width: 100%;
}

.row-top {
  justify-content: space-between;
}

.game-logo {
  max-height: 44px;
  width: auto;
  object-fit: contain;
}

.actions-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #475569;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.icon-btn:hover {
  background-color: #f1f5f9;
  color: #0f172a;
}

.icon-btn .material-symbols-outlined {
  font-size: 26px;
}

/* Rules Tooltip */
.rules-tooltip-container {
  position: relative;
  display: inline-block;
}

.rules-tooltip {
  visibility: hidden;
  opacity: 0;
  width: 260px;
  background-color: #1e293b;
  color: #f8fafc;
  text-align: left;
  border-radius: 8px;
  padding: 14px;
  position: absolute;
  z-index: 10;
  top: 125%;
  right: 0;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
  transition: opacity 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
}

.rules-tooltip::after {
  content: "";
  position: absolute;
  bottom: 100%;
  right: 14px;
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent #1e293b transparent;
}

.rules-tooltip h4 {
  margin: 0 0 6px 0;
  color: #38bdf8;
  font-size: 1rem;
}

.rules-tooltip ul {
  margin: 0;
  padding-left: 16px;
  font-size: 0.8rem;
  line-height: 1.4;
}

.rules-tooltip li {
  margin-bottom: 4px;
}

.rules-tooltip-container:hover .rules-tooltip {
  visibility: visible;
  opacity: 1;
}

/* Row 2: Title */
.row-title {
  justify-content: center;
}

.game-title {
  font-size: 2.75rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ba34eb, #f7f41b); /* #00cc66, #2274a5 */
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;

  display: inline-block;
  will-change: transform, letter-spacing;

  /* Adding 3D perspective depth for smooth horizontal flipping */
  perspective: 1000px;

  animation: moveAndRotateY 1.6s cubic-bezier(0.34, 1.25, 0.64, 1) forwards;
}

@keyframes moveAndRotateY {
  0% {
    /* Starting position top-left */
    transform: translate(0, 0) scale(1) rotateY(0deg);
    letter-spacing: -0.02em;
    opacity: 0.8;
  }
  50% {
    /* Peak of animation: moved right, down, enlarged, flipped 180°, and letters spaced */
    transform: translate(120px, 40px) scale(1.4) rotateY(180deg);
    letter-spacing: 0.5em;
    opacity: 1;
  }
  100% {
    /* Returned to top-left home position, full 360° spin complete, default spacing */
    transform: translate(0, 0) scale(1) rotateY(360deg);
    letter-spacing: -0.02em;
    opacity: 1;
  }
}

/* Difficulty Container for the label and button group */
.difficulty-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 8px 0;
  font-family: system-ui, -apple-system, sans-serif;
}

/* Optional label style */
.difficulty-label {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #64748b;
}

/* The outer pill wrapper */
.difficulty-toggle {
  display: inline-flex;
  background-color: #e2e8f0;
  border-radius: 9999px;
  padding: 4px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

/* Individual difficulty buttons */
.difficulty-btn {
  border: none;
  background: transparent;
  padding: 6px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #64748b;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  outline: none;
}

/* Hover effect for inactive button */
.difficulty-btn:hover:not(.active) {
  color: #1e293b;
}

/* Active state styling */
.difficulty-btn.active {
  background-color: #f7f416; /* Yellow - f7f416 */
  color: #000000;
  /* box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35); */
  box-shadow: 0 2px 6px rgba(255, 255, 255, 1);
}

/* Optional: Slight color twist for Hard mode when active */
#btn-diff-hard.active {
  background-color: #ba34eb; /* Dark purple - hard */
  color: #ffffff;
  /* box-shadow: 0 2px 6px rgba(220, 38, 38, 0.35); */
  box-shadow: 0 2px 6px rgba(255, 255, 255, 1);
}

/* Row 3: Turn Status Banner */
.row-turn {
  justify-content: center;
}

.turn-indicator {
  font-weight: 700;
  font-size: 1.15rem;
  padding: 6px 18px;
  border-radius: 20px;
  letter-spacing: 0.02em;
  transition: all 0.3s ease;
}

/* Turn Banner Indicators */
.turn-indicator.player-turn {
  color: #1d4ed8;
  background-color: #eff6ff;
}

.turn-indicator.cpu-turn {
  color: #c2410c;
  background-color: #fff7ed;
}

.turn-indicator.win-turn {
  color: #15803d;
  background-color: #f0fdf4;
  border: 2px solid #22c55e;
  font-size: 1.35rem;
  padding: 8px 22px;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.turn-indicator.loss-turn {
  color: #b91c1c;
  background-color: #fef2f2;
  border: 2px solid #ef4444;
  font-size: 1.35rem;
  padding: 8px 22px;
  animation: shake 0.5s ease-in-out;
}

.turn-indicator.draw-turn {
  color: #475569;
  background-color: #f1f5f9;
  border: 2px solid #94a3b8;
  font-size: 1.25rem;
  padding: 8px 22px;
  text-align: center;
}
/* IS ABOVE SECTION NEEDED??? */
/* --- Turn & Victory Status Banner --- */
.turn-indicator,
.status-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0px;
  padding: 5px 10px;
  border-radius: 8px;
  text-align: center;
  transition: all 0.3s ease-in-out;
}

/* Normal Turns */
.player-turn {
  /* background-color: #d5f2f0; */
  color: #0d9488;
  border: 1px solid #0d9488;
}

.cpu-turn {
  /* background-color: #fff3e0; */
  color: #e65100;
  border: 1px solid #e65100;
}

/* End Game Highlights */
.win-banner {
  background-color: #0d9488;
  color: #ffffff;
  font-size: 2rem;
  box-shadow: 0 4px 12px rgba(46, 125, 50, 0.4);
  animation: pulse 1.2s infinite alternate;
}

.loss-banner {
  background-color: #e11d48;
  color: #ffffff;
  font-size: 2rem;
  box-shadow: 0 4px 12px rgba(198, 40, 40, 0.4);
}

.draw-banner {
  background-color: #616161;
  color: #ffffff;
  font-size: 2rem;
}

/* Subtle pulse animation for winning */
@keyframes pulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.03); }
}

/* ==========================================
   Top Source Generators (Letter / Number)
   ========================================== */
.source-container-top {
  display: flex;
  justify-content: center;
  gap: 20px;
  width: 100%;
}

.source-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.source-label {
  font-weight: 700;
  font-size: 0.75rem;
  color: #64748b;
  letter-spacing: 0.05em;
}

.source-box {
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: min(52px, 7vh);
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 2px;
}

#source-letter-box { border: 2px dashed #2274a5;  }
#source-number-box { border: 2px dashed #f75c03;  }

/* ==========================================
   5x5 Grid Board
   ========================================== */
.game-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 6px;
  background-color: #ffffff;
  padding: 10px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border: 1px solid #e2e8f0;

  /* Fill whatever vertical space is left after the header, bank rows,
     and copyright line, and stay square, capping on width OR height -
     whichever is tighter. This is what stops it forcing a scrollbar
     on short/wide (desktop) viewports. */
  flex: 1 1 auto;
  min-height: 0;
  width: auto;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

.grid-cell {
  background-color: #f1f5f9;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #64748b;
  transition: background-color 0.2s ease;
}

/* Active Grid Cells */
.grid-cell.active-player {
  background-color: #0d9488;
  color: #ffffff;
}

.grid-cell.active-cpu {
  background-color: #e11d48;
  color: #ffffff;
}

/* ==========================================
   Guaranteed Single-Line Bottom Controls Layout
   ========================================== */
.controls-container {
  display: grid;
  grid-template-columns: 2fr 1fr 2fr;
  gap: 10px;
  width: 100%;
  align-items: start;
  flex-shrink: 0;
  padding: 0 2px 0 2px;
}

.column,
.player-container,
.source-column,
.computer-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-width: 0;
  width: 100%;
}

.player-container, .computer-side { border: 1px solid silver; border-radius: 5px; padding: 4px; }

.row-label {
  font-weight: 700;
  font-size: 0.75rem;
  color: #64748b;
  text-align: center;
  letter-spacing: 0.05em;
  min-height: 30px;
}

.player-container .row-label { color: #0d9488; }
.computer-side .row-label { color: #e11d48; }

/* Enforce rigid grid tracks so elements never spill onto new lines */
.player-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 4px;
  align-items: center;
  width: 100%;
}

.cpu-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 4px;
  align-items: center;
  width: 100%;
}

/* Responsive Target Slot Sizing */
.target-box-letter,
.target-box-number {
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: min(60px, 8vh);
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 2px;
  padding: 1px;
}

.target-box-letter { border: 2px dashed #4f95d6; }
.target-box-number { border: 2px dashed #c49212; }

.target-box-letter.drag-over,
.target-box-number.drag-over {
  background-color: #eff6ff;
  border-color: #0d9488;
}

/* Compact Play Buttons with Strict Width */
.btn-play, .btn-player-play {
  background-color: #0d9488;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 6px 8px;
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  height: 100%;
  max-height: 40px;
  transition: background-color 0.2s ease, opacity 0.2s ease;
}

/* Disabled Play Button State */
.btn-play:disabled,
.btn-play.btn-disabled {
  background-color: #e0e0e0 !important;
  color: #9e9e9e !important;
  border-color: #ccc !important;
  cursor: not-allowed !important;
  opacity: 0.6;
  box-shadow: none !important;
  transform: none !important;
}


.btn-disabled,
button:disabled {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
  filter: grayscale(100%);
}


/* Ensure tiles inside small target slots shrink cleanly */
.target-box-letter .tile,
.target-box-number .tile {
  font-size: 0.85rem;
  border-radius: 4px;
}

/* ==========================================
   CPU Last Grab Highlight
   ========================================== */
   /* CPU Highlight Border */
 .target-box-letter.cpu-last-grab,
 .target-box-number.cpu-last-grab {
   outline: 3px solid #e11d48;
   outline-offset: -1px;
   box-shadow: 0 0 10px rgba(249, 115, 22, 0.4);
 }

/* ==========================================
   Tiles & Buttons
   ========================================== */
.tile {
  aspect-ratio: 1 / 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-weight: 700;
  font-size: 1rem;
  cursor: grab;
  user-select: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tile:active {
  cursor: grabbing;
}

.tile-letter {
  background-color: #4f95d6;
  color: #ffffff;
}

.tile-number {
  background-color: #c49212;
  color: #ffffff;
}



#copyright {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  font-size: 0.8em;
  flex-shrink: 0;
}

/* ==========================================
   Animations & Keyframes
   ========================================== */
@keyframes popIn {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.confetti-particle {
  position: fixed;
  top: -10px;
  z-index: 1000;
  pointer-events: none;
  border-radius: 2px;
  animation: fall linear forwards;
}

confetti({
  particleCount: 100,
  spread: 70,
  origin: { y: 0.6 },
  zIndex: 9999 // Ensures canvas renders on top of everything
});

@keyframes fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ==========================================
   Mobile Touch & Pointer Fixes
   ========================================== */
.tile {
  touch-action: none; /* Prevents scroll gestures on tiles */
  user-select: none;  /* Prevents text highlighting while dragging */
  -webkit-user-select: none;
}

.target-box-letter,
.target-box-number {
  touch-action: none;
}

/* Optional styling to make tiles smooth while floating during drag */
.tile.is-dragging {
  opacity: 0.85;
  z-index: 1000 !important;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
  pointer-events: none; /* Allows elementFromPoint to hit targets below */
}

/* ==========================================
   STATS MODAL & OVERLAY STYLES
   ========================================== */

/* Header Stats Icon Button */
.btn-icon-stats {
  background: transparent;
  border: 2px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.2s ease;
}

.btn-icon-stats:hover {
  background-color: var(--hover-bg, #f1f5f9);
  transform: translateY(-1px);
}

/* Modal Backdrop / Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.65); /* Dark semi-transparent background */
  backdrop-filter: blur(4px); /* Modern blur effect */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  padding: 16px;
}

/* Hidden Class Utility */
.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Modal Card Box */
.modal-card {
  background: #ffffff;
  width: 100%;
  max-width: 380px; /* Perfectly sized for mobile screens */
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  transform: translateY(0);
  transition: transform 0.25s ease;
  box-sizing: border-box;
}

.modal-overlay.hidden .modal-card {
  transform: translateY(20px);
}

/* Header Area */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: #0f172a;
}

.btn-icon-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.btn-icon-close:hover {
  color: #0f172a;
  background-color: #f1f5f9;
}

/* 2x2 Grid for Key Figures */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-box {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.stat-num {
  font-size: 1.6rem;
  font-weight: 800;
  color: #1e293b;
  line-height: 1.1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  font-weight: 600;
}

/* Streak Banner */
.streak-banner {
  background: #fff7ed;
  border: 1px solid #ffedd5;
  color: #c2410c;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.875rem;
  text-align: center;
  margin-bottom: 20px;
}

.streak-banner strong {
  font-weight: 700;
}

/* Modal Actions Footer */
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid #fca5a5;
  color: #dc2626;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-danger-outline:hover {
  background-color: #fef2f2;
  border-color: #ef4444;
}

.btn-secondary {
  background-color: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  background-color: #e2e8f0;
}

/* Ensure target drop slots accept pointer events */
.bank-slot,
[id*="player-target-"] {
  /* min-width: 48px;
  min-height: 48px; */
  max-width: min(60px, 8vh);
  pointer-events: auto !important;
  z-index: 10;
}

/* Ensure tiles are draggable */
.tile {
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.tile:active {
  cursor: grabbing;
}

/* Mobile Tap Selection Highlight */
.tile.selected-mobile {
  outline: 3px solid #ff9800;
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(255, 152, 0, 0.8);
}

/* --- CPU Action Animations & Highlights --- */

/* Highlight when CPU drafts or places a tile */
.tile-cpu-highlight {
  animation: cpuTilePulse 0.8s ease-in-out infinite alternate;
  box-shadow: 0 0 12px #ff9800 !important;
  border: 2px solid #ff9800 !important;
}

/* Flash animation when CPU lands a tile on the grid */
.cell-cpu-placed {
  animation: cpuBoardPlace 0.6s ease-out;
}

@keyframes cpuTilePulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.08); }
}

@keyframes cpuBoardPlace {
  0% { transform: scale(0.8); background-color: #ffe0b2; }
  50% { transform: scale(1.15); background-color: #ffb74d; }
  100% { transform: scale(1); }
}
/*
.tile {
  touch-action: none;
  -webkit-user-drag: element;
  user-select: none;
  -webkit-user-select: none;
}
*/

/* Safe Additions for Mobile & Touch Support */

.tile {
    touch-action: none; /* Prevents mobile web view from scrolling while dragging a tile */
}

.tile.selected-mobile {
    outline: 2px solid #f59e0b;
    box-shadow: 0 0 8px #f59e0b;
}

.cell.drag-over,
.bank.drag-over {
    background-color: #3b82f6;
    border-color: #60a5fa;
}

/* ==========================================
   Desktop/mouse-only layout tuning
   Targets real desktop browsers (mouse or trackpad) without
   affecting touch devices, since the app's fixed max-width
   column looks the same at any viewport size - only input
   type reliably tells "browser" apart from "phone" here.
   ========================================== */
@media (hover: hover) and (pointer: fine) {
  .target-box-letter,
  .target-box-number,
  .bank-slot,
  [id*="player-target-"] {
    max-width: 40px;
  }

  .source-box {
    max-width: 34px;
  }
}
