/* ---------- Farb-Variablen: Hell (Standard) ---------- */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --hover: #f8fafc;
  --field: #ffffff;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --badge-bg: #eef2ff;
  --badge-ink: #3730a3;
  --due-bg: #fee2e2;
  --due-ink: #991b1b;
  --alert-bg: #fef2f2;
  --alert-line: #fecaca;
  --alert-ink: #991b1b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

/* ---------- Dark Mode ---------- */
/* Manuell gewählt … */
:root[data-theme="dark"] {
  --bg: #0b1120;
  --card: #1e293b;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --hover: #273449;
  --field: #0f172a;
  --primary: #3b82f6;
  --primary-ink: #ffffff;
  --danger: #f87171;
  --badge-bg: #1e3a5f;
  --badge-ink: #bfdbfe;
  --due-bg: #7f1d1d;
  --due-ink: #fecaca;
  --alert-bg: #3f1d1d;
  --alert-line: #7f1d1d;
  --alert-ink: #fecaca;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
/* … sonst der Systemeinstellung folgen (solange nicht ausdrücklich "hell" gewählt) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --card: #1e293b;
    --ink: #e2e8f0;
    --muted: #94a3b8;
    --line: #334155;
    --hover: #273449;
    --field: #0f172a;
    --primary: #3b82f6;
    --primary-ink: #ffffff;
    --danger: #f87171;
    --badge-bg: #1e3a5f;
    --badge-ink: #bfdbfe;
    --due-bg: #7f1d1d;
    --due-ink: #fecaca;
    --alert-bg: #3f1d1d;
    --alert-line: #7f1d1d;
    --alert-ink: #fecaca;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.2; }
a { color: var(--primary); }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.empty { padding: 1.5rem; text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  min-height: 40px;
  padding: .5rem .85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(.93); }
.btn-danger { color: var(--danger); border-color: var(--alert-line); }
.btn-danger:hover { background: var(--alert-bg); }
.btn-small { min-height: 34px; padding: .3rem .6rem; font-size: .85rem; }

.badge {
  font-size: .7rem;
  background: var(--muted);
  color: var(--card);
  padding: .1rem .4rem;
  border-radius: 6px;
  vertical-align: middle;
}

/* ---------- Topbar ---------- */
.topbar {
  background: #0f172a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1rem;
}
.topbar strong { font-size: 1.05rem; }
.topbar-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .push-right { margin-left: auto; }
.topbar .btn { background: #1e293b; border-color: #334155; color: #e2e8f0; }
.topbar .btn:hover { background: #334155; }

/* ---------- Layout ---------- */
.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

/* ---------- Auth-Seiten ---------- */
.auth-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}
.auth-card h1 { margin-top: 0; }
.auth-card label { display: block; margin: .75rem 0; font-weight: 600; }
.auth-card input { width: 100%; }
.auth-card .btn { width: 100%; margin-top: .5rem; }
.alert {
  background: var(--alert-bg);
  border: 1px solid var(--alert-line);
  color: var(--alert-ink);
  padding: .6rem .8rem;
  border-radius: var(--radius);
  margin: .5rem 0;
}

/* ---------- Formularfelder ---------- */
input[type=text], input[type=password], input[type=number], textarea, select {
  font: inherit;
  font-size: 16px; /* verhindert Auto-Zoom auf iOS */
  padding: .5rem .6rem;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}
textarea { width: 100%; resize: vertical; }
::placeholder { color: var(--muted); opacity: 1; }

/* ---------- Übungsübersicht ---------- */
.row-form { display: flex; flex-wrap: wrap; gap: .5rem; }
.row-form input[type=text] { flex: 1; min-width: 180px; }
.card-list { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.uebung-card { display: flex; flex-direction: column; justify-content: space-between; margin-bottom: 0; }
.uebung-card.is-archived { opacity: .7; }
.uebung-open { display: flex; flex-direction: column; gap: .15rem; text-decoration: none; color: var(--ink); }
.uebung-name { font-weight: 700; font-size: 1.05rem; }
.uebung-notiz { color: var(--muted); }
.uebung-actions { margin-top: .75rem; }
.uebung-actions form { display: flex; gap: .4rem; }

/* ---------- Fällig-Leiste ---------- */
.faellig-bar {
  position: sticky;
  top: var(--topbar-h, 52px);
  z-index: 15;
  background: #7f1d1d;
  color: #fff;
  padding: .6rem 1rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .35);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { background: #b91c1c; } }
.faellig-title { font-weight: 700; max-width: 960px; margin: 0 auto .3rem; }
.faellig-item {
  max-width: 960px;
  margin: .25rem auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, .12);
  padding: .35rem .5rem;
  border-radius: var(--radius);
}
.faellig-char { font-weight: 700; }
.faellig-text { flex: 1; min-width: 120px; }
.faellig-item .muted { color: #fecaca; }
.faellig-item .btn { background: #fff; color: #7f1d1d; border: none; }

/* ---------- Charakter-Tabs ---------- */
.charaktere-tabs {
  display: flex;
  gap: .4rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: .25rem;
  scrollbar-width: thin;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  flex: 0 0 auto;
  min-height: 40px;
  padding: .45rem .75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}
.tab.is-active { border-color: var(--c, var(--primary)); box-shadow: inset 0 0 0 1px var(--c, var(--primary)); }
.tab-dot { width: .7rem; height: .7rem; border-radius: 50%; background: var(--c, var(--muted)); flex: none; }
.tab-name { white-space: nowrap; }
.tab-count {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: .72rem;
  padding: 0 .4rem;
  min-width: 1.2em;
  text-align: center;
}
.tab-add { color: var(--muted); border-style: dashed; }

/* ---------- Charakter-Werkzeugleiste ---------- */
.char-toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: -.5rem 0 1rem;
  padding: .4rem .6rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.ct-dot { width: .8rem; height: .8rem; border-radius: 50%; flex: none; }
.ct-name { font-weight: 700; }
.ct-rolle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-edit { margin-left: auto; flex: none; }

/* ---------- Charakter-Notizfeld ---------- */
.char-note {
  margin-bottom: 1rem;
  padding: .5rem .6rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.char-note-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-bottom: .35rem;
}
.note-status { white-space: nowrap; }
#char-note-text {
  width: 100%;
  height: 9.5rem;      /* feste Höhe ~6 Zeilen, damit die Seite nicht springt */
  resize: none;        /* nicht veränderbar */
  overflow-y: auto;    /* bei mehr Text intern scrollen */
  line-height: 1.4;
}

/* ---------- Eingabe ---------- */
.eingabe-zeile1 { display: flex; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.eingabe-zeile1 .sel { flex: 1; min-width: 140px; }
.timer-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.timer-buttons { display: flex; gap: .3rem; flex-wrap: wrap; }
.chip {
  min-height: 36px;
  padding: .3rem .7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: .85rem;
}
.chip.is-active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.timer-custom { width: 5.5rem; }
.entry-submit { margin-left: auto; }

/* ---------- Einträge ---------- */
.eintraege { display: flex; flex-direction: column; gap: .5rem; }
.entry {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--c, var(--muted));
  border-radius: var(--radius);
  padding: .6rem .75rem;
  box-shadow: var(--shadow);
}
.entry.is-done { opacity: .55; }
.entry.is-done .entry-text { text-decoration: line-through; }
.entry-check {
  flex: none;
  width: 1.8rem;
  height: 1.8rem;
  border: 2px solid var(--c, var(--muted));
  border-radius: 6px;
  background: var(--field);
  cursor: pointer;
  font-weight: 700;
  color: var(--c, var(--ink));
  line-height: 1;
}
.entry.is-done .entry-check { background: var(--c, var(--muted)); color: #fff; }
.entry-body { flex: 1; min-width: 0; }
.entry-meta { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.entry-char { font-weight: 700; }
.entry-text { white-space: pre-wrap; word-break: break-word; margin-top: .1rem; }
.entry-tools { display: flex; gap: .25rem; flex: none; }
.icon-btn {
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  min-width: 34px;
  min-height: 34px;
  padding: .2rem .4rem;
  font-size: .8rem;
}
.entry.is-editing { border-left-color: var(--primary); }
.edit-text { width: 100%; margin-top: .25rem; }
.edit-actions { display: flex; gap: .4rem; margin-top: .4rem; }

.timer-badge {
  font-size: .78rem;
  background: var(--badge-bg);
  color: var(--badge-ink);
  padding: .05rem .45rem;
  border-radius: 999px;
}
.timer-badge.is-due { background: var(--due-bg); color: var(--due-ink); font-weight: 700; }

/* ---------- Dialog ---------- */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
  padding: 1.25rem;
  max-width: 360px;
  width: 90%;
  background: var(--card);
  color: var(--ink);
}
dialog::backdrop { background: rgba(15, 23, 42, .55); }
dialog h3 { margin-top: 0; }
dialog label { display: block; margin: .6rem 0; font-weight: 600; }
dialog input[type=text] { width: 100%; }
.dialog-actions { display: flex; align-items: center; gap: .5rem; margin-top: 1rem; }
.dialog-actions .spacer { flex: 1; }

/* ---------- Hinweis-Toasts ---------- */
#toast-host {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  width: min(92vw, 460px);
}
.toast {
  background: var(--due-bg);
  color: var(--due-ink);
  border: 1px solid var(--alert-line);
  padding: .6rem .8rem;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  cursor: pointer;
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .container { padding: .75rem; }
  .eingabe-zeile1 .sel { min-width: 0; }
  .entry-submit { margin-left: 0; flex: 1; }
  .timer-row { gap: .4rem; }
  .timer-custom { flex: 1; width: auto; }
}
