:root {
  --cream: #f3e6c8;
  --red: #b3261e;
  --text: #f4e7cc;
  --muted: #b39a78;
  --brass: linear-gradient(180deg, #f8e3a2 0%, #d2a548 16%, #94661f 38%, #e2b85f 56%, #fff0b8 63%, #b5832e 80%, #6b4311 100%);
  --brass-h: linear-gradient(90deg, #6b4311 0%, #c79a3f 18%, #fbe6a6 40%, #d8ac52 58%, #8c5d1b 82%, #e6c26e 100%);
  --serif: "Libre Caslon Text", Georgia, serif;
  --slab: "Rokkitt", "Rockwell", Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  font-family: var(--serif);
  color: var(--text);
  background:
    radial-gradient(ellipse 90% 60% at 50% 30%, #3d1d0c 0%, #1d0c05 60%, #0f0603 100%);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Ladebildschirm ----------
   Ein kleiner Automat: Mahagoni-Schild im Messingrahmen, Fortschritts-Birnen, im Fenster eine Fallblattanzeige. */
.loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  background: radial-gradient(ellipse 90% 60% at 50% 40%, #3d1d0c 0%, #1d0c05 60%, #0f0603 100%);
  transition: opacity .45s ease-out, visibility 0s linear .45s;
}
.loader.done { opacity: 0; visibility: hidden; }
.loader-marquee {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(380px, 94vw);
  padding: 16px 14px 18px;
  border: 4px solid transparent;
  border-radius: 50% 50% 14px 14px / 46px 46px 14px 14px;
  background:
    linear-gradient(100deg, #4a120a 0%, #7b2415 22%, #5a170d 45%, #852b19 68%, #4c130a 100%) padding-box,
    var(--brass) border-box;
  box-shadow: 0 24px 50px rgba(0, 0, 0, .65), inset 0 0 0 2px rgba(0, 0, 0, .3);
}
.loader-plate {
  padding: 7px 14px 5px;
  border-radius: 6px;
  background: var(--brass);
  font: 900 1.05rem var(--slab);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #3a2208;
  text-shadow: 0 1px 0 rgba(255, 244, 205, .75);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(80, 45, 8, .55);
}
.loader-bulbs { display: flex; gap: 10px; }
.loader-bulbs i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff6d8, #f1c25a 55%, #9a6418);
  opacity: .25;
  transition: opacity .25s, box-shadow .25s;
}
/* Fortschritt: leuchtende Birnen von links, die nächste blinkt */
.loader-bulbs i.on { opacity: 1; box-shadow: 0 0 8px 2px rgba(255, 200, 90, .55); }
.loader-bulbs i.next { animation: bulbNext .7s ease-in-out infinite alternate; }
@keyframes bulbNext { to { opacity: .9; box-shadow: 0 0 6px 1px rgba(255, 200, 90, .4); } }
/* Fertig: alle Birnen blinken gemeinsam */
.loader.complete .loader-bulbs i { animation: bulbFlash .3s steps(1, end) 3; }
.loader.failed .loader-bulbs i { animation: none; }
@keyframes bulbFlash { 50% { opacity: .25; box-shadow: none; } }
/* „Starten“: erscheint, sobald alles geladen ist – der Druck darauf schaltet den Ton frei */
.loader-start {
  min-width: 190px;
  animation: startIn .45s ease-out both;
}
.loader-start[hidden] { display: none; }
@keyframes startIn { from { opacity: 0; transform: translateY(6px); } }

/* Fallblattanzeige: dunkle Blätter mit Mittelfuge, cremefarbene Lettern */
.flap-board {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  gap: 2px;
  width: 100%;
  margin-top: 4px;
  padding: 6px;
  border-radius: 8px;
  background: #0b0503;
  box-shadow: 0 0 0 3px #c89a42, 0 3px 8px rgba(0, 0, 0, .6), inset 0 3px 8px #000;
}
.flap {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 4.4;
  overflow: hidden;
  border-radius: 2px;
  background: linear-gradient(180deg, #2b1a10 0 49%, #120904 49% 51%, #23150c 51% 100%);
  font: 800 min(15px, 3.9vw) / 1 var(--slab);
  color: #f3e6c8;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .6);
}
/* Blatt fällt: obere Hälfte klappt nach unten */
.flap.flip::after {
  content: "";
  position: absolute;
  inset: 0 0 50% 0;
  background: linear-gradient(180deg, #3a2416, #1c0f07);
  transform-origin: 50% 100%;
  animation: flap .11s ease-in forwards;
}
@keyframes flap {
  from { transform: perspective(60px) rotateX(0deg); }
  to { transform: perspective(60px) rotateX(-90deg); }
}

/* ---------- Casino-Hintergrund ---------- */
.bokeh {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.bokeh span {
  position: absolute;
  border-radius: 50%;
  animation: twinkle var(--d, 6s) ease-in-out infinite alternate;
}
.bokeh::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 75% 70% at 50% 40%, transparent 30%, rgba(10, 4, 2, .85) 100%);
}
@keyframes twinkle { to { opacity: .25; transform: scale(.9); } }

main, .top, footer {
  width: min(520px, 100%);
  margin: 0 auto;
  padding: 0 16px;
}
main { flex: 1; }

.sr-only {
  position: absolute;
  overflow: hidden;
  white-space: nowrap;
}
.sr-only { width: 1px; height: 1px; clip: rect(0 0 0 0); }

.top {
  display: flex;
  justify-content: flex-end;
  padding-top: max(8px, env(safe-area-inset-top));
}
/* Lautsprecher-Symbol: mit Schallwellen = Ton an, durchgekreuzt = Ton aus */
.sound {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: color .2s;
}
.sound:hover, .sound:focus-visible { color: #f1d38a; outline: none; }
.sound:focus-visible { box-shadow: 0 0 0 2px #f1d38a; }
.sound[aria-pressed="true"] .off, .sound[aria-pressed="false"] .on { display: none; }
.sound[aria-pressed="false"] { opacity: .7; }

/* ---------- Material ---------- */
.brass { background: var(--brass); }

/* Konfetti beim Gewinn: über den Casino-Lichtern, aber hinter Automat und Inhalt */
.confetti {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- Automat ----------
   Gezeichnet wird der Automat auf einer Leinwand (public/machine3d.js): ein Cycles-Render aus Blender (blender/),
   dazu live die Walzen, der Hebel und das Lauflicht. Das Seitenverhältnis ist das des Renders. */
.machine {
  position: relative;
  aspect-ratio: 1200 / 1584;
  margin: 4px -6px 0;
}

/* Die Leinwand erscheint erst, wenn das erste vollständige Bild steht – vorher bleibt die Fläche leer. */
.machine3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity .35s ease-out;
}
.machine3d.ready { opacity: 1; }

/* Grifffläche des Hebels (Lage und Größe setzt machine3d.js passend zum Modell) */
.lever {
  position: absolute;
  z-index: 3;
  top: 0;
  right: 0;
  width: 25%;
  height: 70%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  outline: none;
  border-radius: 10px;
}
.lever.dragging { cursor: grabbing; }
body.intro .lever { pointer-events: none; }   /* während des Kameraflugs zum Automaten */
body.spinning .lever { cursor: progress; }
.lever:focus-visible { outline: 2px solid #f1d38a; outline-offset: 2px; }

/* Ohne WebGL kein Automat – nur ein Hinweis */
.no-webgl {
  margin: 40px 0;
  font-style: italic;
  text-align: center;
  color: var(--muted);
}

/* Der Automat ruckelt kurz, wenn der Hebel einrastet oder anschlägt – samt Hebel */
.machine.shake { animation: shake .32s cubic-bezier(.3, .7, .4, 1); }
@keyframes shake {
  20% { transform: translate(0, 2px); }
  45% { transform: translate(-1px, -1px); }
  70% { transform: translate(1px, .5px); }
}

/* ---------- Aktionen ---------- */
.actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 26px 0 0;
  transition: opacity .4s;
}
.actions.hidden { display: none; }
.button {
  min-height: 46px;
  padding: 0 24px;
  font: 800 .85rem var(--slab);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #3a2208;
  text-shadow: 0 1px 0 rgba(255, 244, 205, .7);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 4px 0 #4a2d08, 0 6px 12px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(80, 45, 8, .5);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.button:active { transform: translateY(3px); box-shadow: 0 1px 0 #4a2d08, 0 2px 6px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(80, 45, 8, .5); }
.button[aria-pressed="true"] { background: linear-gradient(180deg, #d44a3b, #8f1a10 60%, #5c0905); color: var(--cream); text-shadow: 0 -1px 0 rgba(0, 0, 0, .4); }

/* ---------- Archiv ---------- */
.archive { margin: 28px 0 32px; }
.tabs { display: flex; gap: 24px; border-bottom: 1px solid rgba(226, 184, 95, .3); }
.tab {
  position: relative;
  padding: 12px 0;
  font: 800 .78rem var(--slab);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: #f1d38a; }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 3px;
  background: var(--brass-h);
}
#favCount { color: #e46a5b; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid rgba(226, 184, 95, .14);
}
.list li::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  background: var(--red);
  transform: rotate(45deg);
}
.list li span { flex: 1; font-size: 1.05rem; line-height: 1.3; }
.list li button {
  flex: none;
  min-width: 40px;
  min-height: 40px;
  font-size: 1rem;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.empty { margin: 16px 0 0; font-style: italic; color: var(--muted); }
.empty[hidden] { display: none; }

footer {
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  text-align: center;
  font: 700 .7rem var(--slab);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: #6e5a44;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 11px 20px 9px;
  transform: translate(-50%, 16px);
  opacity: 0;
  visibility: hidden;
  font: 800 .8rem var(--slab);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #3a2208;
  background: var(--brass);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .5);
  transition: opacity .3s, transform .3s, visibility 0s .3s;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }

:focus-visible { outline: 2px solid #f1d38a; outline-offset: 3px; }

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