/* ============================================
   AI School - Global Styles
   W3Schools-inspired modern learning platform
   ============================================ */

/* ---------- CSS Variables / Theme ---------- */
:root {
  --primary: #6C63FF;
  --primary-dark: #5A52D5;
  --primary-light: #8B85FF;
  --secondary: #FF6584;
  --accent: #43E97B;
  --bg: #F7F8FC;
  --bg-card: #FFFFFF;
  --bg-sidebar: #1E1E2F;
  --bg-sidebar-hover: #2A2A40;
  --bg-code: #1E1E2F;
  --text: #2D2D3A;
  --text-light: #6B7280;
  --text-sidebar: #C5C6D0;
  --text-sidebar-active: #FFFFFF;
  --border: #E5E7EB;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.10);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s cubic-bezier(.4,0,.2,1);
  --header-height: 64px;
  --sidebar-width: 280px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

[data-theme="dark"] {
  --bg: #13131A;
  --bg-card: #1E1E2F;
  --bg-sidebar: #13131A;
  --bg-sidebar-hover: #1E1E2F;
  --text: #E4E4E7;
  --text-light: #9CA3AF;
  --border: #2A2A3C;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }

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

/* Safe area for notched devices (iPhone X+, etc.) */
@supports (padding: env(safe-area-inset-bottom)) {
  .top-header { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
  .main-content { padding-bottom: max(60px, env(safe-area-inset-bottom)); }
  .footer { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--primary-light); border-radius: 3px; }

/* ---------- Top Header / Navbar ---------- */
.top-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 1000;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  max-width: 100vw;
  overflow: visible;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.header-brand .brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 0;
  display: inline-block;
  object-fit: contain;
  vertical-align: middle;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 24px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex-shrink: 1;
  min-width: 0;
}

.header-nav::-webkit-scrollbar { display: none; }

.header-nav a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-light);
  font-weight: 500;
  font-size: 0.9rem;
  transition: all var(--transition);
  white-space: nowrap;
}

.header-nav a:hover,
.header-nav a.active {
  background: var(--primary);
  color: #fff;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--text-light);
  transition: all var(--transition);
}

.theme-toggle:hover { background: var(--border); color: var(--text); }

.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.3rem;
  color: var(--text);
  align-items: center;
  justify-content: center;
}

.search-box {
  position: relative;
  margin-right: 8px;
  z-index: 1001;
}

.search-box input {
  width: 220px;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font);
  transition: all var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.15);
  width: 280px;
}

.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 0.85rem;
}

/* ---------- Layout ---------- */
.page-wrapper {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
  max-width: 100vw;
  overflow-x: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 16px 0;
  z-index: 900;
  transition: transform var(--transition);
}

.sidebar-section {
  padding: 0 12px;
  margin-bottom: 8px;
}

.sidebar-section-title {
  padding: 8px 12px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--primary-light);
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-sidebar);
  font-size: 0.88rem;
  border-radius: var(--radius-sm);
  margin: 1px 8px;
  transition: all var(--transition);
  font-weight: 400;
}

.sidebar a:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-sidebar-active);
}

.sidebar a.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.sidebar a .nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar a .nav-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar a.active .nav-number {
  background: rgba(255,255,255,0.25);
}

.sidebar-progress {
  margin: 12px 20px;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
}

.sidebar-progress .progress-label {
  font-size: 0.75rem;
  color: var(--text-sidebar);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

.progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ---------- Main Content ---------- */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 40px 48px 80px;
  max-width: 900px;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.main-content.no-sidebar {
  margin-left: 0;
  max-width: 100%;
  padding: 0;
  overflow-x: hidden;
}

/* ---------- Breadcrumb ---------- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-light);
  margin-bottom: 24px;
}

.breadcrumb a { color: var(--text-light); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { opacity: 0.4; }

/* ---------- Typography ---------- */
.content h1 {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.content h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 48px;
  margin-bottom: 16px;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--text);
}

.content p {
  margin-bottom: 16px;
  color: var(--text);
}

.content .subtitle {
  font-size: 1.1rem;
  color: var(--text-light);
  margin-bottom: 32px;
  line-height: 1.6;
}

.content ul, .content ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.content li {
  margin-bottom: 8px;
}

.content strong {
  font-weight: 600;
}

/* ---------- Code Blocks ---------- */
.code-block {
  background: var(--bg-code);
  border-radius: var(--radius);
  margin: 20px 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.code-header .code-lang {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary-light);
}

.code-header .copy-btn {
  padding: 4px 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: transparent;
  color: #aaa;
  font-size: 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  transition: all var(--transition);
}

.code-header .copy-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.code-block pre {
  padding: 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.7;
  color: #E4E4E7;
}

.code-block code {
  font-family: var(--font-mono);
}

/* Inline code */
.content code:not(.code-block code) {
  background: rgba(108,99,255,0.1);
  color: var(--primary);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.88em;
  font-family: var(--font-mono);
}

[data-theme="dark"] .content code:not(.code-block code) {
  background: rgba(108,99,255,0.2);
  color: var(--primary-light);
}

/* ---------- Info / Tip / Warning Boxes ---------- */
.info-box {
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  margin: 20px 0;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 0.92rem;
}

.info-box .box-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.info-box.tip {
  background: rgba(67,233,123,0.08);
  border-left: 4px solid var(--accent);
  color: var(--text);
}

.info-box.note {
  background: rgba(108,99,255,0.08);
  border-left: 4px solid var(--primary);
  color: var(--text);
}

.info-box.warning {
  background: rgba(255,101,132,0.08);
  border-left: 4px solid var(--secondary);
  color: var(--text);
}

.info-box.example {
  background: rgba(255,183,77,0.08);
  border-left: 4px solid #FFB74D;
  color: var(--text);
}

/* ---------- Try It Box ---------- */
.try-it-box {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin: 24px 0;
  box-shadow: var(--shadow);
}

.try-it-box h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.try-it-box textarea {
  width: 100%;
  min-height: 120px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  resize: vertical;
  line-height: 1.6;
  transition: border-color var(--transition);
}

.try-it-box textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.12);
}

.try-it-box .output-area {
  margin-top: 12px;
  padding: 14px;
  background: var(--bg-code);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #E4E4E7;
  min-height: 60px;
  white-space: pre-wrap;
}

/* ---------- Cards Grid ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin: 24px 0;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: all var(--transition);
  text-decoration: none;
  color: var(--text);
  display: block;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
  color: var(--text);
}

.card .card-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 16px;
}

.card .card-icon.purple { background: rgba(108,99,255,0.12); color: var(--primary); }
.card .card-icon.pink { background: rgba(255,101,132,0.12); color: var(--secondary); }
.card .card-icon.green { background: rgba(67,233,123,0.12); color: #2ECC71; }
.card .card-icon.orange { background: rgba(255,183,77,0.12); color: #FF9800; }
.card .card-icon.blue { background: rgba(33,150,243,0.12); color: #2196F3; }

.card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
  margin-top: 0;
}

.card p {
  font-size: 0.88rem;
  color: var(--text-light);
  margin: 0;
  line-height: 1.5;
}

.card .card-arrow {
  margin-top: 16px;
  font-size: 0.82rem;
  color: var(--primary);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---------- Navigation Buttons (Prev/Next) ---------- */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  gap: 16px;
}

.page-nav a {
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  min-width: 180px;
  text-decoration: none;
}

.page-nav a:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.page-nav a .nav-label {
  font-size: 0.75rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 4px;
}

.page-nav a .nav-title {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 600;
}

.page-nav .next { text-align: right; margin-left: auto; }

/* ---------- Tables ---------- */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 0.9rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.content th {
  background: var(--bg-sidebar);
  color: #fff;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.content td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.content tr:last-child td { border-bottom: none; }
.content tr:hover td { background: rgba(108,99,255,0.03); }

/* ---------- Hero Section (Home) ---------- */
.hero {
  text-align: center;
  padding: 80px 24px 60px;
  max-width: 800px;
  margin: 0 auto;
}

.hero h1 {
  font-size: 3.2rem;
  font-weight: 900;
  line-height: 1.15;
  margin-bottom: 20px;
  background: linear-gradient(135deg, var(--primary), var(--secondary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 1.2rem;
  color: var(--text-light);
  max-width: 600px;
  margin: 0 auto 36px;
  line-height: 1.6;
}

.hero-cta {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(108,99,255,0.35);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: #fff;
  transform: translateY(-2px);
}

/* ---------- Features Section ---------- */
.features-section {
  padding: 60px 24px;
  max-width: 1100px;
  margin: 0 auto;
}

.features-section h2 {
  text-align: center;
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--text);
  border: none;
  padding: 0;
}

.features-section .section-subtitle {
  text-align: center;
  color: var(--text-light);
  margin-bottom: 40px;
  font-size: 1.05rem;
}

/* ---------- Stats Row ---------- */
.stats-row {
  display: flex;
  justify-content: center;
  gap: 48px;
  padding: 40px 24px;
  flex-wrap: wrap;
}

.stat-item {
  text-align: center;
}

.stat-item .stat-number {
  font-size: 2.4rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-item .stat-label {
  font-size: 0.88rem;
  color: var(--text-light);
  margin-top: 4px;
}

/* ---------- Footer ---------- */
.footer {
  background: linear-gradient(135deg, #1E1E2F 0%, #2A1F4E 50%, #1E1E2F 100%);
  color: var(--text-sidebar);
  padding: 0;
  margin-top: 80px;
  position: relative;
  overflow: hidden;
}

.footer::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--secondary), var(--accent), var(--primary));
  background-size: 300% 100%;
  animation: gradientShift 8s ease infinite;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.footer-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 48px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.footer-brand .footer-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: contain;
  box-shadow: 0 4px 15px rgba(108,99,255,0.3);
}

.footer-brand h4 {
  color: #fff;
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.3px;
}

.footer p {
  font-size: 0.9rem;
  line-height: 1.7;
  color: rgba(255,255,255,0.6);
  max-width: 500px;
  margin: 0 auto 28px;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 32px;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,0.7);
  font-size: 0.85rem;
  padding: 8px 18px;
  border-radius: 50px;
  border: 1px solid rgba(255,255,255,0.12);
  transition: all var(--transition);
  text-decoration: none;
  font-weight: 500;
}

.footer-links a:hover {
  color: #fff;
  border-color: var(--primary);
  background: rgba(108,99,255,0.15);
  transform: translateY(-1px);
}

.footer-links .link-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: inline-block;
}

.footer-bottom {
  width: 100%;
  padding: 20px 24px;
  border-top: 1px solid rgba(255,255,255,0.08);
  text-align: center;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.2px;
}

.footer-bottom a {
  color: rgba(255,255,255,0.5);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-bottom a:hover { color: var(--primary-light); }

/* Footer decorative circles */
.footer-decor {
  position: absolute;
  border-radius: 50%;
  opacity: 0.04;
  pointer-events: none;
}

.footer-decor-1 {
  width: 300px;
  height: 300px;
  background: var(--primary);
  top: -100px;
  right: -80px;
}

.footer-decor-2 {
  width: 200px;
  height: 200px;
  background: var(--secondary);
  bottom: -60px;
  left: -40px;
}

@media (max-width: 480px) {
  .footer-content { padding: 36px 16px 20px; }
  .footer-brand h4 { font-size: 1.15rem; }
  .footer p { font-size: 0.82rem; margin-bottom: 20px; }
  .footer-links { gap: 6px; }
  .footer-links a { padding: 7px 14px; font-size: 0.8rem; }
  .footer-links .link-dot { display: none; }
  .footer-bottom { font-size: 0.72rem; padding: 16px; }
}

/* ---------- Responsive: Full Device Support ---------- */

/* --- Extra Large Desktop (1920px+) --- */
@media (min-width: 1920px) {
  .main-content { max-width: 1000px; }
  .features-section { max-width: 1300px; }
  .footer-content { max-width: 1300px; }
  .hero h1 { font-size: 3.6rem; }
  .hero p { font-size: 1.3rem; }
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
}

/* --- Large Desktop (1440px - 1919px) --- */
@media (min-width: 1440px) and (max-width: 1919px) {
  .features-section { max-width: 1200px; }
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
}

/* --- Standard Desktop / Laptop (1025px - 1439px) --- */
@media (min-width: 1025px) and (max-width: 1439px) {
  .header-nav a {
    padding: 6px 10px;
    font-size: 0.82rem;
  }
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

/* --- Small Laptop / Large Tablet Landscape (769px - 1024px) --- */
@media (max-width: 1024px) {
  .main-content {
    padding: 32px 24px 80px;
  }

  .header-nav a {
    padding: 6px 8px;
    font-size: 0.78rem;
  }

  .search-box input { width: 160px; }
  .search-box input:focus { width: 200px; }

  .footer-content {
    grid-template-columns: 1fr 1fr;
  }

  .sidebar { width: 240px; }
  .main-content { margin-left: 240px; }

  .content h1 { font-size: 1.9rem; }
  .hero h1 { font-size: 2.8rem; }

  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

/* --- Tablet Portrait & Small Tablets (481px - 768px) --- */
@media (max-width: 768px) {
  .menu-toggle { display: flex; }

  .header-nav { display: none; }

  .search-box {
    position: static;
    margin-right: 4px;
  }

  .search-box input {
    width: 0;
    padding: 8px 0;
    border: none;
    background: transparent;
    opacity: 0;
    transition: all 0.3s ease;
  }

  .search-box .search-icon {
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px;
    position: static;
    transform: none;
  }

  .search-box.active {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-card);
    z-index: 1002;
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    margin: 0;
  }

  .search-box.active input {
    width: 100%;
    opacity: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: var(--radius-sm);
    font-size: 1rem;
  }

  .search-box.active .search-icon {
    display: none;
  }

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

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    margin-left: 0 !important;
    padding: 24px 20px 60px;
    max-width: 100vw;
    width: 100%;
  }

  .page-wrapper {
    max-width: 100vw;
    overflow-x: hidden;
  }

  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  .hero { padding: 50px 20px 40px; }
  .hero h1 { font-size: 2.2rem; }
  .hero p { font-size: 1rem; max-width: 100%; }

  .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }

  .card { padding: 20px 18px; }
  .card h3 { font-size: 1rem; }
  .card p { font-size: 0.82rem; }

  .page-nav { flex-direction: column; }
  .page-nav a { min-width: auto; }

  .stats-row { gap: 24px; }
  .stat-item .stat-number { font-size: 1.8rem; }

  .footer-content { grid-template-columns: 1fr 1fr; gap: 24px; }

  .content h1 { font-size: 1.6rem; }
  .content h2 { font-size: 1.25rem; margin-top: 36px; }
  .content h3 { font-size: 1.05rem; }

  .features-section { padding: 40px 20px; }
  .features-section h2 { font-size: 1.5rem; }

  .code-block pre { font-size: 0.82rem; padding: 14px; }

  .content table { font-size: 0.82rem; display: block; overflow-x: auto; max-width: 100%; }
  .content th, .content td { padding: 10px 12px; }

  .code-block { max-width: 100%; }
  .code-block pre { max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }

  .content img, .content iframe { max-width: 100%; }
  .content ul, .content ol { padding-left: 20px; }
  .content p, .content li { overflow-wrap: break-word; word-break: break-word; }

  .info-box { padding: 14px 16px; font-size: 0.85rem; }

  .try-it-box { padding: 18px; }

  .step-list li { padding-left: 44px; }

  .btn { padding: 10px 22px; font-size: 0.9rem; }

  .accordion-header { padding: 14px 16px; font-size: 0.9rem; }
}

/* --- Large Phone / Phablet (376px - 480px) --- */
@media (max-width: 480px) {
  :root {
    --header-height: 56px;
  }

  html, body { overflow-x: hidden !important; max-width: 100vw !important; }

  .main-content { margin-left: 0 !important; width: 100% !important; max-width: 100vw !important; }

  .header-brand { font-size: 1.05rem; }
  .header-brand .brand-icon { width: 30px; height: 30px; }

  .hero { padding: 36px 16px 30px; }
  .hero h1 { font-size: 1.75rem; line-height: 1.2; }
  .hero p { font-size: 0.92rem; margin-bottom: 24px; }

  .hero-cta { flex-direction: column; align-items: center; }
  .hero-cta .btn { width: 100%; justify-content: center; }

  .stats-row { gap: 16px; padding: 24px 16px; }
  .stat-item .stat-number { font-size: 1.5rem; }
  .stat-item .stat-label { font-size: 0.75rem; }

  .cards-grid { grid-template-columns: 1fr; gap: 14px; }

  .card { padding: 18px 16px; }
  .card .card-icon { width: 42px; height: 42px; font-size: 1.2rem; margin-bottom: 12px; }
  .card h3 { font-size: 0.95rem; }

  .main-content { padding: 16px 14px 50px; }

  .content h1 { font-size: 1.4rem; }
  .content h2 { font-size: 1.15rem; margin-top: 32px; }
  .content h3 { font-size: 1rem; }
  .content p { font-size: 0.9rem; }
  .content .subtitle { font-size: 0.95rem; }

  .code-block pre { font-size: 0.78rem; padding: 12px; line-height: 1.5; }
  .code-header { padding: 8px 12px; }
  .code-header .code-lang { font-size: 0.68rem; }

  .content table { font-size: 0.78rem; }
  .content th, .content td { padding: 8px 10px; }

  .info-box { padding: 12px 14px; font-size: 0.82rem; flex-direction: column; }
  .info-box .box-icon { margin-top: 0; }

  .try-it-box { padding: 14px; }
  .try-it-box textarea { min-height: 100px; font-size: 0.82rem; }

  .step-list li { padding-left: 40px; }
  .step-list li::before { width: 28px; height: 28px; font-size: 0.75rem; }
  .step-list li h4 { font-size: 0.92rem; }
  .step-list li p { font-size: 0.85rem; }

  .page-nav a { padding: 12px 14px; }
  .page-nav a .nav-title { font-size: 0.88rem; }

  .footer { padding: 30px 16px 20px; margin-top: 50px; }
  .footer-content { grid-template-columns: 1fr; gap: 20px; }
  .footer h4 { font-size: 0.88rem; margin-bottom: 10px; }
  .footer p, .footer a { font-size: 0.8rem; }
  .footer-bottom { font-size: 0.72rem; }

  .features-section { padding: 30px 16px; }
  .features-section h2 { font-size: 1.3rem; }
  .features-section .section-subtitle { font-size: 0.9rem; }

  .breadcrumb { font-size: 0.75rem; margin-bottom: 16px; flex-wrap: wrap; }

  .accordion-header { padding: 12px 14px; font-size: 0.85rem; }
  .accordion-body-inner { padding: 0 14px 14px; font-size: 0.82rem; }

  .tag { font-size: 0.65rem; padding: 2px 8px; }

  .btn { padding: 10px 18px; font-size: 0.85rem; }

  .sidebar { width: 260px; }

  .theme-toggle { width: 34px; height: 34px; font-size: 1rem; }
  .menu-toggle { width: 34px; height: 34px; font-size: 1.1rem; }
}

/* --- Small Phone (320px - 375px) --- */
@media (max-width: 375px) {
  :root {
    --header-height: 50px;
  }

  .header-brand { font-size: 0.95rem; gap: 6px; }
  .header-brand .brand-icon { width: 26px; height: 26px; border-radius: 0; }

  .hero h1 { font-size: 1.5rem; }
  .hero p { font-size: 0.85rem; }

  .stats-row { gap: 12px; padding: 20px 12px; }
  .stat-item .stat-number { font-size: 1.3rem; }
  .stat-item .stat-label { font-size: 0.7rem; }

  .main-content { padding: 12px 10px 40px; }

  .content h1 { font-size: 1.25rem; }
  .content h2 { font-size: 1.05rem; }
  .content p { font-size: 0.85rem; line-height: 1.6; }

  .card { padding: 14px 12px; }
  .card .card-icon { width: 36px; height: 36px; font-size: 1rem; margin-bottom: 10px; }
  .card h3 { font-size: 0.9rem; }
  .card p { font-size: 0.78rem; }

  .code-block { max-width: calc(100vw - 24px); }
  .code-block pre { font-size: 0.72rem; padding: 10px; white-space: pre-wrap; word-break: break-word; overflow-x: auto; }

  .sidebar { width: 240px; }

  .features-section { padding: 24px 12px; }

  .footer { padding: 24px 12px 16px; }
}

/* --- Touch Device Optimizations --- */
@media (hover: none) and (pointer: coarse) {
  .card:hover { transform: none; }
  .btn:hover { transform: none; }
  .card:active { transform: scale(0.98); }
  .btn:active { transform: scale(0.97); }

  .sidebar a { padding: 12px 16px; min-height: 44px; }
  .header-nav a { min-height: 44px; display: flex; align-items: center; }
  .accordion-header { min-height: 48px; }

  .code-block pre { -webkit-overflow-scrolling: touch; }
  .comparison-table { -webkit-overflow-scrolling: touch; }
  .content table { -webkit-overflow-scrolling: touch; }
}

/* --- Landscape Phone --- */
@media (max-height: 500px) and (orientation: landscape) {
  .hero { padding: 24px 20px 20px; }
  .hero h1 { font-size: 1.6rem; }
  .hero p { font-size: 0.88rem; margin-bottom: 16px; }
  .stats-row { padding: 16px 24px; }
  .features-section { padding: 24px 20px; }
  .sidebar { top: var(--header-height); }
}

/* --- Print Styles --- */
@media print {
  .top-header, .sidebar, .sidebar-overlay, .menu-toggle,
  .theme-toggle, .search-box, .page-nav, .hero-cta, .btn { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 0 !important; max-width: 100% !important; }
  .content h1 { -webkit-text-fill-color: var(--text) !important; }
  body { background: #fff; color: #000; }
  .code-block { break-inside: avoid; }
  .card { break-inside: avoid; border: 1px solid #ccc; box-shadow: none; }
}

/* --- High DPI / Retina --- */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .code-block pre { -webkit-font-smoothing: antialiased; }
}

/* Mobile nav overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 899;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.active { display: block; }

/* ---------- Syntax Highlighting (basic) ---------- */
.token-keyword { color: #C792EA; }
.token-string { color: #C3E88D; }
.token-comment { color: #676E95; font-style: italic; }
.token-function { color: #82AAFF; }
.token-number { color: #F78C6C; }
.token-operator { color: #89DDFF; }
.token-variable { color: #F07178; }
.token-flag { color: #FFCB6B; }
.token-param { color: #89DDFF; }

/* ---------- Step List ---------- */
.step-list {
  counter-reset: step-counter;
  list-style: none;
  padding-left: 0;
  margin: 24px 0;
}

.step-list li {
  counter-increment: step-counter;
  position: relative;
  padding-left: 52px;
  padding-bottom: 24px;
  margin-bottom: 0;
}

.step-list li:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 18px;
  top: 40px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.step-list li::before {
  content: counter(step-counter);
  position: absolute;
  left: 4px;
  top: 0;
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
}

.step-list li h4 {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.step-list li p {
  font-size: 0.92rem;
  color: var(--text-light);
}

/* ---------- Tag / Badge ---------- */
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tag.beginner { background: rgba(67,233,123,0.12); color: #2ECC71; }
.tag.intermediate { background: rgba(255,183,77,0.12); color: #FF9800; }
.tag.advanced { background: rgba(255,101,132,0.12); color: var(--secondary); }

/* ---------- Accordion / FAQ ---------- */
.accordion {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.accordion-item {
  border-bottom: 1px solid var(--border);
}

.accordion-item:last-child { border-bottom: none; }

.accordion-header {
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-card);
  border: none;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font);
  transition: background var(--transition);
}

.accordion-header:hover { background: var(--bg); }

.accordion-header .acc-icon {
  transition: transform var(--transition);
  font-size: 0.8rem;
}

.accordion-item.open .accordion-header .acc-icon {
  transform: rotate(180deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.accordion-item.open .accordion-body {
  max-height: 500px;
}

.accordion-body-inner {
  padding: 0 20px 16px;
  font-size: 0.9rem;
  color: var(--text-light);
  line-height: 1.7;
}

/* ---------- Comparison Table ---------- */
.comparison-table {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.comparison-table table {
  min-width: 600px;
}

/* Ensure content never overflows viewport */
.content {
  max-width: 100%;
  overflow-x: hidden;
}

.check { color: var(--accent); font-weight: bold; }
.cross { color: var(--secondary); }

/* ---------- Keyboard Shortcut ---------- */
kbd {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.8em;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* ---------- Google AdSense Containers ---------- */
.ad-container {
  max-width: 100%;
  overflow: hidden;
  text-align: center;
  margin: 0 auto;
}

.ad-container ins {
  max-width: 100%;
}

.ad-top {
  padding: 8px 24px;
  background: var(--bg);
}

/* Hide ad containers when ads haven't loaded (empty ins elements) */
.ad-container:has(ins[data-ad-status="unfilled"]),
.ad-container:not(:has(ins iframe)) {
  padding: 0;
  margin: 0;
  min-height: 0;
}

.ad-bottom {
  margin: 40px 0 20px;
  padding: 16px;
}

.ad-in-content {
  margin: 30px 0;
  padding: 12px 0;
}

@media (max-width: 768px) {
  .ad-top { padding: 6px 12px; }
  .ad-bottom { margin: 24px 0 12px; padding: 10px; }
  .ad-in-content { margin: 20px 0; }
}

@media (max-width: 480px) {
  .ad-top { padding: 4px 8px; }
  .ad-bottom { margin: 16px 0 8px; padding: 8px; }
  .ad-in-content { margin: 16px 0; }
}

@media print {
  .ad-container { display: none !important; }
}

/* ---------- Animation utility ---------- */
.fade-in {
  animation: fadeIn 0.5s ease forwards;
  opacity: 0;
}

@keyframes fadeIn {
  to { opacity: 1; }
}

.slide-up {
  animation: slideUp 0.5s ease forwards;
  opacity: 0;
  transform: translateY(20px);
}

@keyframes slideUp {
  to { opacity: 1; transform: translateY(0); }
}
