:root {
  --night-1: #1b1e3f;
  --night-2: #2c245a;
  --night-3: #4b2f63;
  --cream: #fdf4e3;
  --cream-2: #faead1;
  --amber: #f2b86a;
  --amber-2: #e89a55;
  --plum: #6f4b8e;
  --ink: #3a2f4c;
  --ink-soft: #7a6b8f;
  --radius: 24px;
  --shadow: 0 18px 45px rgba(12, 10, 35, 0.45);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100vh; }

body {
  background: radial-gradient(1200px 700px at 80% -10%, var(--night-3), transparent 60%),
              radial-gradient(900px 700px at 0% 110%, #3d2a5e, transparent 55%),
              linear-gradient(160deg, var(--night-1), var(--night-2) 60%, var(--night-3));
  color: var(--cream);
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  padding: calc(28px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           calc(40px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

/* sterrenveld */
.stars {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(1.6px 1.6px at 12% 22%, rgba(255,255,255,.85), transparent 60%),
    radial-gradient(1.2px 1.2px at 78% 12%, rgba(255,255,255,.7), transparent 60%),
    radial-gradient(2px 2px at 34% 60%, rgba(255,255,255,.8), transparent 60%),
    radial-gradient(1px 1px at 62% 40%, rgba(255,255,255,.9), transparent 60%),
    radial-gradient(1.5px 1.5px at 88% 66%, rgba(255,255,255,.75), transparent 60%),
    radial-gradient(1.2px 1.2px at 48% 82%, rgba(255,255,255,.7), transparent 60%),
    radial-gradient(1.8px 1.8px at 20% 80%, rgba(255,255,255,.7), transparent 60%),
    radial-gradient(1px 1px at 94% 30%, rgba(255,255,255,.8), transparent 60%);
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .5; } to { opacity: 1; } }

/* maan */
.moon {
  position: fixed; top: 38px; right: 34px; z-index: 1; pointer-events: none;
  width: 84px; height: 84px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fffbe8, #ffe9a8 55%, #f4c96c);
  box-shadow: 0 0 60px 18px rgba(255, 233, 168, 0.35);
}
.moon::before {
  content: ""; position: absolute; top: 16px; left: 20px;
  width: 14px; height: 14px; border-radius: 50%; background: rgba(185, 160, 90, 0.35);
  box-shadow: 34px 26px 0 rgba(185,160,90,.3), 18px 44px 0 rgba(185,160,90,.25);
}

.wrap { position: relative; z-index: 2; width: 100%; max-width: 640px; padding-top: 20px; }

.head { text-align: center; margin-bottom: 26px; position: relative; }
.logout {
  position: absolute; top: 0; right: 0;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255,255,255,.14);
  color: var(--cream); font-size: 12px; padding: 6px 12px; border-radius: 999px;
  cursor: pointer; transition: background .2s;
}
.logout:hover { background: rgba(255,255,255,.18); }
/* inloggen */
.card.auth { text-align: left; }
.card.auth h2 { font-size: 22px; margin-bottom: 4px; }
.auth .input { margin-top: 12px; }
.auth .btn { margin-top: 14px; width: 100%; }
.auth-msg { margin-top: 12px; font-size: 13px; min-height: 18px; }
.auth-msg.err { color: #ffb3b3; }
.auth-msg.ok { color: #a8e6b8; }
.logo-moon { font-size: 40px; display: block; margin-bottom: 6px; }
.head h1 {
  font-size: 44px; letter-spacing: 2px; font-weight: 700;
  background: linear-gradient(120deg, #fff, var(--amber));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { margin-top: 8px; color: #e8d7c4; font-size: 15px; }

.card {
  background: linear-gradient(180deg, var(--cream), var(--cream-2));
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 26px 30px;
  margin-bottom: 22px;
  transition: opacity .35s ease, transform .35s ease;
}

.options { display: flex; flex-direction: column; gap: 6px; }

.lbl { font-weight: 700; font-size: 14px; color: var(--plum); margin: 16px 0 4px; letter-spacing: .3px; }
.select, .input {
  width: 100%; padding: 13px 14px; font-size: 15px; color: var(--ink);
  background: #fff9; border: 1.6px solid #e4d3b6; border-radius: 14px;
  outline: none; transition: border .2s;
}
.select:focus, .input:focus { border-color: var(--amber-2); }
.opt { font-weight: 400; color: var(--ink-soft); font-size: 12px; }

.ages { display: flex; flex-wrap: wrap; gap: 8px; }
.ages button {
  flex: 1 1 40px; min-width: 40px; padding: 10px 0; text-align: center;
  font-weight: 700; font-size: 15px; border-radius: 12px;
  background: #fff7; color: var(--ink); border: 1.6px solid #e4d3b6; cursor: pointer;
  transition: all .15s;
}
.ages button.on { background: var(--amber-2); border-color: #c97f3c; color: #fff; box-shadow: 0 4px 12px rgba(232,154,85,.4); }

.tones { display: flex; flex-wrap: wrap; gap: 8px; }
.tones button {
  padding: 10px 14px; font-size: 14px; font-weight: 600; border-radius: 999px;
  background: #fff7; color: var(--plum); border: 1.6px solid #e4d3b6; cursor: pointer;
  transition: all .15s;
}
.tones button.on { background: var(--plum); border-color: var(--plum); color: #fff; box-shadow: 0 4px 14px rgba(111,75,142,.35); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin: 22px 0 4px; padding: 14px 16px;
  background: #fff7; border: 1.6px solid #e4d3b6; border-radius: 14px;
}
.toggle-row strong { font-size: 15px; display: block; }
.sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }

.switch { position: relative; width: 56px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 999px;
  background: #d9c9ae; cursor: pointer; transition: background .2s;
}
.slider::before {
  content: ""; position: absolute; width: 25px; height: 25px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--amber-2); }
.switch input:checked + .slider::before { transform: translateX(25px); }

.btn {
  margin-top: 26px; display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; padding: 17px; font-size: 19px; font-weight: 800; letter-spacing: .4px;
  color: #fff; border: none; cursor: pointer; border-radius: 16px;
  background: linear-gradient(120deg, var(--amber-2), var(--plum) 90%);
  box-shadow: 0 10px 24px rgba(111,75,142,.45);
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(111,75,142,.5); filter: brightness(1.04); }
.btn:active { transform: translateY(0); }
.btn:disabled { filter: grayscale(.4) brightness(.85); cursor: not-allowed; transform: none; }
.btn-moon { font-size: 22px; }

/* loading */
.loading { text-align: center; padding: 50px 30px; }
.spinner { font-size: 64px; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.loading p { color: var(--plum); font-weight: 700; font-size: 18px; margin-top: 18px; }
.hint { font-weight: 400 !important; font-size: 14px !important; color: var(--ink-soft) !important; margin-top: 8px; }

/* resultaat */
.result { position: relative; }
.again {
  position: absolute; top: 16px; right: 16px; z-index: 2;
  padding: 9px 14px; border: none; border-radius: 999px; cursor: pointer;
  background: var(--plum); color: #fff; font-weight: 700; font-size: 13px;
  box-shadow: 0 4px 12px rgba(111,75,142,.3); transition: transform .15s;
}
.again:hover { transform: scale(1.04); }
.result-bar { position: relative; min-height: 40px; }
.back {
  position: absolute; top: 16px; left: 16px; z-index: 2;
  padding: 9px 14px; border: 1px solid rgba(255,255,255,.18); border-radius: 999px; cursor: pointer;
  background: rgba(255,255,255,.06); color: var(--cream); font-weight: 600; font-size: 13px;
  transition: background .2s;
}
.back:hover { background: rgba(255,255,255,.15); }
#imageWrap { margin: 0 0 20px; border-radius: 18px; overflow: hidden; }
#image { width: 100%; display: block; border-radius: 18px; box-shadow: 0 8px 20px rgba(0,0,0,.18); }
.rtitle { font-size: 26px; color: var(--plum); margin-bottom: 14px; }
.story {
  font-size: 17.5px; line-height: 1.75; color: var(--ink);
  white-space: pre-wrap; font-family: Georgia, "Times New Roman", serif;
}
.story::first-letter { font-size: 2.2em; color: var(--amber-2); font-weight: 700; }
.goodnight {
  margin-top: 26px; text-align: center; font-size: 16px; font-weight: 700;
  color: var(--plum); border-top: 1.6px dashed #e0cdb0; padding-top: 18px;
}
.saved-note {
  margin-top: 14px; text-align: center; font-size: 13.5px; color: #4c9e63; font-weight: 600;
  background: #eaf6ec; border: 1.4px dashed #9fd0ae; border-radius: 999px; padding: 8px 14px;
  display: inline-block; width: 100%;
}

/* bibliotheek */
.lib { margin: 6px 0 0; }
.lib-title {
  font-size: 21px; color: #f4e3c8; letter-spacing: .3px;
  display: flex; align-items: center; gap: 8px;
}
.lib-sub { color: #d9c6e8; font-size: 13.5px; margin: 6px 0 18px; opacity: .92; }
.lib-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.lib-card {
  position: relative; background: linear-gradient(180deg, var(--cream), var(--cream-2));
  color: var(--ink); border-radius: 18px; overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow); border: 1px solid rgba(255,255,255,.12);
  transition: transform .15s, box-shadow .15s;
  display: flex; flex-direction: column;
}
.lib-card:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(12,10,35,.5); }
.lib-thumb {
  width: 100%; height: 130px; object-fit: cover; background: linear-gradient(135deg, #e6d7c2, #f6ead6);
  display: block;
}
.lib-thumb-placeholder {
  height: 130px; display: flex; align-items: center; justify-content: center;
  font-size: 40px; background: linear-gradient(135deg, #6f4b8e, #8a63b0); color: rgba(255,255,255,.75);
}
.lib-body { padding: 13px 14px 14px; flex: 1; }
.lib-body h3 { font-size: 15.5px; line-height: 1.3; color: var(--plum); margin-bottom: 8px; }
.lib-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.lib-tag {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: #eee0cb; color: var(--plum);
}
.lib-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 14px; border-top: 1px solid #ecddc6; font-size: 12px; color: var(--ink-soft); }
.lib-del {
  border: none; background: transparent; font-size: 15px; cursor: pointer;
  color: #c07a6b; padding: 4px; border-radius: 8px; transition: background .15s;
}
.lib-del:hover { background: #f6ded7; }
.lib-meta .d { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lib-card.open { outline: 3px solid var(--amber-2); }
.lib-empty { text-align: center; color: #e0cfd8; font-size: 14px; padding: 30px 12px; border: 1.6px dashed #5b4777; border-radius: 18px; }

.foot { text-align: center; color: #d9c6e8; font-size: 12.5px; opacity: .85; }

.hidden { display: none !important; }

@media (max-width: 480px) {
  .moon { width: 56px; height: 56px; top: 26px; right: 22px; }
  .head h1 { font-size: 36px; }
  .card { padding: 22px 18px 24px; }
}
