/* Crucian Heritage Archive
   Design language carried over from the original prototype: Plus Jakarta Sans
   + Fraunces, warm-stone/teal palette. Dark mode and a11y layers are additive. */

:root {
  --bg-main: #faf9f6;
  --bg-card: #ffffff;
  --bg-subtle: #f5f5f4;
  --accent-teal: #0d9488;
  --accent-teal-strong: #0f766e;
  --accent-warm: #c2410c;
  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-tertiary: #78716c;
  --border-subtle: rgba(0, 0, 0, 0.06);
  --glass: rgba(255, 255, 255, 0.75);
  --focus-ring: #0d9488;
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.08);
  --shadow-card-hover: 0 20px 60px -15px rgba(0, 0, 0, 0.14);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg-main: #14120f;
  --bg-card: #1f1c19;
  --bg-subtle: #26221e;
  --accent-teal: #2dd4bf;
  --accent-teal-strong: #5eead4;
  --accent-warm: #fb923c;
  --text-primary: #f5f4f2;
  --text-secondary: #d6d3d1;
  --text-tertiary: #a8a29e;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --glass: rgba(20, 18, 15, 0.75);
  --focus-ring: #5eead4;
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-card-hover: 0 20px 60px -15px rgba(0, 0, 0, 0.65);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  scroll-behavior: smooth;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.serif { font-family: 'Fraunces', serif; }

/* --- Accessibility: visible focus rings everywhere, never suppressed --- */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius: 4px;
}

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

.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  background: var(--text-primary);
  color: var(--bg-main);
  padding: 1rem 1.5rem;
  border-radius: 0 0 .75rem 0;
  font-weight: 700;
  z-index: 100;
}
.skip-link:focus {
  left: 0;
  top: 0;
}

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

.glass-header {
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border-subtle);
}

.modern-card {
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  /* Slight overshoot ("back" easing) instead of a flat ease-out gives the
     lift a touch of spring on the catch, rather than just gliding to a
     stop. prefers-reduced-motion already forces all transition-durations
     to 0.01ms globally, so this stays inert for anyone who's asked for it. */
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.3s ease;
  border-radius: 2.5rem;
  border: none;
}

.modern-card:hover {
  transform: translateY(-4px) scale(1.015);
  box-shadow: var(--shadow-card-hover);
}

/* --- Primary nav: floating pill track, matching the modern-card language --- */
.nav-pill {
  position: relative;
  background: var(--bg-subtle);
  border-radius: 999px;
  padding: 0.3rem;
  box-shadow: 0 4px 16px -6px rgba(0, 0, 0, 0.1);
  margin-top: 0.25rem;
}
:root[data-theme="dark"] .nav-pill {
  box-shadow: 0 4px 16px -6px rgba(0, 0, 0, 0.4);
}

/* Sliding pill behind the active tab — JS sets width/transform to match
   whichever button is active, so it springs from one tab to the next
   instead of the old instant class-swap. Sits behind button text (z-index
   0 vs. 1) so labels stay readable while it's mid-slide. */
.nav-indicator {
  position: absolute;
  top: 0.3rem;
  bottom: 0.3rem;
  left: 0;
  width: 0;
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.15);
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), width 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 0;
  pointer-events: none;
}

.nav-btn {
  position: relative;
  z-index: 1;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
}

/* Was a raw Tailwind hover:text-stone-900 utility — invisible in dark mode
   since it has no dark-theme override and rendered near-black text on the
   near-black nav pill. Bound to the theme var so it always tracks. */
.nav-btn:hover {
  color: var(--text-primary);
}

/* Active state is shape + shadow + color together, not color alone —
   readable without relying on hue (WCAG 1.4.1). Background/shadow live
   here for the mobile full-screen nav (no sliding indicator there); the
   desktop pill overrides them off below since .nav-indicator provides
   that same look, animated. */
.nav-active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 800;
  box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.15);
}
.nav-pill .nav-active {
  background: transparent;
  box-shadow: none;
}

/* --- Mobile nav: full-screen takeover with large tap targets, for touch
   and motor-accessibility (WCAG 2.5.5 target size, 44px+). Replaces the old
   cramped dropdown. --- */
.mobile-nav-overlay {
  position: fixed;
  inset: 0;
  top: 0;
  z-index: 40;
  background: var(--bg-main);
  overflow-y: auto;
}

.mobile-nav-btn {
  display: block;
  width: 100%;
  padding: 1.35rem 1.5rem;
  border-radius: 1.5rem;
  font-size: 1.5rem;
  font-weight: 800;
  text-transform: none;
  letter-spacing: -0.01em;
  text-align: center;
  color: var(--text-primary);
}
.mobile-nav-btn:hover,
.mobile-nav-btn:focus-visible {
  background: var(--bg-subtle);
}

.chart-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: auto;
  height: 380px;
}

.alpha-btn.active {
  background: var(--text-primary);
  color: var(--bg-main);
}

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

.animate-in { animation: fadeIn 0.8s ease-out forwards; }

/* --- Scroll-triggered reveal: applied via JS (IntersectionObserver) only
   to static, render-once grids (home teasers, grammar cards) — NOT to
   Dictionary/Proverbs, which re-render on every search keystroke/filter
   click and would flicker if they re-hid themselves each time. */
.reveal-item {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.reveal-item.in-view {
  opacity: 1;
  transform: translateY(0);
}

/* Brief highlight ring when jumping to a card from the Saved drawer. */
@keyframes cardFlash {
  0%, 100% { box-shadow: var(--shadow-card); }
  30% { box-shadow: 0 0 0 4px var(--accent-teal), var(--shadow-card-hover); }
}
.card-flash { animation: cardFlash 1.6s ease-out; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--text-tertiary); border-radius: 10px; }

.search-focus:focus-within {
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
  border-color: var(--accent-teal);
}

/* Placeholder text bound to the theme's tertiary color, not a fixed Tailwind
   shade, so it stays at/above 4.5:1 contrast in both light and dark mode.
   (stone-300 on white was ~1.6:1 — well under WCAG AA.) */
#main-search::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

/* --- Copy-to-clipboard affordance on proverb/glossary cards --- */
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.copy-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}
.copy-btn.copied {
  color: var(--accent-teal-strong);
  border-color: var(--accent-teal);
}
.copy-btn svg { width: 1rem; height: 1rem; pointer-events: none; }
.copy-btn .icon-check { display: none; }
.copy-btn.copied .icon-copy { display: none; }
.copy-btn.copied .icon-check { display: block; }

/* Variant for use on the always-dark Word of the Day card, independent of
   light/dark theme (that card stays dark in both). */
.copy-btn.on-dark {
  border-color: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
}
.copy-btn.on-dark:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.copy-btn.on-dark.copied {
  color: #5eead4;
  border-color: #2dd4bf;
}

/* --- Save/bookmark toggle: shares .copy-btn's circular button chrome,
   swaps to a filled heart + warm accent when saved. Shape change (outline
   -> filled), not color alone, so the state reads without relying on hue. */
.save-btn .icon-heart { fill: none; }
.save-btn.saved {
  color: var(--accent-warm);
  border-color: var(--accent-warm);
}
.save-btn.saved .icon-heart { fill: currentColor; }
.save-btn.on-dark.saved {
  color: #fb923c;
  border-color: #fb923c;
}

/* Bounce on the icon when saving (not on un-saving — the pop is a "yes,
   got it" delight cue, not something you want on removal too). Uses the
   same overshoot vocabulary as the card hover for a consistent feel. */
@keyframes heartPop {
  0% { transform: scale(1); }
  35% { transform: scale(1.35); }
  60% { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.save-btn.pop .icon-heart {
  animation: heartPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center;
}

/* --- Saved count badge on the header icon button. Fixed colors (not theme
   vars) since it's a small filled pill — same "always-legible regardless of
   theme" approach as the WOTD/Support cards. */
#saved-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #c2410c;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
#saved-badge.hidden { display: none; }

/* --- Horizontally-scrolling alphabet strip: no visible scrollbar, a soft
   right-edge fade hints there's more instead. --- */
#alpha-nav {
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 40px), transparent 100%);
  mask-image: linear-gradient(to right, black calc(100% - 40px), transparent 100%);
}
#alpha-nav::-webkit-scrollbar { display: none; }

/* --- Header controls: theme toggle + install button --- */
.icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease;
}
.icon-btn:hover { transform: translateY(-1px); }

/* --- Press feedback: quick tactile scale-down while a button is actually
   held, on top of whatever hover state it's in. Scoped to real action
   buttons, deliberately not .modern-card broadly -- dictionary/proverb
   cards aren't click targets as a whole, and scaling the entire card on
   any mousedown (e.g. selecting text inside it) would feel like a bug. */
.icon-btn:active,
.copy-btn:active,
.nav-btn:active,
.alpha-btn:active,
.prov-filter:active {
  transform: scale(0.94);
}
.btn-press {
  transition: transform 0.2s ease;
}
.btn-press:active {
  transform: scale(0.95);
}

#install-btn {
  display: none;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent-teal-strong);
  color: #fff;
  font-weight: 800;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
}
#install-btn.visible { display: inline-flex; }
/* --accent-teal-strong flips from dark teal (light mode) to light mint
   (dark mode) — the fixed white text above only has contrast in light
   mode. Swap to dark text once the pill itself goes light. */
:root[data-theme="dark"] #install-btn { color: #0c0a09; }

/* --- Grammar section --- */
.grammar-note-card {
  background: var(--bg-card);
  border-radius: 1.75rem;
  padding: 2rem;
  box-shadow: var(--shadow-card);
}

/* Single-letter sound references (c/k, d/t) get set apart in a monospace
   chip so they don't visually fuse into a word on a quick read. */
.letter-chip {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 700;
  background: var(--bg-subtle);
  color: var(--text-primary);
  padding: 0.05rem 0.4rem;
  border-radius: 0.35rem;
  font-style: normal;
}
.example-pair {
  border-left: 3px solid var(--accent-teal);
  padding-left: 1rem;
  margin-bottom: 1rem;
}
.example-pair .crucian { font-weight: 700; color: var(--text-primary); }
.example-pair .standard { color: var(--text-tertiary); font-size: 0.85rem; font-style: italic; }

/* --- Saved (bookmarks) drawer: slide-in panel, own theme-var colors so it
   doesn't depend on the Tailwind dark-mode override list. --- */
.saved-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: flex-end;
}
:root[data-theme="dark"] .saved-drawer-overlay { background: rgba(0, 0, 0, 0.6); }

.saved-drawer-panel {
  width: min(420px, 100%);
  height: 100%;
  background: var(--bg-card);
  padding: 2rem 1.75rem;
  overflow-y: auto;
  box-shadow: -20px 0 60px -20px rgba(0, 0, 0, 0.35);
}

.saved-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--border-subtle);
  border-radius: 1rem;
  padding: 0.25rem;
  margin-bottom: 0.5rem;
}
.saved-item-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-radius: 0.75rem;
  cursor: pointer;
  background: transparent;
  border: none;
}
.saved-item-main:hover,
.saved-item-main:focus-visible {
  background: var(--bg-subtle);
}
.saved-item-kind {
  display: block;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-bottom: 0.15rem;
}
.saved-item-label {
  display: block;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saved-item-remove {
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.saved-item-remove:hover,
.saved-item-remove:focus-visible {
  background: var(--bg-subtle);
  color: var(--accent-warm);
}

/* --- Toast (used for offline / install feedback) --- */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  /* translateY(%) is relative to the element's OWN height, not the 1.5rem
     "bottom" offset above — a percentage alone can't clear both. Below
     ~120px tall (ours is ~40-50px), 120% undershoots and leaves a sliver
     of the pill permanently visible above the viewport edge. Clearing its
     own full height (100%) plus an explicit fixed margin guarantees it's
     fully off-screen regardless of how tall the message text makes it. */
  transform: translateX(-50%) translateY(calc(100% + 2rem));
  background: var(--text-primary);
  color: var(--bg-main);
  padding: 0.9rem 1.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  z-index: 60;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* Dark-mode aware Tailwind color overrides that can't be reached via CSS vars
   because the prototype used Tailwind utility classes directly. */
:root[data-theme="dark"] .bg-white { background-color: var(--bg-card) !important; }
:root[data-theme="dark"] .bg-stone-50 { background-color: var(--bg-subtle) !important; }
:root[data-theme="dark"] .bg-stone-100 { background-color: rgba(255,255,255,0.08) !important; }
:root[data-theme="dark"] .bg-stone-100\/40 { background-color: var(--bg-subtle) !important; }
:root[data-theme="dark"] .bg-stone-100\/60 { background-color: rgba(255,255,255,0.08) !important; }
:root[data-theme="dark"] .bg-stone-200\/40 { background-color: rgba(255,255,255,0.06) !important; }
:root[data-theme="dark"] .text-stone-900 { color: var(--text-primary) !important; }
:root[data-theme="dark"] .text-stone-800 { color: var(--text-primary) !important; }
:root[data-theme="dark"] .text-stone-700 { color: var(--text-secondary) !important; }
:root[data-theme="dark"] .text-stone-600 { color: var(--text-secondary) !important; }
:root[data-theme="dark"] .text-stone-500 { color: var(--text-tertiary) !important; }
:root[data-theme="dark"] .text-stone-400 { color: var(--text-tertiary) !important; }
:root[data-theme="dark"] .border-stone-100 { border-color: var(--border-subtle) !important; }
:root[data-theme="dark"] .border-stone-200 { border-color: var(--border-subtle) !important; }
:root[data-theme="dark"] .hover\:bg-stone-50:hover { background-color: var(--bg-subtle) !important; }
:root[data-theme="dark"] .bg-teal-50 { background-color: rgba(45, 212, 191, 0.12) !important; }
:root[data-theme="dark"] .text-teal-800 { color: var(--accent-teal-strong) !important; }
:root[data-theme="dark"] .bg-orange-50 { background-color: rgba(251, 146, 60, 0.12) !important; }
:root[data-theme="dark"] .text-orange-800 { color: var(--accent-warm) !important; }
:root[data-theme="dark"] .text-teal-700 { color: var(--accent-teal-strong) !important; }
:root[data-theme="dark"] .text-teal-600 { color: var(--accent-teal) !important; }
