/*
 * ─────────────────────────────────────────────────────────────────────────────
 * 📄 File        : style.css
 * 🔧 Project     : That’s Mental Engine (TME)
 * 🧠 Version     : v3.0 Beta
 * 📆 Last Edited : 2025-04-13
 * 💬 About       : Base styles, typography, layout, dark mode, animations, cards
 * ─────────────────────────────────────────────────────────────────────────────
 */

@import url('https://fonts.cdnfonts.com/css/satoshi');

/* CSS Vars for easy theming and future-proofing */
:root {
  --primary: #4f46e5;
  --accent: #14b8a6;
  --danger: #ef4444;
  --bg-light: #ffffff;
  --text-light: #111827;
  --bg-dark: #0f172a;
  --text-dark: #f1f5f9;
  --transition: 0.3s ease-in-out;
  --ajax-fade-duration: 0.4s;
  --bg-menu-light: #ffffff;
  --bg-menu-dark: #0f172a;
  --text-heading-light: #111827;
  --text-heading-dark: #f8fafc;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --shadow-1: 0 10px 20px -5px rgba(0,0,0,0.08), 0 6px 10px -6px rgba(0,0,0,0.06);
  --shadow-2: 0 18px 40px -12px rgba(0,0,0,0.15), 0 8px 24px -16px rgba(0,0,0,0.12);
  --ring: 0 0 0 3px rgba(99,102,241,0.25);
  --surface: rgba(255,255,255,0.7);
  --surface-dark: rgba(15,23,42,0.7);
  --border-light: #e5e7eb;
  --border-dark: #334155;
  --muted-light: #9ca3af;
  --muted-dark: #94a3b8;
  --glass-blur: 10px;
  --glass-saturate: 180%;
}

/* Global Setup */
html {
  scroll-behavior: smooth;
  font-size: 16px;
  font-family: 'Satoshi', sans-serif;
  -webkit-text-size-adjust: 100%;
  color-scheme: light dark;
}

body {
  background-color: var(--bg-light);
  color: var(--text-light);
  line-height: 1.7;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex-grow: 1; }

/* Dark Mode Overrides */
html.dark {
  --bg-light: var(--bg-dark);
  --text-light: var(--text-dark);
  --bg-menu-light: var(--bg-menu-dark);
  --text-heading-light: var(--text-heading-dark);
  --surface: var(--surface-dark);
  --border-light: var(--border-dark);
  --muted-light: var(--muted-dark);
}

html.dark body {
  background-color: var(--bg-dark);
  color: var(--text-dark);
}

/* Cross-platform & PWA Hardening */
html, body { overscroll-behavior-y: none; over-scroll-behavior-x: contain; }

.min-h-screen-dvh { min-height: 100dvh; }
.h-screen-dvh { height: 100dvh; }

.hide-scrollbar { scrollbar-width: none; }
.hide-scrollbar::-webkit-scrollbar { display: none; }

[inert] { pointer-events: none !important; user-select: none !important; }
[inert] :focus { outline: none !important; }

.text-balance { text-wrap: balance; }

/* Typography & Spacing */
h1, h2, h3, h4, h5 {
  font-weight: 700;
  line-height: 1.25;
  margin: 0.75rem 0;
}

p { margin-bottom: 1rem; }

/* AJAX & Loader Effects */
.ajax-fade { animation: ajaxFadeIn var(--ajax-fade-duration) ease forwards; }

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

.loader-wrapper {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader-wrapper.fade { opacity: 0; visibility: hidden; }

.loader {
  width: 44px;
  height: 44px;
  border: 4px solid #e2e8f0;
  border-top: 4px solid transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Search Suggestions */
#suggestions {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-height: 350px;
  overflow-y: auto;
  scrollbar-color: #94a3b8 transparent;
  scrollbar-width: thin;
  background-color: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: 0.75rem;
  box-shadow: 0 18px 40px -18px rgba(0,0,0,0.25);
  margin-top: 0.5rem;
  width: 100%;
  z-index: 9999;
}

html.dark #suggestions {
  background-color: var(--bg-dark);
  border-color: var(--border-dark);
  box-shadow: 0 10px 25px -5px rgba(255,255,255,0.05);
}

#suggestions.show { opacity: 1 !important; transform: translateY(0) !important; }

#suggestions li {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.2s ease;
}

#suggestions li:hover { background-color: #f8fafc; }

html.dark #suggestions li { border-color: var(--border-dark); }

html.dark #suggestions li:hover { background-color: #0b1220; }

/* Tags & Filters */
.tag-filter {
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  overflow: hidden;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.tag-filter:hover { background: #e0f2fe; color: #0c4a6e; }

html.dark .tag-filter { background: var(--bg-dark); border-color: #334155; color: var(--text-dark); }

html.dark .tag-filter:hover { background: #0f172a; color: #38bdf8; }

/* Accessibility */
:is(input, select, button, textarea, a):focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  border-color: var(--primary);
  box-shadow: var(--ring);
  transition: box-shadow 0.2s ease;
}

/* Surfaces & Elevation */
.card {
  border-radius: var(--radius-xl);
  background: var(--surface);
  backdrop-filter: saturate(160%) blur(8px);
  box-shadow: var(--shadow-1);
}

html.dark .card { background: var(--surface-dark); }

/* Buttons */
.tm-btn { 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 12px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  padding: 0.875rem 1.125rem;
  border: 2px solid var(--tm-outline);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.tm-btn:focus-visible { box-shadow: var(--ring); outline: none; }
.tm-btn:active { transform: translateY(1px); }

.tm-btn--solid {
  background: #0b1220;
  color: #fff;
  border-color: #0b1220;
}

html.dark .tm-btn--solid { background: #ffffff; color: #0b1220; border-color: #ffffff; }

.tm-btn--ghost { background: var(--tm-paper); color: var(--tm-ink); }

html.dark .tm-btn--ghost { background: var(--tm-paper-2); color: var(--tm-ink); }

.tm-btn--grad { background: var(--tm-grad-2); color: #0b1220; border-color: transparent; }
html.dark .tm-btn--grad { color: #0b1220; }

/* Pill chips (filters/tags) */
.tm-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: 9999px;
  font-weight: 700;
  font-size: 0.875rem;
  line-height: 1;
  background: #f3f4f6;
  color: #0b1220;
  border: 2px solid var(--tm-outline);
}

.tm-chip:hover { background: #e5e7eb; }

html.dark .tm-chip { background: #0f172a; color: #f1f5f9; border-color: var(--tm-outline); }

/* List & Grids */
.tm-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(1, minmax(0, 1fr));
}
@media (min-width: 640px) { .tm-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1.25rem; } }
@media (min-width: 1024px) { .tm-grid { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 1.5rem; } }

/* Compact meta row (author/date/tags) */
.tm-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; font-size: 0.875rem; color: #475569; }
.tm-meta img { width: 28px; height: 28px; border-radius: 9999px; border: 2px solid var(--tm-outline); }
html.dark .tm-meta { color: #cbd5e1; }

/* Sticky sidebar */
.tm-sticky { position: sticky; top: calc(72px + env(safe-area-inset-top)); align-self: start; z-index: 30; }

/* A–Z rail */
.tm-az { display: flex; gap: 0.5rem; overflow: auto; padding: 0.25rem 0; }
.tm-az a { display: inline-block; padding: 0.375rem 0.625rem; overflow: hidden; border-radius: 10px; border: 2px solid var(--tm-outline); background: var(--tm-paper); color: var(--tm-ink); font-weight: 800; }
html.dark .tm-az a { background: var(--tm-paper-2); }
.tm-az a:hover { transform: translateY(-1px); box-shadow: var(--tm-shadow-lift); }

/* Inputs (search bars) */
.tm-input { 
  width: 100%; padding: 0.875rem 1rem; border-radius: 14px; border: 2px solid var(--tm-outline);
  background: var(--tm-paper); color: var(--tm-ink); font-weight: 600;
}
.tm-input::placeholder { color: #94a3b8; }
html.dark .tm-input { background: var(--tm-paper-2); color: var(--tm-ink); }

/* Progress bar */
.tm-progress { height: 4px; background: var(--tm-grad-1); border-radius: 9999px; }

/* Utility: black-outline container */
.tm-outline-contrast { border: 2px solid var(--tm-outline); }

/* Utility: subtle inner separator */
.tm-sep { border-top: 1px dashed rgba(2,6,23,0.15); }
html.dark .tm-sep { border-top-color: rgba(226,232,240,0.2); }

/* Utility: clamp text lines */
.tm-line-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tm-line-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Hover pop for cards */
.tm-pop:hover { transform: translateY(-2px); box-shadow: var(--tm-shadow-lift); }

/* CTA stripe */
.tm-stripe { background: var(--tm-grad-2); color: #0b1220; border-radius: 12px; padding: 0.5rem 0.75rem; font-weight: 800; display: inline-block; }
html.dark .tm-stripe { color: #0b1220; }

/* Footer/toolbar safe area */
.tm-toolbar { padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); }

/* Heartbeat anim */
@keyframes tm-heartbeat {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(244,63,94,0)); }
  20% { transform: scale(1.18); filter: drop-shadow(0 0 6px rgba(244,63,94,0.45)); }
  35% { transform: scale(1.04); }
  50% { transform: scale(1.18); filter: drop-shadow(0 0 6px rgba(244,63,94,0.45)); }
  70% { transform: scale(1.02); }
}
.tm-heartbeat { animation: tm-heartbeat 1.25s ease-in-out infinite; transform-origin: center; }

/* Global Toasts */
.tm-toast {
  max-width: 320px;
  background: #111;
  color: #fff;
  padding: 1rem;
  border-radius: 0.75rem;
  box-shadow: 0 5px 20px rgba(0,0,0,0.3);
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s, transform 0.3s;
}

.tm-toast.show { opacity: 1; transform: translateY(0); }

.tm-toast h4 { font-weight: 800; margin: 0.1rem 0 0.25rem; font-size: 0.95rem; }

.tm-toast p { margin: 0.25rem 0 0.25rem; line-height: 1.35; }

.tm-toast .tm-toast-buttons { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }

.tm-toast .tm-btn { background: #7c3aed; color: #fff; padding: 0.375rem 0.6rem; border-radius: 0.5rem; font-weight: 700; font-size: 0.8rem; }

.tm-toast .tm-btn.secondary { background: #374151; }

/* Help Card */
.help-card {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.75rem;
  text-decoration: none;
  border-radius: 16px;
  border: 2px solid #2e3a4a;
  background: #f8f8f8;
  box-shadow: 0 2px 0 #2e3a4a, 0 6px 16px rgba(0,0,0,0.15);
  min-height: 240px;
  padding: 0.75rem 0.75rem 1rem;
}
@media (min-width: 640px) { .help-card { min-height: 280px; padding: 1rem 1rem 1.25rem; } }
@media (min-width: 1024px) { .help-card { min-height: 320px; } }

.help-card__cta {
  background: #1f2a37;
  color: #fff;
  font-weight: 700;
  text-align: center;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  line-height: 1.2;
}

.help-card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #fff;
  border-radius: 12px;
  padding: 1rem;
}

.help-card__body h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.125rem;
  line-height: 1.2;
  color: #0b1220;
}

.help-card__body p {
  margin: 0 0 0.75rem 0;
  color: #4b5563;
}

.help-card__more {
  align-self: center;
  display: inline-block;
  padding: 0.5rem 0.875rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e5e7eb;
  font-weight: 600;
  color: #0b1220;
}

/* Make it feel clickable & keyboard friendly */
.help-card:hover, .help-card:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 3px 0 #2e3a4a, 0 10px 22px rgba(0,0,0,0.18);
}
.help-card:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }

/* Make sure targets are big enough for touch */
.help-card__cta, .help-card__more { min-height: 44px; }

  /* Crisis page local tweaks */
  .help-card--short { min-height: 160px; }
  @media (min-width: 640px) { .help-card--short { min-height: 184px; } }
  @media (min-width: 1024px) { .help-card--short { min-height: 192px; } }
  /* Small slide-up for overlay panel (respects hidden class) */
  [data-overlay] .overlay-panel { transform: translateY(6px); opacity: 0; transition: transform 0.16s ease-out, opacity 0.16s ease-out; }
  .is-open [data-overlay] .overlay-panel { transform: translateY(0); opacity: 1; }