:root {
  --bg: #0e1520;
  --panel: #172232;
  --text: #eef2f6;
  --muted: #93a0b0;
  --line: #2a3a50;
  --yellow: #f0c14a;
  --yellow-ink: #1c1404;
  --red: #e0453a;
  --ok: #8ee0b5;
  --radius: 14px;
  font-family: "SF Pro Text", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at top, #24344c, var(--bg) 55%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1.4rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

button, input { font: inherit; color: inherit; touch-action: manipulation; }

.top { text-align: center; margin-bottom: 0.9rem; }
.top h1 { margin: 0; font-size: 1.8rem; letter-spacing: 0.02em; }
.tagline { margin: 0.3rem 0 0; color: var(--muted); }
.top-links { margin: 0.45rem 0 0; }
.help-link { color: var(--yellow); text-decoration: none; }
.help-link:hover { text-decoration: underline; }

.panel {
  width: min(440px, 100%);
  background: rgba(23, 34, 50, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

.help-page .panel { width: min(680px, 100%); }
.help-page nav { width: min(680px, 100%); margin: 0 0 0.6rem; }
.help-page nav a { color: var(--yellow); text-decoration: none; }
.doc h1 { font-size: 1.4rem; }
.doc h2 { font-size: 1.1rem; margin-top: 1.3rem; }
.doc p, .doc li { color: #d5dde6; line-height: 1.45; }
.doc code { font-size: 0.92em; }
.doc-table { width: 100%; border-collapse: collapse; margin: 0.6rem 0 1rem; }
.doc-table th, .doc-table td {
  text-align: left;
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field span, .label {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
input[type="text"] {
  width: 100%;
  background: #0e1724;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.8rem;
  font-size: 1rem;
}
input:focus { outline: 2px solid rgba(240, 193, 74, 0.55); border-color: transparent; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }
button {
  border: 0;
  border-radius: 12px;
  padding: 0.75rem 0.95rem;
  background: #24344a;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--yellow); color: var(--yellow-ink); font-weight: 650; }
button.ghost { background: transparent; border: 1px solid var(--line); }

.sep { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.muted { color: var(--muted); }
.hint { color: #d5dde6; min-height: 1.3em; }
.flash {
  background: #243044;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  margin: 0 0 0.8rem;
}

.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.code { margin: 0.1rem 0 0; font-size: 1.6rem; letter-spacing: 0.14em; font-weight: 700; }

.open-rooms, .seats { list-style: none; margin: 0.4rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.open-rooms li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.7rem 0.75rem;
  background: #101a28;
  border: 1px solid rgba(240, 193, 74, 0.45);
  border-radius: 12px;
}
.offer-text { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.offer-host { font-weight: 650; }
.offer-meta { color: var(--muted); font-size: 0.85rem; letter-spacing: 0.04em; }
.room-link, .seat {
  width: 100%;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  background: #101a28;
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
}
.room-meta, .seat-meta { color: var(--muted); font-size: 0.85rem; }
.seat.you { outline: 1px solid rgba(240, 193, 74, 0.45); }
.seat-main { display: flex; align-items: center; gap: 0.5rem; }

.players { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.player {
  background: #101a28;
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  border: 1px solid transparent;
  min-width: 0;
}
.player.on { border-color: rgba(240, 193, 74, 0.8); }
.player-line { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.player-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.dot { width: 0.8rem; height: 0.8rem; border-radius: 50%; flex: none; }
.dot.y { background: var(--yellow); box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.dot.r { background: var(--red); box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }

.turn {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 650;
  margin: 0.75rem 0 0.65rem;
  min-height: 1.4em;
}
.turn.win { color: var(--ok); }
.turn.lose { color: #ffb1ab; }
.turn.draw { color: var(--yellow); }

.board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
  padding: 8px 8px 12px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.22), transparent 26%),
    linear-gradient(180deg, #2d68cc, #173e86 70%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.3), 0 12px 24px rgba(0,0,0,.35);
}

.col {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 0;
  background: transparent;
  border-radius: 0;
}
.col:disabled { cursor: default; }
.col:not(:disabled):hover { filter: brightness(1.05); }

.ghost { height: 18px; display: grid; place-items: center; }
.ghost i {
  width: 78%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: block;
  opacity: 0;
}
.ghost i.y { background: var(--yellow); }
.ghost i.r { background: var(--red); }
.col:not(:disabled):hover .ghost i,
.col:not(:disabled):focus-visible .ghost i { opacity: 0.9; }

.hole {
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #0b1422 42%, #050910 74%);
  box-shadow: inset 0 5px 7px rgba(0,0,0,.7), 0 1px 0 rgba(255,255,255,.2);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.hole.last { box-shadow: inset 0 0 0 2px rgba(255,255,255,.7), inset 0 5px 7px rgba(0,0,0,.45); }
.hole.win { box-shadow: inset 0 0 0 3px #fff, 0 0 10px rgba(255,255,255,.45); }

.disc { width: 86%; height: 86%; border-radius: 50%; display: block; }
.disc.y {
  background: radial-gradient(circle at 35% 30%, #fff3b0, #f0c14a 42%, #b8860b);
  box-shadow: inset 0 -3px 4px rgba(0,0,0,.25);
}
.disc.r {
  background: radial-gradient(circle at 35% 30%, #ffc2bb, #e0453a 46%, #9d261e);
  box-shadow: inset 0 -3px 4px rgba(0,0,0,.25);
}
.disc.drop { animation: fall var(--dur, 0.35s) cubic-bezier(.2, .75, .2, 1); }

@keyframes fall {
  from { transform: translateY(calc(-1 * var(--fall, 80px))); }
  to { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .disc.drop { animation: none; }
}

/* Shared game layout and controls */
.game-suite {
  --suite-bg: #0f1419;
  --suite-panel: #1a2332;
  --suite-field: #101a28;
  --suite-text: #e8ecf1;
  --suite-muted: #a4b0bf;
  --suite-border: #415671;
  --suite-accent: #78b5ff;
  --suite-gap: .75rem;
  --suite-title-size: 2rem;
  font: 400 1rem/1.45 "SF Pro Text", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: dark;
  color: var(--suite-text);
  background: radial-gradient(ellipse at top, #24344c, var(--suite-bg) 60%);
  min-height: 100dvh;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.game-suite .top {
  min-height: 3.5rem;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  margin-bottom: 1rem;
}
.game-suite .top h1:not(.wordmark) {
  margin: 0;
  font-size: var(--suite-title-size);
  line-height: 1.15;
  letter-spacing: .04em;
}
.game-suite .top .tagline { color: var(--suite-muted); margin: .25rem 0 0; font-size: .95rem; }
.game-suite .panel, .game-suite #lobby, .game-suite #game {
  background: var(--suite-panel);
  border: 1px solid var(--suite-border);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: 0 16px 40px rgb(0 0 0 / 28%);
}
.game-suite .panel:not(.doc), .game-suite #lobby { width: min(440px, 100%); }
.game-suite :is(.field-label, .field > span, .suite-open > h2) {
  color: var(--suite-muted);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.game-suite :is(.field, #lobby label) { display: grid; gap: .35rem; min-width: 0; }
.game-suite .suite-home :is(input, select) {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  font: inherit;
  color: var(--suite-text);
  background: var(--suite-field);
  border: 1px solid var(--suite-border);
  border-radius: 10px;
  padding: .55rem .7rem;
}
.game-suite .suite-home select {
  appearance: none;
  padding-right: 2rem;
  background:
    linear-gradient(45deg, transparent 50%, var(--suite-muted) 50%) right 1.1rem center / .35rem .35rem no-repeat,
    linear-gradient(135deg, var(--suite-muted) 50%, transparent 50%) right .75rem center / .35rem .35rem no-repeat,
    var(--suite-field);
}
.game-suite .suite-home > .status:empty { display: none; }
.game-suite .suite-create { margin-top: var(--suite-gap); }
.game-suite .suite-open, .game-suite .suite-join {
  border-top: 1px solid var(--suite-border);
  margin: 1rem 0 0;
  padding: .85rem 0 0;
}
.game-suite .suite-open h2 { margin: 0 0 .45rem; }
.game-suite .suite-open p { margin: .4rem 0 0; color: var(--suite-muted); font-size: .9rem; }
.game-suite :is(.open-rooms, #rooms) { margin: 0; }
.game-suite :is(.open-rooms li, #rooms li) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding: .4rem .45rem .4rem .65rem;
  border: 1px solid var(--suite-border);
  border-radius: 10px;
  background: var(--suite-field);
}
.game-suite .suite-join {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: .5rem;
}
.game-suite .suite-rules {
  border-top: 1px solid var(--suite-border);
  margin: 1rem 0 0;
  padding: .8rem 0 0;
  color: var(--suite-accent);
  font-size: .9rem;
}
.game-suite .suite-rules a { color: inherit; }
.game-suite .suite-rules summary { color: inherit; }
.game-suite .suite-room-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-bottom: var(--suite-gap);
}
.game-suite .suite-room-head .code { margin: .15rem 0 0; }
.game-suite :is(.lobby-head .code, #room) { letter-spacing: .04em; font-weight: 700; }
.game-suite :is(.video-options, .video-extra) {
  margin: .85rem 0;
  padding: .65rem 0;
  border-block: 1px solid var(--suite-border);
}
.game-suite :is(.video-actions, .video-extra__row) { gap: .5rem; }
.game-suite button:not(.cell, .col, .cube-slot, .playing-card, #hand button),
.game-suite :is(.video-actions, .video-extra__row) a {
  min-height: 44px;
  border: 1px solid #536e8e;
  border-radius: 10px;
  background: #283d55;
  color: #f3f7fc;
  padding: .5rem .75rem;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.game-suite button:is(.primary, #create, #start, #place):not(.cell, .col, .playing-card, #hand button) {
  border-color: var(--suite-accent);
  background: var(--suite-accent);
  color: #0b182a;
}
.game-suite button:not(:disabled, .cell, .col, .cube-slot, .playing-card, #hand button):hover,
.game-suite :is(.video-actions, .video-extra__row) a:hover { filter: brightness(1.18); }
.game-suite :is(button, input, select, a, summary):focus-visible {
  outline: 3px solid var(--suite-accent);
  outline-offset: 2px;
}
.game-suite button:disabled:not(.cell, .col, .cube-slot, .playing-card, #hand button) {
  background: #222830;
  color: #a5aab1;
  border: 1px dashed #717984;
  opacity: 1;
  cursor: not-allowed;
}
.game-suite :is(.col, .cell, .playing-card, #hand button):disabled { cursor: not-allowed; }
.game-suite #hand button:disabled { filter: grayscale(1); opacity: .48; }
.game-suite .col:disabled { opacity: .6; }
.game-suite :is(#delete-room, #confirm-delete):not(:disabled) { color: #ffc0c0; }

/* Decorative motifs for the game titles */
.game-suite .top .playful-title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
}
.title-motif {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 1.15em;
  height: 1.15em;
}

.title-motif--tubes {
  width: 1.28em;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: .06em;
}
.title-motif--tubes span {
  position: relative;
  width: 100%;
  height: .99em;
  border: 1px solid #9dbbdb;
  border-radius: 45% 45% 36% 36% / 11% 11% 10% 10%;
  background: linear-gradient(90deg, #16283f 25%, #55718b 82%, #21344b);
  box-shadow: 0 2px 4px #0008;
}
.title-motif--tubes span:nth-child(2) { height: 1.14em; }
.title-motif--tubes span:last-child { height: .86em; }
.title-motif--tubes span::before {
  content: "";
  position: absolute;
  inset: -1px -1px auto;
  height: .18em;
  border: 1px solid #9dbbdb;
  border-radius: 50%;
  background: #0e192a;
}
.title-motif--tubes span::after {
  content: "";
  position: absolute;
  bottom: .07em;
  left: 50%;
  width: .23em;
  height: .23em;
  transform: translateX(-50%);
  border-radius: 50%;
  background: #f0c14a;
}
.title-motif--tubes span:first-child::after { box-shadow: 0 -.26em #e0453a; }
.title-motif--tubes span:nth-child(2)::after { background: #e0453a; box-shadow: 0 -.26em #f0c14a; }

/* Vier Ebenen und drehbare Würfelansicht */
.view-controls { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .65rem; }
#board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.cube-layer { background: #101a28; border: 1px solid #415671; border-radius: 12px; padding: .45rem; }
.cube-layer h3 { margin: 0 0 .4rem; font-size: .82rem; color: #a4b0bf; }
.cube-grid, #tubes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .2rem; }
.game-suite .cube-slot {
  appearance: none;
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid #435877;
  border-radius: 50%;
  background: #172941;
  font-size: clamp(.58rem, 3vw, .76rem);
}
.game-suite #board:not(.spatial) button.cube-slot:not(:disabled) { background: #345a88; border-color: #78b5ff; }
.game-suite #board:not(.spatial) button.cube-slot:disabled { background: #222830; color: #a5aab1; border-color: #717984; }
.cube-slot .disc { width: 84%; height: 84%; }
.cube-slot.winning-slot { outline: 2px solid #f7fbff; outline-offset: -1px; }
.cube-slot.last-slot:not(.winning-slot) { border-color: #78b5ff; }
#tubes { margin-top: .55rem; }
#tubes[hidden], #view-sliders[hidden] { display: none; }
.view-sliders {
  display: grid;
  grid-template-columns: minmax(5.5rem, auto) minmax(0, 1fr);
  align-items: center;
  gap: .3rem .6rem;
  color: #a4b0bf;
  font-size: .9rem;
}
.view-sliders label { display: flex; justify-content: space-between; gap: .3rem; }
.view-sliders input { width: 100%; min-width: 0; min-height: 36px; accent-color: var(--suite-accent); }
.view-sliders output { font-variant-numeric: tabular-nums; }
#board.spatial {
  display: block;
  position: relative;
  min-height: 230px;
  max-height: 275px;
  aspect-ratio: 1.4;
  perspective: 700px;
  transform-style: preserve-3d;
}
.spatial .cube-layer {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(52%, 190px);
  background: rgb(16 26 40 / 23%);
  border-color: rgb(143 180 220 / 58%);
  pointer-events: none;
  transform: translate(-50%, -50%) rotateX(var(--view-tilt, 56deg)) rotateZ(var(--view-angle, -27deg))
    translateZ(calc((var(--layer) - 1.5) * 55px));
}
.spatial .cube-top button { pointer-events: auto; }
.game-suite .spatial .cube-slot {
  border-color: rgb(132 169 210 / 55%);
  background: rgb(23 41 65 / 20%);
}
.game-suite .spatial .cube-top button:not(:disabled) {
  border-color: #78b5ff;
  text-shadow: 0 1px 3px #000;
}
.game-suite .spatial .cube-top button:disabled {
  opacity: 1;
  color: transparent;
}
.game-suite .spatial .cube-top button:not(:disabled):hover {
  background: #5482b7;
  outline: 2px solid #e8f3ff;
}
.spatial .cube-layer h3 { display: none; }
.spatial :is(.cube-layer, .cube-grid, .cube-slot) { transform-style: preserve-3d; }
.spatial .cube-slot .disc {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 84%;
  height: auto;
  aspect-ratio: 1;
  pointer-events: none;
  transform:
    translate3d(-50%, -50%, .32rem)
    rotateZ(calc(0deg - var(--view-angle, -27deg)))
    rotateX(calc(0deg - var(--view-tilt, 56deg)));
  box-shadow: inset -.09rem -.16rem .27rem #0007, 0 .11rem .2rem #0008;
}
.spatial .cube-slot .disc.y {
  background: radial-gradient(circle at 34% 27%, #fff8cc, #ffd962 30%, #e8a921 62%, #885408 94%);
}
.spatial .cube-slot .disc.r {
  background: radial-gradient(circle at 34% 27%, #ffd1c2, #ff6853 30%, #cb2d28 62%, #721316 94%);
}
