:root {
  --ink: #2a1220;
  --night: #140a28;
  --sand: #f6d7a2;
  --foam: #fff6e4;
  --trap: #ef6a2f;
  --boost: #2fd0e0;
  --shield: #6b92ff;
  --alien: #b6e04a;
  --hot: #e4376a;
  color: var(--ink);
  font-family: Figtree, "Avenir Next", "Segoe UI", sans-serif;
  background: var(--night);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 90% 70%, #2f6f86 0, transparent 30%),
    radial-gradient(circle at 8% 80%, #5a3480 0, transparent 32%),
    radial-gradient(circle at 50% 0%, #3a1c66 0, transparent 45%),
    var(--night);
}

/* Zwei Sternschichten, die langsam gegeneinander driften. */
body::before, body::after {
  content: "";
  position: fixed;
  inset: -50%;
  pointer-events: none;
  z-index: 0;
  background-repeat: repeat;
}

body::before {
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 1px, transparent 1.6px),
    radial-gradient(circle, rgba(255, 232, 190, 0.8) 0 1.2px, transparent 1.8px);
  background-size: 190px 170px, 260px 230px;
  background-position: 0 0, 70px 90px;
  animation: drift 160s linear infinite, twinkle 4s ease-in-out infinite alternate;
}

body::after {
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.7) 0 0.8px, transparent 1.4px),
    radial-gradient(circle, rgba(170, 220, 255, 0.8) 0 1.4px, transparent 2px);
  background-size: 110px 120px, 330px 300px;
  background-position: 30px 50px, 140px 20px;
  animation: drift 260s linear infinite reverse, twinkle 6s ease-in-out 1s infinite alternate;
}

@keyframes drift {
  to { transform: translate3d(190px, 170px, 0); }
}

@keyframes twinkle {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

body > * { position: relative; z-index: 1; }

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid #fff6e4;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px var(--ink);
}

h1, .mark {
  font-family: Shrikhand, "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  font-weight: 400;
  line-height: 0.95;
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 8vw, 2.9rem);
  background: linear-gradient(100deg, #2a1220 20%, #8b1f52 55%, #2a1220 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 0 transparent;
}

.card {
  width: min(34rem, calc(100% - 2rem));
  margin: auto;
  padding: 4.5rem 1.4rem 1.4rem;
  position: relative;
  background: linear-gradient(165deg, #ffe7bd 0%, var(--sand) 55%, #e6b878 100%);
  border-radius: 2rem;
  box-shadow:
    0 0 0 4px rgba(42, 18, 32, 0.9),
    0 0 60px rgba(255, 180, 90, 0.25),
    0 30px 60px rgba(0, 0, 0, 0.45);
  animation: rise 0.6s cubic-bezier(0.2, 1.2, 0.3, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
}

#lobby { padding-top: 1.6rem; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.8rem;
  font-weight: 700;
}

.field input, #join-form input, #chat input {
  border: 2px solid transparent;
  background: var(--foam);
  border-radius: 999px;
  padding: 0.7rem 0.9rem;
  font-weight: 500;
  box-shadow: inset 0 2px 4px rgba(42, 18, 32, 0.12);
}

.field input:focus, #join-form input:focus, #chat input:focus {
  border-color: var(--ink);
}

#join-form, #chat {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.7rem 0;
}

#join-form input { width: 6.5rem; text-transform: uppercase; letter-spacing: 0.15em; }
#chat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}
#chat input { min-width: 0; }

.code-label { margin: 0; font-weight: 700; }
.code-line { margin: 0.2rem 0 0.8rem; font-size: 2.2rem; letter-spacing: 0.12em; }
.code-line strong {
  font-family: Shrikhand, sans-serif;
  font-weight: 400;
  color: #8b1f52;
}
#crew, #roster { list-style: none; margin: 0 0 0.8rem; padding: 0; }
#crew li {
  padding: 0.35rem 0.8rem;
  background: rgba(255, 246, 228, 0.7);
  border-radius: 999px;
  animation: rise 0.35s both;
}
#crew li + li, #roster li + li { margin-top: 0.3rem; }
#menu-status, #lobby-status { min-height: 1.3em; font-weight: 700; }

.peek {
  position: absolute;
  left: 1.2rem;
  top: -3rem;
  width: 8rem;
  transform-origin: 50% 100%;
  animation: peek 4.5s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

@keyframes peek {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  45% { transform: translateY(-0.35rem) rotate(2deg); }
  50% { transform: translateY(-0.35rem) rotate(2deg) scaleY(1.04); }
}

.peek-alien { width: 100%; height: auto; display: block; overflow: visible; }

.lead {
  margin: 0.8rem 0 1rem;
  max-width: 38rem;
  line-height: 1.45;
}

.setup-actions, aside {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

#start, #roll, #again, #create, #join-form button {
  border: 0;
  background: linear-gradient(180deg, #4a2438, var(--ink));
  color: var(--foam);
  border-radius: 999px;
  padding: 0.75rem 1.2rem;
  font-weight: 700;
  box-shadow: 0 4px 0 #0e0510, 0 8px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}

#start:hover, #roll:hover:not(:disabled), #again:hover, #create:hover, #join-form button:hover {
  transform: translateY(-2px);
  filter: brightness(1.15);
}

#start:active, #roll:active:not(:disabled), #again:active, #create:active, #join-form button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0e0510;
}

#start:disabled, #roll:disabled {
  opacity: 0.5;
  cursor: default;
}

button.text {
  border: 0;
  background: transparent;
  padding: 0.4rem 0.2rem;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

/* Spielregeln und Legende */
.rules {
  margin-top: 0.6rem;
  background: rgba(255, 246, 228, 0.55);
  border-radius: 1.1rem;
  padding: 0.5rem 0.9rem;
}

.rules summary { cursor: pointer; font-weight: 700; }
.rules p { margin: 0.5rem 0 0.2rem; font-size: 0.92rem; }

.legend {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  font-size: 0.92rem;
  line-height: 1.35;
}

.legend li { display: flex; gap: 0.55rem; align-items: flex-start; }
.legend li + li { margin-top: 0.4rem; }
.legend.compact { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; margin: 0.3rem 0; font-size: 0.82rem; }
.legend.compact li + li { margin-top: 0; }
.legend.compact li { align-items: center; gap: 0.35rem; }

.dot {
  flex: none;
  width: 0.9rem;
  height: 0.9rem;
  margin-top: 0.15rem;
  border-radius: 50%;
  border: 2px solid rgba(42, 18, 32, 0.6);
}
.legend.compact .dot { margin-top: 0; }
.dot.trap { background: var(--trap); }
.dot.boost { background: var(--boost); }
.dot.shield { background: var(--shield); }
.dot.one { background: #ffd23f; }
.dot.six { background: #14b89a; }
.dot.hunt { background: var(--hot); }

/* Tisch */
#table {
  flex: 1;
  width: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: 0.8rem;
  padding: 0.8rem;
}

#board-wrap {
  position: relative;
  min-height: calc(100dvh - 1.6rem);
  border-radius: 1.6rem;
  overflow: hidden;
  background: radial-gradient(circle at 50% 50%, rgba(40, 20, 80, 0.55), rgba(10, 4, 24, 0.7));
  box-shadow: inset 0 0 0 2px rgba(255, 246, 228, 0.12);
}

/* Rotes Pulsieren am Rand, wenn das Alien jemanden fast hat. */
#board-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 90px 20px rgba(255, 40, 80, 0.55);
  transition: opacity 0.4s;
}

#board-wrap.danger::after {
  opacity: 1;
  animation: heartbeat 0.9s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { opacity: 0.35; }
  15% { opacity: 1; }
  30% { opacity: 0.45; }
  45% { opacity: 0.9; }
}

#board {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  display: block;
}

#crater {
  position: absolute;
  left: 1rem;
  top: 0.8rem;
  right: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 1rem;
  pointer-events: none;
  color: var(--foam);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}

.mark {
  font-size: clamp(1.1rem, 2vw, 1.7rem);
  background: linear-gradient(180deg, #fff6e4, #f6c27a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 8px rgba(255, 150, 80, 0.4));
}

#status {
  margin: 0;
  color: var(--sand);
  font-weight: 700;
  font-size: clamp(0.95rem, 1.6vw, 1.2rem);
}

#status.pop { animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
#status[data-mood="bad"] { color: #ff8aa8; }
#status[data-mood="good"] { color: #8ff0c8; }
#status[data-mood="turn"] { color: #ffe08a; }

@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

aside {
  align-self: start;
  align-content: start;
  background: linear-gradient(170deg, rgba(255, 231, 189, 0.97), rgba(240, 200, 138, 0.97));
  border-radius: 1.6rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  box-shadow: 0 0 0 3px rgba(42, 18, 32, 0.9), 0 20px 40px rgba(0, 0, 0, 0.35);
}

.round-chip {
  margin: 0;
  align-self: flex-start;
  background: var(--ink);
  color: var(--foam);
  border-radius: 999px;
  padding: 0.2rem 0.8rem;
  font-weight: 700;
  font-size: 0.85rem;
}

#code-chip { margin: 0; }

#roster li { display: flex; align-items: center; padding: 0.25rem 0.5rem; border-radius: 0.8rem; }
#roster i {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  margin-right: 0.5rem;
  background: var(--swatch, var(--ink));
  border: 2px solid rgba(42, 18, 32, 0.6);
}
#roster li[aria-current="true"] {
  font-weight: 700;
  background: rgba(255, 246, 228, 0.85);
  box-shadow: 0 0 0 2px var(--ink);
  animation: turn-pulse 1.4s ease-in-out infinite;
}
#roster .gone { opacity: 0.5; text-decoration: line-through; }

.badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--shield);
  color: #fff;
}

@keyframes turn-pulse {
  50% { box-shadow: 0 0 0 2px var(--ink), 0 0 14px rgba(255, 255, 255, 0.9); }
}

#roll {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  border-radius: 1.4rem;
  padding: 0.9rem;
}

#roll.ready {
  animation: invite 1.2s ease-in-out infinite;
}

@keyframes invite {
  0%, 100% { box-shadow: 0 4px 0 #0e0510, 0 0 0 0 rgba(255, 210, 63, 0.9); }
  50% { box-shadow: 0 4px 0 #0e0510, 0 0 0 10px rgba(255, 210, 63, 0); }
}

#die {
  width: 5.6rem;
  height: 5.6rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 0.7rem;
  background: linear-gradient(145deg, #ffffff, #ecd9b0);
  border-radius: 1rem;
  box-shadow: inset 0 -4px 0 rgba(42, 18, 32, 0.15), 0 6px 14px rgba(0, 0, 0, 0.35);
}

#die.rolling { animation: tumble 0.5s linear infinite; }
#die.settle { animation: settle 0.45s cubic-bezier(0.2, 1.8, 0.4, 1); }

@keyframes tumble {
  0% { transform: rotate(0) translateY(0) scale(1); }
  25% { transform: rotate(110deg) translateY(-0.6rem) scale(1.08); }
  50% { transform: rotate(200deg) translateY(0) scale(1); }
  75% { transform: rotate(290deg) translateY(-0.6rem) scale(1.08); }
  100% { transform: rotate(360deg) translateY(0) scale(1); }
}

@keyframes settle {
  0% { transform: scale(1.35) rotate(-14deg); }
  100% { transform: scale(1) rotate(0); }
}

#die i {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  justify-self: center;
  align-self: center;
  background: transparent;
}

#die[data-face="1"] i:nth-child(5),
#die[data-face="2"] i:nth-child(1),
#die[data-face="2"] i:nth-child(9),
#die[data-face="3"] i:nth-child(1),
#die[data-face="3"] i:nth-child(5),
#die[data-face="3"] i:nth-child(9),
#die[data-face="4"] i:nth-child(1),
#die[data-face="4"] i:nth-child(3),
#die[data-face="4"] i:nth-child(7),
#die[data-face="4"] i:nth-child(9),
#die[data-face="5"] i:nth-child(1),
#die[data-face="5"] i:nth-child(3),
#die[data-face="5"] i:nth-child(5),
#die[data-face="5"] i:nth-child(7),
#die[data-face="5"] i:nth-child(9),
#die[data-face="6"] i:nth-child(1),
#die[data-face="6"] i:nth-child(3),
#die[data-face="6"] i:nth-child(4),
#die[data-face="6"] i:nth-child(6),
#die[data-face="6"] i:nth-child(7),
#die[data-face="6"] i:nth-child(9) {
  background: radial-gradient(circle at 35% 35%, #6a2f50, var(--ink));
}

#die[data-face="1"] i:nth-child(5) { background: radial-gradient(circle at 35% 35%, #ff7a9c, var(--hot)); }

#log {
  list-style: none;
  margin: 0.4rem 0;
  padding: 0;
  max-height: 16rem;
  overflow: auto;
  line-height: 1.35;
  font-size: 0.92rem;
}

#log li {
  padding-left: 0.55rem;
  border-left: 3px solid rgba(42, 18, 32, 0.2);
  animation: slide-in 0.3s both;
}
#log li + li { margin-top: 0.35rem; }
#log li[data-kind="eaten"], #log li[data-kind="win"] { border-color: var(--hot); font-weight: 700; }
#log li[data-kind="trap"], #log li[data-kind="hunt"], #log li[data-kind="stumble"] { border-color: var(--trap); }
#log li[data-kind="boost"] { border-color: var(--boost); }
#log li[data-kind="shield"], #log li[data-kind="pickup"] { border-color: var(--shield); }
#log li[data-kind="escaped"], #log li[data-kind="bonus"] { border-color: #14b89a; font-weight: 700; }
#log li[data-kind="roll"] { border-color: var(--ink); }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(10px); }
}

.audio-row { display: flex; gap: 0.8rem; }

@media (max-width: 800px) {
  #table {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(24rem, 68dvh) auto;
  }

  #board-wrap { min-height: 0; }

  #log { max-height: 8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
