/*
 * Botchee 4x4 - Stylesheet
 * Palette inspired by Gary Stout's extendUIColor.swift:
 * Palatinate Blue: #006388
 * Cobalt / Dark Blue: #001f3f, #00112c
 * Royal Blue: #4169e1
 * Ghost White: #f8f8ff
 * Alice Blue: #f0f8ff
 */

:root {
  --bg-gradient-start: #00112c;
  --bg-gradient-end: #003366;
  --palatinate-blue: #006388;
  --cobalt-blue: #004b7a;
  --sky-blue: #87ceeb;
  --ghost-white: #f8f8ff;
  --alice-blue: #f0f8ff;
  --board-bg: #0b1e38;
  --cell-bg: #142a4a;
  --cell-hover: #1e3c66;
  --cell-target: #0088cc;
  --cell-conflict: #d32f2f;
  --die-bg: #ffffff;
  --die-pip-color: #001f3f;
  --die-border: #ccddee;
  --die-selected: #ffd700;
  --die-botched: #78909c;
  --p1-accent: #00c0ff;
  --p2-accent: #ff9900;
  --bonus-color: #00e676;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font-family);
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  color: var(--ghost-white);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  overflow-x: hidden;
}

.botchee-container {
  width: 100%;
  max-width: 460px;
  background: rgba(11, 30, 56, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 99, 136, 0.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

/* Header & Controls */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 8px;
}

.logo-section h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(45deg, #87ceeb, #ffffff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.mode-badge {
  display: inline-block;
  font-size: 0.7rem;
  background: var(--palatinate-blue);
  color: #fff;
  -webkit-text-fill-color: #ffffff;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  margin-left: 6px;
  vertical-align: middle;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--ghost-white);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.06);
}

/* Opponent & Bot Bar */
.match-config-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.82rem;
}

.config-select-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.config-select-group select {
  background: #002244;
  color: #fff;
  border: 1px solid var(--palatinate-blue);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.btn-new-game {
  background: linear-gradient(135deg, #0077b6, #0096c7);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 150, 199, 0.4);
  transition: all 0.2s ease;
}

.btn-new-game:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

/* Scoreboard */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 10px;
  position: relative;
}

.player-card {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.3s ease;
  position: relative;
}

.player-card.active-p1 {
  border-color: var(--p1-accent);
  box-shadow: 0 0 12px rgba(0, 192, 255, 0.4);
  background: rgba(0, 192, 255, 0.1);
}

.player-card.active-p2 {
  border-color: var(--p2-accent);
  box-shadow: 0 0 12px rgba(255, 153, 0, 0.4);
  background: rgba(255, 153, 0, 0.1);
}

.player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 700;
}

.player-type-pill {
  font-size: 0.65rem;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  text-transform: uppercase;
}

.score-stats {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.turn-score-box {
  font-size: 0.75rem;
  color: #b0c4de;
}

.turn-score-box span {
  font-weight: bold;
  color: var(--ghost-white);
  margin-left: 2px;
}

.total-score-box {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.total-score-box.score-pulse {
  transform: scale(1.3);
  color: #ffe600;
}

/* Turn Status Notice */
.turn-status-banner {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 22px;
  color: #bfe3f7;
  letter-spacing: 0.3px;
}

/* Game Board */
.board-container {
  display: flex;
  justify-content: center;
  position: relative;
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 4px;
  width: 100%;
  aspect-ratio: 1;
  max-width: 360px;
  background: var(--board-bg);
  border: 3px solid var(--palatinate-blue);
  border-radius: 12px;
  padding: 6px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.6), 0 4px 15px rgba(0, 0, 0, 0.4);
  position: relative;
}

/* 2x2 Quadrant demarcation */
.board-cell {
  background: var(--cell-bg);
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Quadrant borders (thick lines between 2x2 boxes) */
.board-cell[data-col="1"] {
  border-right: 2px solid rgba(135, 206, 235, 0.6);
  margin-right: 2px;
}
.board-cell[data-row="1"] {
  border-bottom: 2px solid rgba(135, 206, 235, 0.6);
  margin-bottom: 2px;
}

.board-cell:hover:not(.filled) {
  background: var(--cell-hover);
  border-color: rgba(255, 255, 255, 0.3);
  transform: scale(0.97);
}

.board-cell.target-highlight {
  background: rgba(0, 136, 204, 0.35);
  border-color: var(--sky-blue);
  box-shadow: 0 0 10px rgba(0, 136, 204, 0.6);
}

.board-cell.conflict-shake {
  animation: cellConflict 0.4s ease;
  background: var(--cell-conflict) !important;
  border-color: #ff5252 !important;
}

@keyframes cellConflict {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.board-cell.filled {
  cursor: default;
  background: rgba(255, 255, 255, 0.03);
}

/* Dice Graphics (Authentic 3D Pips) */
.die {
  width: 90%;
  height: 90%;
  background: var(--die-bg);
  border-radius: 8px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35), inset 0 -2px 4px rgba(0, 0, 0, 0.15), inset 0 2px 3px rgba(255, 255, 255, 0.9);
  display: grid;
  padding: 6px;
  border: 1px solid var(--die-border);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: pointer;
  position: relative;
}

.die:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.45);
}

.die.selected {
  outline: 3px solid var(--die-selected);
  box-shadow: 0 0 12px var(--die-selected);
  transform: translateY(-4px) scale(1.05);
}

.die.plunk-anim {
  animation: diePlunk 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes diePlunk {
  0% { transform: scale(1.4) translateY(-10px); opacity: 0.6; }
  60% { transform: scale(0.92); }
  100% { transform: scale(1); opacity: 1; }
}

/* Die Pip Layouts (1, 2, 3, 4) */
.pip {
  background: var(--die-pip-color);
  border-radius: 50%;
  width: 10px;
  height: 10px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
  justify-self: center;
  align-self: center;
}

/* Pip Grids */
.die[data-value="1"] {
  display: flex;
  justify-content: center;
  align-items: center;
}

.die[data-value="2"] {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.die[data-value="2"] .pip:nth-child(1) { grid-area: 1 / 1; }
.die[data-value="2"] .pip:nth-child(2) { grid-area: 2 / 2; }

.die[data-value="3"] {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}
.die[data-value="3"] .pip:nth-child(1) { grid-area: 1 / 1; }
.die[data-value="3"] .pip:nth-child(2) { grid-area: 2 / 2; }
.die[data-value="3"] .pip:nth-child(3) { grid-area: 3 / 3; }

.die[data-value="4"] {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.die[data-value="4"] .pip:nth-child(1) { grid-area: 1 / 1; }
.die[data-value="4"] .pip:nth-child(2) { grid-area: 1 / 2; }
.die[data-value="4"] .pip:nth-child(3) { grid-area: 2 / 1; }
.die[data-value="4"] .pip:nth-child(4) { grid-area: 2 / 2; }

/* Stash / Dice Tray */
.dice-stash-section {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: #a0b8cc;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.stash-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stash-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
}

.stash-slot .die {
  width: 54px;
  height: 54px;
}

.stash-count {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--ghost-white);
  background: rgba(0, 0, 0, 0.4);
  padding: 1px 7px;
  border-radius: 10px;
}

/* Botched & Depleted Dice States */
.stash-slot.depleted .die {
  opacity: 0.25;
  filter: grayscale(100%);
  cursor: not-allowed;
  pointer-events: none;
}

.stash-slot.botched .die {
  background: var(--die-botched);
  opacity: 0.5;
  box-shadow: none;
  border-color: #f44336;
}

.stash-slot.botched::after {
  content: "BOTCHED";
  position: absolute;
  top: 18px;
  font-size: 0.6rem;
  font-weight: 800;
  color: #ff3d00;
  background: rgba(0, 0, 0, 0.85);
  padding: 1px 4px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  pointer-events: none;
}

/* Flying Dice Pip Animation Layer */
.flying-pips-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999;
}

.flying-pip {
  position: absolute;
  width: 12px;
  height: 12px;
  background: radial-gradient(circle, #fff, #ffd700);
  border-radius: 50%;
  box-shadow: 0 0 10px #ffea00, 0 0 16px #ff9900;
  pointer-events: none;
  will-change: transform, opacity;
}

/* Floating Bonus Toast */
.bonus-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  background: rgba(0, 17, 44, 0.95);
  border: 2px solid var(--bonus-color);
  color: #fff;
  padding: 12px 24px;
  border-radius: 14px;
  box-shadow: 0 0 30px rgba(0, 230, 118, 0.6);
  text-align: center;
  z-index: 1000;
  pointer-events: none;
  animation: bonusPop 1.4s ease forwards;
}

.bonus-toast h3 {
  font-size: 1.3rem;
  color: var(--bonus-color);
  margin-bottom: 4px;
}

.bonus-toast p {
  font-size: 0.9rem;
  color: #e0f2fe;
}

@keyframes bonusPop {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  35% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80% { transform: translate(-50%, -70%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -90%) scale(0.8); opacity: 0; }
}

/* Game Over Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: linear-gradient(135deg, #071e3d, #001f3f);
  border: 2px solid var(--palatinate-blue);
  border-radius: 18px;
  max-width: 440px;
  width: 90%;
  padding: 24px;
  color: #fff;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8), 0 0 25px rgba(0, 99, 136, 0.5);
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 10px;
}

.modal-header h2 {
  font-size: 1.3rem;
  color: var(--sky-blue);
}

.modal-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  font-size: 0.88rem;
  line-height: 1.5;
  color: #cfd8dc;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-body h4 {
  color: #fff;
  margin-top: 6px;
}

.modal-body ul {
  padding-left: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary {
  background: linear-gradient(135deg, #0077b6, #0096c7);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 150, 199, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 8px 18px;
  cursor: pointer;
}

/* Plan Drawer Preview */
.blueprint-card {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 150, 199, 0.3);
  border-radius: 10px;
  padding: 12px;
  margin-top: 8px;
}

.blueprint-card code {
  background: rgba(0, 0, 0, 0.5);
  padding: 2px 5px;
  border-radius: 4px;
  color: #80d8ff;
  font-size: 0.82rem;
}

/* Responsive Scaling */
@media (max-width: 400px) {
  .botchee-container {
    padding: 10px;
  }
  .stash-slot .die {
    width: 44px;
    height: 44px;
  }
  .pip {
    width: 8px;
    height: 8px;
  }
}
