/* Traumzeilen – für Tablets gebaut: große Tippflächen, ruhige Nachtfarben. */

:root {
  --bg: #141a33;
  --bg-deep: #0e1327;
  --card: #1f2749;
  --card-2: #283158;
  --line: rgba(243, 234, 216, 0.14);
  --text: #f3ead8;
  --muted: #b5b3c8;
  --accent: #f5c56b;
  --accent-ink: #2a2140;
  --accent-soft: rgba(245, 197, 107, 0.16);
  --danger: #ffb4a8;
  --shadow: 0 10px 30px rgba(4, 6, 20, 0.35);
  --story-size: 22px;
  --ui: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --radius: 22px;
}

[data-theme="day"] {
  --bg: #fbf5e9;
  --bg-deep: #f4ebd9;
  --card: #ffffff;
  --card-2: #f6eee0;
  --line: rgba(43, 37, 64, 0.14);
  --text: #2b2540;
  --muted: #6c6680;
  --accent: #e0a12f;
  --accent-ink: #2a2140;
  --accent-soft: rgba(224, 161, 47, 0.18);
  --danger: #b3261e;
  --shadow: 0 10px 30px rgba(60, 45, 20, 0.12);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 18px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(255,255,255,.8) 50%, transparent 51%),
    radial-gradient(1px 1px at 28% 62%, rgba(255,255,255,.6) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 44% 9%, rgba(255,255,255,.7) 50%, transparent 51%),
    radial-gradient(1px 1px at 61% 38%, rgba(255,255,255,.5) 50%, transparent 51%),
    radial-gradient(2px 2px at 77% 14%, rgba(255,255,255,.75) 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 71%, rgba(255,255,255,.55) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 7% 84%, rgba(255,255,255,.6) 50%, transparent 51%),
    radial-gradient(1px 1px at 52% 88%, rgba(255,255,255,.5) 50%, transparent 51%),
    radial-gradient(120% 80% at 50% -10%, #263066 0%, transparent 60%),
    linear-gradient(var(--bg), var(--bg-deep));
}
[data-theme="day"] .sky {
  background: radial-gradient(120% 80% at 50% -10%, #fff7e0 0%, transparent 60%), linear-gradient(var(--bg), var(--bg-deep));
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
main:focus { outline: none; }

/* ---------- Kopfzeile ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 10px max(20px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 10px 0 4px;
  background: none;
  border: 0;
  border-radius: 16px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: .01em;
}

.moon-mark, .moon {
  display: inline-block;
  border-radius: 50%;
  background: transparent;
  box-shadow: inset -9px -5px 0 0 var(--accent);
  transform: rotate(-22deg);
}
.moon-mark { width: 30px; height: 30px; }

.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.tool {
  min-width: 52px;
  min-height: 52px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-weight: 600;
  font-size: 17px;
}
.tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.tool:active { transform: scale(.96); }
.tool small { font-size: 13px; }

/* ---------- Grundlayout ---------- */

main {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 8px max(20px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

h1, h2, h3 { margin: 0; line-height: 1.15; text-wrap: balance; }

.hero { text-align: center; padding: 18px 0 26px; }
.hero .moon { width: 84px; height: 84px; box-shadow: inset -24px -13px 0 0 var(--accent); margin-bottom: 14px; }
.hero h1 { font-family: var(--serif); font-size: clamp(40px, 6vw, 58px); font-weight: 600; }
.hero p { margin: 10px auto 0; max-width: 30em; color: var(--muted); font-size: 20px; text-wrap: pretty; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

fieldset { border: 0; margin: 0 0 18px; min-width: 0; }
legend { padding: 0; margin-bottom: 14px; font-size: 22px; font-weight: 700; }
legend small { font-weight: 500; font-size: 16px; color: var(--muted); }

.ages { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; }
.age {
  aspect-ratio: 1;
  min-height: 52px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card-2);
  font-size: 24px;
  font-weight: 700;
}

.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 112px;
  padding: 12px 8px;
  border-radius: 20px;
  border: 2px solid var(--line);
  background: var(--card-2);
  font-weight: 600;
  font-size: 17px;
  text-align: center;
  line-height: 1.2;
}
.cat .icon { font-size: 38px; line-height: 1; }

.age[aria-pressed="true"], .cat[aria-pressed="true"], .seg[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.age:active, .cat:active, .seg:active, .option:active { transform: scale(.97); }

.field {
  width: 100%;
  min-height: 60px;
  padding: 0 20px;
  border-radius: 18px;
  border: 2px solid var(--line);
  background: var(--bg-deep);
  font-size: 19px;
}
.field::placeholder { color: var(--muted); opacity: .85; }
.field:focus { outline: none; border-color: var(--accent); }
.cats + .field { margin-top: 14px; }

.segs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.seg {
  min-height: 68px;
  padding: 8px;
  border-radius: 18px;
  border: 2px solid var(--line);
  background: var(--card-2);
  font-weight: 700;
  font-size: 18px;
  line-height: 1.2;
}
.seg small { display: block; font-weight: 500; font-size: 14px; opacity: .8; }

.primary {
  width: 100%;
  min-height: 72px;
  margin-top: 6px;
  border: 0;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 23px;
  font-weight: 800;
  box-shadow: 0 8px 24px rgba(245, 197, 107, 0.25);
}
.primary:active { transform: scale(.985); }
.primary:disabled { opacity: .55; }

.ghost {
  min-height: 56px;
  padding: 0 20px;
  border-radius: 18px;
  border: 2px solid var(--line);
  background: transparent;
  font-weight: 600;
  font-size: 17px;
}

.notice { margin: 0 0 16px; padding: 14px 18px; border-radius: 16px; background: var(--accent-soft); font-size: 17px; }
.notice.error { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); font-weight: 600; }
.hint { color: var(--muted); font-size: 15px; margin: 10px 2px 0; }

/* ---------- Regal ---------- */

.shelf { margin-top: 30px; }
.shelf h2 { font-size: 22px; margin-bottom: 12px; }
.shelf ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.shelf li { display: flex; gap: 8px; }
.book {
  flex: 1;
  min-height: 68px;
  padding: 10px 18px;
  text-align: left;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 700;
  font-size: 18px;
  line-height: 1.25;
}
.book small { display: block; font-weight: 500; color: var(--muted); font-size: 14px; margin-top: 2px; }
.book-remove { min-width: 56px; border-radius: 18px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 22px; }

/* ---------- Lesen ---------- */

.reader { width: min(760px, 100%); margin: 0 auto; }
.reader-head { text-align: center; padding: 10px 0 22px; }
.story-title { margin: 0 0 12px; color: var(--muted); font-size: 17px; font-weight: 600; letter-spacing: .02em; }
.reader-head h2 { font-family: var(--serif); font-weight: 600; font-size: clamp(30px, 4.6vw, 42px); }
.chapter-no { margin: 14px 0 6px; color: var(--accent); font-weight: 700; font-size: 16px; letter-spacing: .12em; text-transform: uppercase; }

.dots { display: flex; justify-content: center; gap: 8px; }
.dot { width: 12px; height: 12px; padding: 0; border-radius: 50%; border: 2px solid var(--line); background: transparent; }
.dot.done { background: var(--accent); border-color: var(--accent); opacity: .55; }
.dot.current { background: var(--accent); border-color: var(--accent); opacity: 1; transform: scale(1.3); }
button.dot { position: relative; }
button.dot::after { content: ""; position: absolute; inset: -14px -5px; }

.story-text {
  font-family: var(--serif);
  font-size: var(--story-size);
  line-height: 1.7;
  hyphens: auto;
  -webkit-hyphens: auto;
  text-wrap: pretty;
}
.story-text p { margin: 0 0 1em; border-radius: 10px; transition: background-color .3s; }
.story-text p:first-child::first-letter {
  font-size: 3.1em;
  line-height: .9;
  float: left;
  padding: .06em .1em 0 0;
  color: var(--accent);
  font-weight: 600;
}
.story-text p.speaking { background: var(--accent-soft); box-shadow: 0 0 0 8px var(--accent-soft); }
.story-text.streaming p:last-child::after {
  content: "";
  display: inline-block;
  width: .5em;
  height: .5em;
  margin-left: .25em;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.loading { text-align: center; padding: 70px 0 90px; }
.loading .moon { width: 96px; height: 96px; box-shadow: inset -27px -15px 0 0 var(--accent); animation: sway 3.2s ease-in-out infinite; }
.loading p { margin: 26px 0 0; font-size: 22px; color: var(--muted); min-height: 1.5em; }

.choice { margin-top: 34px; }
.choice h3 { font-family: var(--serif); font-weight: 600; font-size: clamp(24px, 3.4vw, 30px); text-align: center; margin-bottom: 18px; }
.options { display: grid; gap: 12px; }
.option {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 76px;
  padding: 14px 20px;
  text-align: left;
  border-radius: 20px;
  border: 2px solid var(--line);
  background: var(--card-2);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}
.option .num {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}
.own { display: flex; gap: 10px; margin-top: 14px; }
.own .field { flex: 1; min-width: 0; }
.own button { flex: none; min-width: 92px; min-height: 60px; border: 0; border-radius: 18px; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 19px; }
.choice .ghost { width: 100%; margin-top: 18px; }

.chosen { margin-top: 30px; text-align: center; }
.chosen p { margin: 0 0 14px; color: var(--muted); }
.chosen strong { color: var(--text); }

.the-end { margin-top: 34px; text-align: center; }
.the-end .flourish { font-family: var(--serif); font-size: 40px; color: var(--accent); margin: 0 0 6px; }
.the-end p { color: var(--muted); font-size: 20px; margin: 0 0 20px; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 26px; }
.pager .ghost { flex: 1; }
.pager .ghost:only-child { flex: 0 1 auto; margin-left: auto; }

.info { margin-top: 30px; text-align: center; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; opacity: .8; }

.noscript { padding: 40px; text-align: center; }

@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes sway { 0%, 100% { transform: rotate(-28deg); } 50% { transform: rotate(-14deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Hochformat und kleinere Geräte */
@media (max-width: 700px) {
  .brand-name { display: none; }
  .tool { min-width: 48px; min-height: 48px; padding: 0 10px; }
  .tool .label { display: none; }
  .card { padding: 16px; }
  .cats { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
  .segs { gap: 8px; }
}

.cat { hyphens: auto; -webkit-hyphens: auto; overflow-wrap: anywhere; }

.login { width: min(520px, 100%); padding-top: 6vh; }
.who { color: var(--muted); font-size: 15px; text-align: center; margin: 26px 0 0; }
.who button { background: none; border: 0; padding: 12px 8px; color: var(--text); text-decoration: underline; font-size: 15px; }
