/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Tablet — ≤ 900px */
@media (max-width: 900px) {
  .sim-layout,
  .cell-layout,
  .dna-layout,
  .eco-layout,
  .mol-layout,
  .ph-layout {
    grid-template-columns: 1fr;
  }

  .hero h1 { font-size: 2.25rem; }
  h1 { font-size: 1.75rem; }

  .periodic-table-grid { gap: 1px; }
  .pt-cell .pt-name { display: none; }

  .element-detail-panel { width: 95%; padding: 1.75rem; }

  .experiment-info { padding: 1.25rem 1.35rem; }
}

/* Mobile — ≤ 640px */
@media (max-width: 640px) {
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }
  .navbar {
    padding-top: env(safe-area-inset-top, 0px);
  }
  .navbar-inner {
    height: 60px;
    padding: 0 1rem;
    gap: 0.5rem;
  }
  .logo { font-size: 1.1rem; }
  .nav-links { display: none; }
  .search-wrapper { display: none; }
  .mobile-only { display: flex; }

  .icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    font-size: 1.15rem;
  }

  /* Prevent iOS Safari auto-zoom */
  input[type="text"], input[type="search"], select, textarea {
    font-size: 16px !important;
  }

  .hero { padding: 3.5rem 1.25rem 3rem; }
  .hero h1 { font-size: 2rem; }
  .hero-sub { font-size: 0.95rem; }

  .subject-grid { grid-template-columns: 1fr; gap: 1rem; }
  .subject-card { padding: 1.5rem; border-radius: 16px; }

  .stats-bar { padding: 1.15rem; gap: 1rem; border-radius: 14px; }
  .stat strong { font-size: 1.35rem; }

  .module-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x mandatory;
    padding: 6px 8px;
    gap: 4px;
    border-radius: 14px;
  }
  .module-tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex-shrink: 0;
    scroll-snap-align: start;
    min-height: 38px;
    padding: 0.5rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 550;
    border-radius: 10px;
  }

  /* Slider touch handling */
  .sim-controls input[type="range"] { height: 8px; border-radius: 4px; }
  .sim-controls input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; border-radius: 50%; }

  .sim-controls, .cell-info-panel, .dna-controls, .eco-controls, .mol-controls {
    padding: 1.15rem; border-radius: 14px;
  }
  .sim-canvas-wrap, .cell-canvas-wrap, .dna-canvas-wrap, .eco-canvas-wrap, .mol-canvas-wrap {
    border-radius: 14px;
    overflow: hidden;
    touch-action: pan-y;
  }
  .sim-canvas-wrap canvas, .cell-canvas-wrap canvas, .dna-canvas-wrap canvas,
  .eco-canvas-wrap canvas, .mol-canvas-wrap canvas {
    width: 100%;
    height: auto;
  }

  .lang-interactive table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Single column quiz options */
  .quiz-options, .varn-quiz-opt, div[style*="grid-template-columns:1fr 1fr"], div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Element detail modal containment */
  .element-detail-panel {
    max-height: 85vh;
    overflow-y: auto;
    width: min(440px, 92vw);
    padding: 1.5rem;
    border-radius: 18px;
  }

  .periodic-table-grid {
    grid-template-columns: repeat(18, 1fr);
    overflow-x: auto; min-width: 600px;
  }
  #tab-periodic { overflow-x: auto; }
  .pt-cell { font-size: 0.5rem; border-radius: 4px; }
  .pt-cell .pt-sym { font-size: 0.6rem; }
  .pt-cell .pt-num { display: none; }

  .dashboard-grid { grid-template-columns: 1fr; }

  .container { padding: 0 1rem 1.75rem; }
  .page-header { padding: 2rem 1rem 1.25rem; }

  .experiment-info { padding: 1.15rem; border-radius: 14px; margin-bottom: 1rem; }
  .experiment-info h3 { font-size: 1.05rem; }

  .btn { padding: 0.5rem 1rem; font-size: 0.825rem; border-radius: 9px; }
  .btn-lg { padding: 0.7rem 1.75rem; font-size: 0.95rem; }

  .quiz-question { padding: 1.35rem; border-radius: 14px; }
  .quiz-option { padding: 0.75rem 1rem; border-radius: 10px; }
}

/* Small mobile — ≤ 400px */
@media (max-width: 400px) {
  .hero h1 { font-size: 1.65rem; }
  .hero-sub { font-size: 0.9rem; }
  .hero-actions { flex-direction: column; align-items: center; }

  .icon-btn { width: 34px; height: 34px; border-radius: 8px; }
  .navbar-inner { height: 56px; padding: 0 1rem; }

  .tab { font-size: 0.7rem; padding: 0.35rem 0.55rem; }
}

/* Large screens — ≥ 1400px */
@media (min-width: 1400px) {
  .container { max-width: 1360px; }
  .sim-layout { grid-template-columns: 1fr 360px; }
}

/* Print styles */
@media print {
  .navbar, .site-footer, .btn, .sim-controls, .module-tabs,
  .search-wrapper, .nav-actions, .mobile-menu { display: none !important; }
  .page { display: block !important; }
  .sim-canvas-wrap { border: 1px solid #ccc; }
  body { background: #fff; color: #000; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
