/* ============================================================
   Parlaris „Atelier" — Editorial Luxury
   Basis: Tokens, Reset, Typografie, gemeinsame Komponenten
   ============================================================ */

:root {
  /* Papier & Tinte (warmes Fast-Weiß, warmes Fast-Schwarz) */
  --paper: #fbfaf6;
  --paper-2: #f4f2ea;
  --paper-3: #edeae0;
  --ink: #161c18;
  --ink-2: #4c554f;
  --ink-3: #87908a;
  --ink-4: #b4bcb6;

  /* Marke: brasilianische Flagge, hell & edel inszeniert */
  --brand-green: #10844a;
  --brand-green-deep: #0a5a32;
  --brand-yellow: #f2c200;
  --brand-blue: #012169;
  --brand-green-soft: #e6f4ec;
  --brand-yellow-soft: #fdf6dc;
  --brand-blue-soft: #e8ecf6;

  /* Sprach-Theme (dynamisch via themes.js gesetzt) */
  --t-from: #10844a;
  --t-to: #0a5a32;
  --t-accent: #f2c200;
  --t-ink: #052a18;
  --t-soft: #e6f4ec;

  /* Linien & Schatten: dünne Ringe statt harter Rahmen */
  --ring: rgba(22, 28, 24, 0.08);
  --ring-strong: rgba(22, 28, 24, 0.14);
  --shadow-soft: 0 1px 2px rgba(22, 28, 24, 0.04), 0 10px 30px rgba(22, 28, 24, 0.06);
  --shadow-float: 0 2px 8px rgba(22, 28, 24, 0.07), 0 28px 70px rgba(22, 28, 24, 0.13);
  --shadow-pop: 0 4px 14px rgba(22, 28, 24, 0.1), 0 40px 90px rgba(22, 28, 24, 0.18);

  /* Radien: weich, großzügig */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 30px;

  /* Typografie: Display-Serife + System-Sans (keine externen Fonts) */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Didot, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --amber-bg: #fdf3dd;
  --amber-ring: #ecd9ad;
  --amber-ink: #7a5a12;
  --ok: #10844a;
  --err: #b23149;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.44, 1);
}

/* ---------------------------------------------------- Reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg, canvas { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
a { color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
::selection { background: var(--brand-yellow-soft); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--t-from);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------------------------------------------------- Typografie */
.serif { font-family: var(--serif); }
.display {
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.06;
}
.display em, .display i {
  font-style: italic;
  letter-spacing: 0;
}
.eyebrow {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 10px;
}
.eyebrow::before {
  content: "";
  width: 22px;
  height: 1px;
  background: var(--ink-4);
}
.eyebrow.no-line::before { display: none; }
.muted { color: var(--ink-2); }
.small { font-size: 13.5px; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------- Logo (der Punkt lebt) */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  font-size: 19px;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.logo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--t-from);
  transition: background 0.6s var(--ease-out), transform 0.4s var(--ease-spring);
  position: relative;
  flex: none;
}
.logo-dot::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1.5px solid var(--t-from);
  opacity: 0;
  transform: scale(0.6);
}
.logo-dot.pulse { transform: scale(1.25); }
.logo-dot.pulse::after { animation: dot-ring 0.9s var(--ease-out); }
.logo-dot.pulse-miss { background: var(--err); }
@keyframes dot-ring {
  0% { opacity: 0.9; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(1.7); }
}

/* ---------------------------------------------------- Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 13px 26px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 15.5px;
  line-height: 1.2;
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s var(--ease-out),
    background 0.25s var(--ease-out), opacity 0.2s;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(160deg, var(--t-from), var(--t-to));
  color: #fff;
  box-shadow: 0 10px 26px color-mix(in srgb, var(--t-to) 32%, transparent);
}
.btn-primary:hover { transform: translateY(-1.5px); box-shadow: 0 14px 34px color-mix(in srgb, var(--t-to) 42%, transparent); }
.btn-ghost {
  background: #fff;
  border-color: var(--ring-strong);
  color: var(--ink);
}
.btn-ghost:hover { border-color: var(--ink-3); transform: translateY(-1px); }
.btn-soft {
  background: var(--t-soft);
  color: var(--t-to);
}
.btn-soft:hover { filter: brightness(0.97); }
.btn-quiet { color: var(--ink-2); padding: 10px 14px; }
.btn-quiet:hover { color: var(--ink); }
.btn-sm { padding: 9px 16px; font-size: 13.5px; border-radius: 12px; }
.btn-lg { padding: 16px 34px; font-size: 17px; border-radius: 18px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn-accent {
  background: var(--t-accent);
  color: var(--t-ink);
}

/* ---------------------------------------------------- Karten & Flächen */
.card {
  background: #fff;
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 1px var(--ring), var(--shadow-soft);
  padding: 24px;
}
.card-hover { transition: transform 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out); }
.card-hover:hover {
  transform: translateY(-3px);
  box-shadow: 0 0 0 1px var(--ring), var(--shadow-float);
}
.card-selected { box-shadow: 0 0 0 2px var(--t-from), var(--shadow-float); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--paper-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill-theme { background: var(--t-soft); color: var(--t-to); }
.pill-accent { background: var(--brand-yellow-soft); color: #7a5a12; }
.pill-onheader { background: rgba(255, 255, 255, 0.22); color: #fff; }
.divider { height: 1px; background: var(--ring); border: 0; margin: 20px 0; }

/* ---------------------------------------------------- Formulare */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input {
  padding: 13px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--ring-strong);
  background: #fff;
  font-size: 15.5px;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}
.input:focus {
  outline: none;
  border-color: var(--t-from);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--t-from) 14%, transparent);
}

/* ---------------------------------------------------- Fortschritt */
.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--paper-3);
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--t-from), var(--t-to));
  transition: width 0.6s var(--ease-out);
}

/* ---------------------------------------------------- Toast */
#layer-toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--paper);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 550;
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.45s var(--ease-spring);
  pointer-events: auto;
  max-width: min(88vw, 480px);
}
.toast.leaving { animation: toast-out 0.3s var(--ease-out) forwards; }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--t-accent); flex: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px) scale(0.95); }
}

/* ---------------------------------------------------- Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 28, 24, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 800;
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade-in 0.25s ease;
}
.modal {
  background: var(--paper);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-pop);
  max-width: 620px;
  width: 100%;
  max-height: 86vh;
  overflow: auto;
  padding: 34px;
  animation: modal-in 0.4s var(--ease-spring);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(22px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------------------------------------------------- Wort-Popup (Kern-Loop) */
.word {
  cursor: pointer;
  border-radius: 5px;
  padding: 0 1px;
  margin: 0 -1px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.word:hover { background: color-mix(in srgb, var(--t-accent) 30%, transparent); }
.word.saved {
  background: linear-gradient(transparent 72%, color-mix(in srgb, var(--t-accent) 55%, transparent) 72%);
}
.word.saved::after {
  content: "";
  position: absolute;
  top: -1px;
  right: -2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--t-from);
}

#layer-popup { position: relative; z-index: 850; }
.word-popup {
  position: absolute;
  width: min(360px, calc(100vw - 28px));
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 0 0 1px var(--ring), var(--shadow-pop);
  padding: 20px;
  z-index: 850;
  animation: pop-in 0.3s var(--ease-spring);
  transform-origin: top center;
}

/* Handy: Wort-Popup als Bottom-Sheet am Daumen (statt frei schwebend). */
.wp-scrim { display: none; }
@media (max-width: 560px) {
  .word-popup.as-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: 100%;
    max-height: 84svh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 20px 20px 0 0;
    padding: 16px 20px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 40px rgba(22, 28, 24, 0.16), 0 0 0 1px var(--ring);
    animation: sheet-up 0.32s var(--ease-out);
    transform-origin: bottom center;
  }
  .word-popup.as-sheet::before {
    content: "";
    display: block;
    width: 40px; height: 4px;
    border-radius: 999px;
    background: var(--ring-strong);
    margin: 2px auto 14px;
  }
  .word-popup.as-sheet .wp-actions {
    position: sticky;
    bottom: calc(-1 * env(safe-area-inset-bottom));
    background: linear-gradient(to top, #fff 72%, transparent);
    padding-top: 10px;
    margin-top: 14px;
  }
  .word-popup.as-sheet .wp-actions .btn { flex: 1; padding: 12px 14px; }
  .wp-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 12, 0.3);
    z-index: 849;
    animation: wp-fade 0.3s ease;
  }
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes wp-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.word-popup .wp-term {
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.word-popup .wp-pos { font-family: var(--sans); font-size: 12px; color: var(--ink-3); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.word-popup .wp-listen {
  align-self: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  box-shadow: 0 0 0 1px var(--ring);
  color: var(--ink-2);
  cursor: pointer;
  transition: box-shadow 0.2s var(--ease-out), color 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}
.word-popup .wp-listen:hover { box-shadow: 0 0 0 1.5px var(--t-accent); color: var(--t-accent); transform: scale(1.06); }
.word-popup .wp-listen:active { transform: scale(0.96); }
.word-popup .wp-trans { font-size: 16px; font-weight: 600; margin-top: 3px; }
.word-popup .wp-expl { font-size: 13.5px; color: var(--ink-2); margin-top: 8px; }
.word-popup .wp-example {
  margin-top: 10px;
  padding: 10px 14px;
  border-left: 2px solid var(--t-accent);
  background: var(--paper-2);
  border-radius: 0 12px 12px 0;
  font-size: 13.5px;
}
.word-popup .wp-example .de { color: var(--ink-3); font-size: 12.5px; margin-top: 2px; }
.word-popup .wp-conj { margin-top: 10px; font-size: 12.5px; }
.word-popup .wp-conj table { border-collapse: collapse; width: 100%; }
.word-popup .wp-conj td { padding: 3px 8px 3px 0; color: var(--ink-2); }
.word-popup .wp-conj td:first-child { color: var(--ink-3); width: 40%; }
.word-popup .wp-note { margin-top: 10px; font-size: 12.5px; color: var(--ink-2); background: var(--brand-yellow-soft); padding: 9px 12px; border-radius: 12px; }
.word-popup .wp-src { margin-top: 10px; font-size: 11.5px; color: var(--ink-3); font-style: italic; }
.word-popup .wp-actions { margin-top: 14px; display: flex; gap: 8px; }
.word-popup .wp-loading { display: flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: 13.5px; padding: 6px 0; }

/* Denk-Punkte (Laden) */
.thinking { display: inline-flex; gap: 5px; align-items: center; }
.thinking i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-4);
  animation: think 1.2s infinite ease-in-out;
}
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes think {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------------------------------------------------- Scroll-Choreografie */
.reveal {
  opacity: 0;
  transform: translateY(26px);
  transition: opacity 0.8s var(--ease-out), transform 0.8s var(--ease-out);
  transition-delay: var(--reveal-delay, 0s);
}
.reveal.in { opacity: 1; transform: none; }

/* ---------------------------------------------------- Utility */
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 16px; }
.center { text-align: center; }
.hide { display: none !important; }
.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;
}

/* ---------------------------------------------------- Reduzierte Bewegung */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1; transform: none; }
}
html[data-motion="reduced"] .reveal { opacity: 1; transform: none; }

/* Sprachpunkt: ersetzt Flaggen-Emojis — der „lebende Punkt" in den Farben
   der jeweiligen Sprachwelt (Standard: aktives Theme, per Inline-Style
   überschreibbar für Sprachlisten). */
.lang-dot {
  display: inline-block;
  width: 0.72em;
  height: 0.72em;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--t-from), var(--t-to));
  vertical-align: -0.02em;
  margin-right: 0.45em;
  flex: none;
}
