/* assets/css/app.css - SpriteGrid Modern SaaS Styling */

:root {
  --bg: #0B0F17;
  --bg-card: #131B2A;
  --bg-surface: #1B263B;
  --border: #23324D;
  --border-focus: #4F46E5;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --accent: #E31C6E;
  --accent-hover: #C21861;
  --text-main: #F1F5F9;
  --text-muted: #94A3B8;
  --text-dim: #64748B;
  --success: #10B981;
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --error: #EF4444;
  --error-bg: rgba(239, 68, 68, 0.12);
  --radius: 8px;
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Space Grotesk', var(--font-sans);
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background-color: var(--bg);
  background-image: 
    radial-gradient(circle at 50% 0%, rgba(79, 70, 229, 0.15) 0%, transparent 60%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 32px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 32px);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* Typography & Links */
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* App Wrapper */
.app-container { max-width: 1240px; margin: 0 auto; padding: 0 24px 64px; }

/* Header & Nav */
.header-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}
.brand-area { display: flex; align-items: center; gap: 14px; }
.logo-box {
  width: 38px; height: 38px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 20px; color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}
.brand-title { font-size: 20px; letter-spacing: -0.02em; }
.brand-title span { color: var(--accent); }
.brand-sub { font-size: 12px; color: var(--text-dim); }

.nav-actions { display: flex; align-items: center; gap: 12px; }
.user-widget { display: flex; align-items: center; gap: 10px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px; border-radius: var(--radius);
  font-family: var(--font-display); font-weight: 600; font-size: 13.5px;
  cursor: pointer; transition: all 0.15s ease; border: none; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-surface); color: var(--text-main); border: 1px solid var(--border); }
.btn-secondary:hover { background: #23324D; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text-main); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 11px; }

/* Badges */
.tier-badge {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 4px; text-transform: uppercase;
}
.tier-free { background: rgba(148, 163, 184, 0.15); color: #94A3B8; border: 1px solid rgba(148, 163, 184, 0.3); }
.tier-pro { background: rgba(227, 28, 110, 0.15); color: var(--accent); border: 1px solid rgba(227, 28, 110, 0.4); }
.tag-pro {
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 3px;
  margin-left: 6px; vertical-align: middle;
}

/* Hero Section */
.hero-section {
  text-align: center;
  max-width: 780px;
  margin: 0 auto 36px;
}
.hero-section h1 { font-size: 36px; letter-spacing: -0.02em; margin-bottom: 12px; }
.hero-section p { font-size: 16px; color: var(--text-muted); margin-bottom: 20px; }
.hero-stats {
  display: inline-flex; gap: 24px; padding: 8px 18px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px;
  font-family: var(--font-mono); font-size: 13px; color: var(--text-muted);
}
.hero-stats b { color: var(--text-main); }

/* Main Studio Layout */
.studio-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 960px) {
  .studio-grid { grid-template-columns: 1fr; }
}

/* Panels & Cards */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.controls-panel { position: sticky; top: 20px; }

/* Steps */
.step { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.step:last-child { border-bottom: none; }
.step-title {
  font-size: 13px; font-weight: 700; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px; color: var(--text-main);
}
.step-num {
  font-family: var(--font-mono); font-size: 11px;
  background: rgba(79, 70, 229, 0.2); color: #818CF8;
  border: 1px solid rgba(79, 70, 229, 0.4); border-radius: 4px; padding: 2px 7px;
}
.step.disabled { opacity: 0.4; pointer-events: none; }

/* Dropzone */
.dropzone {
  display: block;
  width: 100%;
  border: 2px dashed rgba(79, 70, 229, 0.35);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  background: rgba(19, 27, 42, 0.6);
  transition: all 0.2s ease;
  color: var(--text-muted);
  font-size: 13.5px;
  user-select: none;
}
.dropzone * {
  pointer-events: none;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--accent);
  background: rgba(227, 28, 110, 0.08);
  color: var(--text-main);
}
.dropzone strong {
  display: block;
  color: var(--text-main);
  font-size: 14px;
  margin-bottom: 4px;
}
.dropzone input {
  display: none;
}
.file-chip {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; margin-top: 10px; font-size: 13px;
}
.file-chip button {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 12px; text-decoration: underline; padding: 0;
}

/* Fields & Toggles */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 5px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type="number"], select, input[type="text"], input[type="password"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text-main); font-family: var(--font-mono); font-size: 13px;
}
input:focus, select:focus {
  outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.25);
}
.mode-toggle {
  display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: 12px;
}
.mode-toggle button {
  flex: 1; border: none; background: var(--bg); padding: 8px 10px; font-size: 12.5px;
  color: var(--text-muted); cursor: pointer; transition: all 0.15s ease;
}
.mode-toggle button.active { background: var(--primary); color: #fff; font-weight: 600; }
.hint { font-size: 12px; color: var(--text-dim); margin-top: 5px; }
.warn-box {
  font-size: 12px; color: var(--warning); background: var(--warning-bg);
  border: 1px solid rgba(245, 158, 11, 0.3); border-radius: 6px; padding: 8px 10px; margin-top: 8px;
}
.checkline {
  display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 6px; cursor: pointer;
}
.checkline input { width: auto; }

/* Preview Column */
.preview-card { padding: 18px 20px 20px; margin-bottom: 24px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; }
.card-head .sub { font-size: 12.5px; color: var(--text-dim); }

.canvas-wrap {
  position: relative; border: 1px solid var(--border); border-radius: 6px;
  background: #0d131f; max-height: 440px; display: flex; align-items: center; justify-content: center;
  padding: 14px; overflow: auto;
}
.canvas-wrap.checker {
  background-image:
    linear-gradient(45deg, #182234 25%, transparent 25%),
    linear-gradient(-45deg, #182234 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #182234 75%),
    linear-gradient(-45deg, transparent 75%, #182234 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #0f172a;
}
.canvas-stack { position: relative; line-height: 0; }
canvas { max-width: 100%; height: auto; image-rendering: pixelated; display: block; }
.canvas-stack canvas.overlay { position: absolute; top: 0; left: 0; pointer-events: none; }
.empty-state { color: var(--text-dim); font-size: 13.5px; text-align: center; padding: 48px 16px; }
.readout {
  display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px;
  font-family: var(--font-mono); font-size: 12px; color: var(--text-muted);
}
.readout b { color: var(--text-main); }

/* Animation Player Section */
.player-controls {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 14px; margin-top: 12px;
}
.player-btn-group { display: flex; gap: 6px; }
.player-slider-group { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.player-slider-group input[type="range"] { width: 90px; }
.player-canvas-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 160px; border-radius: 6px; border: 1px solid var(--border); padding: 16px;
}
.player-canvas-wrap.checker {
  background-image:
    linear-gradient(45deg, #222e44 25%, transparent 25%),
    linear-gradient(-45deg, #222e44 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #222e44 75%),
    linear-gradient(-45deg, transparent 75%, #222e44 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #162032;
}
.player-canvas-wrap.dark { background: #0B0F17; }
.player-canvas-wrap.light { background: #FFFFFF; }
.player-canvas-wrap.game { background: #1B4332; }

/* Code Exporter Card */
.engine-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.engine-tab {
  background: none; border: none; padding: 8px 14px; color: var(--text-muted);
  font-family: var(--font-display); font-size: 13px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; transition: all 0.15s ease;
}
.engine-tab:hover { color: var(--text-main); }
.engine-tab.active { color: #818CF8; border-bottom-color: #818CF8; }
.script-card pre {
  background: #090D14; color: #E2E8F0; padding: 16px; border-radius: 6px;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.6;
  overflow-x: auto; margin: 0; border: 1px solid var(--border);
}

/* Modals */
.modal-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 999;
  padding: 20px;
}
.modal-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 480px; padding: 24px; position: relative;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}
.modal-close {
  position: absolute; top: 16px; right: 16px; background: none; border: none;
  color: var(--text-dim); font-size: 20px; cursor: pointer;
}
.modal-close:hover { color: var(--text-main); }
.modal-card h2 { font-size: 20px; margin-bottom: 6px; }
.modal-card .modal-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }

/* Pricing Grid in Modal */
.pricing-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 18px 0; }
.price-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; text-align: center;
}
.price-box.featured { border-color: var(--accent); background: rgba(227, 28, 110, 0.05); }
.price-box h4 { font-size: 14px; margin-bottom: 4px; }
.price-box .cost { font-size: 22px; font-weight: 700; color: var(--text-main); margin-bottom: 10px; }
.price-box ul { list-style: none; padding: 0; margin: 0; font-size: 12px; color: var(--text-muted); text-align: left; }
.price-box li { margin-bottom: 6px; }

/* Project Items */
.project-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 8px;
}
.project-info strong { display: block; font-size: 13.5px; }
.project-info small { font-size: 11.5px; color: var(--text-dim); }
.project-actions { display: flex; gap: 6px; }

/* Footer */
.footer {
  text-align: center; padding: 36px 0 16px; border-top: 1px solid var(--border);
  margin-top: 50px; font-size: 12.5px; color: var(--text-dim);
}
.footer a { color: var(--text-muted); }

/* ==========================================
   Mobile & Responsive Enhancements
   ========================================== */

@media (max-width: 960px) {
  .app-container { padding: 0 16px 48px; }
  .studio-grid { grid-template-columns: 1fr; gap: 20px; }
  .controls-panel { position: static; }
  .header-nav { flex-direction: column; align-items: flex-start; gap: 16px; padding: 16px 0 20px; }
  .nav-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
}

@media (max-width: 768px) {
  /* Prevent iOS Safari 16px zoom-in on input focus */
  input[type="number"], select, input[type="text"], input[type="password"] {
    font-size: 16px;
    padding: 10px 12px;
  }
  
  .hero-section h1 { font-size: 26px; }
  .hero-section p { font-size: 14.5px; }
  .hero-stats {
    display: flex; flex-direction: column; gap: 6px;
    border-radius: 12px; padding: 10px 16px; width: 100%;
  }
  .hero-stats span:nth-child(2), .hero-stats span:nth-child(4) { display: none; }

  /* Touch friendly buttons */
  .btn { min-height: 40px; font-size: 14px; }
  .btn-sm { min-height: 34px; }

  /* Player responsiveness */
  .player-controls {
    flex-direction: column; align-items: stretch; gap: 12px;
  }
  .player-btn-group {
    display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; width: 100%;
  }
  .player-btn-group .btn { width: 100%; }
  .player-slider-group {
    display: flex; justify-content: space-between; align-items: center; width: 100%;
  }
  .player-slider-group input[type="range"] { flex: 1; max-width: 140px; }

  /* Horizontally scrollable engine code tabs */
  .engine-tabs {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .engine-tab { flex-shrink: 0; }

  /* Modal responsiveness */
  .modal-backdrop { padding: 12px; }
  .modal-card { padding: 20px 16px; max-height: 92vh; overflow-y: auto; }
  .pricing-boxes { grid-template-columns: 1fr; gap: 12px; }

  /* Canvas preview touch friendly scrolling */
  .canvas-wrap {
    max-height: 320px;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
  }

  /* Dropzone on small devices */
  .dropzone { padding: 20px 12px; }
  
  /* User badge truncate */
  #userEmailBadge {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
  }
}

@media (max-width: 480px) {
  .row-2 { grid-template-columns: 1fr; }
  .brand-title { font-size: 18px; }
  .logo-box { width: 32px; height: 32px; font-size: 17px; }
  .nav-actions { flex-direction: column; align-items: stretch; }
  .user-widget { width: 100%; justify-content: space-between; }
  #upgradeNavBtn { width: 100%; }
}
