*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font: 'Quicksand', system-ui, -apple-system, sans-serif;
  --font-title: 'Unbounded', 'Quicksand', system-ui, sans-serif;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px var(--shadow-color);
  --transition: 0.2s ease;
  --tap-size: 44px;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  font-size: calc(16px * var(--font-scale, 1));
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

a { color: var(--accent); text-decoration: none; }

/* ── Focus visible (keyboard navigation) ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; font-size: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

html { scroll-behavior: smooth; }

/* ── Lucide icons ── */
[data-lucide] {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Fade-in ── */
#app.fade-in {
  animation: view-fade-in 0.3s ease-out forwards;
}
@keyframes view-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Toast notification ── */
#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--surface);
  color: var(--text);
  padding: 10px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
}
#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── PWA install banner ── */
.pwa-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 9998;
  animation: pwa-slide-up 0.3s ease;
}
@keyframes pwa-slide-up {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.pwa-banner-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.pwa-banner-install {
  padding: 6px 14px;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.pwa-banner-install:active { opacity: 0.7; }
.pwa-banner-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  touch-action: manipulation;
}
.pwa-banner-close:active { opacity: 0.7; }

/* ── Hover & tap feedback ── */
@media (hover: hover) {
  /* Navigation buttons */
  .btn-back:hover, .btn-icon:hover {
    background: var(--surface2);
  }

  /* Ban bar */
  .cardlist-banbar:not(.banned):not(.just-toggled):hover {
    width: 18px;
    background: var(--text-muted);
  }
  .cardlist-banbar.banned:not(.just-toggled):hover {
    width: 18px;
    background: var(--accent);
  }

  /* Cards: border highlight + elevation */
  .ch-card:hover,
  .subject-card:hover,
  .search-result-card:hover,
  .cardlist-card:hover,
  .glossary-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(56,189,248,.1);
  }

  /* Action buttons: scale + brightness */
  .ch-action-btn:hover {
    transform: scale(1.03);
    filter: brightness(1.15);
  }

  /* Stat boxes: border + scale */
  .dashboard-stat.clickable:hover {
    border-color: var(--accent);
    transform: scale(1.03);
  }

  /* Badge clicks */
  .fc-badge.clickable:hover { filter: brightness(1.2); }

  /* Sort buttons (allcards) */
  .fc-filter-btn:hover:not(.active) {
    border-color: var(--accent);
    color: var(--accent);
  }

  /* Filter items */
  .fc-filter-item:hover:not(.active) {
    background: var(--surface2);
  }
  .fc-filter-trigger:hover {
    border-color: var(--accent);
  }

  /* TOC items: background */
  .cours-toc-section:hover { background: var(--surface2); }
  .cours-toc-sub:hover { background: var(--surface2); }
  .cours-toc-toggle:hover { background: var(--surface2); }

  /* Glossary clear button */
  .glossary-search-clear:hover { background: var(--accent); color: var(--on-accent); }

  /* Glossary letter buttons */
  .glossary-letter-btn:hover:not(.dimmed) {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
  }

  /* Glossary search focus */
  .glossary-search:hover { border-color: var(--accent); }

  /* List toggle */
  .fc-list-toggle:hover:not(.active) {
    border-color: var(--accent);
    color: var(--accent);
  }

  /* Back to top */
  .back-to-top:hover { filter: brightness(1.15); }
}
@media (hover: none) {
  button:active, a:active, [onclick]:active {
    transition-duration: 0.05s !important;
  }
}
