:root {
  --bg: #0a0a0f;
  --bg2: #111118;
  --bg3: #1a1a26;
  --surface: #1e1e2e;
  --surface2: #252535;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.15);
  --text: #e8e8f0;
  --text2: #9090a8;
  --text3: #5a5a72;
  --accent: #7c6fff;
  --accent2: #9d8fff;
  --accent-glow: rgba(124,111,255,0.3);
  --green: #4fffb0;
  --red: #ff4f6e;
  --radius: 10px;
  --radius-lg: 16px;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Nav ── */
#nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 24px;
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 0.5px solid var(--border);
}

#nav .logo {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  margin-right: 16px;
  text-decoration: none;
  letter-spacing: -0.02em;
}

#nav a {
  text-decoration: none;
  color: var(--text2);
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
#nav a:hover, #nav a.active { color: var(--text); background: var(--surface); }

#nav .spacer { flex: 1; }

#admin-btn {
  font-size: 11px;
  color: var(--text3);
  background: none;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#admin-btn:hover { color: var(--text2); border-color: var(--border2); }

/* ── Page wrapper ── */
.page {
  padding-top: 56px;
  min-height: 100vh;
}

/* ── Canvas bg ── */
.bg-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

.page-content {
  position: relative;
  z-index: 1;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: 0.5px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.btn:hover { background: var(--surface2); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { background: rgba(255,79,110,0.1); border-color: var(--red); color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.icon-only { padding: 8px; }

/* ── Inputs ── */
input[type=text], input[type=password], input[type=number], input[type=url],
textarea, select {
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  width: 100%;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg2); }

label { font-size: 12px; color: var(--text2); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 0.5px solid var(--border);
}
.modal-title { font-size: 17px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text2);
  font-size: 20px; cursor: pointer; padding: 4px; border-radius: 6px;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast-item {
  background: var(--surface2);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast-item.success { border-color: var(--green); }
.toast-item.error { border-color: var(--red); }
@keyframes slideIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* ── Captcha overlay ── */
#captcha-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
}
#captcha-overlay.open { display: flex; }
.captcha-box {
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  width: min(360px, calc(100vw - 32px));
}
#hcaptcha-container { display: flex; justify-content: center; margin: 8px 0; }
#captcha-submit:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Section titles ── */
.section-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.section-sub {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 24px;
}

/* ── Custom emoji in text ── */
.cemoji {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  vertical-align: -0.2em;
  object-fit: contain;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE STYLES (@media max-width: 640px)
   ══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {

  /* ── Nav: horizontal scroll ── */
  #nav {
    padding: 10px 12px;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #nav::-webkit-scrollbar { display: none; }
  #nav .logo { margin-right: 8px; flex-shrink: 0; font-size: 15px; }
  #nav a { flex-shrink: 0; font-size: 12px; padding: 4px 10px; white-space: nowrap; }
  #nav .spacer { flex: 0 0 8px; }
  #admin-btn { flex-shrink: 0; }

  /* ── Home page: map canvas doesn't stretch ── */
  #map-canvas {
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
  }

  /* ── Home: projects single column ── */
  #projects-grid {
    grid-template-columns: 1fr !important;
    grid-auto-rows: 180px !important;
  }
  #projects-grid .project-tile.wide {
    grid-column: span 1 !important;
    grid-row: span 1 !important;
  }
  .projects-section { padding: 24px 12px 60px; }

  /* ── Vibe-coding: vertical layout, AI panel slides in from right ── */
  .vibe-page { padding-top: 56px; }
  .vibe-toolbar {
    padding: 6px 8px !important;
    gap: 4px !important;
    overflow-x: auto;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
  }
  .vibe-toolbar::-webkit-scrollbar { display: none; }
  .vibe-toolbar .btn { flex-shrink: 0; white-space: nowrap; }
  .vibe-toolbar select { flex-shrink: 0; }

  .vibe-main {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: unset !important;
    position: relative;
  }
  .editor-panel {
    flex: 1 !important;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  #code-editor {
    flex: 1 !important;
    min-height: 180px;
    font-size: 12px !important;
  }
  .output-panel {
    height: 130px !important;
  }

  /* Chat panel: overlay from right, hidden by default on mobile */
  .chat-panel {
    position: fixed !important;
    top: 0 !important;
    right: -100% !important;
    bottom: 0 !important;
    width: 88vw !important;
    max-width: 340px;
    z-index: 500;
    transition: right 0.3s ease !important;
    box-shadow: -4px 0 24px rgba(0,0,0,0.5);
    border-right: none !important;
  }
  .chat-panel.mobile-open {
    right: 0 !important;
  }

  /* Toggle button for chat */
  #mobile-chat-toggle {
    display: flex !important;
  }

  /* Files page: already ok, just ensure padding */
  .files-page { padding: 70px 12px 40px !important; }
}

/* Chat toggle button — hidden on desktop */
#mobile-chat-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 16px;
  z-index: 9000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(124,111,255,0.6);
  transition: background 0.15s;
  touch-action: manipulation;
}
#mobile-chat-toggle:hover { background: var(--accent2); }

/* Close button inside chat for mobile */
#mobile-chat-close {
  display: none;
}
@media (max-width: 640px) {
  #mobile-chat-close {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 12px 4px;
    flex-shrink: 0;
  }
  #mobile-chat-close button {
    background: none;
    border: none;
    color: var(--text2);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
  }
  #mobile-chat-close button:hover { color: var(--text); }
}
