/* ========================================================================
   MARKDOWN TOOLS — CROSS-CULTURAL DESIGN SYSTEM
   Target: RO / DACH / EN | Psychological: Trust + Clarity + Micro-reward
   ======================================================================== */

/* 1. VARIABLES & THEME =================================================== */
:root {
  /* Colors */
  --bg-page: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-surface: #F1F5F9;
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --warm: #D97706;
  --success: #10B981;
  --error: #EF4444;
  --border: #E2E8F0;
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.08);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.12);
  --focus-ring: 0 0 0 3px rgba(37,99,235,0.25);
  /* Diff colors */
  --diff-added-bg: #DCFCE7;
  --diff-added-text: #166534;
  --diff-removed-bg: #FEE2E2;
  --diff-removed-text: #991B1B;
  --diff-unchanged-bg: transparent;
  --diff-unchanged-text: var(--text-secondary);
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  /* Layout */
  --radius: 12px;
  --radius-sm: 8px;
  --max-width: 1200px;
  --header-height: 64px;
  /* Typography */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", "Cascadia Mono", "Consolas", "Liberation Mono", monospace;
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.8125rem, 0.75rem + 0.3vw, 0.9375rem);
  --text-base: clamp(0.875rem, 0.8rem + 0.3vw, 1rem);
  --text-lg: clamp(1rem, 0.9rem + 0.4vw, 1.125rem);
  --text-xl: clamp(1.25rem, 1rem + 1vw, 1.5rem);
  --text-2xl: clamp(1.5rem, 1.2rem + 1.2vw, 1.875rem);
  --text-3xl: clamp(1.875rem, 1.5rem + 1.5vw, 2.25rem);
  /* Motion */
  --ease: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --ease-slow: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #0B1120;
    --bg-card: #111827;
    --bg-surface: #1E293B;
    --text-primary: #F1F5F9;
    --text-secondary: #CBD5E1;
    --text-muted: #64748B;
    --border: #334155;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --diff-added-bg: #052E16;
    --diff-added-text: #86EFAC;
    --diff-removed-bg: #450A0A;
    --diff-removed-text: #FCA5A5;
  }
}

html.theme-dark {
  --bg-page: #0B1120;
  --bg-card: #111827;
  --bg-surface: #1E293B;
  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-muted: #64748B;
  --border: #334155;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --diff-added-bg: #052E16;
  --diff-added-text: #86EFAC;
  --diff-removed-bg: #450A0A;
  --diff-removed-text: #FCA5A5;
}

/* 2. BASE & RESET ======================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
}
body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
img, svg { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; }
ul, ol { list-style: none; }

/* 3. LAYOUT & CONTAINERS ================================================ */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding-inline: var(--space-lg);
}
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--text-primary);
  font-size: var(--text-lg);
  line-height: 1.2;
  transition: opacity var(--ease);
}
.logo:hover { opacity: 0.9; }
.logo-img {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: block;
  border-radius: var(--radius-sm);
}
.logo strong {
  font-weight: 700;
  letter-spacing: -0.02em;
}
main { flex: 1; padding-block: var(--space-2xl); }

/* Sub-site banner */
.subsite-banner {
  background: var(--accent);
  color: #fff;
  text-align: center;
  padding: 10px 16px;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.3px;
  position: sticky;
  top: var(--header-height);
  z-index: 49;
}
.subsite-banner a {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 700;
}

/* Legal footer */
.subsite-legal-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  z-index: 9998;
  text-align: center;
  font-size: var(--text-sm);
}
.subsite-legal-footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

/* 4. TYPOGRAPHY & UTILITIES ============================================= */
h1, h2, h3, h4 {
  text-wrap: balance;
  line-height: 1.2;
  font-weight: 600;
}
h1 { font-size: var(--text-2xl); margin-bottom: var(--space-sm); }
h2 { font-size: var(--text-xl); margin-bottom: var(--space-sm); }
h3 { font-size: var(--text-lg); }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.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;
}

/* 5. COMPONENTS ========================================================= */

/* Language Switcher - Pill Design */
.lang-switch {
  display: inline-flex;
  background: var(--bg-surface);
  padding: 4px;
  border-radius: 999px;
  gap: 4px;
  align-items: center;
  width: auto;
}
.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  transition: all 0.2s ease;
  white-space: nowrap;
  text-decoration: none;
}
.lang-btn:hover { color: var(--text-primary); }
.lang-btn.active {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
}

/* Theme Toggle */
.theme-toggle {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  display: grid; place-items: center;
  font-size: 1.1rem;
}

/* Tool Card */
.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
  max-width: 1100px;
  margin: 0 auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  transition: var(--ease);
}
.btn:hover { background: var(--accent-hover); }
.btn--outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}
.btn--outline:hover { background: var(--bg-surface); }

/* Forms */
.form-group { margin-bottom: var(--space-md); }
.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: var(--space-xs);
}
.form-input, .form-textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--text-base);
  font-family: var(--font-sans);
  transition: var(--ease);
}
.form-textarea {
  resize: vertical;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
}
.form-input:focus, .form-textarea:focus {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--accent);
}

/* 6. TOOL-SPECIFIC ======================================================= */

/* ── Tab Navigation ── */
.tab-nav {
  display: flex;
  gap: var(--space-xs);
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-lg);
  padding-bottom: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  padding: var(--space-sm) var(--space-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--ease), border-color var(--ease);
  white-space: nowrap;
}
.tab-btn:hover {
  color: var(--text-primary);
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* Tab Panels */
.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

/* ── Markdown Editor ── */
.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin-top: var(--space-md);
}
.editor-pane {
  display: flex;
  flex-direction: column;
  min-width: 0; /* Prevent grid blowout */
}
.md-textarea {
  flex: 1;
  min-height: 300px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
}
.md-preview {
  flex: 1;
  min-height: 300px;
  padding: var(--space-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-y: auto;
  font-size: var(--text-base);
  line-height: 1.7;
}

/* Markdown preview typography */
.md-preview h1, .md-preview h2, .md-preview h3,
.md-preview h4, .md-preview h5, .md-preview h6 {
  margin-top: var(--space-md);
  margin-bottom: var(--space-sm);
  line-height: 1.3;
}
.md-preview h1 { font-size: 1.8em; }
.md-preview h2 { font-size: 1.5em; }
.md-preview h3 { font-size: 1.25em; }
.md-preview p { margin-bottom: var(--space-sm); }
.md-preview ul, .md-preview ol {
  margin-bottom: var(--space-sm);
  padding-left: var(--space-lg);
  list-style: disc;
}
.md-preview ol { list-style: decimal; }
.md-preview li { margin-bottom: var(--space-xs); }
.md-preview blockquote {
  border-left: 4px solid var(--accent);
  margin: var(--space-sm) 0;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.md-preview code {
  background: var(--bg-surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.md-preview pre {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  overflow-x: auto;
  margin: var(--space-sm) 0;
}
.md-preview pre code {
  background: none;
  padding: 0;
  font-size: var(--text-sm);
}
.md-preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-md) 0;
}
.md-preview a {
  color: var(--accent);
  text-decoration: underline;
}
.md-preview img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}
.md-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-sm) 0;
}
.md-preview th, .md-preview td {
  border: 1px solid var(--border);
  padding: var(--space-xs) var(--space-sm);
  text-align: left;
}
.md-preview th {
  background: var(--bg-surface);
  font-weight: 600;
}
.md-preview del {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* ── Text Diff ── */
.diff-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin-top: var(--space-md);
}
.diff-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.diff-textarea {
  flex: 1;
  min-height: 200px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.diff-legend {
  display: flex;
  gap: var(--space-md);
  margin: var(--space-sm) 0 var(--space-md);
  font-size: var(--text-xs);
  font-weight: 500;
}
.diff-legend-added    { color: var(--diff-added-text); }
.diff-legend-removed  { color: var(--diff-removed-text); }
.diff-legend-unchanged { color: var(--diff-unchanged-text); }

.diff-legend-added::before,
.diff-legend-removed::before,
.diff-legend-unchanged::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}
.diff-legend-added::before    { background: var(--diff-added-bg); border: 1px solid var(--diff-added-text); }
.diff-legend-removed::before  { background: var(--diff-removed-bg); border: 1px solid var(--diff-removed-text); }
.diff-legend-unchanged::before { background: var(--bg-surface); border: 1px solid var(--border); }

.diff-summary {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.diff-output {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.5;
  background: var(--bg-surface);
}

.diff-line {
  padding: 2px var(--space-sm) 2px 0;
  display: flex;
  align-items: flex-start;
  min-height: 1.5em;
}
.diff-line + .diff-line {
  border-top: 1px solid var(--border);
}
.diff-prefix {
  display: inline-block;
  width: 2em;
  text-align: center;
  font-weight: 700;
  flex-shrink: 0;
  user-select: none;
}

.diff-line-added {
  background: var(--diff-added-bg);
  color: var(--diff-added-text);
}
.diff-line-added .diff-prefix { color: var(--diff-added-text); }

.diff-line-removed {
  background: var(--diff-removed-bg);
  color: var(--diff-removed-text);
}
.diff-line-removed .diff-prefix { color: var(--diff-removed-text); }

.diff-line-unchanged {
  background: var(--diff-unchanged-bg);
  color: var(--diff-unchanged-text);
}
.diff-line-unchanged .diff-prefix { color: var(--text-muted); }

.diff-identical {
  text-align: center;
  padding: var(--space-lg);
  color: var(--success);
  font-weight: 500;
}

/* ── Word / Character Counter ── */
.counter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-md);
  margin-top: var(--space-md);
}
.counter-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.counter-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}
.counter-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Case Converter ── */
.case-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}
.case-btn {
  font-family: var(--font-mono) !important;
  font-size: var(--text-xs) !important;
}

/* 7. STICKY DONATE ======================================================= */
.sticky-donate-wrapper {
  position: fixed;
  bottom: 44px;
  right: 24px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--ease), transform var(--ease);
  pointer-events: none;
}
.sticky-donate-wrapper.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.sticky-donate-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #FFDD00;
  color: #111;
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  border: none;
  text-decoration: none;
  transition: transform var(--ease), box-shadow var(--ease);
}
.sticky-donate-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 16px rgba(255, 205, 0, 0.3);
}
.sticky-donate-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.donate-icon { font-size: 1.2em; }

/* 8. MODAL =============================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.is-active {
  opacity: 1;
  visibility: visible;
}
.modal-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}
.modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  z-index: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
}
.modal-close:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}
.modal-content {
  padding: var(--space-2xl);
  overflow-y: auto;
  max-height: 80vh;
}
.modal-loading {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

/* 9. ANIMATIONS ========================================================== */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* 10. RESPONSIVE ========================================================= */
@media (max-width: 640px) {
  :root {
    --space-xl: 1.5rem;
    --space-2xl: 2rem;
  }

  /* Tool card less padding on mobile */
  .tool-card {
    padding: var(--space-md);
  }

  /* Editor split: stack vertically */
  .editor-split {
    grid-template-columns: 1fr;
  }
  .md-textarea, .md-preview {
    min-height: 200px;
  }

  /* Diff split: stack vertically */
  .diff-split {
    grid-template-columns: 1fr;
  }
  .diff-textarea {
    min-height: 150px;
  }

  /* Counter grid: 2 columns */
  .counter-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Case buttons: smaller */
  .case-btn {
    padding: 4px 8px;
  }

  /* Tab navigation scrollable */
  .tab-nav {
    gap: 0;
  }
  .tab-btn {
    padding: var(--space-sm) var(--space-sm);
    font-size: var(--text-xs);
  }

  /* Lang switcher: hide text, keep flags */
  .lang-btn span { display: none; }
  .lang-btn { padding: 6px 8px; font-size: 1.2rem; }

  /* Sticky donate */
  .sticky-donate-wrapper { bottom: 36px; right: 16px; }
  .sticky-donate-btn { padding: 8px 14px; font-size: var(--text-xs); border-radius: 999px; }
  .sticky-donate-btn .donate-text { display: inline-flex !important; }
}

/* 11. REDUCED MOTION ===================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .sticky-donate-wrapper, .sticky-donate-btn {
    transition: none !important;
    animation: none !important;
  }
}

/* 12. PRINT ============================================================== */
@media print {
  .site-header,
  .subsite-banner,
  .btn,
  .theme-toggle,
  .lang-switch,
  .tab-nav,
  .sticky-donate-wrapper,
  .subsite-legal-footer,
  .modal-overlay {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
    padding-bottom: 0 !important;
  }
  .tool-card {
    box-shadow: none;
    border: 1px solid #000;
    padding: 0;
  }
  .tab-panel { display: block !important; }
  .editor-split, .diff-split {
    grid-template-columns: 1fr;
  }
  .md-preview {
    border: 1px solid #ccc;
  }
}

/* Focus Accessibility */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}
