* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
}

:root {
  --bg: #0b0f19;
  --card: #151d30;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #ec4899;
  --accent-hover: #db2777;
  --gold: #f59e0b;
  --gold-glow: rgba(245, 158, 11, 0.28);
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #222f4e;
}

html, body {
  background-color: var(--bg);
  color: var(--text);
  overflow-x: hidden !important;
  width: 100%;
  scroll-behavior: smooth;
}

img, video {
  max-width: 100%;
  height: auto;
}

/* Loading */
#loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 15px;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Navbar */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
}

/* Brand & Logo Styles */
.brand {
  font-size: 1.15rem;
  font-weight: 800;
  color: #818cf8;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  user-select: none;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid rgba(245, 158, 11, 0.55);
  box-shadow: 0 0 14px var(--gold-glow);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  flex-shrink: 0;
}

.brand:hover .brand-logo {
  transform: rotate(6deg) scale(1.05);
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.45);
}

.brand-text {
  font-weight: 800;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
}

.brand-text .gold {
  color: var(--gold);
}

.brand-text .divider {
  color: #64748b;
  margin: 0 5px;
  font-weight: 400;
}

.brand-text .studio {
  color: #a5b4fc;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.clock-badge {
  background: #080c16;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: monospace;
  font-size: 1rem;
  letter-spacing: 1px;
}

/* Dropdown */
.dropdown { position: relative; }
.dropdown-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}
.dropdown-menu {
  position: absolute;
  top: 125%;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  list-style: none;
  min-width: 190px;
  display: none;
  box-shadow: 0 10px 20px rgba(0,0,0,0.4);
  z-index: 999;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a {
  display: block;
  padding: 0.6rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
}
.dropdown-menu a:hover {
  background: var(--primary);
  border-radius: 6px;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  width: 100%;
}

/* Welcome Banner */
.welcome-card {
  background: linear-gradient(135deg, #3730a3, #4f46e5);
  border-radius: 12px;
  padding: 1.2rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.2);
}
.close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 5px;
}

/* Slider */
.swiper {
  width: 100%;
  height: 190px;
  border-radius: 12px;
}
.swiper-slide {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border-radius: 12px;
  text-align: center;
  padding: 15px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.slide-1 { background: linear-gradient(45deg, #1e1b4b, #4338ca); }
.slide-2 { background: linear-gradient(45deg, #064e3b, #059669); }
.slide-3 { background: linear-gradient(45deg, #701a75, #c026d3); }

/* Tools Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
  width: 100%;
}
.tool-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
}
.tool-box h3 {
  font-size: 1.1rem;
  color: #818cf8;
  display: flex;
  align-items: center;
  gap: 8px;
}

input, textarea, select {
  width: 100%;
  background: #0b0f19;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  outline: none;
  font-size: 0.9rem;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
}
button.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button.btn:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent) !important; }
.btn-accent:hover { background: var(--accent-hover) !important; }

/* معلم مبناها */
#base-section {
  border: 1px solid #312e81;
  background: radial-gradient(circle at top left, #171e38 0%, #111827 100%);
}
#base-section input[type="number"] {
  direction: ltr;
}
#baseSteps {
  max-height: 380px;
  overflow-y: auto;
  border-radius: 8px;
  padding: 12px;
  background: #030712;
  border: 1px solid #1f2937;
  scrollbar-width: thin;
  scrollbar-color: #4f46e5 #0b0f19;
}

/* Result Box */
.result-box {
  background: #080c16;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  min-height: 45px;
  word-break: break-all;
  font-size: 0.9rem;
  color: #38bdf8;
}
.steps-list {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 5px;
  list-style: none;
  max-height: 120px;
  overflow-y: auto;
}
.steps-list li { margin-bottom: 4px; }

/* Tic Tac Toe */
.ttt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 180px;
  margin: 0 auto;
}
.ttt-cell {
  width: 55px;
  height: 55px;
  background: #0b0f19;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
}

/* Accordion */
.accordion-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.accordion-header {
  width: 100%;
  padding: 0.9rem 1.2rem;
  background: none;
  border: none;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 0.95rem;
}
.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: 0.3s ease;
  padding: 0 1.2rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}
.accordion-item.active .accordion-body {
  padding: 0.8rem 1.2rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 15px;
}
.modal.show { display: flex; }
.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}

.help-modal-content {
  max-width: 600px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}
.help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.8rem;
  margin-bottom: 1rem;
}
.help-scroll-body {
  overflow-y: auto;
  padding-left: 5px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.help-guide-item {
  background: #0b0f19;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
}
.help-guide-item h5 {
  font-size: 0.95rem;
  color: #818cf8;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.help-guide-item p {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
}

/* کیبورد ماشین حساب */
.deep-calc-modal-content {
  max-width: 480px;
  padding: 16px;
}
.calc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.calc-title {
  font-size: 0.9rem;
  font-weight: bold;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 6px;
}
.mode-badge {
  font-size: 0.75rem;
  background: #312e81;
  color: #a5b4fc;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  border: 1px solid #4338ca;
}
.screen-container {
  background: #020617;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.screen-input {
  min-height: 44px;
  font-size: 1.4rem;
  color: #38bdf8;
  direction: ltr;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow-x: auto;
  white-space: nowrap;
}
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
button.key {
  border: none;
  outline: none;
  border-radius: 8px;
  padding: 10px 0;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
}
button.key:active { transform: scale(0.95); }
.key-num { background: #334155; color: #f8fafc; font-size: 1.1rem; }
.key-fn { background: #1e1b4b; color: #a5b4fc; font-size: 0.85rem; }
.key-op { background: #4338ca; color: #fff; font-size: 1.1rem; }
.key-del { background: #991b1b; color: #fecaca; }
.key-back { background: #b45309; color: #fef3c7; }
.key-equal { background: #059669; color: #fff; grid-column: span 2; font-size: 1rem; }

.steps-container {
  background: #090d16;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 8px 10px;
  max-height: 140px;
  overflow-y: auto;
}
.steps-title {
  font-size: 0.75rem;
  color: #64748b;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}
.step-badge {
  background: #1e293b;
  border-radius: 6px;
  padding: 5px 8px;
  direction: ltr;
  font-size: 0.8rem;
  border-left: 3px solid #38bdf8;
  margin-bottom: 4px;
}

#topBtn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: var(--primary);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 90;
}

/* کپسول اختصاصی امضا */
.studio-signature-wrap {
  margin: 60px 0 35px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sig-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  cursor: pointer;
  user-select: none;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.sig-badge:hover {
  border-color: rgba(99, 102, 241, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(99, 102, 241, 0.15);
}

.sig-icon {
  color: #818cf8;
  font-size: 0.95rem;
  transition: transform 0.4s ease, color 0.3s ease;
}

.sig-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: 0.3px;
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.3s ease;
}

.sig-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #475569;
}

.sig-hint {
  font-size: 0.8rem;
  color: #94a3b8;
  transition: color 0.3s ease;
}

/* ========================================================
   بخش جادویی ریسپانسیو اختصاصی موبایل (زیر 768px)
   ======================================================== */
@media (max-width: 768px) {
  .navbar {
    padding: 0.65rem 0.8rem !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }

  .navbar .brand {
    font-size: 0.92rem !important;
    flex: 1 1 auto;
    gap: 8px !important;
  }

  .brand-logo {
    width: 30px !important;
    height: 30px !important;
  }

  .navbar .nav-actions {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    margin-right: auto;
  }

  .clock-badge {
    font-size: 0.75rem !important;
    padding: 0.25rem 0.5rem !important;
  }

  .dropdown-btn, #openModal {
    font-size: 0.75rem !important;
    padding: 0.35rem 0.6rem !important;
    white-space: nowrap !important;
  }

  .dropdown-menu {
    right: auto !important;
    left: 0 !important;
    min-width: 170px !important;
  }

  .container {
    padding: 0 10px !important;
    margin: 1rem auto !important;
    gap: 1.25rem !important;
  }

  .welcome-card {
    padding: 0.9rem 1rem !important;
  }
  .welcome-card h3 {
    font-size: 1rem !important;
  }

  .swiper {
    height: 160px !important;
  }
  .swiper-slide h2 {
    font-size: 1.05rem !important;
    margin-bottom: 4px;
  }
  .swiper-slide p {
    font-size: 0.8rem !important;
  }

  /* گرید ابزارها کاملاً تک‌ستونه */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .tool-box {
    padding: 1rem !important;
  }

  /* ورودی‌های معلم مبناها */
  #base-section > div[style*="display: grid"] {
    grid-template-columns: 1fr !important;
  }

  /* دکمه‌های تبدیل و تدریس در موبایل */
  #base-section div[style*="display:flex"] {
    flex-direction: column !important;
  }
  #base-section div[style*="display:flex"] button {
    width: 100% !important;
    flex: none !important;
  }

  /* ورودی‌های دوتایی */
  .tool-box div[style*="display:flex"] {
    flex-direction: column !important;
  }
  .tool-box div[style*="display:flex"] input,
  .tool-box div[style*="display:flex"] select,
  .tool-box div[style*="display:flex"] button {
    width: 100% !important;
  }

  .modal {
    padding: 10px !important;
  }
  .deep-calc-modal-content {
    padding: 12px !important;
  }
  .keypad-grid {
    gap: 4px !important;
  }
  button.key {
    padding: 9px 0 !important;
    font-size: 0.85rem !important;
  }
}
