@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&display=swap');

:root {
  --primary: #4a90e2;
  --secondary: #ffffff;
  --accent: #f39c12;
  --bg-gradient: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%);
  --glass: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
  --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

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

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-gradient);
  color: #102a43;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
}

body.grabbing {
  cursor: grabbing !important;
}

header {
  margin-top: 2rem;
  text-align: center;
  z-index: 10;
}

h1 {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #102a43, #486581);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

.top-controls {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 1rem;
  width: 100%;
  max-width: 900px;
  margin: 0.5rem auto 0;
}

.status-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  background: var(--glass);
  backdrop-filter: blur(10px);
  padding: 0 1.5rem;
  min-height: 54px;
  border-radius: 50px;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.progress-card {
  flex: 0 0 280px;
}

.timer-card {
  flex: 0 0 160px;
  font-variant-numeric: tabular-nums;
  font-family: 'Courier New', Courier, monospace; /* Guarantee monospace for digits */
}

.utility-card {
  flex: 0 0 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--glass);
  backdrop-filter: blur(10px);
  padding: 0 0.8rem;
  min-height: 54px;
  border-radius: 50px;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

.utility-card button {
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid var(--glass-border);
  color: #102a43;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.utility-card button:hover {
  background: var(--primary);
  color: white;
  transform: scale(1.1);
}

#refresh-btn {
  font-size: 1.5rem;
}

#refresh-btn:hover {
  transform: rotate(180deg) scale(1.1) !important;
}

#timer {
  text-align: right;
}

.main-layout {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 2rem;
  padding: 2rem;
  width: 100%;
  max-width: 1400px;
}

.game-container {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#map-board {
  position: relative;
  width: 800px;
  height: 500px;
  background: var(--glass);
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.outline {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.2;
}

.placed-piece {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
}

.tray-container {
  position: relative;
  width: 180px;
  height: 500px;
  z-index: 100;
}

.tray {
  width: 100%;
  height: 100%;
  background: var(--glass);
  backdrop-filter: blur(15px);
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0;
  gap: 1.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none; /* Firefox */
}

.scroll-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 50px;
  height: 50px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  z-index: 110;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  transition: all 0.2s;
  opacity: 0.8;
}

.scroll-btn:hover {
  opacity: 1;
  transform: translateX(-50%) scale(1.1);
}

.scroll-btn.left { /* Becomes Top in vertical */
  top: -25px;
  transform: translateX(-50%) rotate(90deg);
}

.scroll-btn.right { /* Becomes Bottom in vertical */
  bottom: -25px;
  transform: translateX(-50%) rotate(90deg);
}

@media (max-width: 1100px) {
  .main-layout {
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    gap: 1rem;
    padding-bottom: 220px; /* Space for fixed tray */
  }

  .tray-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 900px;
    height: 180px;
  }

  .tray {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 1rem;
  }

  .scroll-btn {
    top: 50%;
    transform: translateY(-50%);
  }

  .scroll-btn.left {
    left: -25px;
    top: 50%;
    transform: translateY(-50%);
  }

  .scroll-btn.right {
    right: -25px;
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
  }
}

.tray::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.tray-piece {
  width: 140px;
  height: 140px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 15px;
  flex-shrink: 0;
  cursor: grab;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.tray-piece:hover {
  background: #fff;
  transform: translateY(-5px) scale(1.05);
  border-color: var(--primary);
}

.tray-piece img, .tray-piece svg {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.tray-piece.label {
  width: auto;
  min-width: 140px;
  height: 60px;
  padding: 0 1.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: #102a43;
}

.placed-center-label {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(5px);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  color: #102a43;
  pointer-events: none;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  white-space: nowrap;
  animation: pinDrop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pinDrop {
  0% { transform: translate(-50%, -150%); opacity: 0; }
  100% { transform: translate(-50%, -50%); opacity: 1; }
}

.draggable-proxy {
  position: fixed;
  width: 800px;
  height: 500px;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.8;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.2));
  user-select: none;
}

@keyframes pieceReturn {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(0.2); opacity: 0; }
}

.draggable-proxy.returning {
  animation: pieceReturn 0.4s ease-out forwards;
}

.win-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(16, 42, 67, 0.8);
  backdrop-filter: blur(8px);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  color: #fff;
}

.win-content {
  text-align: center;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  padding: 2rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.win-content h1 {
  font-size: 4rem;
  background: linear-gradient(135deg, #fff95b 0%, #ff930f 50%, #fff95b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.6));
  margin-bottom: 1rem;
  text-transform: uppercase;
}

.win-content p {
  font-size: 1.5rem;
  font-weight: 500;
  color: #fff;
  margin-bottom: 2rem;
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.btn-restart {
  margin-top: 2rem;
  padding: 1rem 2.5rem;
  font-size: 1.2rem;
  font-family: inherit;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(0,0,0,0.2);
  transition: all 0.2s;
}

.btn-restart:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 30px rgba(0,0,0,0.3);
}

/* Animations */
@keyframes snap {
  0% { transform: scale(1.1); filter: brightness(1.5); }
  100% { transform: scale(1); filter: brightness(1); }
}

.snap-anim {
  animation: snap 0.4s ease-out;
}

/* Level 3 Minerals */
.tray-piece.mineral {
  flex-direction: column;
  height: auto;
  min-height: 100px;
  padding: 1rem;
}

.mineral-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.mineral-name {
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

.placed-mineral {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  cursor: help;
  z-index: 150;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
  animation: mineralDrop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.placed-mineral:hover::after {
  content: attr(data-name);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(16, 42, 67, 0.9);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 200;
}

@keyframes mineralDrop {
  0% { transform: translate(-50%, -200%) scale(2); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
