/* ==========================================================================
   PlayForge 3D - Modern Cyber/Sandbox Game Stylesheet
   ========================================================================== */

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

:root {
  --bg-dark: #020617;
  --panel-bg: rgba(15, 23, 42, 0.92);
  --border-color: #1e293b;
  --accent-indigo: #6366f1;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-cyan: #06b6d4;
  --accent-yellow: #facc15;
  --accent-purple: #a855f7;
  --font-main: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: #ffffff;
  font-family: var(--font-main);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app-container {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--bg-dark);
}

/* ==========================================================================
   TOP HEADER NAVIGATION BAR
   ========================================================================== */
.game-header {
  width: 100%;
  height: 52px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 30;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.4);
  padding: 5px 10px;
  border-radius: 10px;
  color: #c7d2fe;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.08em;
}

.brand-icon {
  color: var(--accent-yellow);
  font-size: 14px;
  animation: pulse-glow 2s infinite ease-in-out;
}

.theme-button {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-button:hover {
  background: #334155;
  border-color: #475569;
}

/* Mode Switcher Pill */
.mode-switcher {
  display: flex;
  align-items: center;
  background: rgba(2, 6, 23, 0.85);
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  color: #94a3b8;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mode-btn:hover {
  color: #ffffff;
}

.mode-btn.active-build {
  background: var(--accent-amber);
  color: #020617;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
  transform: scale(1.02);
}

.mode-btn.active-play {
  background: var(--accent-emerald);
  color: #020617;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
  transform: scale(1.02);
}

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

.btn-icon-text {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #f1f5f9;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon-text:hover {
  background: #334155;
}

.btn-share {
  background: #4338ca;
  border-color: #6366f1;
}

.btn-share:hover {
  background: #4f46e5;
}

/* ==========================================================================
   MAIN 3D VIEWPORT & CANVAS
   ========================================================================== */
.canvas-viewport {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
  background-color: var(--bg-dark);
  overflow: hidden;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

/* ==========================================================================
   HUD OVERLAY (PLAY MODE)
   ========================================================================== */
.play-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  pointer-events: none;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: opacity 0.3s ease;
}

.hud-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.hearts-container {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 16px;
}

.heart {
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.heart.lost {
  opacity: 0.25;
  filter: grayscale(1);
  transform: scale(0.8);
}

.hud-divider {
  width: 1px;
  height: 16px;
  background: #334155;
}

.stars-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  font-size: 13px;
  color: var(--accent-yellow);
}

.key-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.5);
  color: #fde68a;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 800;
  animation: key-bounce 1s infinite alternate ease-in-out;
}

.time-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: #94a3b8;
  font-weight: 600;
}

/* ==========================================================================
   TOAST NOTIFICATION
   ========================================================================== */
.toast {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-indigo);
  color: #ffffff;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.5);
  border: 1px solid #818cf8;
  z-index: 50;
  pointer-events: none;
  animation: toast-drop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ==========================================================================
   MOBILE ON-SCREEN CONTROLS (PLAY MODE)
   ========================================================================== */
.mobile-controls {
  position: absolute;
  inset-x: 0;
  bottom: 24px;
  padding: 0 24px;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  z-index: 20;
}

.dpad-container {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  padding: 8px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.dpad-row {
  display: flex;
  gap: 6px;
}

.dpad-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.1s ease;
  user-select: none;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: var(--accent-indigo);
  border-color: #818cf8;
  transform: scale(0.92);
}

.action-buttons-container {
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.reset-btn {
  width: 50px;
  height: 50px;
  min-width: 50px;
  min-height: 50px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid #334155;
  border-radius: 16px;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s ease;
}

.reset-btn:active {
  background: #334155;
  transform: scale(0.92);
}

.jump-btn {
  width: 68px;
  height: 68px;
  min-width: 68px;
  min-height: 68px;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  border: 2px solid #6ee7b7;
  border-radius: 24px;
  color: #020617;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
  transition: all 0.1s ease;
}

.jump-btn .jump-icon {
  font-size: 24px;
  line-height: 1;
}

.jump-btn .jump-label {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.jump-btn:active, .jump-btn.pressed {
  transform: scale(0.92);
  filter: brightness(1.15);
}

/* ==========================================================================
   BUILDER BOTTOM TOOLBAR (BUILD MODE)
   ========================================================================== */
.builder-toolbar {
  width: 100%;
  background: #0f172a;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 30;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
}

.toolbar-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(2, 6, 23, 0.6);
  border-bottom: 1px solid rgba(30, 41, 59, 0.6);
  gap: 8px;
}

.category-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: #ffffff;
}

.tab-btn.active {
  background: var(--accent-indigo);
  color: #ffffff;
  border-color: #818cf8;
}

.tool-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layer-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  padding: 3px 8px;
  border-radius: 8px;
}

.layer-label {
  font-size: 10px;
  font-weight: 800;
  color: #94a3b8;
}

.layer-btn {
  width: 22px;
  height: 22px;
  background: #334155;
  border: none;
  border-radius: 6px;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.layer-btn:hover {
  background: #475569;
}

.layer-val {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-amber);
  min-width: 14px;
  text-align: center;
}

.btn-tool {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid #334155;
  background: #1e293b;
  color: #cbd5e1;
  transition: all 0.2s ease;
}

.btn-tool:hover {
  background: #334155;
}

.btn-tool.active-erase {
  background: #dc2626;
  border-color: #f87171;
  color: #ffffff;
  box-shadow: 0 0 10px rgba(220, 38, 38, 0.4);
}

.btn-tool:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.catalog-carousel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

.catalog-carousel::-webkit-scrollbar {
  height: 4px;
}

.catalog-carousel::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}

.block-card {
  min-width: 58px;
  height: 60px;
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid #1e293b;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.block-card:hover {
  border-color: #334155;
  background: #1e293b;
}

.block-card.selected {
  border-color: var(--accent-yellow);
  background: #1e293b;
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 4px 12px rgba(250, 204, 21, 0.25);
}

.block-icon {
  font-size: 22px;
  line-height: 1;
  margin-bottom: 2px;
}

.block-title {
  font-size: 10px;
  font-weight: 700;
  color: #cbd5e1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   MODAL OVERLAYS & DIALOGS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

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

.modal-card {
  background: #0f172a;
  border: 2px solid var(--border-color);
  border-radius: 20px;
  padding: 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.open .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 22px;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 0.02em;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}

.modal-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.modal-btn-primary {
  background: var(--accent-emerald);
  color: #020617;
}

.modal-btn-primary:hover {
  filter: brightness(1.1);
}

.modal-btn-secondary {
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
}

.modal-btn-secondary:hover {
  background: #334155;
}

.modal-btn-danger {
  background: rgba(153, 27, 27, 0.4);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

.modal-btn-danger:hover {
  background: rgba(185, 28, 28, 0.6);
}

.modal-btn-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 12px;
  cursor: pointer;
  padding: 8px;
  text-align: center;
}

.modal-btn-close:hover {
  color: #ffffff;
}

.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.info-card {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
  color: #cbd5e1;
}

.info-card-title {
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 4px;
}

.preset-item {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: border-color 0.2s ease;
}

.preset-item:hover {
  border-color: var(--accent-indigo);
}

.preset-badge {
  font-size: 10px;
  font-weight: 700;
  background: #334155;
  color: #94a3b8;
  padding: 2px 8px;
  border-radius: 20px;
}

.share-input-row {
  display: flex;
  gap: 8px;
}

.share-input {
  flex: 1;
  background: #020617;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  color: #ffffff;
  outline: none;
}

.share-input:focus {
  border-color: var(--accent-indigo);
}

/* Victory Modal Specifics */
.victory-card {
  border-color: var(--accent-yellow);
  text-align: center;
  align-items: center;
}

.trophy-icon {
  font-size: 48px;
  margin-bottom: 6px;
  animation: trophy-bounce 1s infinite alternate ease-in-out;
}

.victory-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--accent-yellow);
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.victory-subtitle {
  font-size: 12px;
  color: #cbd5e1;
  margin-bottom: 16px;
}

.victory-stats-box {
  width: 100%;
  background: rgba(2, 6, 23, 0.8);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.victory-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #94a3b8;
}

.victory-stat-val {
  font-weight: 800;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes pulse-glow {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.15); opacity: 1; }
}

@keyframes key-bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-3px); }
}

@keyframes trophy-bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-6px); }
}

@keyframes toast-drop {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .theme-button span.theme-label {
    display: none;
  }
  .btn-icon-text span {
    display: none;
  }
  .dpad-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  .jump-btn {
    width: 60px;
    height: 60px;
    min-width: 60px;
    min-height: 60px;
  }
}
