*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body, 'Inter', sans-serif);
  background-color: var(--bg-main);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  padding-top: 64px;
  /* Synchronized with global nav height */
}

.app-content {
  display: flex;
  flex-direction: row;
  flex: 1;
  width: 100%;
  overflow: hidden;
}

/* CUSTOM SCROLLBARS (the "sliders") */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-light);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* MAIN AREA (Left Scroll) */
.main {
  flex: 1;
  height: 100%;
  /* Relative to app-content */
  padding: 3rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
  width: 100%;
  flex-shrink: 0;
}

h1 {
  font-size: clamp(2.5rem, 5vw, 4rem);
  background: linear-gradient(to bottom, #F8FAFC, #94A3B8);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0 0 0.5rem 0;
  font-weight: 800;
  letter-spacing: -2px;
  text-align: center;
}

.hero-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 1.15rem;
  margin-bottom: 3rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
}

#menuToggle {
  display: none;
  background: #ffffff;
  border: 2px solid #90e0ef;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  width: 44px;
  height: 44px;
  flex-direction: column;
  justify-content: space-around;
  z-index: 1001;
}

#menuToggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: #0077b6;
  transition: all 0.3s ease;
}

#menuOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 48, 73, 0.4);
  backdrop-filter: blur(4px);
  z-index: 9990;
  /* Above nav, below drawer */
}

.search-container {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-bottom: 2rem;
}

#conceptSearch {
  width: 100%;
  max-width: 500px;
  padding: 1rem 1.5rem;
  border-radius: 30px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-main);
  font-size: 1rem;
  transition: all 0.3s ease;
  outline: none;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

#conceptSearch:focus {
  border-color: var(--primary);
  box-shadow: 0 0 15px var(--primary-glow);
}

#menuSearchContainer {
  display: none;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
  padding-bottom: 3rem;
  width: 100%;
  flex: 1;
  overflow-y: auto;
  justify-content: center;
  align-content: flex-start;
}

/* Elite Glass Cards */
.card {
  padding: 1.8rem;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  text-align: left;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.5rem;
  height: auto;
  overflow: visible !important;
}

.card h3 {
  margin: 0;
  color: var(--text-main);
  /* Standard heading color */
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
  transition: color 0.3s ease;
}

.concept-desc {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: block !important;
  visibility: visible !important;
}

.card:hover {
  background: var(--bg-card);
  transform: translateY(-10px) scale(1.02);
  border-color: var(--primary);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.card:hover h3 {
  color: var(--primary);
}

#demoDrawer {
  background: var(--bg-card);
  z-index: 10005;
  padding: 3rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
}

/* PC STYLES (> 1024px) */
@media (min-width: 1025px) {
  #demoDrawer {
    width: 35%;
    height: 100%;
    position: relative;
    right: 0 !important;
    border-left: 1px solid var(--border);
  }

  #closeDrawer {
    display: none;
  }
}

/* Hide close button by default */
#closeDrawer {
  display: none;
}

#variablesPanel {
  width: 100%;
  padding: 0;
}

#demoSection {
  width: 100%;
  padding: 0;
}

#canvasBox {
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  background: #000;
  border: 1px solid var(--glass-border);
  width: 100%;
  position: relative;
}

#canvasBox::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 24px;
  box-shadow: inset 0 0 20px rgba(2, 132, 199, 0.2);
  pointer-events: none;
}

canvas {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

/* Controls Box */
#controls {
  margin-top: 1rem;
  padding: 1.5rem;
  background: var(--bg-dark);
  border-radius: 16px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

#controls p strong {
  color: var(--primary);
}

#controls label {
  display: inline-block;
  margin-top: 1rem;
  font-weight: 600;
  color: var(--primary);
}

/* LIVE VARIABLES PANEL */
#variablesPanel {
  padding: 2.5rem 2rem 1rem 2rem;
}

#variablesPanel h2 {
  margin-top: 0;
  color: var(--text-main);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

#variablesPanel h2::before {
  content: '{ }';
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 1.2rem;
}

.varItem {
  padding: 0.75rem 1rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
  font-family: var(--font-mono, monospace);
  font-size: 0.95rem;
  color: var(--text-main);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  transition: border-color 0.2s;
}

.varItem:hover {
  border-color: var(--primary);
}

input[type="text"],
input[type="number"] {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-dark);
  color: var(--text-main);
  margin-top: 0.5rem;
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

button {
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  font-family: inherit;
  margin-right: 0.5rem;
  transition: all 0.3s ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px var(--primary-glow);
  filter: brightness(1.1);
}

button.secondary {
  background: var(--bg-light);
  color: var(--text-main);
  box-shadow: none;
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

small.note {
  color: var(--text-muted);
  display: block;
  margin-top: 1rem;
  font-style: italic;
}

/* RESPONSIVE DESIGN */
@media (max-width: 1024px) {
  body {
    display: block;
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }

  /* Show overlay on mobile when drawer is open */
  body.drawer-open #menuOverlay {
    display: block;
  }

  .main {
    width: 100%;
    max-width: 100vw;
    height: auto;
    padding: 1.5rem;
    overflow: visible;
  }

  .cards {
    overflow-y: visible;
    padding-bottom: 0;
    padding-right: 0;
  }

  .nav-header {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .cards {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
  }

  #demoDrawer {
    position: fixed;
    top: 64px;
    /* Below the sticky nav */
    right: -100% !important;
    width: 100%;
    max-width: 100vw;
    height: calc(100vh - 64px);
    padding: 2rem 1.5rem;
    z-index: 10005;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-card);
    overflow-x: hidden;
    box-sizing: border-box;
    border-top: 1px solid var(--border);
  }

  body.drawer-open #demoDrawer {
    right: 0 !important;
  }

  #closeDrawer {
    display: flex;
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    font-size: 2rem;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    z-index: 10006;
  }

  #closeDrawer:hover {
    background: var(--primary);
    color: white;
  }

  /* Custom Scrollbar for Mobile Popup */
  #demoDrawer::-webkit-scrollbar {
    width: 6px;
  }

  .search-container {
    display: block;
    margin: 1rem 0;
    width: 100%;
    order: 3;
  }

  #variablesPanel {
    width: 100%;
    padding: 0;
  }

  #variablesPanel h2 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    display: inline-block;
    margin-right: 1rem;
  }

  #varList {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.75rem;
    padding-bottom: 5px;
  }

  .varItem {
    margin-bottom: 0;
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
  }

  #demoSection {
    width: 100%;
    padding: 0;
    margin-top: 1rem;
  }

  /* Canvas sizing for mobile */
  #canvasBox {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    margin-top: 0;
  }

  canvas {
    display: block;
    max-height: 250px;
    width: 100%;
    max-width: 100%;
    object-fit: contain;
    margin: 0 auto;
  }

  h1 {
    font-size: 2rem;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 1rem;
  }

  .nav-header {
    margin-bottom: 1.5rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  .search-container {
    margin: 0.5rem 0;
  }

  #demoDrawer {
    padding: 4rem 1rem 1rem 1rem;
  }

  #closeDrawer {
    top: 0.75rem;
    right: 0.75rem;
    width: 40px;
    height: 40px;
  }

  .card {
    padding: 1.25rem;
  }

  button {
    width: 100%;
    margin-right: 0;
    margin-bottom: 0.5rem;
  }
}

.ad-mobile {
  display: none;
}

@media(max-width: 768px) {
  .ad-mobile {
    display: flex;
    justify-content: center;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #fff;
    padding: 5px 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 999;
  }

  body {
    padding-bottom: 60px;
  }

  /* prevent content hiding behind ad */
}


.ad-top {
  display: flex;
  justify-content: center;
  margin: 15px 0;
}

@media(max-width: 768px) {
  .ad-top {
    display: none;
  }

  /* hide large banner on mobile */
}