/* ===== Lokale Handschrift-Schrift (Google Fonts: Dancing Script, variabel) ===== */
@font-face {
  font-family: 'Dancing Script';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/dancing-script-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Dancing Script';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/dancing-script-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --paper: #f6f1e7;
  --paper-shade: #efe7d8;
  --ink-user: #1c2a4a;
  --ink-reply: #6b4423;
  --reply-font: 'Dancing Script', 'Segoe Script', cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  position: fixed;           /* verhindert Scroll-Bounce auf iPad/Android */
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Papier + Schreibfläche ===== */
#ink {
  position: fixed;
  inset: 0;
  touch-action: none;
  cursor: crosshair;
  /* dezente Papiertextur, rein per CSS (liegt HINTER der Tinte) */
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, 0.55), rgba(0, 0, 0, 0) 65%),
    repeating-linear-gradient(0deg, rgba(120, 96, 60, 0.022) 0 2px, rgba(0, 0, 0, 0) 2px 5px),
    repeating-linear-gradient(90deg, rgba(120, 96, 60, 0.018) 0 3px, rgba(0, 0, 0, 0) 3px 7px),
    linear-gradient(160deg, var(--paper) 0%, var(--paper-shade) 100%);
}
#ink.eraser-active { cursor: cell; }

/* ===== Gestreamte Antwort (Handschrift-Animation) ===== */
#reply {
  position: fixed;
  pointer-events: none;
  font-family: var(--reply-font);
  color: var(--ink-reply);
  z-index: 5;
}
#reply .line { white-space: pre; min-height: 1em; }
#reply .w {
  display: inline;
  opacity: 0;
  animation: ink-in 0.55s ease-out forwards;
}
/* buchstabenweises "Schreiben" der Tagebuch-Antwort */
#reply .ch {
  display: inline;
  opacity: 0;
  animation: ink-ch 0.24s ease-out forwards;
}
@keyframes ink-ch {
  from { opacity: 0; filter: blur(1.5px); }
  to   { opacity: 1; filter: blur(0); }
}
#reply.error-note {
  opacity: 0.75;
  font-size: 0.85em;
  transition: opacity 1.2s ease;
}
@keyframes ink-in {
  from { opacity: 0; filter: blur(2px); }
  60%  { opacity: 0.85; }
  to   { opacity: 1; filter: blur(0); }
}

/* ===== Seitenwechsel-Blende ===== */
#pageturn {
  position: fixed;
  inset: 0;
  background: var(--paper);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
  z-index: 8;
}
#pageturn.active { opacity: 1; }

/* ===== Status-Punkt ===== */
#status {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink-reply);
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 10;
}
#status.busy {
  opacity: 0.6;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.35; }
  50%      { transform: scale(1.5); opacity: 0.75; }
}

/* ===== Banner (Fehler / Hinweise) ===== */
#banner {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(85vw, 480px);
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(60, 42, 20, 0.88);
  color: #f6f1e7;
  font: 14px/1.45 system-ui, sans-serif;
  text-align: center;
  z-index: 20;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}
#banner a { color: #ffd9a0; }

/* ===== Werkzeuge: blasser Punkt, expandiert bei Tipp ===== */
#tools {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 10;
}
#toolsToggle {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-reply);
  font-size: 18px;
  opacity: 0.18;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.3s ease, background 0.3s ease;
}
#toolsToggle:hover, #tools.open #toolsToggle {
  opacity: 0.85;
  background: rgba(107, 68, 35, 0.08);
}
#toolsMenu {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(107, 68, 35, 0.22);
  background: rgba(255, 253, 247, 0.97);
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.16);
  min-width: 230px;
  max-width: min(78vw, 300px);
  max-height: min(70vh, 560px);
  overflow-y: auto;
  font: 15px/1.35 system-ui, sans-serif;
  color: #4a321e;
}
#toolsMenu[hidden], #reply[hidden], #banner[hidden], #sendBtn[hidden] { display: none; }

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.menu-section + .menu-section {
  border-top: 1px solid rgba(107, 68, 35, 0.15);
  padding-top: 10px;
}
.menu-heading {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
}
#toolsMenu button {
  border: 1px solid rgba(107, 68, 35, 0.25);
  border-radius: 10px;
  background: rgba(255, 253, 247, 0.92);
  color: #4a321e;
  font: 15px/1 system-ui, sans-serif;
  padding: 11px 14px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
#toolsMenu button:active { background: #efe4d2; }
#toolsMenu button[aria-pressed="true"] {
  background: #e6d5bd;
  border-color: rgba(107, 68, 35, 0.55);
}

.menu-field { display: flex; flex-direction: column; gap: 3px; }
.menu-label { font-size: 12px; opacity: 0.65; }
.menu-field select {
  border: 1px solid rgba(107, 68, 35, 0.3);
  border-radius: 8px;
  background: #fffdf7;
  color: #4a321e;
  font: 14px system-ui, sans-serif;
  padding: 8px 10px;
  max-width: 100%;
}

.menu-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
}
.menu-check input { width: 17px; height: 17px; accent-color: #6b4423; }

.menu-cta { font-size: 13.5px; line-height: 1.45; opacity: 0.9; }
.menu-cta a, .menu-links a { color: #6b4423; font-weight: 600; }

.menu-links {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 13px;
}
.menu-links a { text-decoration: none; opacity: 0.75; }
.menu-links a:hover { text-decoration: underline; opacity: 1; }
.menu-user { opacity: 0.6; font-size: 13px; }

/* ===== Manueller Auslöser (✒) ===== */
#sendBtn {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(107, 68, 35, 0.3);
  background: rgba(255, 253, 247, 0.9);
  color: var(--ink-reply);
  font-size: 24px;
  cursor: pointer;
  touch-action: manipulation;
  opacity: 0.75;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.12);
  transition: opacity 0.3s ease, transform 0.15s ease;
  z-index: 10;
}
#sendBtn:hover { opacity: 1; }
#sendBtn:active { transform: translateX(-50%) scale(0.94); }

/* Tablets im Querformat & Desktop: etwas größere Antwortschrift kommt aus JS */
@media (pointer: coarse) {
  #toolsToggle { width: 48px; height: 48px; font-size: 20px; }
  #toolsMenu button { padding: 14px 18px; font-size: 16px; }
}

/* ============================================================
   Intro: das Tagebuch klappt auf
   Ablauf: Buch erscheint (0–0,7 s) → Einband öffnet (0,8–2,1 s,
   Buch rückt dabei in die Mitte) → ein Blatt schlägt um (1,9–2,9 s)
   → Zoom in die Seite + Überblendung (ab 2,9 s, js/intro.js räumt auf)
   ============================================================ */
#intro {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 32%, #4c3a26 0%, #2c2115 55%, #1d1610 100%);
  perspective: 1500px;
  cursor: pointer;
  transition: opacity 0.7s ease;
}
#intro.out { opacity: 0; pointer-events: none; }

#intro .book {
  /* --bw = Breite EINER Buchseite */
  --bw: min(38vw, 34vh, 280px);
  --bh: calc(var(--bw) * 1.35);
  position: relative;
  width: calc(var(--bw) * 2);
  height: var(--bh);
  transform-style: preserve-3d;
  animation:
    book-in 0.7s ease-out both,
    book-shift 1.3s cubic-bezier(0.65, 0, 0.3, 1) 0.8s both,
    book-zoom 1.1s cubic-bezier(0.6, 0, 0.8, 1) 2.9s both;
}
/* weicher Schatten auf dem "Tisch" */
#intro .book::before {
  content: '';
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: -9%;
  height: 14%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 70%);
}

/* hinterer Buchdeckel (schaut minimal unter den Seiten hervor) */
#intro .book-backboard {
  position: absolute;
  left: 50%;
  top: -1.5%;
  width: 51.5%;
  height: 103%;
  background: linear-gradient(135deg, #4e3319, #33200e);
  border-radius: 0 10px 10px 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* rechte Buchhälfte: Seitenstapel mit der späteren Schreibseite */
#intro .book-base {
  position: absolute;
  left: 50%;
  top: 0;
  width: 50%;
  height: 100%;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0) 12%),
    linear-gradient(160deg, #f6f1e7, #efe7d8);
  border-radius: 0 6px 6px 0;
  /* Kanten des Seitenstapels */
  box-shadow:
    2px 1px 0 #e6dcc9,
    4px 3px 0 #f2ebdc,
    6px 5px 0 #e6dcc9,
    8px 7px 0 #f2ebdc;
}

/* umklappende Elemente: Einband und ein Blatt */
#intro .book-cover,
#intro .book-leaf {
  position: absolute;
  left: 50%;
  top: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
}
#intro .book-cover {
  z-index: 6;
  animation: flip-open 1.3s cubic-bezier(0.65, 0, 0.3, 1) 0.8s both;
}
#intro .book-leaf {
  z-index: 5;
  animation: flip-open 1s cubic-bezier(0.6, 0, 0.35, 1) 1.9s both;
}

#intro .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
#intro .face.back { transform: rotateY(180deg); }

/* Einband vorn: Leder mit Goldprägung */
#intro .cover-front {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--bw) * 0.05);
  background:
    radial-gradient(ellipse at 30% 25%, rgba(255, 220, 160, 0.14), rgba(0, 0, 0, 0) 55%),
    linear-gradient(135deg, #6a4526 0%, #4a2f16 55%, #38230f 100%);
  border-radius: 0 10px 10px 0;
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.28),
    inset 0 0 44px rgba(0, 0, 0, 0.38);
}
#intro .cover-front::before {
  content: '';
  position: absolute;
  inset: 7%;
  border: 1.5px solid rgba(210, 175, 110, 0.55);
  border-radius: 5px;
}
#intro .cover-title {
  font-family: var(--reply-font);
  font-weight: 600;
  font-size: calc(var(--bw) * 0.17);
  color: #d9b877;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}
#intro .cover-orn {
  color: rgba(217, 184, 119, 0.85);
  font-size: calc(var(--bw) * 0.08);
}

/* Einband innen: Vorsatzpapier */
#intro .cover-back {
  background:
    linear-gradient(270deg, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0) 14%),
    linear-gradient(200deg, #efe7d8, #e6dcc9);
  border-radius: 10px 0 0 10px;
}

/* umklappendes Blatt: vorn mit angedeuteten alten Zeilen, hinten blanko */
#intro .leaf-front {
  background:
    repeating-linear-gradient(
      180deg,
      rgba(0, 0, 0, 0) 0 calc(var(--bh) * 0.09),
      rgba(107, 68, 35, 0.16) calc(var(--bh) * 0.09) calc(var(--bh) * 0.098),
      rgba(0, 0, 0, 0) calc(var(--bh) * 0.098) calc(var(--bh) * 0.115)
    ) 0 calc(var(--bh) * 0.12) / 78% calc(var(--bh) * 0.62) no-repeat,
    linear-gradient(90deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0) 12%),
    linear-gradient(160deg, #f6f1e7, #efe7d8);
  background-position: 11% calc(var(--bh) * 0.12), 0 0, 0 0;
  border-radius: 0 6px 6px 0;
}
#intro .leaf-back {
  background:
    linear-gradient(270deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0) 12%),
    linear-gradient(200deg, #f6f1e7, #efe7d8);
  border-radius: 6px 0 0 6px;
}

@keyframes book-in {
  from { opacity: 0; transform: translateX(-25%) translateY(4vh) scale(0.94); }
  to   { opacity: 1; transform: translateX(-25%) translateY(0) scale(1); }
}
/* beim Öffnen rückt das Buch physikalisch korrekt in die Mitte */
@keyframes book-shift {
  from { transform: translateX(-25%); }
  to   { transform: translateX(0); }
}
@keyframes flip-open {
  from { transform: rotateY(0deg); }
  to   { transform: rotateY(-180deg); }
}
/* Zoom in die aufgeschlagene Seite */
@keyframes book-zoom {
  from { transform: translateX(0) scale(1); }
  to   { transform: translateX(-12%) translateY(4%) scale(2.7); }
}
