/*
 * RAM Stacker: Silicon Tycoon
 * Cartoon RAM Design System & Responsive CSS
 */

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

:root {
  --bg-dark: #070a12;
  --bg-card: rgba(15, 23, 42, 0.85);
  --border-neon: rgba(0, 240, 255, 0.3);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-cyan: #00f0ff;
  --accent-green: #1bf5af;
  --accent-gold: #ffd700;
  --accent-purple: #c084fc;
  --accent-pink: #f43f5e;
  --font-main: 'Outfit', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* PERMANENT BRANDING FOOTER (ALWAYS VISIBLE & EMBEDDABLE) */
.app-footer {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 250;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  pointer-events: auto !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}

.nubel-link {
  color: var(--accent-cyan);
  text-decoration: none;
  font-weight: 800;
  transition: all 0.2s ease;
  border-bottom: 1px dashed var(--accent-cyan);
}

.nubel-link:hover {
  color: var(--accent-green);
  border-bottom-color: var(--accent-green);
  text-shadow: 0 0 8px var(--accent-green);
}

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

.hidden {
  display: none !important;
}

#money-rain-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 150;
}

/* LARGE STATIC BACKGROUND CHARACTER ON COMPLETION MODAL (NON-SCROLLABLE & AUTO-HEIGHT) */
#modal-completion {
  max-height: none !important;
  height: auto !important;
  overflow: visible !important;
  overflow-y: visible !important;
}

.completion-modal-bg {
  position: relative;
  overflow: visible;
  padding: 24px;
}

.completion-bg-character-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 18px;
  overflow: hidden;
}

.tycoon-static-bg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.38;
  filter: contrast(1.15) brightness(0.85);
  transform: scale(1.15);
}

.completion-content-layer {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

body, html {
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-main);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Background Animated Micro-Circuit Grid */
#app-container {
  width: 100%;
  height: 100%;
  max-width: 1200px;
  max-height: 900px;
  display: flex;
  flex-direction: column;
  position: relative;
  background: radial-gradient(circle at 50% 30%, #1e1b4b 0%, #070a12 70%);
  overflow: hidden;
  box-shadow: 0 0 50px rgba(0, 240, 255, 0.15);
}

/* Top Header Bar */
.game-header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-neon);
  z-index: 10;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.4rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.5px;
}

.brand-icon {
  font-size: 1.6rem;
  filter: drop-shadow(0 0 8px var(--accent-cyan));
}

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

.btn-icon {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--accent-cyan);
  color: var(--accent-cyan);
  padding: 8px 14px;
  border-radius: 8px;
  font-family: var(--font-main);
  font-weight: 900;
  font-size: 1.1rem;
  cursor: pointer !important;
  pointer-events: auto !important;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999 !important;
  user-select: none;
}

.btn-icon:hover {
  background: var(--accent-pink) !important;
  color: #ffffff !important;
  border-color: var(--accent-pink) !important;
  box-shadow: 0 0 15px var(--accent-pink) !important;
  transform: scale(1.1);
}

.btn-close-modal {
  cursor: pointer !important;
  pointer-events: auto !important;
  position: relative;
  z-index: 999 !important;
  user-select: none;
}

/* Main Layout Grid */
.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 240px;
  gap: 16px;
  padding: 16px;
  align-items: center;
  position: relative;
}

/* Side Panels */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
}

.hud-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-neon);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.card-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--accent-gold);
  font-family: var(--font-mono);
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

/* Progress Quota Bar */
.progress-container {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-green));
  box-shadow: 0 0 10px var(--accent-green);
  transition: width 0.3s ease;
}

/* AI Buyer Contract Widget */
.buyer-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(30, 41, 59, 0.5);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.15);
}

.buyer-icon {
  font-size: 1.8rem;
}

.buyer-name {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--accent-cyan);
}

/* Canvas Game Stage Center */
.stage-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  position: relative;
}

.canvas-wrapper {
  position: relative;
  border: 2px solid var(--accent-cyan);
  border-radius: 12px;
  padding: 4px;
  background: #000;
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.25);
}

#game-canvas {
  display: block;
  border-radius: 8px;
}

/* Piece Preview & Hold Canvas Boxes */
.canvas-preview {
  background: #080d1a;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: 4px;
}

/* Touch Controls Bar (Mobile Only) */
.touch-controls {
  display: none;
  width: 100%;
  max-width: 450px;
  margin-top: 10px;
  gap: 12px;
  justify-content: space-between;
  z-index: 5;
}

.touch-dpad, .touch-actions {
  display: flex;
  gap: 8px;
}

.btn-touch {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.9));
  border: 1px solid var(--accent-cyan);
  color: var(--text-main);
  width: 52px;
  height: 52px;
  border-radius: 12px;
  font-size: 1.4rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.btn-touch:active {
  background: var(--accent-cyan);
  color: #000;
  transform: scale(0.92);
}

/* MODAL OVERLAY & TITLE SCREEN ISOLATION */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #040812 !important;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 16px;
}

/* Full solid background on main title menu to prevent HUD bleed-through */
body.title-mode .game-layout,
body.title-mode .game-header {
  display: none !important;
}

body.title-mode #app-container {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: radial-gradient(circle at 50% 40%, #172033 0%, #050811 80%) !important;
  box-shadow: none !important;
}

body.title-mode .modal-overlay {
  position: relative !important;
  width: 100% !important;
  height: 100% !important;
  background: transparent !important;
  backdrop-filter: none !important;
}

.modal-overlay.hidden {
  display: none !important;
}

/* CRT GLITCH MONITOR FRAME FOR HOME SCREEN */
.crt-frame {
  width: 100%;
  max-width: 480px;
  background: #141b27 !important;
  border: 10px solid #222c3e;
  border-bottom: 28px solid #18202e;
  border-radius: 24px;
  padding: 16px;
  position: relative;
  z-index: 10 !important;
  box-shadow: 0 20px 60px rgba(0, 240, 255, 0.3), inset 0 0 20px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.crt-screen {
  background: #040914;
  border: 2px solid rgba(0, 240, 255, 0.3);
  border-radius: 14px;
  padding: 24px 20px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 35px rgba(0, 0, 0, 0.95);
}

#title-lightning-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0 !important;
}

.crt-scanlines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%, 
    rgba(0, 0, 0, 0.35) 50%
  );
  background-size: 100% 4px;
  pointer-events: none;
  z-index: 1;
  opacity: 0.7;
}

.crt-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
}

/* Glitch Title & Subtitle */
.crt-glitch-text {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--accent-green);
  text-shadow: 2px 2px 0px rgba(255, 0, 80, 0.7), -2px -2px 0px rgba(0, 240, 255, 0.7);
  letter-spacing: 2px;
  animation: crtGlitch 3s infinite;
  text-transform: uppercase;
}

.crt-subtitle {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-cyan);
  letter-spacing: 2px;
  background: rgba(0, 240, 255, 0.1);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(0, 240, 255, 0.3);
}

.crt-desc {
  color: #cbd5e1;
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 4px 0 8px 0;
}

.crt-button-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.crt-audio-row {
  display: flex;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

.btn-audio-toggle {
  flex: 1;
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-main);
  border: 1px solid rgba(0, 240, 255, 0.3);
  padding: 10px 8px;
  border-radius: 10px;
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-audio-toggle:hover {
  background: rgba(0, 240, 255, 0.2);
  border-color: var(--accent-cyan);
  transform: translateY(-1px);
}

.btn-audio-toggle.active {
  border-color: var(--accent-pink);
  color: var(--accent-pink);
}

/* CRT Bottom Bezel & Power LED */
.crt-bezel-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
}

.crt-brand-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 800;
  color: #64748b;
  letter-spacing: 1px;
}

#crt-power-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer !important;
  user-select: none;
  padding: 3px 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

#crt-power-toggle:hover {
  background: rgba(0, 240, 255, 0.15);
}

.crt-led-label {
  font-size: 0.65rem;
  font-weight: 800;
  color: #64748b;
  transition: color 0.2s ease;
}

.crt-power-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1bf5af;
  box-shadow: 0 0 8px #1bf5af;
  animation: ledPulse 2s infinite alternate;
  transition: all 0.2s ease;
}

#crt-power-toggle.off .crt-power-led {
  background: #ef4444 !important;
  box-shadow: 0 0 6px #ef4444 !important;
  animation: none !important;
}

#crt-power-toggle.off .crt-led-label {
  color: #ef4444 !important;
}

@keyframes ledPulse {
  0% { opacity: 0.5; }
  100% { opacity: 1.0; }
}

@keyframes crtGlitch {
  0% { text-shadow: 2px 2px 0px rgba(255, 0, 80, 0.7), -2px -2px 0px rgba(0, 240, 255, 0.7); }
  20% { text-shadow: -2px 1px 0px rgba(255, 0, 80, 0.7), 2px -1px 0px rgba(0, 240, 255, 0.7); }
  22% { text-shadow: 4px -2px 0px rgba(255, 0, 80, 0.9), -4px 2px 0px rgba(0, 240, 255, 0.9); }
  24% { text-shadow: 2px 2px 0px rgba(255, 0, 80, 0.7), -2px -2px 0px rgba(0, 240, 255, 0.7); }
  60% { text-shadow: 2px -1px 0px rgba(255, 0, 80, 0.7), -2px 1px 0px rgba(0, 240, 255, 0.7); }
  80% { text-shadow: -3px 2px 0px rgba(255, 0, 80, 0.8), 3px -2px 0px rgba(0, 240, 255, 0.8); }
  100% { text-shadow: 2px 2px 0px rgba(255, 0, 80, 0.7), -2px -2px 0px rgba(0, 240, 255, 0.7); }
}

#modal-shop,
#modal-level-select,
#modal-embed,
.modal-card {
  position: relative !important;
  z-index: 50 !important;
  background-color: #060a14 !important;
  background-image: none !important;
  opacity: 1 !important;
  border: 2px solid var(--accent-cyan);
  border-radius: 18px;
  padding: 28px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 1), 0 0 40px rgba(0, 240, 255, 0.3) !important;
  animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-action-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-green));
  color: #000;
  border: none;
  padding: 14px 24px;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(27, 245, 175, 0.4);
  transition: all 0.2s ease;
  width: 100%;
}

.btn-action-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(27, 245, 175, 0.6);
}

.btn-action-secondary {
  background: #111a2e;
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
}

.btn-action-secondary:hover {
  background: rgba(51, 65, 85, 0.9);
  border-color: var(--accent-cyan);
}

/* 100 Level Grid Cards */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 4px;
}

.level-card {
  background: #111a2e;
  border: 2px solid var(--border-neon);
  border-radius: 10px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.level-card.unlocked:hover {
  transform: scale(1.08);
  box-shadow: 0 0 15px var(--accent-cyan);
  background: rgba(0, 240, 255, 0.15);
}

.level-card.locked {
  opacity: 0.35;
  cursor: not-allowed;
}

.level-card.current {
  box-shadow: 0 0 15px var(--accent-gold);
  border-color: var(--accent-gold) !important;
}

.level-num {
  font-weight: 900;
  font-size: 0.9rem;
}

.level-buyer {
  font-size: 1.2rem;
}

.level-target {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--accent-gold);
}

/* Level Hover Tooltip Container */
.level-tooltip-container {
  background-color: #0d1526 !important;
  border: 1px solid var(--accent-cyan);
  border-radius: 12px;
  padding: 12px 16px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.95), 0 0 15px rgba(0, 240, 255, 0.2);
  transition: all 0.2s ease;
  min-height: 64px;
}

.level-tooltip-container .tooltip-icon {
  font-size: 2rem;
  background: rgba(0, 240, 255, 0.1);
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.level-tooltip-container .tooltip-details {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.level-tooltip-container .tooltip-company {
  font-weight: 900;
  font-size: 0.95rem;
  color: var(--accent-cyan);
}

.level-tooltip-container .tooltip-quote {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.2;
}

/* Shop Item Cards */
.shop-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#modal-shop .shop-card,
.shop-card {
  background-color: #0d1526 !important;
  background-image: none !important;
  opacity: 1 !important;
  border: 1px solid rgba(0, 240, 255, 0.4) !important;
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.95) !important;
}

.shop-icon {
  font-size: 2rem;
}

.shop-info {
  flex: 1;
}

.shop-title {
  font-weight: 800;
  font-size: 1rem;
}

.shop-lvl {
  font-size: 0.75rem;
  color: var(--accent-cyan);
}

.shop-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-buy {
  background: linear-gradient(135deg, var(--accent-gold), #f59e0b);
  color: #000;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-buy.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #334155;
  color: #94a3b8;
}

/* Embed Textarea Box */
.embed-box {
  width: 100%;
  height: 90px;
  background: #000;
  border: 1px solid var(--accent-cyan);
  border-radius: 8px;
  color: var(--accent-green);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 10px;
  resize: none;
}

/* --- RESPONSIVE MEDIA QUERIES FOR MOBILE PHONES & IFRAMES --- */
@media (max-width: 820px) {
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    padding: 8px;
    gap: 8px;
    overflow-y: auto;
  }

  .side-panel {
    flex-direction: row;
    justify-content: space-between;
    height: auto;
  }

  .hud-card {
    padding: 8px 12px;
    flex: 1;
  }

  .card-value {
    font-size: 1.1rem;
  }

  .touch-controls {
    display: flex;
  }
}
