/* Goolee - Web Version - Matching Unity 3D Board Style */

:root {
  --bg-dark: #0d0a12;
  --bg-board: #14101c;
  --node-base: #2a2438;
  --node-rim: #4a4458;
  --connection-line: rgba(180, 175, 195, 0.6);
  --highlight-allowed: rgba(100, 220, 180, 0.5);
  --highlight-glow: rgba(100, 220, 180, 0.8);
  --piece-blue: #4a90d9;
  --piece-green: #5cb85c;
  --piece-red: #d9534f;
  --piece-yellow: #f0ad4e;
  --text-primary: #e8e4ef;
  --text-muted: #9a94a8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.game-container {
  width: 100%;
  max-width: 1200px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  min-height: 0;
  flex: 1;
  box-sizing: border-box;
}

.game-header {
  text-align: center;
}

.game-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Main area: Top = Reference | Bottom = Gameplay */
.main-area {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
}

/* Desktop: Left-Right layout */
@media (min-width: 1201px) {
  .main-area {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 2rem;
  }

  .reference-panel {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    align-self: center;
    max-width: 520px;
  }

  .reference-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .game-panel {
    flex: 1 1 auto;
    order: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .scoreboard-panel {
    flex: 0 0 auto;
    order: 2;
    align-self: flex-start;
    min-width: 260px;
    max-width: 340px;
  }
}

.reference-panel {
  background: linear-gradient(145deg, #1a1525 0%, #14101c 100%);
  border: 1px solid var(--node-rim);
  border-radius: 12px;
  padding: 1rem;
  flex-shrink: 0;
  max-width: 520px;
  width: 100%;
}

.reference-toggle {
  display: none;
}

.reference-content {
  display: block;
}

.reference-panel h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  text-align: center;
}

.gameplay-label {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  font-weight: 600;
}

.goal-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.5rem;
}

.goal-board {
  width: 100%;
  max-width: 520px;
  height: auto;
  aspect-ratio: 520 / 420;
  background: var(--bg-board);
  border-radius: 8px;
  overflow: hidden;
}

.goal-board-svg {
  width: 100%;
  height: 100%;
}

.game-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.scoreboard-panel {
  background: linear-gradient(145deg, #1a1525 0%, #14101c 100%);
  border: 1px solid var(--node-rim);
  border-radius: 12px;
  padding: 1.25rem;
  min-width: 260px;
  flex: 1;
  max-width: 340px;
}

.scoreboard-panel h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-align: center;
}

.score-history-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  text-align: center;
}

.score-history-list {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.score-history-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.5rem;
}

.score-history-item {
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  color: var(--text-primary);
}

.scoreboard-stats-live {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.scoreboard-stats-live .score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.scoreboard-stats-live .score-row span {
  color: var(--text-muted);
}

.scoreboard-stats-live .score-row strong {
  color: var(--text-primary);
  font-size: 1.1rem;
}

.goal-board-svg line {
  stroke: rgba(180, 175, 195, 0.4);
  stroke-width: 1;
  stroke-linecap: round;
}

.goal-board-svg .goal-piece {
  stroke: rgba(255,255,255,0.2);
  stroke-width: 1;
}

.goal-board-svg .goal-piece-blue { fill: var(--piece-blue); }
.goal-board-svg .goal-piece-green { fill: var(--piece-green); }
.goal-board-svg .goal-piece-red { fill: var(--piece-red); }
.goal-board-svg .goal-piece-yellow { fill: var(--piece-yellow); }
.goal-board-svg .goal-empty {
  fill: var(--node-base);
  stroke: var(--node-rim);
  stroke-width: 1;
}

/* Board - 3D-ish look */
.board-wrapper {
  position: relative;
  padding: 1rem;
  border-radius: 12px;
  background: radial-gradient(ellipse at center, #1a1525 0%, var(--bg-board) 70%);
  box-shadow: 
    0 0 60px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.board {
  position: relative;
  width: 520px;
  height: 420px;
  max-width: 100%;
  min-height: 0;
}

.board-connections {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.board-connections line {
  stroke: var(--connection-line);
  stroke-width: 2;
  stroke-linecap: round;
}

/* Node spots - circular recessed style */
.nodes-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.node {
  position: absolute;
  width: 44px;
  height: 44px;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Empty node - grey recessed look */
.node.empty {
  background: radial-gradient(circle at 35% 35%, #3a3548, var(--node-base));
  border: 2px solid var(--node-rim);
  box-shadow: 
    inset 0 2px 4px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.05);
}

.node.empty:hover {
  transform: translate(-50%, -50%) scale(1.05);
}

/* Node with piece - glossy sphere */
.node.has-piece {
  background: transparent;
  border: none;
  box-shadow: none;
}

.node.has-piece .piece {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  box-shadow: 
    inset -4px -4px 12px rgba(0, 0, 0, 0.35),
    inset 4px 4px 12px rgba(255, 255, 255, 0.25),
    0 4px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.node.has-piece:hover .piece {
  transform: scale(1.1);
  box-shadow: 
    inset -4px -4px 12px rgba(0, 0, 0, 0.3),
    inset 4px 4px 12px rgba(255, 255, 255, 0.3),
    0 6px 20px rgba(0, 0, 0, 0.5);
}

.node.has-piece.selected .piece {
  transform: scale(1.15);
  box-shadow: 
    inset -4px -4px 12px rgba(0, 0, 0, 0.3),
    inset 4px 4px 12px rgba(255, 255, 255, 0.35),
    0 0 0 3px var(--highlight-glow),
    0 0 24px var(--highlight-allowed);
}

/* Allowed move highlight */
.node.allowed-move {
  background: radial-gradient(circle at 35% 35%, #3a4050, #2a3545);
  border: 2px solid var(--highlight-glow);
  box-shadow: 
    inset 0 2px 4px rgba(0, 0, 0, 0.3),
    0 0 12px var(--highlight-allowed);
  animation: pulse-glow 1.2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: inset 0 2px 4px rgba(0,0,0,0.3), 0 0 12px var(--highlight-allowed); }
  50% { box-shadow: inset 0 2px 4px rgba(0,0,0,0.3), 0 0 20px var(--highlight-glow); }
}

/* Piece colors - glossy spheres */
.piece.blue {
  background: linear-gradient(135deg, #6ba3e8 0%, #3a7bc8 40%, #2563a8 100%);
}

.piece.green {
  background: linear-gradient(135deg, #7cc87c 0%, #4aad4a 40%, #2d8a2d 100%);
}

.piece.red {
  background: linear-gradient(135deg, #e87070 0%, #c74a4a 40%, #a83030 100%);
}

.piece.yellow {
  background: linear-gradient(135deg, #f5c165 0%, #e0a030 40%, #c48820 100%);
}

/* Footer */
.game-footer {
  position: relative;
  display: flex;
  gap: 1rem;
  align-items: center;
}

.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-reset {
  background: linear-gradient(135deg, #3a3548 0%, #2a2438 100%);
  color: var(--text-primary);
  border: 1px solid var(--node-rim);
}

.btn-reset:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Win overlay */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.win-overlay.visible {
  display: flex;
}

.win-card {
  background: linear-gradient(145deg, #1e1a2a 0%, #15121e 100%);
  border: 1px solid var(--node-rim);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: win-pop 0.4s ease-out;
}

@keyframes win-pop {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.win-card h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: #5cb85c;
}

.win-card p {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.scoreboard-stats {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
}

.win-download-badges {
  margin-bottom: 1.25rem;
}

.win-badges-label {
  font-size: 2rem;
  color: #5cb85c;
  margin-bottom: 0.75rem;
}

.win-badges-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.win-badge-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.win-badge-link:hover {
  transform: scale(1.05);
  opacity: 0.95;
}

.win-badge-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

/* ========== DESKTOP: Resize each button manually (width / height) ========== */
.win-badge-steam {
  width: 180px;
  height: 90px;
}
.win-badge-appstore {
  width: 160px;
  height: 44px;
}
.win-badge-playstore {
  width: 180px;
  height: 90px;
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
}

.score-row span {
  color: var(--text-muted);
}

.score-row strong {
  color: var(--text-primary);
  font-size: 1.1rem;
}

.btn-next {
  background: linear-gradient(135deg, #5cb85c 0%, #4a9a4a 100%);
  color: white;
}

.btn-next:hover {
  box-shadow: 0 4px 16px rgba(92, 184, 92, 0.4);
}

@media (max-width: 1200px) {
  .game-container {
    padding: 1rem;
    align-items: stretch;
  }

  .reference-panel,
  .scoreboard-panel {
    min-width: auto;
    width: 100%;
    max-width: 100%;
  }

  .scoreboard-stats-live {
    flex-direction: row;
    justify-content: center;
    gap: 2rem;
  }
}

@media (max-width: 640px) {
  .game-container {
    padding: 0.5rem 0.75rem 1rem;
    overflow-x: hidden;
  }

  .game-header {
    margin-bottom: 0;
  }

  .game-header h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.75rem;
    line-height: 1.4;
    padding: 0;
    margin-bottom: 0.75rem;
  }

  .main-area {
    flex-direction: column;
    gap: 0.75rem;
    overflow-x: hidden;
  }

  /* Mobile: Top = reference, bottom = gameplay (natural DOM order) */
  .reference-panel {
    width: 100%;
    max-width: 100%;
    padding: 1rem;
  }

  .reference-toggle {
    display: block;
    width: 100%;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: linear-gradient(135deg, #2a2438 0%, #1a1525 100%);
    color: var(--text-primary);
    border: 1px solid var(--node-rim);
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation;
  }

  .reference-content {
    display: block;
  }

  .reference-panel:not(.reference-expanded) .reference-content {
    display: none;
  }

  .reference-panel h3 {
    font-size: 0.9rem;
  }

  .goal-board {
    max-width: 100%;
    width: 100%;
  }

  .gameplay-label {
    font-size: 0.9rem;
  }

  .scoreboard-panel {
    padding: 1rem;
  }

  .scoreboard-panel h3 {
    font-size: 0.9rem;
  }

  .board-wrapper {
    padding: 0.5rem;
    width: 100%;
  }

  .board {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 520 / 420;
    max-width: 100%;
  }

  .board-connections,
  .nodes-container {
    width: 100%;
    height: 100%;
  }

  /* Smaller colored game pieces on mobile */
  .node {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }

  .node.has-piece .piece {
    width: 28px;
    height: 28px;
  }

  .game-footer {
    flex-wrap: wrap;
    justify-content: center;
    padding: 0.5rem 0;
  }

  .btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 6px;
    touch-action: manipulation;
  }

  .game-footer .btn-reset {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
  }

  .win-overlay {
    padding: 1rem;
    align-items: center;
    justify-content: center;
  }

  .win-card {
    margin: 0;
    padding: 1.5rem;
    max-width: min(360px, calc(100vw - 2rem));
    width: 100%;
  }

  .win-card h2 {
    font-size: 1.2rem;
  }

  .win-badges-row {
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
  }

  /* ========== MOBILE: Resize each button manually (width / height) ========== */
  .win-badge-steam {
    width: 200px;
    height: 65px;
  }
  .win-badge-appstore {
    width: 200px;
    height: 48px;
  }
  .win-badge-playstore {
    width: 200px;
    height: 65px;
  }

  .win-badge-img {
    height: 100%;
    max-width: 100%;
  }

  .score-history-list {
    max-height: 100px;
  }
}

@media (max-width: 380px) {
  .node {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }

  .node.has-piece .piece {
    width: 24px;
    height: 24px;
  }
}
