@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=JetBrains+Mono:wght@400;500;700&family=Playfair+Display:ital,wght@0,400;0,700;1,400&display=swap');

:root {
  /* Default: IDE Theme */
  --bg-base: #1e1e1e;
  --bg-surface: rgba(30,30,30,0.6);
  --bg-elevated: rgba(45,45,45,0.8);
  --text-primary: #cccccc;
  --text-secondary: #888888;
  --text-code: #9cdcfe;
  --text-comment: #6a9955;
  
  --accent: #007acc;
  --accent-hover: rgba(0, 122, 204, 0.8);
  --accent-neon: #007acc;
  --accent-bg: rgba(0, 122, 204, 0.1);
  --border-light: rgba(255,255,255,0.05);
  --shadow-soft: 0 20px 50px rgba(0,0,0,0.3);
  --input-bg: rgba(0,0,0,0.2);

  --font-main: 'DM Sans', sans-serif;
  --font-serif: 'Playfair Display', serif;
  --font-code: 'JetBrains Mono', monospace;

  --sidebar-w: 360px;
  --header-h: 90px;
  --radius-md: 16px;
  --radius-sm: 8px;
}

[data-theme="pro"] {
  /* Pro / Light Portfolio Theme */
  --bg-base: #faf9f6;
  --bg-surface: rgba(255, 255, 255, 0.7);
  --bg-elevated: rgba(255, 255, 255, 0.95);
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-code: #1a1a1a;
  --text-comment: #888888;
  
  --accent: #1a1a1a;
  --accent-hover: #333333;
  --accent-neon: #1a1a1a;
  --accent-bg: rgba(0, 0, 0, 0.04);
  --border-light: rgba(0,0,0,0.06);
  --shadow-soft: 0 15px 45px rgba(0,0,0,0.03);
  --input-bg: rgba(0,0,0,0.02);
}

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

body {
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  transition: background-color 0.3s, color 0.3s;
}

h1, h2, h3, h4 {
  font-family: var(--font-code);
  font-weight: 500;
  color: var(--accent);
}

/* Layout - IDE Structure */
.fluid-bg {
  position: absolute; inset: -50%; z-index: -1;
  background: radial-gradient(circle at 10% 20%, rgba(0, 0, 0, 0.04) 0%, transparent 40%),
              radial-gradient(circle at 80% 80%, rgba(0, 0, 0, 0.02) 0%, transparent 40%);
  filter: blur(80px);
  animation: liquidShift 20s infinite alternate linear;
}
[data-theme="ide"] .fluid-bg {
  background: radial-gradient(circle at 10% 20%, rgba(0, 122, 204, 0.1) 0%, transparent 40%),
              radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.02) 0%, transparent 40%);
}
@keyframes liquidShift { 0% { transform: scale(1) translate(0,0); } 100% { transform: scale(1.1) translate(10%, 10%); } }

.app-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 10;
}

/* Activity Bar / Top Nav */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--header-h);
  padding: 0 40px;
  background: transparent;
  border-bottom: 1px solid var(--border-light);
}

.logo { display: flex; align-items: center; gap: 12px; }

.logo h1 {
  font-size: 1.8rem; font-weight: 700; font-family: var(--font-serif);
  letter-spacing: -0.5px; color: var(--text-primary); text-transform: none;
}

.top-actions { display: flex; align-items: center; gap: 20px; }

.workspace {
  display: flex; flex: 1; height: calc(100vh - var(--header-h));
  overflow: hidden; padding: 30px 40px; gap: 30px;
}

/* Sidebars / Explorers */
.sidebar-left, .sidebar-right {
  width: var(--sidebar-w); height: 100%; display: flex; flex-direction: column;
  background: var(--bg-surface); backdrop-filter: blur(20px);
  border-radius: var(--radius-md); border: 1px solid var(--border-light);
  box-shadow: var(--shadow-soft); overflow: hidden;
}

.sidebar-header {
  padding: 24px 28px; border-bottom: 1px solid var(--border-light); background: transparent;
}

.sidebar-header h2 {
  font-size: 1.5rem; text-transform: none; color: var(--text-primary);
  margin-bottom: 16px; letter-spacing: 0; font-family: var(--font-serif); font-weight: 500;
}

.sidebar-content { flex: 1; padding: 24px 28px; overflow-y: auto; }

/* Canvas Area / Editor Tabs */
.canvas-area {
  flex: 1; position: relative; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: transparent; border-radius: var(--radius-md);
  border: 1px solid var(--border-light); backdrop-filter: blur(5px);
  box-shadow: var(--shadow-soft); overflow: hidden;
}

.upload-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 30, 46, 0.8);
  backdrop-filter: blur(5px);
  z-index: 10;
  transition: opacity 0.2s;
}
.upload-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.upload-box {
  width: 360px;
  padding: 40px;
  border: 1px dashed var(--accent);
  background: var(--accent-bg);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.upload-box i { font-size: 32px; color: var(--accent); }
.upload-box h3 { color: var(--text-primary); font-family: var(--font-main); }
.upload-box p { font-family: var(--font-code); font-size: 12px; color: var(--text-comment); }

.canvas-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 40px;
  overflow: hidden;
}

canvas#main-canvas {
  max-width: 100%;
  max-height: 100%;
  background-color: #000;
  box-shadow: 0 0 30px rgba(0,0,0,0.5);
  border: 1px solid var(--border-light);
}

/* IDE Scrollbars */
.styled-scroll::-webkit-scrollbar { width: 8px; }
.styled-scroll::-webkit-scrollbar-track { background: var(--bg-surface); }
.styled-scroll::-webkit-scrollbar-thumb { background: var(--bg-elevated); border: 2px solid var(--bg-surface); border-radius: 4px; }
.styled-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

.styled-scroll-x::-webkit-scrollbar { height: 8px; }
.styled-scroll-x::-webkit-scrollbar-track { background: var(--bg-surface); }
.styled-scroll-x::-webkit-scrollbar-thumb { background: var(--bg-elevated); border: 2px solid var(--bg-surface); border-radius: 4px; }

/* Buttons & Terminal feel */
button { cursor: pointer; border: none; background: none; font-family: var(--font-code); color: inherit; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
}
.icon-btn:hover, .icon-btn.active { color: var(--accent); background: var(--accent-bg); }

.text-btn {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.text-btn:hover { color: var(--accent); background: var(--accent-bg); }

.primary-btn {
  background: var(--text-primary);
  color: var(--bg-base);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-main);
  text-transform: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s;
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }

.secondary-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-main);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s;
}
.secondary-btn:hover { border-color: var(--text-primary); color: var(--text-primary); }

.divider { width: 1px; height: 20px; background: var(--border-light); }

/* File Tabs / Editor Tabs */
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--border-light); margin-bottom: 15px;}
.tab {
  font-size: 13px; font-weight: 500; font-family: var(--font-main); color: var(--text-secondary);
  padding: 8px 0; background: transparent; border: none; border-bottom: 2px solid transparent; letter-spacing: 0.5px;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--text-primary); background: transparent; border-bottom: 2px solid var(--text-primary);
}

/* Sliders (Code Editor Parameters) */
.tool-group { margin-bottom: 16px; font-family: var(--font-code); }
.tool-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--text-code);
}
.tool-header span:first-child::before { content: '>'; color: var(--accent); margin-right: 6px; }
.tool-val { color: var(--accent-neon); }

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: transparent;
  height: 12px; 
}
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 2px;
  background: var(--bg-elevated);
}
input[type=range]::-webkit-slider-thumb {
  height: 16px; width: 16px; border-radius: 50%;
  background: var(--bg-surface); border: 2px solid var(--text-primary);
  -webkit-appearance: none; appearance: none; margin-top: -7px; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
input[type=range]:active::-webkit-slider-thumb { background: var(--accent-neon); }

/* Toggles */
.mode-toggle {
  display: flex; background: var(--input-bg); padding: 4px; border-radius: 999px;
}
.toggle-btn {
  flex: 1; padding: 8px 16px; font-size: 12px; font-weight: 500; font-family: var(--font-main);
  color: var(--text-secondary); text-transform: none; border-radius: 999px; transition: all 0.2s;
}
.toggle-btn.active {
  background: var(--bg-surface); color: var(--text-primary); border-bottom: none; box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

/* Bottom Toolbar (Terminal aesthetic) */
.bottom-toolbar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-light);
  z-index: 20;
}
.zoom-level { 
  font-size: 11px; 
  font-family: var(--font-code);
  color: var(--text-code);
  min-width: 40px; 
}

/* Snippets / Presets Grids */
.search-bar {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--border-light);
  padding: 6px 10px;
  margin-bottom: 16px;
}
.search-bar:focus-within { border-color: var(--accent); }
.search-bar i { color: var(--text-comment); margin-right: 8px; font-size: 14px;}
.search-bar input {
  background: none; border: none; color: var(--text-primary);
  width: 100%; font-size: 12px; font-family: var(--font-code); outline: none;
}
.search-bar input::placeholder { color: var(--text-comment); }

.categories { display: flex; gap: 4px; margin-bottom: 16px; }
.category-chip {
  padding: 4px 10px;
  background: transparent;
  color: var(--text-comment);
  border: 1px dashed transparent;
  font-size: 11px;
}
.category-chip:hover, .category-chip.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-bg);
}

.templates-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.template-card {
  border: 1px solid var(--border-light); border-radius: 12px;
  position: relative; cursor: pointer; overflow: hidden;
  background: var(--bg-surface); transition: transform 0.3s, box-shadow 0.3s;
}
.template-card:hover, .template-card.active { border-color: var(--text-primary); transform: translateY(-2px); box-shadow: 0 10px 20px rgba(0,0,0,0.05); }
.template-card .info { padding: 12px; text-align: center; }
.template-card h4 { font-size: 12px; font-weight: 500; font-family: var(--font-main); color: var(--text-primary); }

/* ── Preset Preview Thumbnail ── */
.preset-preview {
  width: 100%;
  height: 88px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

/* Subtle dark vignette overlay so the card always reads cleanly */
.preset-preview-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.06) 0%,
    rgba(0,0,0,0.28) 100%
  );
}

/* Shimmer animation on hover */
.template-card:hover .preset-preview::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 30%,
    rgba(255,255,255,0.15) 50%,
    transparent 70%
  );
  animation: preview-shimmer 0.55s ease forwards;
}

@keyframes preview-shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%);  }
}

/* ── Trend Badge ── */
.trend-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 9px;
  font-family: var(--font-code);
  color: var(--accent-neon);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 2px;
  letter-spacing: 0.03em;
}

/* ── Face Blur Modal ── */
.fb-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.fb-modal.open { display: flex; }

.fb-modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  animation: modal-drop 0.22s cubic-bezier(0.34,1.56,0.64,1) forwards;
}

@keyframes modal-drop {
  from { opacity: 0; transform: translateY(-16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1);    }
}

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

.fb-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-code);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}
.fb-modal-title i { font-size: 20px; }

.fb-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  font-family: var(--font-code);
}

.fb-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border-light);
}

.fb-status-row p {
  font-size: 12px;
  font-family: var(--font-code);
  color: var(--text-code);
}

/* Spinning loader icon */
.fb-spin {
  font-size: 16px;
  color: var(--accent);
  animation: fb-rotate 1s linear infinite;
  flex-shrink: 0;
}
@keyframes fb-rotate {
  from { transform: rotate(0deg);   }
  to   { transform: rotate(360deg); }
}

.fb-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.fb-actions .primary-btn,
.fb-actions .secondary-btn { flex: 1; min-width: 120px; justify-content: center; }

/* Face picker checkboxes */
#fb-pick-area {
  border-top: 1px solid var(--border-light);
  padding-top: 14px;
}
.fb-pick-label {
  font-size: 11px;
  font-family: var(--font-code);
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.fb-face-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 4px;
  background: var(--input-bg);
  border: 1px solid var(--border-light);
  font-size: 12px;
  font-family: var(--font-code);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s;
}
.fb-face-option:hover { border-color: var(--accent); }
.fb-face-option input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
}

/* Mobile tweaks for modal */
@media (max-width: 768px) {
  .fb-modal-box { padding: 18px; gap: 12px; }
  .fb-actions { flex-direction: column; }
  .fb-actions .primary-btn,
  .fb-actions .secondary-btn { width: 100%; }
}

/* AI Terminal / Output Panel */
#ai-panel { display: flex; flex-direction: column; height: 100%; }
.ai-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.ai-avatar {
  font-family: var(--font-code);
  color: var(--accent-neon);
  font-size: 14px; font-weight: bold;
}
.ai-title h3 { font-size: 12px; color: var(--text-primary); }
.ai-title p { font-size: 10px; color: var(--text-comment); font-family: var(--font-code); }

.chat-container { 
  flex: 1; display: flex; flex-direction: column; gap: 8px; 
  padding: 10px; background: var(--input-bg); border: 1px solid var(--border-light);
  margin-bottom: 16px;
}
.chat-message { font-family: var(--font-code); font-size: 11px; line-height: 1.6; }
.chat-message.ai { color: var(--text-code); }
.chat-message.ai::before { content: '~$ '; color: var(--accent-neon); }
.chat-message.user { color: var(--text-primary); }
.chat-message.user::before { content: '> '; color: var(--accent); }

.chat-suggestions { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.suggestion-chip {
  background: transparent; color: var(--text-comment);
  border: 1px solid var(--border-light);
  padding: 2px 8px; font-size: 10px;
}
.suggestion-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

.input-wrapper { display: flex; align-items: center; position: relative; }
.input-wrapper input {
  width: 100%; background: var(--bg-base); border: 1px solid var(--border-light);
  padding: 12px 30px 12px 15px; color: var(--text-primary); font-family: var(--font-main); font-size: 13px; outline: none;
  border-radius: 999px; transition: border-color 0.3s;
}
.input-wrapper input:focus { border-color: var(--accent); }
.ai-send-btn { position: absolute; right: 2px; width: 24px; height: 24px; color: var(--accent); }

/* Tooltips */
.tooltip { position: relative; }
.tooltip::before {
  content: attr(data-tip);
  position: absolute; top: -28px; left: 50%; transform: translateX(-50%);
  background: var(--bg-base); color: var(--accent); border: 1px solid var(--accent);
  padding: 4px 6px; font-size: 10px; font-family: var(--font-code);
  white-space: nowrap; opacity: 0; pointer-events: none;
}
.tooltip:hover::before { opacity: 1; }

/* ========================================================
   MOBILE RESPONSIVE  (≤ 768px)
   ======================================================== */

/* Mobile bottom nav bar */
.mobile-nav {
  display: none;
}

@media (max-width: 768px) {

  /* ── Body & layout ── */
  body {
    overflow: hidden;
    height: 100dvh;   /* dynamic viewport height for mobile browsers */
  }

  .app-wrapper {
    height: 100dvh;
  }

  /* ── Top Bar ── */
  .top-bar {
    padding: 0 12px;
    gap: 8px;
    flex-wrap: nowrap;
    height: var(--header-h);
  }

  /* Hide less-critical buttons in the top bar on small screens */
  .top-actions .divider { display: none; }
  #btn-compare { display: none; }
  #btn-undo, #btn-redo { width: 28px; height: 28px; font-size: 14px; }
  #btn-export { padding: 5px 10px; font-size: 11px; gap: 5px; }
  #btn-export i { display: none; }

  /* Auth area – shrink avatar text */
  #user-name { display: none; }
  #btn-login { padding: 5px 8px; font-size: 11px; }
  #btn-login i { margin: 0; }

  /* Hide Drive label on very small screens, keep icon */
  #btn-login span { display: none; }

  /* ── Main workspace – stack vertically, reserve bottom nav ── */
  .workspace {
    flex-direction: column;
    height: calc(100dvh - var(--header-h) - 52px); /* 52px = mobile-nav height */
    overflow: hidden;
  }

  /* ── Sidebars become full-screen panels hidden by default ── */
  .sidebar-left,
  .sidebar-right {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: 100%;
    height: calc(100dvh - var(--header-h) - 52px);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    border-top: 1px solid var(--border-light);
  }

  .sidebar-right {
    transform: translateX(100%);
  }

  /* When a sidebar is active/visible */
  .sidebar-left.mobile-open,
  .sidebar-right.mobile-open {
    transform: translateX(0);
  }

  /* ── Canvas area fills all remaining space ── */
  .canvas-area {
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .canvas-container {
    padding: 16px;
  }

  /* Wider upload box on mobile */
  .upload-box {
    width: calc(100vw - 48px);
    max-width: 360px;
    padding: 28px 20px;
  }

  /* ── Bottom toolbar: scrollable strip ── */
  .bottom-toolbar {
    gap: 8px;
    padding: 4px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    /* push it just above the mobile nav */
    bottom: 52px;
  }
  .bottom-toolbar::-webkit-scrollbar { display: none; }

  /* ── Tabs inside left sidebar ── */
  .tabs {
    overflow-x: auto;
    white-space: nowrap;
  }
  .tabs::-webkit-scrollbar { display: none; }

  /* Adjust sidebar inner padding */
  .sidebar-content {
    padding: 14px;
  }

  .sidebar-header {
    padding: 10px 14px;
  }

  /* Template rows stay single-column on mobile (matches global 1fr rule) */

  /* ── Mobile bottom navigation bar ── */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 52px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
    z-index: 200;
    align-items: stretch;
  }

  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-code);
    font-size: 9px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    padding: 6px 4px;
    border-radius: 0;
  }

  .mobile-nav-btn i {
    font-size: 20px;
    line-height: 1;
  }

  .mobile-nav-btn.active,
  .mobile-nav-btn:hover {
    color: var(--accent);
    background: var(--accent-bg);
  }

  .mobile-nav-btn.active i {
    text-shadow: 0 0 10px var(--accent);
  }
}

/* ── Extra-small phones (≤ 400px) ── */
@media (max-width: 400px) {
  .logo h1 { font-size: 12px; }
  #btn-export { font-size: 10px; }
}
