:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --text: #1d1a16;
  --muted: #7a7062;
  --border: #e3dac8;
  --accent: #8a5a12;
  --accent-text: #fffdf8;
  --shadow: 0 10px 30px rgba(60, 40, 10, 0.08);
  --m-nom: #f4c7c3;
  --m-gen: #f3e3a0;
  --m-dat: #c9e8c4;
  --m-akk: #c4dcf5;
  --m-abl: #f6cfae;
  --m-vok: #e0c8f2;
  --m-text: #1d1a16;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f;
    --surface: #1d1916;
    --text: #efe8da;
    --muted: #9b917f;
    --border: #2f2923;
    --accent: #d9a441;
    --accent-text: #14110f;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    --m-nom: #7a3532;
    --m-gen: #7a6320;
    --m-dat: #38683a;
    --m-akk: #2f5680;
    --m-abl: #80512a;
    --m-vok: #62407a;
    --m-text: #f4ede0;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.top {
  width: 100%;
  max-width: 760px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0 8px;
}

.top h1 {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 1.4rem;
  letter-spacing: 0.04em;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

select {
  max-width: 62vw;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 8px 0;
}

.card {
  width: 100%;
  padding: 24px 24px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.badge {
  display: inline-block;
  margin-bottom: 20px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
}

.sentence {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(1.05rem, 1.2vw + 0.8rem, 1.3rem);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding: 24px 0 8px;
}

button {
  padding: 12px 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button:hover { filter: brightness(1.08); }
button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hint {
  margin: 0;
  padding: 0 0 20px;
  color: var(--muted);
  font-size: 0.8rem;
}

@media (hover: none) { .hint { display: none; } }

.version { margin: 0; padding: 0 0 16px; color: var(--muted); font-size: 0.7rem; opacity: 0.8; }

/* Markierwerkzeuge */
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 500;
}

.tool kbd {
  color: var(--muted);
  font: inherit;
  font-size: 0.7rem;
}

.tool[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--m-text);
  opacity: 0.25;
}

.tool[data-tool="nom"] .swatch { background: var(--m-nom); opacity: 1; }
.tool[data-tool="gen"] .swatch { background: var(--m-gen); opacity: 1; }
.tool[data-tool="dat"] .swatch { background: var(--m-dat); opacity: 1; }
.tool[data-tool="akk"] .swatch { background: var(--m-akk); opacity: 1; }
.tool[data-tool="abl"] .swatch { background: var(--m-abl); opacity: 1; }
.tool[data-tool="vok"] .swatch { background: var(--m-vok); opacity: 1; }
.tool[data-tool="pra"] .swatch { background: none; opacity: 1; outline: 2px solid var(--text); outline-offset: -2px; }
.tool[data-tool="inf"] .swatch { background: none; opacity: 1; outline: 2px dashed var(--text); outline-offset: -2px; }
.tool[data-tool="kon"] .swatch { background: none; opacity: 1; outline: 2px dotted var(--text); outline-offset: -2px; }
.tool[data-tool="prp"] .swatch { background: none; opacity: 1; border-bottom: 2px solid var(--text); border-radius: 0; }
.tool.clear { color: var(--muted); }

.tool-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; width: 100%; }
.group-label { min-width: 64px; color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; }

.w {
  cursor: pointer;
  border-radius: 4px;
  padding: 0 2px;
  margin: 0 -2px;
}

.w:hover { background: var(--border); }

.w[data-mark] { color: var(--m-text); }
.w[data-mark="nom"] { background: var(--m-nom); }
.w[data-mark="gen"] { background: var(--m-gen); }
.w[data-mark="dat"] { background: var(--m-dat); }
.w[data-mark="akk"] { background: var(--m-akk); }
.w[data-mark="abl"] { background: var(--m-abl); }
.w[data-mark="vok"] { background: var(--m-vok); }
.w[data-mark="pra"] { outline: 2px solid var(--text); outline-offset: 1px; }
.w[data-mark="inf"] { outline: 2px dashed var(--text); outline-offset: 1px; }
.w[data-mark="kon"] { outline: 2px dotted var(--text); outline-offset: 1px; font-weight: 700; }
.w[data-mark="prp"] { text-decoration: underline wavy var(--text); text-underline-offset: 4px; }

.w sup { font-family: system-ui, sans-serif; font-size: 0.55em; font-weight: 600; margin-left: 2px; vertical-align: super; line-height: 0; }
.w sup.num { padding: 0 4px; border-radius: 999px; background: var(--accent); color: var(--accent-text); }
.w .br { color: var(--accent); font-weight: 700; font-size: 1.15em; margin: 0 1px; }
.w.pending { outline: 2px dashed var(--accent); outline-offset: 1px; }

/* Übersetzung & Selbstkontrolle */
.translate { display: flex; flex-direction: column; gap: 10px; }

textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  resize: vertical;
}

textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

details {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

summary { cursor: pointer; font-weight: 600; }

.note { margin: 10px 0 0; color: var(--muted); font-size: 0.8rem; }

.checklist { margin: 10px 0 0; padding: 0; list-style: none; font-size: 0.9rem; }
.checklist li { padding: 3px 0; }

.check-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 12px; }
.check-actions a { color: var(--accent); font-size: 0.9rem; }

/* Titel + Info-Knopf */
.title { display: flex; align-items: center; gap: 6px; }
.icon-btn { min-width: 40px; min-height: 40px; padding: 0; border-radius: 999px; font-size: 1.2rem; line-height: 1; color: var(--muted); }
.linklike { border: none; background: none; color: var(--muted); text-decoration: underline; font-weight: 500; padding: 8px; }

/* Splash */
.splash {
  --accent: #d9a441; --accent-text: #14110f; --border: #2f2923; --text: #efe8da; --muted: #9b917f; --surface: #1d1916;
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; background: #14110f; color: var(--text); text-align: center;
}
.splash[hidden] { display: none; }
.bust-wrap { position: relative; width: min(52vw, 220px); max-height: 42vh; }
.bust { display: block; width: 100%; height: auto; max-height: 42vh; object-fit: contain; }
/* Glanz: heller Streifen, nur in der Form der Büste sichtbar (Maske = die Büste selbst) */
.bust-wrap::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(110deg, transparent 38%, rgba(255, 248, 220, 0.75) 50%, transparent 62%);
  background-size: 300% 100%; background-position: 100% 0;
  -webkit-mask: url("icons/caesar.svg") center / contain no-repeat;
  mask: url("icons/caesar.svg") center / contain no-repeat;
}
.motto { margin: 0; font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif; font-size: clamp(1.6rem, 6vw, 2.6rem); letter-spacing: 0.18em; color: #d9a441; }
.motto span { display: inline-block; }
.motto-sub { margin: 0; color: var(--muted); letter-spacing: 0.3em; text-transform: uppercase; font-size: 0.8rem; }
.splash-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.splash.play .bust-wrap { animation: fade-up 0.9s ease both; }
.splash.play .bust-wrap::after { animation: shine 1.3s 1.1s ease-in-out both; }
.splash.leaving { animation: splash-out 0.5s ease forwards; pointer-events: none; }
.splash.leaving .bust-wrap { animation: bust-out 0.5s ease forwards; }
@keyframes shine { from { background-position: 100% 0; } to { background-position: 0% 0; } }
@keyframes splash-out { to { opacity: 0; } }
@keyframes bust-out { to { transform: scale(1.12) translateY(-8px); } }
.splash.play .motto span { animation: fade-up 0.7s ease both; }
.splash.play .motto span:nth-child(1) { animation-delay: 0.5s; }
.splash.play .motto span:nth-child(2) { animation-delay: 1.1s; }
.splash.play .motto span:nth-child(3) { animation-delay: 1.7s; }
.splash.play .motto-sub { animation: fade-up 0.7s 2.3s ease both; }
.splash.play .splash-actions { animation: fade-up 0.7s 2.6s ease both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .splash.play *, .splash.play .bust-wrap::after { animation: none !important; }
}

/* Willkommens-/Info-Fenster */
dialog {
  width: min(92vw, 560px); max-height: 86vh; overflow: auto;
  padding: 22px 22px 18px; border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 8px; font-family: Georgia, "Iowan Old Style", serif; font-size: 1.3rem; }
dialog h3 { margin: 14px 0 6px; font-size: 0.95rem; }
dialog p { margin: 0; font-size: 0.9rem; line-height: 1.5; }
dialog ul { margin: 0; padding-left: 1.1rem; font-size: 0.9rem; line-height: 1.5; }
dialog li { margin-bottom: 4px; }
.about-version { margin-top: 12px !important; color: var(--muted); font-size: 0.8rem !important; }
.about-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 14px; }

/* Kompakter auf dem Handy */
body:has(.splash:not([hidden])) { overflow: hidden; }
dialog h2:focus { outline: none; }
.tool { min-height: 36px; padding: 4px 8px; }
.tool-group { gap: 4px; }
@media (hover: none) { .tool kbd { display: none; } }
@media (max-width: 520px) {
  .group-label { width: 100%; min-width: 0; margin-top: 4px; }
  .tools { gap: 2px; }
}

/* Kein seitliches Scrollen: Kopfzeile bricht um, Auswahlfelder teilen sich die Breite */
body { overflow-x: clip; }
.top { flex-wrap: wrap; }
.filters { flex: 1 1 260px; min-width: 0; max-width: 100%; justify-content: flex-end; flex-wrap: nowrap; }
.filters label { flex: 1 1 0; min-width: 0; }
.filters select { width: 100%; max-width: 100%; text-overflow: ellipsis; }

/* Begrüßung im Splash + Namensfeld */
.salve { margin: 0; font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif; font-style: italic; font-size: clamp(1.2rem, 5vw, 1.6rem); color: #efe8da; overflow-wrap: anywhere; }
.splash.play .salve { animation: fade-up 0.7s 0.2s ease both; }
.name-field { display: block; margin-top: 14px; font-size: 0.85rem; color: var(--muted); }
.name-field input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; font-size: 1rem; }
.name-field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Bewegung in der App: Satzwechsel + Pop beim Markieren (nur ohne "Bewegung reduzieren") */
.w { display: inline-block; }
@keyframes slide-in { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.2); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: no-preference) {
  .card.swap .badge, .card.swap .sentence { animation: slide-in 0.35s ease both; }
  .w.pop { animation: pop 0.3s ease; }
}
