:root {
  --bg: #0f0f11;
  --bg-2: #16161a;
  --bg-3: #1d1d22;
  --line: #2a2a31;
  --line-soft: #232329;
  --ink: #e9e6e0;
  --ink-2: #a9a49b;
  --ink-3: #6f6b64;
  --accent: #c9a227;
  --accent-soft: #3a3120;
  --ok: #5fb37a;
  --warn: #d79a3e;
  --err: #d9604f;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Grundgerüst ---------- */

.app { display: flex; flex-direction: column; min-height: 100vh; }

header.top {
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.4rem; height: 58px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-2) 85%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 50;
}

.brand { display: flex; align-items: baseline; gap: .55rem; cursor: pointer; }
.brand .mark { font-family: var(--serif); font-size: 1.32rem; letter-spacing: -.01em; }
.brand .mark em { color: var(--accent); font-style: normal; }
.brand .tag { font-size: .7rem; color: var(--ink-3); letter-spacing: .13em; text-transform: uppercase; }

.top .spacer { flex: 1; }
header.top button { flex: none; white-space: nowrap; }

/* Auf dem Handy muss die Kopfzeile mit Marke und drei Schaltflächen auskommen,
   ohne die Seite seitlich zu verschieben. */
@media (max-width: 560px) {
  header.top { padding: 0 .7rem; gap: .35rem; }
  .brand .tag { display: none; }
  .brand .mark { font-size: 1.15rem; }
  header.top button { padding: .42rem .6rem; font-size: .78rem; }
  main { padding: 1.4rem 1rem 4rem; }
}
@media (max-width: 430px) {
  header.top { padding: 0 .55rem; gap: .28rem; }
  .brand .mark { font-size: .98rem; }
  header.top button { padding: .38rem .45rem; font-size: .72rem; }
}

main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 2.2rem 1.4rem 5rem; }
main.wide { max-width: 1240px; }

/* ---------- Bedienelemente ---------- */

button, .btn {
  font: inherit; font-size: .88rem; font-weight: 500;
  padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-3); color: var(--ink);
  cursor: pointer; transition: .15s border-color, .15s background, .15s color;
  display: inline-flex; align-items: center; gap: .45rem;
}
button:hover:not(:disabled), .btn:hover { border-color: #3c3c46; background: #24242b; text-decoration: none; }
button:disabled { opacity: .45; cursor: not-allowed; }

button.primary {
  background: var(--accent); border-color: var(--accent); color: #17150c; font-weight: 600;
}
button.primary:hover:not(:disabled) { background: #dcb433; border-color: #dcb433; }
button.ghost { background: transparent; }
button.danger { color: var(--err); border-color: #3a2523; background: transparent; }
button.danger:hover:not(:disabled) { background: #2a1a18; border-color: var(--err); }
button.sm { padding: .34rem .7rem; font-size: .8rem; }

input, textarea, select {
  font: inherit; font-size: .9rem; width: 100%;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem .75rem;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
select { cursor: pointer; }
label { display: block; font-size: .8rem; color: var(--ink-2); margin-bottom: .35rem; font-weight: 500; }
.hint { font-size: .76rem; color: var(--ink-3); margin-top: .3rem; line-height: 1.45; }

.field { margin-bottom: 1.1rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 720px) { .row, .row-3 { grid-template-columns: 1fr; } }

/* ---------- Karten ---------- */

.card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.4rem;
}
.card + .card { margin-top: 1.1rem; }
.card h2 { margin: 0 0 .3rem; font-size: 1.05rem; font-weight: 600; }
.card h3 { margin: 1.5rem 0 .6rem; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .13em; color: var(--ink-3); font-weight: 600; }
.card h3:first-child { margin-top: 0; }

.page-head { margin-bottom: 1.6rem; }
.page-head h1 { font-family: var(--serif); font-size: 2rem; margin: 0 0 .3rem; font-weight: 500; letter-spacing: -.01em; }
.page-head p { color: var(--ink-2); margin: 0; max-width: 62ch; font-size: .92rem; }

.muted { color: var(--ink-3); }
.small { font-size: .82rem; }

/* ---------- Bibliothek ---------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }

.book-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.15rem; cursor: pointer; transition: .15s; position: relative; overflow: hidden;
}
.book-card:hover { border-color: #3c3c46; transform: translateY(-1px); }
.book-card .spine { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: .5; }
.book-card h3 { font-family: var(--serif); font-size: 1.18rem; margin: 0 0 .35rem;
  text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 500; }
.book-card .meta { font-size: .78rem; color: var(--ink-3); display: flex; gap: .6rem; flex-wrap: wrap; }
.book-card h3 { padding-right: 3.6rem; }

.card-actions { position: absolute; top: .7rem; right: .7rem; display: flex; gap: .25rem;
  opacity: 0; transition: opacity .15s; }
.book-card:hover .card-actions, .card-actions:focus-within { opacity: 1; }
.icon-btn { padding: .3rem .38rem; line-height: 0; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink-3); }
.icon-btn svg { display: block; }
.icon-btn:hover { color: var(--ink); border-color: #3c3c46; background: var(--bg-3); }
.icon-btn.danger-hover:hover { color: var(--err); border-color: var(--err); background: #2a1a18; }
@media (hover: none) { .card-actions { opacity: 1; } }

.badge {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 600;
  padding: .18rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2);
  display: inline-block;
}
.badge.gen { color: var(--accent); border-color: var(--accent-soft); background: #221d10; }
.badge.done { color: var(--ok); border-color: #1f3a2a; background: #142019; }
.badge.err { color: var(--err); border-color: #3a2523; background: #201514; }
.badge.paused { color: var(--warn); border-color: #3a2f1c; }

.empty { text-align: center; padding: 4.5rem 1rem; color: var(--ink-3); }
.empty .big { font-family: var(--serif); font-size: 1.5rem; color: var(--ink-2); margin-bottom: .5rem; }

/* ---------- Konzept ---------- */

.concept-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1.2rem; align-items: start; }
@media (max-width: 900px) { .concept-grid { grid-template-columns: 1fr; } }

.blurb {
  font-family: var(--serif); font-size: 1.05rem; line-height: 1.68; color: #d8d3ca;
  border-left: 2px solid var(--accent-soft); padding-left: 1.1rem; margin: 0;
}

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { font-size: .77rem; padding: .25rem .6rem; border-radius: 6px;
  background: var(--bg-3); border: 1px solid var(--line-soft); color: var(--ink-2); }

.person { padding: .9rem 0; border-top: 1px solid var(--line-soft); }
.person:first-of-type { border-top: none; padding-top: 0; }
.person .nm { font-family: var(--serif); font-size: 1.06rem; }
.person .rl { font-size: .74rem; color: var(--accent); text-transform: uppercase; letter-spacing: .09em; margin-left: .5rem; }
.person p { margin: .3rem 0 0; font-size: .88rem; color: var(--ink-2); }
.person .voice { font-size: .82rem; color: var(--ink-3); font-style: italic; margin-top: .25rem; }

.spoiler-note {
  display: flex; gap: .7rem; align-items: flex-start;
  background: #171a15; border: 1px solid #253022; color: #a8c4a0;
  padding: .8rem 1rem; border-radius: 8px; font-size: .84rem; line-height: 1.5;
}
.spoiler-note strong { color: #bcd9b3; }

/* ---------- Fortschritt ---------- */

.progress-hero { text-align: center; padding: 1.5rem 0 .5rem; }
.progress-hero .pct { font-family: var(--serif); font-size: 3.6rem; line-height: 1; color: var(--ink); }
.progress-hero .pct span { font-size: 1.4rem; color: var(--ink-3); }
.progress-hero .act { color: var(--ink-2); margin-top: .7rem; font-size: .95rem; min-height: 1.4em; }

.bar { height: 6px; background: var(--bg-3); border-radius: 999px; overflow: hidden; margin: 1.3rem 0 .4rem; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #8a6f1c, var(--accent));
  border-radius: 999px; transition: width .6s cubic-bezier(.4,0,.2,1); }
.bar.indet > i { width: 30% !important; animation: slide 1.6s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 1px;
  background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: 8px; overflow: hidden; }
.stat { background: var(--bg-2); padding: .85rem .9rem; }
.stat .k { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); }
.stat .v { font-size: 1.22rem; margin-top: .22rem; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: .7rem; color: var(--ink-3); font-weight: 400; }

.logbox { max-height: 230px; overflow-y: auto; font-family: var(--mono); font-size: .76rem;
  line-height: 1.7; color: var(--ink-2); background: var(--bg); border: 1px solid var(--line-soft);
  border-radius: 8px; padding: .7rem .85rem; }
.logbox div { white-space: pre-wrap; word-break: break-word; }
.logbox .t { color: var(--ink-3); }
.logbox .warn { color: var(--warn); }
.logbox .err { color: var(--err); }
.logbox .ok { color: var(--ok); }

/* ---------- Leseansicht ---------- */

.reader { max-width: 36em; margin: 0 auto; font-family: var(--serif); font-size: 1.13rem; line-height: 1.75; }
.reader h2 { font-size: .78rem; letter-spacing: .15em; text-transform: uppercase; color: var(--accent);
  font-family: var(--sans); font-weight: 600; margin: 4rem 0 .3rem; }
.reader h3 { font-size: 1.6rem; font-weight: 500; margin: 0 0 2rem; }
.reader p { margin: 0; text-indent: 1.35em; text-align: justify; hyphens: auto; }
.reader p.first { text-indent: 0; }
.reader p.brk { text-align: center; text-indent: 0; margin: 1.6rem 0; color: var(--accent); letter-spacing: .6em; }

/* ---------- Modal ---------- */

.overlay { position: fixed; inset: 0; background: rgba(6,6,8,.72); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding: 3rem 1rem; z-index: 100; overflow-y: auto; }
.modal { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  width: 100%; max-width: 720px; box-shadow: 0 24px 60px rgba(0,0,0,.5); }
.modal.lg { max-width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: var(--bg-2); border-radius: 12px 12px 0 0; z-index: 2; }
.modal-head h2 { margin: 0; font-size: 1.02rem; }
.modal-body { padding: 1.4rem; }
.modal-foot { padding: 1rem 1.4rem; border-top: 1px solid var(--line); display: flex;
  justify-content: flex-end; gap: .6rem; }
.x { background: none; border: none; color: var(--ink-3); font-size: 1.3rem; padding: 0 .3rem; line-height: 1; }
.x:hover { color: var(--ink); background: none; }

/* ---------- Einstellungen ---------- */

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1.4rem; flex-wrap: wrap; }
.tab { padding: .6rem .95rem; font-size: .86rem; color: var(--ink-3); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; border-radius: 0;
  border-left: none; border-right: none; border-top: none; }
.tab:hover { color: var(--ink-2); background: none; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.provider-card { border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem; margin-bottom: 1rem; }
.provider-card.on { border-color: #34342f; }
.provider-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .2rem; }
.provider-head .nm { font-weight: 600; font-size: .95rem; }
.provider-body { margin-top: 1rem; }

.switch { position: relative; width: 38px; height: 21px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch i { position: absolute; inset: 0; background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 999px; transition: .18s; }
.switch i::after { content: ''; position: absolute; width: 15px; height: 15px; border-radius: 50%;
  background: var(--ink-3); top: 2px; left: 2px; transition: .18s; }
.switch input:checked + i { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + i::after { transform: translateX(17px); background: var(--accent); }

.test-result { margin-top: .8rem; padding: .65rem .85rem; border-radius: 8px; font-size: .83rem;
  line-height: 1.5; white-space: pre-wrap; }
.test-result.ok { background: #14201a; border: 1px solid #1f3a2a; color: #9fd3b0; }
.test-result.err { background: #201514; border: 1px solid #3a2523; color: #e0a99f; }
.test-result.pending { background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-2); }

.role-row { display: grid; grid-template-columns: 200px 1fr 1fr; gap: .7rem; align-items: center;
  padding: .75rem 0; border-top: 1px solid var(--line-soft); }
.role-row:first-of-type { border-top: none; }
.role-row .rname { font-size: .87rem; font-weight: 500; }
.role-row .rhint { font-size: .74rem; color: var(--ink-3); line-height: 1.35; }
@media (max-width: 760px) { .role-row { grid-template-columns: 1fr; } }

/* ---------- Diverses ---------- */

.toast-wrap { position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 200;
  display: flex; flex-direction: column; gap: .5rem; max-width: 380px; }
.toast { background: var(--bg-3); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: .75rem 1rem; font-size: .86rem; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: pop .2s ease-out; }
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

.spin { width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.export-row { display: flex; flex-wrap: wrap; gap: .55rem; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; font-size: .85rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.divider { height: 1px; background: var(--line-soft); margin: 1.4rem 0; }

.inline-edit { font-family: var(--serif); font-size: 1.5rem; background: transparent; border: none;
  border-bottom: 1px dashed var(--line); padding: .2rem 0; color: var(--ink); }
.inline-edit:focus { border-bottom-color: var(--accent); }

.warn-box { background: #201b12; border: 1px solid #3a2f1c; color: #d9b678;
  padding: .8rem 1rem; border-radius: 8px; font-size: .85rem; line-height: 1.5; }
.ok-box { background: #14201a; border: 1px solid #1f3a2a; color: #9fd3b0;
  padding: .8rem 1rem; border-radius: 8px; font-size: .85rem; line-height: 1.5; }

/* ---------- Kosten- und Preistabellen ---------- */

.cost-table, .price-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.cost-table th, .price-table th { text-align: left; font-weight: 600; font-size: .68rem;
  text-transform: uppercase; letter-spacing: .09em; color: var(--ink-3);
  padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
.cost-table td, .price-table td { padding: .55rem .5rem; border-bottom: 1px solid var(--line-soft);
  vertical-align: top; }
.cost-table tbody tr:last-child td { border-bottom: none; }
.cost-table tfoot th { border-bottom: none; border-top: 1px solid var(--line);
  color: var(--ink); font-size: .84rem; text-transform: none; letter-spacing: 0; padding-top: .6rem; }
.nu { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.th-sub { font-weight: 400; text-transform: none; letter-spacing: 0; font-size: .64rem; color: var(--ink-3); }
.m-name { color: var(--ink); word-break: break-word; }
.m-prov { font-size: .72rem; color: var(--ink-3); margin-top: .1rem; }
.price-table input { width: 108px; text-align: right; padding: .38rem .5rem; font-size: .84rem; }
.tag { font-size: .62rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3);
  border: 1px solid var(--line); border-radius: 4px; padding: .05rem .3rem; margin-left: .35rem; }

.token-split { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.token-split .k { font-size: .66rem; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-3); }
.token-split .v { font-size: 1.02rem; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.err-box { background: #201514; border: 1px solid #3a2523; color: #e0a99f;
  padding: .8rem 1rem; border-radius: 8px; font-size: .85rem; line-height: 1.5; }
