:root {
  --bg: #f7f3ee;
  --card: #ffffff;
  --text: #24221f;
  --muted: #736c64;
  --line: #e7e0d7;
  --primary: #e8664a;
  --primary-dark: #cf5237;
  --accent: #2f8f83;
  --error: #c8443a;
  --ok: #2f8a4c;
  --warn: #c7841f;
  --note: #fff5e8;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(40, 30, 20, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18171a;
    --card: #232126;
    --text: #ece9e4;
    --muted: #a59f97;
    --line: #36333a;
    --primary: #ef7a5f;
    --primary-dark: #e8664a;
    --note: #2f2a22;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Leelawadee UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--error); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
h1, h2, h3 { line-height: 1.25; }
h2 { margin: 0 0 12px; }
h3 { margin: 24px 0 10px; }
a { color: var(--primary); }

button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type="range"] { padding: 0; border: 0; background: none; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 10px 16px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; color: var(--text);
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 0.88rem; }
.btn.big { padding: 14px 22px; font-size: 1.05rem; }
.btn.danger { color: var(--error); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.note { background: var(--note); padding: 10px 12px; border-radius: 10px; margin: 0; }

/* ---------------- Anmeldung */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  background: var(--card); border-radius: 24px; box-shadow: var(--shadow);
  padding: 28px 24px; width: 100%; max-width: 400px; text-align: center;
}
.auth-card form { text-align: left; margin-top: 16px; }
.auth-card h1 { margin: 8px 0 4px; }
.auth-logo { font-size: 3rem; }
.lang-switch { display: inline-flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 999px; margin-top: 8px; }
.lang-switch button { border: 0; background: transparent; padding: 5px 14px; border-radius: 999px; font-size: 0.9rem; }
.lang-switch button.active { background: var(--primary); color: #fff; }

/* ---------------- Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.logo { font-size: 1.4rem; }
.nav { display: flex; gap: 2px; overflow-x: auto; }
.nav a { padding: 8px 12px; border-radius: 10px; white-space: nowrap; color: var(--muted); text-decoration: none; }
.nav a.active { background: var(--bg); color: var(--text); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---------------- Karten / Raster */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; text-decoration: none; color: var(--text);
}
.card .cover { aspect-ratio: 16 / 9; background: var(--line); object-fit: cover; width: 100%; display: block; }
.card .cover.square { aspect-ratio: 1; object-fit: contain; background: #fff; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.card .body strong { overflow-wrap: anywhere; }
.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: #e3f3e7; color: var(--ok); }
.badge.warn { background: #fbefd9; color: var(--warn); }
.badge.error { background: #f9e1de; color: var(--error); }
.badge.busy { background: #e3eefb; color: #2f62a8; }
@media (prefers-color-scheme: dark) {
  .badge.ok { background: #20372a; } .badge.warn { background: #3a2f1c; }
  .badge.error { background: #3d2220; } .badge.busy { background: #1f2c3d; color: #8fb4e8; }
}
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px 6px 6px;
  display: inline-flex; align-items: center; gap: 8px;
}
.chip img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #fff; }
.chip.active { border-color: var(--primary); background: var(--note); font-weight: 600; }
.voice-row { display: flex; gap: 8px; }
.voice-row select { flex: 1; }

/* ---------------- Statusleiste */
.statusbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--note);
  margin-bottom: 14px;
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary);
  animation: spin 0.9s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Szenen */
.scenes { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.scene {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px;
  display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 14px;
}
.scene.portrait { grid-template-columns: minmax(0, 200px) minmax(0, 1fr); }
.scene-img {
  position: relative; border-radius: 10px; overflow: hidden; background: var(--line); aspect-ratio: 16 / 9;
  display: grid; place-items: center;
}
.scene.portrait .scene-img { aspect-ratio: 9 / 16; }
.scene-img img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.scene-img .num {
  position: absolute; left: 8px; top: 8px; background: rgba(0, 0, 0, 0.6); color: #fff; border-radius: 8px;
  padding: 1px 8px; font-weight: 700; font-size: 0.85rem;
}
.scene-img .overlay {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255, 255, 255, 0.55);
}
@media (prefers-color-scheme: dark) { .scene-img .overlay { background: rgba(0, 0, 0, 0.5); } }
.scene-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.scene-side textarea.lines { min-height: 70px; }
.check-note { font-size: 0.88rem; padding: 6px 10px; border-radius: 8px; background: var(--note); }
details summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
details textarea { margin-top: 6px; min-height: 70px; font-size: 0.92rem; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.hint-box { display: flex; gap: 6px; }
.render-box { margin-top: 20px; }
.video-player { width: 100%; max-height: 70vh; background: #000; border-radius: 12px; display: block; }
.video-player.portrait { max-width: 420px; margin: 0 auto; }

/* ---------------- Figuren-Varianten */
.variants { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 10px; }
.variant { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; border: 3px solid transparent; display: flex; flex-direction: column; gap: 8px; }
.variant.active { border-color: var(--primary); }
.variant img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 10px; cursor: zoom-in; }

/* ---------------- Listen */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.list-item audio { max-width: 100%; height: 36px; }
.settings { max-width: 480px; }

.lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85); z-index: 60; display: grid; place-items: center;
  padding: 16px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 70;
  background: #24221f; color: #fff; padding: 10px 18px; border-radius: 12px; max-width: calc(100% - 32px);
  box-shadow: var(--shadow); text-align: center;
}
code { word-break: break-all; font-size: 0.85rem; }

/* ---------------- Handy */
@media (max-width: 760px) {
  .brand span:not(.logo) { display: none; }
  .nav a { padding: 8px 8px; font-size: 0.92rem; }
  .scene, .scene.portrait { grid-template-columns: 1fr; }
  .scene.portrait .scene-img { max-width: 240px; }
}
