/* Würfeln: Tisch mit beliebig vielen Würfeln, Ergebnis, Werkbank-Karten je Würfel. */

.buehne-wuerfel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 6px 12px 10px;
}

/* ---------- Tisch ---------- */
.wuerfel-flaeche {
  --w: min(44vw, 30dvh, 210px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  align-content: center;
  gap: calc(var(--w) * .22);
  width: 100%;
  max-width: 820px;
  min-height: calc(var(--w) * 1.6);
  padding: calc(var(--w) * .25) 8px calc(var(--w) * .1);
}
/* Würfelbrett: Filz mit hellem Rand — dieselbe Sprache wie der Spieltisch der Flasche.
   Die Fläche bleibt, wie sie war; das Brett liegt als eigene Schicht dahinter. */
.wuerfel-flaeche { position: relative; isolation: isolate; }
.wuerfel-flaeche::before {
  content: "";
  position: absolute;
  inset: calc(var(--w) * .08) 0 calc(var(--w) * -.05);
  z-index: -1;
  border-radius: 32px;
  background:
    radial-gradient(circle, rgba(255, 255, 255, .05) 1px, transparent 1.5px) 0 0 / 5px 5px,
    radial-gradient(ellipse at 45% 30%, #3b3aa8, #2a2580 55%, #191550 100%);
  box-shadow:
    inset 0 0 0 10px rgba(255, 255, 255, .7),
    inset 0 0 0 12px rgba(255, 255, 255, .3),
    inset 0 0 40px 12px rgba(20, 8, 60, .35),
    0 18px 40px rgba(80, 60, 160, .25);
}
.wuerfel-flaeche.g2 { --w: min(36vw, 26dvh, 180px); }
.wuerfel-flaeche.g4 { --w: min(28vw, 21dvh, 150px); }
.wuerfel-flaeche.g6 { --w: min(25vw, 18dvh, 128px); }
.wuerfel-flaeche.g12 { --w: min(19vw, 14dvh, 100px); }
.wuerfel-flaeche.g24 { --w: min(14.5vw, 10dvh, 78px); }

.wuerfel {
  position: relative;
  width: var(--w);
  height: var(--w);
  padding: 0;
  border: 0;
  background: none;
  color: var(--w-schrift);
  perspective: calc(var(--w) * 4);
  container-type: inline-size;
  rotate: var(--w-kipp);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.wuerfel:focus-visible { outline: 2px solid var(--akzent); outline-offset: 6px; border-radius: 22%; }
/* Weicher Schatten auf dem Tisch */
.wuerfel::before {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -9%;
  height: 16%;
  border-radius: 50%;
  background: rgb(10, 4, 30);
  opacity: .45;
  filter: blur(6px);
}

/* Festgehalten: Ring im Akzent und ein kleines Schild */
.wuerfel.gehalten { scale: .92; }
.wuerfel.gehalten::after {
  content: "fest";
  position: absolute;
  left: 50%;
  bottom: -30%;
  translate: -50% 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--verlauf);
  color: #fff;
  font-size: max(11px, 12cqw);
  font-weight: 650;
  box-shadow: 0 4px 12px rgba(139, 92, 246, .35);
}
.wuerfel.gehalten .w6-seite, .wuerfel.gehalten .w-form { box-shadow: 0 0 0 3px var(--akzent); }
.wuerfel.gehalten .w-form { box-shadow: none; filter: drop-shadow(0 0 0 var(--akzent)) drop-shadow(0 0 3px var(--akzent)); }

/* ---------- Sechsseiter in 3D ---------- */
.w6-koerper {
  position: absolute;
  inset: 7%;
  transform-style: preserve-3d;
}
.w6-seite {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 10%;
  border-radius: 18%;
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, .45), transparent 55%),
    linear-gradient(160deg, color-mix(in oklab, var(--w-farbe) 88%, #fff), color-mix(in oklab, var(--w-farbe) 82%, #000));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35), inset 0 -4cqw 8cqw rgba(0, 0, 0, .12);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
/* Kern: eckige Platten knapp unter den runden Seiten — füllen die Ecken (gerundete Kanten) */
.w6-kern {
  position: absolute;
  inset: 3.5%;
  border-radius: 13%;
  background: color-mix(in oklab, var(--w-farbe) 70%, #000);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.w6-kern.vorn { transform: translateZ(41.5cqw); }
.w6-kern.rechts { transform: rotateY(90deg) translateZ(41.5cqw); }
.w6-kern.hinten { transform: rotateY(180deg) translateZ(41.5cqw); }
.w6-kern.links { transform: rotateY(-90deg) translateZ(41.5cqw); }
.w6-kern.oben { transform: rotateX(90deg) translateZ(41.5cqw); }
.w6-kern.unten { transform: rotateX(-90deg) translateZ(41.5cqw); }
.w6-seite.vorn { transform: translateZ(43cqw); }
.w6-seite.rechts { transform: rotateY(90deg) translateZ(43cqw); }
.w6-seite.hinten { transform: rotateY(180deg) translateZ(43cqw); }
.w6-seite.links { transform: rotateY(-90deg) translateZ(43cqw); }
.w6-seite.oben { transform: rotateX(90deg) translateZ(43cqw); }
.w6-seite.unten { transform: rotateX(-90deg) translateZ(43cqw); }

.augen {
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  place-items: center;
  width: 82%;
  height: 82%;
}
.augen i { width: 70%; aspect-ratio: 1; border-radius: 50%; }
.augen i.auge {
  background: var(--w-schrift);
  box-shadow: inset 0 1.2cqw 1.6cqw rgba(0, 0, 0, .35);
}

/* ---------- Echte 3D-Würfel (WebGL) ----------
   Die Leinwand ist größer als der Knopf, damit Ecken beim Überschlagen nicht abgeschnitten werden. */
.w-3d {
  position: absolute;
  left: -14%;
  top: -14%;
  width: 128%;
  height: 128%;
  pointer-events: none;
}
.wuerfel.gehalten .w-3d { filter: drop-shadow(0 0 2px var(--akzent)) drop-shadow(0 0 6px var(--akzent)); }

/* ---------- Andere Seitenzahlen als Form ---------- */
.w-flach { position: absolute; inset: 0; }
.w-form { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 4px 6px rgba(80, 60, 160, .2)); }
.w-flaeche { fill: var(--w-farbe); stroke: color-mix(in oklab, var(--w-farbe) 55%, #fff); stroke-width: 1.6; stroke-linejoin: round; }
.w-form .wv-hell { stop-color: color-mix(in oklab, var(--w-farbe) 72%, #fff); }
.w-form .wv-mitte { stop-color: var(--w-farbe); }
.w-form .wv-dunkel { stop-color: color-mix(in oklab, var(--w-farbe) 72%, #000); }
.w-facette { fill: rgba(255, 255, 255, .12); stroke: rgba(0, 0, 0, .14); stroke-width: 1; stroke-linejoin: round; }
.w-kante { stroke: rgba(0, 0, 0, .14); stroke-width: 1; }
.w-glanz { fill: rgba(255, 255, 255, .28); }
.w-schild {
  position: absolute;
  inset: 22%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2cqw;
}
.w-schild.unten { inset: 34% 24% 12%; }

/* Text und Bild auf einer Seite (beide Bauarten) */
.w-text {
  max-width: 100%;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.02em;
  text-align: center;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.w6-seite img, .w-schild img {
  width: 74%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5cqw rgba(255, 255, 255, .7);
}
.w-text.mit-bild { margin-top: -6cqw; padding: 1cqw 3cqw; border-radius: 999px; background: rgba(255, 255, 255, .85); color: #1e1b3a; }

/* Pasch: alle Würfel leuchten golden auf */
/* am Knopf, nicht am Körper: ein filter auf preserve-3d drückt den Würfel flach */
.wuerfel-flaeche.jubel .wuerfel:not(.gehalten) { animation: pasch-jubel 1.4s ease-out; }
@keyframes pasch-jubel {
  0% { filter: drop-shadow(0 0 0 rgba(253, 224, 71, 0)); }
  25% { filter: drop-shadow(0 0 18px rgba(253, 224, 71, .95)) brightness(1.15); }
  100% { filter: drop-shadow(0 0 0 rgba(253, 224, 71, 0)); }
}
@media (prefers-reduced-motion: reduce) {
  .wuerfel-flaeche.jubel .wuerfel { animation: none; }
}

/* ---------- Ergebnis ---------- */
.wuerfel-ergebnis { display: grid; justify-items: center; gap: 2px; min-height: 4.4rem; text-align: center; }
.w-ergebnis {
  margin: 0;
  font-size: clamp(2.6rem, 13vw, 4.2rem);
  font-weight: 750;
  letter-spacing: -.04em;
  line-height: 1;
}
.w-ergebnis.lang { font-size: clamp(1.4rem, 6vw, 2.2rem); letter-spacing: -.02em; }
.w-ergebnis.neu { animation: aufploppen .4s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes aufploppen { from { transform: scale(.5); opacity: 0; } }
.w-ergebnis-detail { margin: 0; min-height: 1.2em; font-weight: 550; color: var(--tusche-weich); }

.wuerfel-knoepfe { display: grid; justify-items: center; gap: 8px; }
.wurf-knopf {
  min-width: min(80vw, 300px);
  min-height: 60px;
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: -.01em;
}
/* Würfe pro Runde (A.16.1.0): „Wurf 2 von 3“ mit Punkten */
.wurf-zaehler { margin: 0; display: flex; align-items: center; gap: 10px; font-size: .95rem; font-weight: 600; color: var(--tusche-weich); }
.wurf-zaehler .punkte { display: inline-flex; gap: 6px; }
.wurf-zaehler .punkte i { width: 11px; height: 11px; border-radius: 50%; border: 2px solid currentColor; opacity: .5; }
.wurf-zaehler .punkte i.an { background: var(--akzent); border-color: var(--akzent); opacity: 1; }
.wurf-zaehler.vorbei { color: var(--tusche); }
.halt-hinweis { margin: 0; max-width: 30em; font-size: .9rem; font-weight: 500; color: var(--tusche-weich); text-align: center; }

.verlauf { display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 680px; }
.verlauf-titel { font-weight: 600; color: var(--tusche-weich); }
.verlauf ol { display: contents; list-style: none; }
.verlauf li {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--flaeche);
  box-shadow: var(--schatten-klein);
  font-weight: 550;
  font-size: .9rem;
  max-width: 16em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.verlauf li:first-child { background: var(--verlauf); color: #fff; }
.verlauf .knopf.leise { min-height: 32px; padding: 0 6px; font-size: .9rem; }

/* ---------- Werkbank: eine Karte je Würfel ---------- */
.w-liste { list-style: none; margin: 6px 0 14px; padding: 0; display: grid; gap: 12px; }
.w-karte {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  background: var(--flaeche);
  box-shadow: var(--schatten-klein);
}
.w-karte-kopf { display: flex; align-items: center; gap: 8px; }
.w-karte-kopf strong { flex: 1; font-weight: 650; }
.w-marke {
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 36px;
  padding: 0 8px;
  border-radius: 11px;
  background: var(--w-farbe);
  color: var(--w-schrift, #fff);
  font-weight: 700;
  font-size: .9rem;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), 0 2px 6px rgba(80, 60, 160, .2);
}
.w-seiten { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; }
.w-seiten .gewicht { margin-left: 0; }
.w-zahl {
  width: 70px;
  min-height: 40px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--papier-2);
  font-weight: 650;
  text-align: center;
}
.w-zahl:focus { outline: none; border-color: var(--akzent); background: #fff; }
/* Alle sieben in einer Reihe (vorher brach W100 allein in die zweite Zeile) */
.w-chips { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.w-chips .knopf { min-height: 36px; padding: .3em 0; font-size: .85rem; letter-spacing: -.01em; }
.w-chips .knopf[aria-pressed="true"] { background: var(--verlauf); color: #fff; }
.w-flaechen { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.w-flaechen li { display: grid; grid-template-columns: 36px minmax(0, 1fr) 36px; gap: 8px; align-items: center; }
.w-flaechen li > * { grid-area: auto; }
.w-flaechen .feld-bild.hat-bild { padding: 2px; overflow: hidden; }
.w-flaechen .feld-bild img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.farb-wahl { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.farb-wahl button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), inset 0 -4px 0 rgba(0, 0, 0, .12);
  cursor: pointer;
}
.farb-wahl.klein button { width: 32px; height: 32px; }
.farb-wahl button[aria-pressed="true"] { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), 0 0 0 3px #fff, 0 0 0 5px var(--akzent); }
.farb-wahl input { width: 52px; height: 40px; border: 0; border-radius: 12px; padding: 3px; background: var(--flaeche); box-shadow: var(--schatten-klein); }

@media (pointer: coarse) {
  .w-chips .knopf { min-height: 44px; }
  .farb-wahl.klein button { width: 40px; height: 40px; }
  .w-flaechen li { grid-template-columns: 44px minmax(0, 1fr) 44px; }
}

@media (min-width: 980px) {
  .wuerfel-flaeche { --w: min(20vw, 30dvh, 230px); }
  .wuerfel-flaeche.g2 { --w: min(17vw, 26dvh, 200px); }
  .wuerfel-flaeche.g4 { --w: min(13vw, 22dvh, 160px); }
  .wuerfel-flaeche.g6 { --w: min(11vw, 19dvh, 140px); }
  .wuerfel-flaeche.g12 { --w: min(8.5vw, 15dvh, 110px); }
  .wuerfel-flaeche.g24 { --w: min(6.5vw, 11dvh, 84px); }
}

/* ---------- Handy quer: Würfel links, Ergebnis und Knopf rechts ---------- */
@media (orientation: landscape) and (max-height: 540px) and (min-width: 480px) {
  .buehne-wuerfel {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-rows: 1fr repeat(5, auto) 1fr;
    align-content: center;
    justify-items: center;
    column-gap: 24px;
    row-gap: 10px;
    padding: 0 16px 8px;
  }
  .buehne-wuerfel > :first-child { grid-row: 1 / -1; grid-column: 1; }
  .buehne-wuerfel > :not(:first-child) { grid-column: 2; }
  .buehne-wuerfel > :nth-child(2) { grid-row: 2; }
  .buehne-wuerfel > :nth-child(3) { grid-row: 3; }
  .buehne-wuerfel > :nth-child(4) { grid-row: 4; }
  .buehne-wuerfel > :nth-child(5) { grid-row: 5; }
  .wuerfel-flaeche { --w: min(22vw, 34dvh); min-height: 0; }
  .wuerfel-flaeche.g2 { --w: min(18vw, 30dvh); }
  .wuerfel-flaeche.g4 { --w: min(13vw, 24dvh); }
  .wuerfel-flaeche.g6 { --w: min(11vw, 20dvh); }
  .wuerfel-flaeche.g12, .wuerfel-flaeche.g24 { --w: min(7.5vw, 14dvh); }
}
