:root {
  --brand-1: #6366f1;
  --brand-2: #a855f7;
  --brand-3: #ec4899;
  --ink: #1e1b4b;
  --muted: #6b7280;
  --bg: #f8f7ff;
  --card: #ffffff;
  --radius: 1.1rem;
  --shadow: 0 6px 24px rgba(99, 102, 241, 0.10);
  --shadow-lg: 0 14px 40px rgba(99, 102, 241, 0.18);
  --surface: rgba(255, 255, 255, 0.82);
}

* { -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(168, 85, 247, 0.12), transparent 60%),
    radial-gradient(900px 450px at -10% 15%, rgba(99, 102, 241, 0.12), transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.text-gradient {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2) 50%, var(--brand-3));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ---------- Navbar ---------- */
.app-navbar {
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(99, 102, 241, 0.12);
}
.app-navbar .navbar-brand {
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
}
.brand-badge {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-3));
  display: grid; place-items: center;
  color: #fff; font-size: 1.15rem;
  box-shadow: var(--shadow);
}
.app-navbar .nav-link {
  font-weight: 600;
  color: var(--muted);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  margin-inline: 0.15rem;
  transition: all 0.18s ease;
}
.app-navbar .nav-link:hover, .app-navbar .nav-link.active {
  color: var(--brand-1);
  background: rgba(99, 102, 241, 0.10);
}
.theme-toggle {
  border: 0;
  background: rgba(99, 102, 241, 0.10);
  color: var(--brand-1);
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  transition: all 0.18s ease;
}
.theme-toggle:hover { background: rgba(99, 102, 241, 0.20); }
.app-navbar > .container { gap: 0.35rem; }

/* ---------- Hero ---------- */
.hero {
  padding: 3.5rem 0 2rem;
  text-align: center;
}
.hero h1 { font-weight: 900; font-size: clamp(1.7rem, 4vw, 3rem); line-height: 1.25; }
.hero p { color: var(--muted); font-size: clamp(0.98rem, 2vw, 1.15rem); max-width: 640px; margin-inline: auto; }

/* ---------- Cards ---------- */
.tool-card {
  height: 100%;
  background: var(--card);
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  position: relative;
  overflow: hidden;
}
.tool-card::after {
  content: "";
  position: absolute;
  inset-inline-end: -35%;
  top: -45%;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.10), transparent 70%);
  pointer-events: none;
}
.tool-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(99, 102, 241, 0.35);
  color: inherit;
}
.tool-ico {
  width: 58px; height: 58px;
  border-radius: 16px;
  display: grid; place-items: center;
  font-size: 1.55rem;
  color: #fff;
  box-shadow: var(--shadow);
}
.ico-indigo { background: linear-gradient(135deg, var(--brand-1), #818cf8); }
.ico-purple { background: linear-gradient(135deg, #a855f7, #c084fc); }
.ico-pink   { background: linear-gradient(135deg, #ec4899, #f472b6); }
.ico-cyan   { background: linear-gradient(135deg, #06b6d4, #38bdf8); }

.tool-card h3 { font-weight: 800; font-size: 1.15rem; margin: 0; }
.tool-card p { color: var(--muted); font-size: 0.9rem; margin: 0; flex-grow: 1; }
.card-link-more {
  color: var(--brand-1);
  font-weight: 700;
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* ---------- Page shells ---------- */
.page-head { padding: 2rem 1rem; }
.page-head .breadcrumb { margin-bottom: 0.4rem; }
.page-head h1 { font-weight: 900; font-size: clamp(1.4rem, 3vw, 2rem); }
.page-head p { color: var(--muted); margin: 0; }

.panel {
  background: var(--card);
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.panel-title {
  font-weight: 800;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.panel-title i { color: var(--brand-1); }

/* ---------- Drop zones ---------- */
.drop-zone {
  border: 2px dashed rgba(99, 102, 241, 0.45);
  border-radius: var(--radius);
  background: rgba(99, 102, 241, 0.045);
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--brand-2);
  background: rgba(168, 85, 247, 0.07);
}
.drop-zone i { font-size: 2.6rem; color: var(--brand-1); }
.drop-zone p { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.92rem; }
.drop-zone p strong { color: var(--ink); }

/* ---------- Buttons ---------- */
.btn-gradient {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff;
  border: 0;
  font-weight: 700;
  border-radius: 0.8rem;
  padding: 0.5rem 1.1rem;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
  transition: all 0.18s ease;
}
.btn-gradient:hover, .btn-gradient:focus {
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.45);
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
}
.btn-soft {
  background: rgba(99, 102, 241, 0.10);
  color: var(--brand-1);
  border: 0;
  font-weight: 700;
  border-radius: 0.8rem;
  padding: 0.5rem 1.1rem;
  transition: all 0.18s ease;
}
.btn-soft:hover { background: rgba(99, 102, 241, 0.18); color: var(--brand-1); }
.btn-outline-soft {
  background: transparent;
  color: var(--brand-1);
  border: 1.5px solid rgba(99, 102, 241, 0.45);
  font-weight: 700;
  border-radius: 0.8rem;
  padding: 0.5rem 1rem;
  transition: all 0.18s ease;
}
.btn-outline-soft:hover { background: rgba(99, 102, 241, 0.08); color: var(--brand-1); }

/* ---------- Tabs ---------- */
.nav-tabs.tool-tabs {
  border-bottom: 0;
  gap: 0.4rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs.tool-tabs::-webkit-scrollbar { display: none; }
.nav-tabs.tool-tabs .nav-item { flex: 0 0 auto; }
.nav-tabs.tool-tabs .nav-link {
  border: 0;
  border-radius: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0.55rem 1rem;
  white-space: nowrap;
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(99, 102, 241, 0.12);
}
.nav-tabs.tool-tabs .nav-link.active {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff;
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}

/* ---------- Range sliders ---------- */
.form-range::-webkit-slider-thumb {
  background: var(--brand-1);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}
.form-range::-webkit-slider-runnable-track { background: rgba(99, 102, 241, 0.18); }
.form-range::-moz-range-thumb { background: var(--brand-1); border: 0; }

/* ---------- Form controls ---------- */
.form-control, .form-select {
  border-radius: 0.75rem;
  border-color: rgba(99, 102, 241, 0.25);
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-1);
  box-shadow: 0 0 0 0.25rem rgba(99, 102, 241, 0.15);
}
.input-group-text { border-radius: 0 0.75rem 0.75rem 0; }

/* Checkerboard behind transparent images */
.checker {
  background-image:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  border-radius: 0.9rem;
  border: 1px solid rgba(99,102,241,0.15);
  overflow: hidden;
}
.preview-frame {
  max-width: 100%;
  max-height: 420px;
  display: block;
  margin-inline: auto;
}

/* ---------- Whiteboard ---------- */
.board-layout { display: flex; gap: 1rem; align-items: flex-start; }
.board-main { flex: 1; min-width: 0; }
.board-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #fff;
  touch-action: none;
}
.board-wrap canvas { display: block; width: 100%; height: calc(100vh - 225px); min-height: 360px; cursor: crosshair; }

.board-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.board-sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1rem 0.65rem;
  border-bottom: 1px solid rgba(99, 102, 241, 0.10);
}
.board-sidebar-title { font-weight: 800; font-size: 0.95rem; display: flex; align-items: center; gap: 0.5rem; }
.sidebar-close {
  border: 0; background: rgba(99,102,241,0.10); color: var(--brand-1);
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
}
.board-sidebar-body { padding: 1rem; overflow-y: auto; }
.tool-group { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
.side-label { font-size: 0.72rem; font-weight: 800; color: var(--muted); margin: 1.15rem 0 0.5rem; }
.side-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.side-actions .btn { display: flex; align-items: center; justify-content: center; gap: 0.35rem; font-size: 0.78rem; }
.side-actions .btn.btn-gradient { grid-column: 1 / -1; }

.board-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1045;
  background: rgba(30, 27, 75, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.board-backdrop.show { opacity: 1; pointer-events: auto; }

.board-fab {
  position: fixed;
  bottom: 80px;
  inset-inline-end: 16px;
  z-index: 1035;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 0;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff;
  font-size: 1.3rem;
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.45);
  display: grid;
  place-items: center;
}

.board-toolbar { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.chip {
  border: 1.5px solid rgba(99,102,241,0.25);
  background: #fff;
  width: 44px; height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--brand-1); color: var(--brand-1); }
.chip.active {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  border-color: transparent;
  color: #fff;
}
.swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease;
  outline: 2px solid transparent;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { outline-color: var(--brand-1); transform: scale(1.15); }
.size-dot { border-radius: 50%; background: var(--ink); }

@media (max-width: 991px) {
  .board-layout { display: block; }
  .board-wrap canvas { height: calc(100vh - 175px); min-height: 340px; }
  .board-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    z-index: 1050;
    width: min(300px, 84vw);
    max-height: none;
    border-radius: 0;
    box-shadow: var(--shadow-lg);
    transform: translateX(110%);
    transition: transform 0.28s ease;
  }
  .board-sidebar.open { transform: translateX(0); }
}

/* ---------- Whiteboard clear confirm ---------- */
.board-confirm {
  position: fixed;
  inset: 0;
  z-index: 1070;
  display: grid;
  place-items: center;
  background: rgba(30, 27, 75, 0.45);
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.board-confirm[hidden] { display: none; }
.board-confirm-box {
  background: var(--card);
  border-radius: 1rem;
  padding: 1.4rem;
  box-shadow: var(--shadow-lg);
  max-width: 330px;
  width: 100%;
  text-align: center;
}
.board-confirm-box .check-ico {
  width: 52px; height: 52px;
  margin-inline: auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fee2e2;
  color: #dc2626;
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
}

/* ---------- QR ---------- */
.qr-preview-box {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid rgba(99,102,241,0.15);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.qr-preview-box img { width: 100%; max-width: 260px; height: auto; }

.color-row { display: flex; align-items: center; gap: 0.6rem; }
.color-row input[type=color] {
  width: 46px; height: 46px;
  border: 0; padding: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
}
.color-row input[type=color]::-webkit-color-swatch-wrapper { padding: 3px; }
.color-row input[type=color]::-webkit-color-swatch { border-radius: 10px; border: 1px solid rgba(99,102,241,0.25); }
.mini-swatch {
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.6);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

/* ---------- Alerts / misc ---------- */
.alert-soft { border-radius: 0.9rem; border: 0; }
.file-item {
  display: flex; align-items: center; gap: 0.6rem;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(99,102,241,0.15);
  border-radius: 0.8rem;
  padding: 0.45rem 0.7rem;
  font-size: 0.9rem;
}
.file-item .del {
  color: #ef4444;
  cursor: pointer;
  margin-inline-start: auto;
  font-size: 1rem;
}
.text-muted-2 { color: var(--muted); }

footer.app-footer {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 2rem 0 1.5rem;
  text-align: center;
}
footer.app-footer a.credit-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
}
footer.app-footer a.credit-link:hover { color: var(--brand-1); }

.spinner-ring {
  width: 34px; height: 34px;
  border: 3.5px solid rgba(99,102,241,0.2);
  border-top-color: var(--brand-1);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-inline: auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.d-none-mid { display: none !important; }
@media (max-width: 767px) { .d-sm-none-mid { display: none !important; } }

/* ---------- Mobile bottom nav ---------- */
.mobile-botnav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 1040;
  display: none;
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(99, 102, 241, 0.18);
  box-shadow: 0 -6px 24px rgba(30, 27, 75, 0.08);
  padding-bottom: env(safe-area-inset-bottom);
}
.mobile-botnav .botnav-inner { display: flex; }
.mobile-botnav .botnav-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.5rem 0.2rem 0.45rem;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
  border-radius: 0;
}
.mobile-botnav .botnav-link i { font-size: 1.18rem; line-height: 1; }
.mobile-botnav .botnav-link.active { color: var(--brand-1); }
.mobile-botnav .botnav-link.active i {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
@media (max-width: 767px) {
  .mobile-botnav { display: block; }
  body { padding-bottom: 74px; }
  .container { --bs-gutter-x: 1.4rem; }
  .hero { padding-inline: 1rem; }
}

/* ---------- Dark mode ---------- */
html[data-theme="dark"] { color-scheme: dark; }
[data-theme="dark"] {
  --ink: #e7e9f5;
  --muted: #a6adc8;
  --bg: #0e1226;
  --card: #171d3a;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.50);
  --surface: rgba(14, 18, 38, 0.88);
}
[data-theme="dark"] .theme-toggle { background: rgba(255, 255, 255, 0.10); }
[data-theme="dark"] .theme-toggle:hover { background: rgba(255, 255, 255, 0.18); }
[data-theme="dark"] .navbar-toggler-icon { filter: invert(1); }
[data-theme="dark"] .drop-zone { background: rgba(99, 102, 241, 0.08); border-color: rgba(99, 102, 241, 0.35); }
[data-theme="dark"] .nav-tabs.tool-tabs .nav-link { background: rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .chip { background: var(--card); color: var(--ink); }
[data-theme="dark"] .file-item { background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .breadcrumb-item, [data-theme="dark"] .breadcrumb-item a { color: var(--muted); }
[data-theme="dark"] .board-wrap { background: #0e1226; }