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

html {
  scroll-behavior: smooth;
  /* Prevent rubber-band scroll bounce on iOS */
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  /* iOS home indicator safe area */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Garden Pop dreamy blobs (fixed backdrop) ===== */
.blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  filter: blur(70px);
  opacity: 0.5;
  pointer-events: none;
}

.blobs .blob {
  position: absolute;
  border-radius: 50%;
  animation: drift 18s ease-in-out infinite alternate;
}

.blobs .b1 { width: 420px; height: 420px; background: var(--lavender); top: -140px; left: -100px; }
.blobs .b2 { width: 360px; height: 360px; background: var(--peach); top: 22%; right: -120px; animation-delay: -5s; }
.blobs .b3 { width: 300px; height: 300px; background: var(--mint); bottom: -80px; left: 15%; animation-delay: -9s; }

[data-theme="dark"] .blobs { opacity: 0.22; }

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(40px, 30px) scale(1.12); }
}

/* ===== KEYFRAMES ===== */

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50%       { transform: translateY(-6px); }
}

@keyframes progressGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(155, 125, 245, 0.4); }
  50%       { box-shadow: 0 0 16px rgba(155, 125, 245, 0.7); }
}

/* Gamification — streak flame flicker, sparkle twinkle, confetti rise */
@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(-3deg); }
  50%      { transform: scale(1.15) rotate(4deg); }
}

@keyframes twinkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.8); }
}

@keyframes rise {
  from { transform: translateY(0) rotate(0deg); opacity: 1; }
  to   { transform: translateY(-90px) rotate(200deg); opacity: 0; }
}

@keyframes rollIn {
  0%, 86%, 100% { transform: rotate(0deg); }
  92%           { transform: rotate(-18deg); }
  96%           { transform: rotate(12deg); }
}

@keyframes popIn {
  0%   { transform: scale(0.6); opacity: 0; }
  70%  { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== END KEYFRAMES ===== */

/* Global focus-visible ring — keyboard nav support */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Suppress focus ring for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

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

/* View-enter transition (class re-applied by the router on every route change) */
#app.view-enter {
  animation: fadeSlideUp var(--duration-entrance) var(--ease-out-quart) both;
}

/* App shell */
#app {
  min-height: 100vh;
  /* Left/right safe area for landscape */
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* Top bar */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  /* Semi-transparent bg so backdrop-filter actually shows */
  background: var(--bg-blur);
  border-bottom: 1px solid var(--border-light);
  /* Account for iOS status bar in PWA full-screen mode */
  padding: env(safe-area-inset-top, 0px) 1.5em 0;
  height: calc(var(--nav-height) + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.top-bar .logo {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.4em;
}

.top-bar .logo .logo-mark {
  font-size: 1.15rem;
  line-height: 1;
  flex-shrink: 0;
}

.top-bar .nav-links {
  display: flex;
  gap: 1em;
  align-items: center;
}

.top-bar .nav-link {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
  /* 44px touch target: use min-height + padding */
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.25em;
}

.top-bar .nav-link:hover {
  color: var(--text);
}

.top-bar .nav-link.active {
  color: var(--text);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.3em 0.6em;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-secondary);
  transition: all var(--transition);
  /* 44px touch target on mobile via height */
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

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

/* ── Library section tabs ─────────────────────────────── */
.lib-tabs {
  display: flex;
  justify-content: center;
  padding: 0.85em 1.5em 0;
  gap: 0;
}

.lib-tabs-inner {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-sm);
}

.lib-tab {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.35em 1.1em;
  border-radius: 999px;
  transition: color var(--transition-fast), background var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.lib-tab:hover {
  color: var(--text);
}

.lib-tab.active {
  color: #fff;
  background: var(--grad-hero);
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(155, 125, 245, 0.35);
}

/* Narrow screens: the pill was sized for 4 tabs and a 5th (Courses) pushes it
   ~88px past a 375px viewport. Two parts to the fix:
   1. Tighten the tab metrics so all five fit on a normal phone.
   2. Scroll rather than clip if they still don't (320px, larger text sizes).
      The centring must come from `margin: 0 auto` on the inner pill, NOT
      `justify-content: center` on a scrolling flex parent - that clips the
      leading edge unreachably, which is exactly what was happening here. */
@media (max-width: 560px) {
  .lib-tabs {
    padding-left: 0.3em;
    padding-right: 0.3em;
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .lib-tabs::-webkit-scrollbar { display: none; }

  .lib-tabs-inner {
    margin-inline: auto;   /* centred while it fits, flush-left once it scrolls */
    flex: none;
  }

  .lib-tab {
    padding: 0.5em 0.46em;   /* more vertical: 24px was a tight tap target */
    font-size: 0.72rem;
  }
}

/* Content container */
.container {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2em 1.5em;
}

.container.wide {
  max-width: var(--content-wide);
}

/* Reading progress bar */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--grad-progress);
  z-index: 60;
  transition: width 0.1s linear;
  width: 0%;
  /* Gradient tail for polish */
  box-shadow: 0 0 8px rgba(155, 125, 245, 0.4);
}

/* Search & filters */
.list-controls {
  margin-bottom: 1.5em;
}

.search-input {
  width: 100%;
  padding: 0.6em 1em;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  background: var(--bg-surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  margin-bottom: 0.75em;
  /* Prevent iOS zoom on focus */
  font-size: max(16px, 0.9rem);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
}

.filter-btn {
  padding: 0.25em 0.65em;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--bg);
  cursor: pointer;
  transition: background var(--transition),
              border-color var(--transition),
              color var(--transition),
              transform var(--duration-feedback) var(--ease-out-quint);
  -webkit-tap-highlight-color: transparent;
}

.filter-btn:active {
  transform: scale(0.94);
}

.filter-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border);
  color: var(--text);
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 500;
}

/* Sort controls */
.sort-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1em;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.sort-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  padding: 0.3em 0.5em;
  min-height: 36px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.sort-btn:hover {
  color: var(--text);
}

.sort-btn.active {
  color: var(--accent);
  font-weight: 500;
}

/* Back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: 1.5em;
  transition: color var(--transition), transform var(--transition-fast);
  cursor: pointer;
  /* 44px touch target */
  min-height: 44px;
}

.back-link:hover {
  color: var(--text);
  transform: translateX(-2px);
}

/* Dashboard filter bar */
.dash-controls {
  display: flex;
  gap: 0.75em;
  align-items: center;
  margin-bottom: 1.5em;
  flex-wrap: wrap;
}

.dash-search {
  flex: 1;
  min-width: 200px;
  padding: 0.5em 0.8em;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.dash-search:focus {
  border-color: var(--accent);
}

/* Font size control */
.font-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}

.font-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25em 0.5em;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition);
  line-height: 1;
  min-width: 30px;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.font-btn {
  /* Override transition: all from base with specific properties */
  transition: border-color var(--transition-fast),
              color var(--transition-fast),
              transform var(--duration-feedback) var(--ease-out-quint);
}

.font-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text);
}

.font-btn:active {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(0.92);
}

/* Font family button — wider to fit name */
.font-family-btn {
  min-width: 80px;
  font-weight: 500;
  font-size: 0.72rem;
  letter-spacing: 0.01em;
}

/* Responsive */
@media (max-width: 768px) {
  .top-bar {
    /* Override safe-area height on mobile for cleaner layout */
    padding: env(safe-area-inset-top, 0px) 0.75em 0;
    height: calc(var(--nav-height) + env(safe-area-inset-top, 0px));
  }

  .top-bar .logo {
    font-size: 0.9rem;
  }

  .top-bar .nav-links {
    gap: 0.5em;
  }

  .top-bar .nav-link {
    font-size: 0.8rem;
  }

  /* Touch-sized font controls */
  .font-btn {
    min-height: 40px;
    min-width: 40px;
    font-size: 0.85rem;
    padding: 0.3em 0.5em;
  }

  .container {
    padding: 1em 1em; /* Slightly more side breathing room for reading */
  }

  .container.wide {
    max-width: 100%;
    padding: 1em 0.75em;
  }

  .prose {
    font-size: 1.05rem; /* Slightly larger than 1rem for comfortable mobile reading */
    line-height: 1.8;   /* More breathing room on small screens */
  }

  .note-meta .title {
    font-size: 1.75rem; /* Scaled down from 2.5rem but still display-sized */
    letter-spacing: -0.01em;
  }

  .note-meta .summary {
    font-size: 0.9rem;
    padding: 0.65em 0.9em;
  }

  .note-meta .meta-row {
    margin-bottom: 0.5em;
  }

  .note-meta .author {
    font-size: 0.875rem;
  }

  /* List cards: horizontal layout on mobile */
  .note-card {
    flex-direction: row;
    padding: 0.85em 0.75em;
    gap: 0.75em;
    min-height: 80px; /* Comfortable touch target */
  }

  .note-card .card-cover {
    width: 64px;
    height: 64px;
    border-radius: 16px;
  }

  .note-card .card-title {
    font-size: 0.92rem; /* Up from 0.88rem — more readable */
  }

  .note-card .card-author {
    font-size: 0.78rem;
  }

  .note-card .card-summary {
    font-size: 0.82rem; /* Up from 0.78rem — more readable */
    -webkit-line-clamp: 2;
  }

  .note-card .card-body .platform-badge {
    font-size: 0.65rem;
    padding: 0.15em 0.45em;
  }

  /* Search and filters */
  .search-input {
    padding: 0.5em 0.75em;
    font-size: 16px; /* Prevents iOS zoom on focus */
    margin-bottom: 0.5em;
  }

  .filter-row {
    gap: 0.3em;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .filter-row::-webkit-scrollbar {
    display: none;
  }

  .filter-btn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 0.3em 0.6em;
    font-size: 0.75rem;
  }

  .sort-row {
    margin-bottom: 0.6em;
    font-size: 0.75rem;
  }

  .list-controls {
    margin-bottom: 0.75em;
  }

  /* Tag cloud — mobile */
  .tag-cloud {
    max-height: 3.2em;
    gap: 0.25em;
  }

  .tag-chip {
    font-size: 0.68rem;
    padding: 0.2em 0.5em;
  }

  .tag-cloud-wrap {
    margin-top: 0.5em;
  }

  /* Resume toast — mobile */
  .resume-toast {
    bottom: 5rem;
  }

  /* Section nav — mobile */
  .section-nav-toggle {
    font-size: 0.75rem;
    padding: 0.4em 0.75em;
  }

  .toc-item {
    font-size: 0.75rem;
    padding: 0.55em 0.75em;
    min-height: 36px;
    display: flex;
    align-items: center;
  }

  .toc-item.sub {
    padding-left: 1.25em;
    font-size: 0.7rem;
  }

  /* Back link */
  .back-link {
    margin-bottom: 1em;
    font-size: 0.8rem;
  }

  /* Tags */
  .tag-pills {
    gap: 0.3em;
  }

  .tag-pill {
    font-size: 0.7rem;
    padding: 0.1em 0.5em;
  }

  /* View original */
  .view-original {
    font-size: 0.8rem;
  }

  /* Status tabs — mobile */
  .status-tabs {
    gap: 0.3em;
    padding: 0.25em;
  }

  .status-tab {
    padding: 0.5em 0.3em;
    gap: 0.3em;
  }

  .status-tab-icon {
    font-size: 0.85rem;
  }

  .status-tab-label {
    font-size: 0.73rem;
  }

  .status-tab-count {
    font-size: 0.6rem;
    min-width: 1.3em;
    height: 1.3em;
  }

  /* Complete button — mobile */
  .complete-btn {
    font-size: 0.8rem;
    padding: 0.6em 1.2em;
  }

  /* Status toast — mobile */
  .status-toast {
    bottom: 5rem;
    font-size: 0.8rem;
  }

  /* Dashboard */
  .dash-controls {
    gap: 0.5em;
  }

  .dash-search {
    min-width: 150px;
    font-size: 16px;
  }

  .hl-dashboard-group .group-title {
    font-size: 0.95rem;
  }

  .hl-card {
    padding: 0.6em 0.75em;
  }

  .hl-card .hl-text {
    font-size: 0.85rem;
  }
}

/* Extra small screens (iPhone SE etc.) */
@media (max-width: 375px) {
  .container {
    padding: 0.75em 0.65em;
  }

  .note-card .card-cover {
    width: 58px;
    height: 58px;
  }

  .note-meta .title {
    font-size: 1.5rem;
  }
}

/* Landscape orientation on phones — compact layout */
@media (max-width: 768px) and (orientation: landscape) {
  :root {
    --nav-height: 40px;
  }

  .container {
    padding: 0.75em 1em;
  }

  .note-meta .title {
    font-size: 1.5rem;
  }

  .prose {
    font-size: 1rem;
  }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3em 1em;
  color: var(--text-secondary);
  animation: fadeIn var(--duration-entrance) var(--ease-out-quart) both;
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5em;
  display: inline-block;
  animation: float 3s ease-in-out infinite;
}

.empty-state p {
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

/* Loading */
@keyframes loadingPulse {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.8; }
}

.loading {
  text-align: center;
  padding: 3em;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

.loading-spinner {
  display: block;
  font-size: 2rem;
  animation: spin 1.5s linear infinite;
  margin-bottom: 0.75rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Skeleton loaders (list cold load) ===== */
.skel {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--border-light) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: skelShimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
}
@keyframes skelShimmer { to { background-position: -200% 0; } }

.skeleton-card { pointer-events: none; }
.skeleton-card .skel-cover { width: 70px; height: 70px; border-radius: 18px; flex-shrink: 0; }
.skeleton-card .card-body { display: flex; flex-direction: column; gap: 0.55em; flex: 1; justify-content: center; }
.skeleton-card .skel-line { height: 0.8em; }

/* ===== Floating Typography FAB ===== */
.type-fab {
  position: fixed;
  bottom: 1.75rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  z-index: 200;
}

.type-fab-trigger {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 1px 4px rgba(0,0,0,0.1);
  transition: background var(--transition),
              transform var(--duration-state) var(--ease-out-quint),
              box-shadow var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.type-fab-trigger:hover {
  background: var(--accent-hover);
  transform: scale(1.07);
  box-shadow: 0 6px 22px rgba(0,0,0,0.24), 0 2px 6px rgba(0,0,0,0.12);
}

.type-fab-trigger:active {
  transform: scale(0.93);
}

.type-fab.open .type-fab-trigger {
  background: var(--text-secondary);
  transform: rotate(8deg) scale(1.04);
}

/* Panel — hidden by default, slides up on open */
.type-fab-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.22s var(--ease-out-quint),
              transform 0.26s var(--ease-out-quint);
}

.type-fab.open .type-fab-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Size row: A− and A+ side by side */
.type-fab-size {
  display: flex;
  gap: 0.4rem;
}

/* Individual option buttons */
.type-fab-option {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background var(--transition-fast),
              border-color var(--transition-fast),
              transform var(--duration-feedback) var(--ease-out-quart),
              box-shadow var(--transition-fast);
}

.type-fab-option:hover {
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
}

.type-fab-option:active {
  transform: scale(0.92);
}

/* Size buttons */
#font-down, #font-up {
  padding: 0.45em 0.8em;
  min-width: 44px;
  text-align: center;
  letter-spacing: -0.01em;
}

/* Font family button — wider pill */
.type-fab-font {
  padding: 0.45em 1.1em;
  min-width: 128px;
  text-align: center;
  letter-spacing: -0.01em;
}
