:root {
  --bg1: #1a1340;
  --bg2: #0b2b4d;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-b: rgba(255, 255, 255, 0.14);
  --text: #f4f1ff;
  --muted: #b7b0d8;
  --accent: #ffcf3f;
  --accent2: #ff7ab6;
  --good: #5ee6a0;
  --glass: rgba(215, 232, 255, 0.6);
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* kein Zoom bei Doppeltipp (iOS); Scrollen und Pinch-Zoom bleiben erhalten */
html, body, .screen, .overlay, .scroll, button, input, select, label { touch-action: manipulation; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(120% 80% at 20% 0%, #3a1f6e 0%, transparent 55%),
              radial-gradient(100% 70% at 100% 100%, #0f5c73 0%, transparent 55%),
              linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Hintergrund-Blasen */
.bubbles { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.bubbles i {
  position: absolute; bottom: -60px; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.12); background: rgba(255, 255, 255, 0.03);
  animation: rise 18s linear infinite;
}
.bubbles i:nth-child(1) { left: 6%; animation-delay: 0s; }
.bubbles i:nth-child(2) { left: 18%; width: 30px; height: 30px; animation-delay: -6s; animation-duration: 24s; }
.bubbles i:nth-child(3) { left: 33%; width: 10px; height: 10px; animation-delay: -12s; }
.bubbles i:nth-child(4) { left: 48%; animation-delay: -3s; animation-duration: 21s; }
.bubbles i:nth-child(5) { left: 63%; width: 26px; height: 26px; animation-delay: -9s; }
.bubbles i:nth-child(6) { left: 77%; width: 12px; height: 12px; animation-delay: -15s; animation-duration: 16s; }
.bubbles i:nth-child(7) { left: 88%; animation-delay: -1s; animation-duration: 26s; }
.bubbles i:nth-child(8) { left: 95%; width: 8px; height: 8px; animation-delay: -7s; }
@keyframes rise { to { transform: translateY(-115vh) translateX(20px); } }

#app { position: relative; z-index: 1; height: 100%; }
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 8px) 12px calc(var(--safe-b) + 8px);
  opacity: 0; visibility: hidden; transform: scale(0.98); pointer-events: none;
  transition: opacity 0.25s, transform 0.25s, visibility 0s 0.25s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; pointer-events: auto; transition: opacity 0.25s, transform 0.25s; }
.scroll { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.2) transparent; -webkit-overflow-scrolling: touch; padding-bottom: 20px; }

/* Buttons */
.btn {
  border: 1px solid var(--panel-b); background: var(--panel); border-radius: 14px;
  padding: 12px 18px; font-weight: 700; letter-spacing: 0.2px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25); transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
  backdrop-filter: blur(6px);
}
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }
.btn.primary { background: linear-gradient(180deg, #ffd955, #ffac2f); color: #3a2300; border-color: #ffe28a; }
.btn.big { font-size: 1.15rem; padding: 16px 22px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.ghost-btn { border-style: dashed; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--panel-b);
  background: var(--panel); font-size: 1.25rem; display: grid; place-items: center;
}
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Menü */
#scr-menu { justify-content: center; align-items: center; gap: 28px; }
.logo { text-align: center; }
.logo h1 {
  font-size: clamp(2.8rem, 12vw, 4.6rem); margin: 6px 0 0; letter-spacing: 1px;
  background: linear-gradient(90deg, #ff7ab6, #ffcf3f, #5ee6a0, #56b4ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35));
}
.logo p { margin: 4px 0 0; color: var(--muted); }
.logo-bottles { display: flex; gap: 14px; justify-content: center; height: 96px; align-items: flex-end; }
.logo-bottles span {
  width: 30px; height: 88px; border: 3px solid var(--glass); border-top: 0; border-radius: 4px 4px 16px 16px;
  background: linear-gradient(to top, var(--a) 0 30%, var(--b) 30% 55%, var(--c) 55% 78%, transparent 78%);
  position: relative; animation: bob 3s ease-in-out infinite;
}
.logo-bottles span::before { content: ""; position: absolute; top: -5px; left: -6px; right: -6px; height: 6px; border-radius: 3px; background: var(--glass); }
.logo-bottles span:nth-child(2) { height: 96px; animation-delay: -1s; }
.logo-bottles span:nth-child(3) { animation-delay: -2s; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(3deg); } }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: min(340px, 100%); }

/* Kopfzeile */
.topbar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; min-height: 48px; }
.topbar .title { text-align: center; font-weight: 800; font-size: 1.15rem; line-height: 1.1; }
.topbar .title small { display: block; font-weight: 600; font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.stars-total { color: var(--accent); font-weight: 800; text-align: right; white-space: nowrap; font-size: 0.95rem; }
#scr-campaign .topbar { grid-template-columns: 44px 1fr 64px; }

/* Levelübersicht */
.chapter { margin: 18px auto 8px; max-width: 640px; }
.chapter h2 { font-size: 1rem; margin: 0 4px 10px; color: var(--muted); font-weight: 700; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.lvl {
  aspect-ratio: 1; border-radius: 16px; border: 1px solid var(--panel-b); background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-weight: 800; font-size: 1.2rem; position: relative; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}
.lvl .st { font-size: 0.7rem; letter-spacing: 1px; color: var(--accent); }
.lvl .st .off { color: rgba(255, 255, 255, 0.2); }
.lvl .mech { position: absolute; top: 3px; right: 5px; font-size: 0.6rem; opacity: 0.8; }
.lvl.locked { opacity: 0.35; pointer-events: none; }
.lvl.current { background: linear-gradient(180deg, #ffd955, #ffac2f); color: #3a2300; animation: pulse 1.8s infinite; }
.lvl.current .st .off { color: rgba(58, 35, 0, 0.3); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 207, 63, 0.25), 0 3px 0 rgba(0, 0, 0, 0.25); } }

/* Lobby */
.lobby { max-width: 460px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 14px; padding-top: 8px; }
.lead { color: var(--muted); margin: 4px 2px; line-height: 1.4; }
.card { background: var(--panel); border: 1px solid var(--panel-b); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.card h3 { margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.field input, .field select {
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--panel-b); border-radius: 12px; padding: 12px; color: var(--text); font-size: 1rem;
}
.field select option { background: #241a52; }
.code-input { text-transform: uppercase; letter-spacing: 6px; font-weight: 800; text-align: center; font-size: 1.4rem !important; }

/* Spielbildschirm */
.board-wrap { flex: 1; position: relative; min-height: 0; min-width: 0; display: flex; }
.board {
  --bw: 50px; --per: 6;
  flex: 1; min-width: 0; min-height: 0; display: grid; grid-template-columns: repeat(var(--per), auto);
  justify-content: center; align-content: center;
  column-gap: calc(var(--bw) * 0.1); row-gap: calc(var(--bw) * 0.3);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.slot {
  width: calc(var(--bw) * 1.35); padding-top: calc(var(--bw) * 0.55);
  display: flex; flex-direction: column; align-items: center; position: relative; cursor: pointer;
}
.bottle {
  position: relative; width: var(--bw); height: calc(var(--bw) * 3.3);
  transform-origin: 50% 0; transition: transform 0.18s cubic-bezier(.3, 1.6, .5, 1);
}
.bottle::before {
  content: ""; position: absolute; z-index: 3; top: -5px; left: -6px; right: -6px; height: 8px; border-radius: 4px;
  background: linear-gradient(180deg, #eef6ff, #a9c3e6); opacity: 0.85;
}
.glass {
  position: absolute; inset: 0; overflow: hidden;
  border: 3px solid var(--glass); border-top: 0;
  border-radius: 5px 5px calc(var(--bw) * 0.46) calc(var(--bw) * 0.46);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02) 40%, rgba(255, 255, 255, 0.07));
  box-shadow: inset 0 -6px 14px rgba(0, 0, 0, 0.25), 0 6px 18px rgba(0, 0, 0, 0.25);
  transition: box-shadow 0.2s;
}
.liquid { position: absolute; left: 0; right: 0; bottom: 0; height: 84%; }
.seg {
  position: absolute; left: 0; right: 0; bottom: calc(var(--k) * 25%); height: calc(25% + 0.5px);
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0) 30%, rgba(255, 255, 255, 0.18) 58%, rgba(0, 0, 0, 0.16)), var(--col);
  transform-origin: 50% 100%;
  display: grid; place-items: center;
}
.seg:last-child::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 18%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent);
}
.seg i { font-style: normal; display: none; color: rgba(0, 0, 0, 0.5); font-size: calc(var(--bw) * 0.34); line-height: 1; }
.symbols .seg i { display: block; }
.seg.hidden {
  background: repeating-linear-gradient(135deg, #3b3358 0 7px, #2c2545 7px 14px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.seg.hidden i { display: block; color: rgba(255, 255, 255, 0.55); font-weight: 900; }
.seg.flip { animation: flip 0.5s ease-out; }
@keyframes flip { 0% { transform: scaleX(0.05); filter: brightness(2.5); } 60% { transform: scaleX(1.08); } 100% { transform: none; } }
.shine {
  position: absolute; left: 14%; top: 6%; width: 13%; height: 72%; border-radius: 99px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.05));
  pointer-events: none;
}
.cork {
  position: absolute; z-index: 4; left: 16%; right: 16%; top: calc(var(--bw) * -0.34); height: calc(var(--bw) * 0.42);
  border-radius: 4px 4px 2px 2px; opacity: 0; transform: translateY(-40px);
  background: linear-gradient(90deg, #8a5a2b, #c48a4f 45%, #8a5a2b);
}
.num { margin-top: 6px; font-size: 0.72rem; font-weight: 800; opacity: 0.4; min-width: 20px; text-align: center; border-radius: 8px; padding: 0 5px; }
.ghost { display: none; }
.who {
  display: none; position: absolute; top: 0; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: var(--pc); color: #111; font-size: 0.7rem; font-weight: 800; padding: 1px 7px; border-radius: 8px; z-index: 5;
}

.slot.sel .bottle { transform: translateY(calc(var(--bw) * -0.35)); }
.slot.sel .glass { box-shadow: 0 0 0 2px #fff, 0 0 22px rgba(255, 255, 255, 0.55); }
.slot.rsel .bottle { transform: translateY(calc(var(--bw) * -0.2)); }
.slot.rsel .glass { box-shadow: 0 0 0 3px var(--pc), 0 0 20px var(--pc); }
.slot.rsel .who { display: block; }
.slot.mfrom .num, .slot.mto .num { opacity: 1; background: var(--mc); color: #111; }
.slot.mfrom .num::before { content: "↑ "; }
.slot.mto .num::before { content: "↓ "; }
.slot.hint-from .glass, .slot.hint-to .glass { animation: hint 0.9s ease-in-out infinite; }
.slot.hint-to .glass { animation-delay: 0.45s; }
@keyframes hint { 50% { box-shadow: 0 0 0 3px var(--good), 0 0 24px var(--good); } }
.slot.flying { z-index: 30; }
.slot.flying .bottle { transition: none; }
.slot.empty .num { opacity: 0.25; }

.fx-bottle { position: fixed; z-index: 45; pointer-events: none; margin: 0; }
.fx-bottle .cork { animation: cork 0.35s cubic-bezier(.3, 1.5, .6, 1) forwards; }
.fx-bottle .glass { box-shadow: 0 0 0 2px #fff, 0 0 30px 8px rgba(255, 255, 255, 0.6); }
@keyframes cork { to { opacity: 1; transform: none; } }

.slot.gone { pointer-events: none; }
.slot.gone .bottle { visibility: hidden; }
.slot.gone .ghost {
  display: block; position: absolute; top: calc(var(--bw) * 1.9); left: 0; right: 0; text-align: center;
  font-size: calc(var(--bw) * 0.5); color: rgba(255, 255, 255, 0.16); animation: twinkle 3s ease-in-out infinite;
}
.slot.gone .num { visibility: hidden; }
@keyframes twinkle { 50% { color: rgba(255, 255, 255, 0.3); transform: scale(1.15); } }

.veil { display: none; }
.slot.veiled .veil, .fx-veil {
  display: grid; place-items: center; position: absolute; z-index: 6; inset: -6px -7px -3px;
  border-radius: 12px 12px calc(var(--bw) * 0.5) calc(var(--bw) * 0.5);
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.18), transparent 40%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.18) 0 4px, transparent 4px 12px),
    linear-gradient(180deg, #7a57c9, #4b2f8f 60%, #36206e);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 -8px 12px rgba(0, 0, 0, 0.3);
}
.fx-veil { position: fixed; inset: auto; z-index: 44; pointer-events: none; }
.veil-tag { display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 900; }
.veil-tag b { font-size: calc(var(--bw) * 0.38); }
.veil-tag span {
  background: rgba(0, 0, 0, 0.35); border-radius: 99px; min-width: calc(var(--bw) * 0.5); padding: 1px 6px; text-align: center;
  font-size: calc(var(--bw) * 0.3);
}

.stream { position: fixed; width: 6px; border-radius: 3px; transform-origin: 50% 0; z-index: 40; pointer-events: none; box-shadow: 0 0 6px rgba(255, 255, 255, 0.35); }

.status { min-height: 26px; text-align: center; color: var(--muted); font-size: 0.9rem; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.status .cdot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.5); vertical-align: middle; }
.status b { color: var(--text); }
.status .btn { padding: 6px 12px; font-size: 0.85rem; }

.toolbar { display: flex; justify-content: center; gap: 10px; padding-top: 6px; }
.tool {
  flex: 0 1 96px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 1px solid var(--panel-b); background: var(--panel); border-radius: 14px; padding: 8px 6px;
  font-size: 0.78rem; font-weight: 700; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}
.tool span { font-size: 1.35rem; line-height: 1.1; }
.tool:active { transform: translateY(2px); box-shadow: none; }
.tool:disabled { opacity: 0.4; pointer-events: none; }

.tip {
  display: flex; gap: 10px; align-items: center; margin: 4px auto 0; max-width: 560px;
  background: rgba(94, 230, 160, 0.14); border: 1px solid rgba(94, 230, 160, 0.4);
  border-radius: 12px; padding: 8px 10px 8px 14px; font-size: 0.9rem; line-height: 1.35;
  animation: drop 0.4s ease-out;
}
.tip[hidden] { display: none; }
.tip button { border: 0; background: none; font-size: 1rem; opacity: 0.7; padding: 4px; }
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } }

/* Mehrspieler */
.mp-bar { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin-top: 4px; }
.mp-bar[hidden] { display: none; }
.pchip {
  --pc: #ffb321;
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 12px; min-width: 0;
  background: var(--panel); border: 2px solid transparent; transition: border-color 0.2s, box-shadow 0.2s;
}
.pchip[data-slot="1"] { --pc: #36d3ff; flex-direction: row-reverse; }
.pchip .dot { width: 9px; height: 9px; border-radius: 50%; background: #666; flex: none; }
.pchip.online .dot { background: var(--good); box-shadow: 0 0 6px var(--good); }
.pchip .pname { font-weight: 800; color: var(--pc); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip .pscore { margin-left: auto; font-size: 1.1rem; }
.pchip[data-slot="1"] .pscore { margin-left: 0; margin-right: auto; }
.pchip.active { border-color: var(--pc); box-shadow: 0 0 14px color-mix(in srgb, var(--pc) 50%, transparent); }
.turn { font-size: 0.8rem; font-weight: 800; text-align: center; color: var(--muted); }
.turn.mine { color: var(--accent); animation: pulseText 1.2s infinite; }
@keyframes pulseText { 50% { opacity: 0.55; } }

.waiting {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  text-align: center; background: rgba(15, 10, 40, 0.82); border-radius: 20px; padding: 20px; backdrop-filter: blur(4px);
}
.waiting[hidden] { display: none; }
.waiting h2 { margin: 0; }
.waiting p { margin: 0; color: var(--muted); }
.big-code {
  font-size: clamp(2rem, 11vw, 3.2rem); font-weight: 900; letter-spacing: 8px; padding: 8px 18px; border-radius: 16px;
  background: rgba(255, 255, 255, 0.08); border: 2px dashed rgba(255, 255, 255, 0.3); user-select: all;
}

/* Overlay / Dialoge */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: rgba(8, 5, 25, 0.6); backdrop-filter: blur(3px); animation: fade 0.2s;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(400px, 100%); max-height: 90vh; overflow-y: auto; background: linear-gradient(180deg, #2c2064, #1d1848);
  border: 1px solid var(--panel-b); border-radius: 22px; padding: 22px; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); animation: pop 0.35s cubic-bezier(.3, 1.5, .5, 1);
}
@keyframes pop { from { transform: scale(0.8); opacity: 0; } }
.modal h2 { margin: 0 0 8px; font-size: 1.5rem; }
.modal .mbody { color: var(--muted); line-height: 1.45; }
.modal .mbody b { color: var(--text); }
.modal .mbtns { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; justify-content: center; }
.modal .mbtns .btn { flex: 1 1 110px; }
.modal.left .mbody { text-align: left; }
.bigstars { font-size: 3rem; letter-spacing: 6px; margin: 6px 0; }
.bigstars span { display: inline-block; color: rgba(255, 255, 255, 0.18); }
.bigstars span.on { color: var(--accent); animation: star 0.5s cubic-bezier(.3, 1.8, .5, 1) backwards; text-shadow: 0 0 18px rgba(255, 207, 63, 0.7); }
.bigstars span.on:nth-child(2) { animation-delay: 0.25s; }
.bigstars span.on:nth-child(3) { animation-delay: 0.5s; }
@keyframes star { from { transform: scale(0) rotate(-120deg); } }
.howto p { margin: 8px 0; }
.opt { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); text-align: left; }
.opt:last-child { border: 0; }
.switch { width: 52px; height: 30px; border-radius: 99px; border: 0; background: #555; position: relative; flex: none; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch.on { background: var(--good); }
.switch.on::after { transform: translateX(22px); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 90px); transform: translate(-50%, 20px); z-index: 120;
  background: rgba(20, 14, 50, 0.95); border: 1px solid var(--panel-b); padding: 10px 16px; border-radius: 12px;
  font-weight: 700; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 90; }

@media (min-width: 700px) {
  .levels { grid-template-columns: repeat(10, 1fr); }
  .tool { flex-basis: 110px; }
}
@media (max-height: 560px) {
  .logo-bottles { display: none; }
  #scr-menu { gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .bubbles, .logo-bottles span, .lvl.current, .turn.mine { animation: none; }
}
