/* =========================================================
   Gleiche Hirnzelle – Styles (mobile-first)
   ========================================================= */

@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url(fonts/fredoka-latin-wght-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url(fonts/fredoka-latin-ext-wght-normal.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --ink: #23123f;
  --ink-soft: #5b4a7a;
  --paper: #ffffff;
  --paper-2: #f7f2ff;
  --line: rgba(35, 18, 63, 0.1);
  --pink: #ff4d8d;
  --purple: #7b3cff;
  --blue: #3d7bff;
  --yellow: #ffcc33;
  --green: #14c38e;
  --orange: #ff7a2f;
  --shadow: 0 18px 40px -18px rgba(53, 16, 110, 0.45);
  --radius: 28px;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background: #5a2bd6;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.35;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Hintergrund ---------- */
.bg {
  position: fixed; inset: 0; z-index: 0; overflow: hidden;
  background: linear-gradient(160deg, #7b3cff 0%, #c23cff 38%, #ff4d8d 70%, #ff9a3c 100%);
}
.blob {
  position: absolute; border-radius: 50%; filter: blur(50px); opacity: 0.55;
  animation: float 18s ease-in-out infinite alternate;
}
.b1 { width: 60vmax; height: 60vmax; background: #3d7bff; top: -25vmax; left: -20vmax; }
.b2 { width: 45vmax; height: 45vmax; background: #ffcc33; bottom: -20vmax; right: -15vmax; animation-delay: -6s; }
.b3 { width: 30vmax; height: 30vmax; background: #14e3b0; top: 40%; left: -12vmax; animation-delay: -11s; opacity: 0.35; }
.b4 { width: 26vmax; height: 26vmax; background: #ff4d8d; top: 8%; right: -8vmax; animation-delay: -3s; }
@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(4vmax, 3vmax) scale(1.08); }
  100% { transform: translate(-3vmax, 5vmax) scale(0.95); }
}

/* ---------- Layout ---------- */
.app {
  position: relative; z-index: 1;
  width: 100%; max-width: 520px; margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  display: flex; flex-direction: column;
}
.screen { flex: 1; display: flex; flex-direction: column; gap: 16px; animation: screenIn 0.45s var(--ease-bounce) both; }
.screen.center { justify-content: center; align-items: center; text-align: center; }
@keyframes screenIn { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }

.card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 22px 20px;
  box-shadow: var(--shadow);
  position: relative;
}
.card.soft { background: rgba(255, 255, 255, 0.16); color: #fff; box-shadow: none; border: 2px solid rgba(255, 255, 255, 0.25); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
.muted { color: var(--ink-soft); }
.white { color: #fff; }
.small { font-size: 0.9rem; }
.tiny { font-size: 0.78rem; }
.center-text { text-align: center; }
.spacer { flex: 1; }

/* ---------- Logo ---------- */
.logo { text-align: center; color: #fff; margin: 6vh 0 6px; }
.logo-brain { font-size: 84px; line-height: 1; display: inline-block; animation: wobble 3.2s ease-in-out infinite; filter: drop-shadow(0 10px 18px rgba(0,0,0,0.25)); }
.logo h1 {
  margin: 10px 0 4px; font-size: clamp(2.3rem, 11vw, 3.3rem); line-height: 0.95; font-weight: 700; letter-spacing: -0.5px;
  text-shadow: 0 4px 0 rgba(60, 10, 120, 0.35);
}
.logo h1 span { display: block; color: var(--yellow); }
.logo p { margin: 8px 0 0; font-size: 1.08rem; opacity: 0.95; }
@keyframes wobble {
  0%, 100% { transform: rotate(-6deg) scale(1); }
  50% { transform: rotate(6deg) scale(1.07); }
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 62px; padding: 14px 22px;
  border-radius: 22px; font-size: 1.25rem; font-weight: 600;
  background: var(--yellow); color: var(--ink);
  box-shadow: 0 6px 0 #d99a00, 0 14px 24px -10px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s;
  touch-action: manipulation;
}
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 #d99a00, 0 6px 12px -8px rgba(0, 0, 0, 0.35); }
.btn:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }
.btn.pink { background: var(--pink); color: #fff; box-shadow: 0 6px 0 #c4245f, 0 14px 24px -10px rgba(0,0,0,0.35); }
.btn.pink:active { box-shadow: 0 1px 0 #c4245f; }
.btn.purple { background: var(--purple); color: #fff; box-shadow: 0 6px 0 #4f17c2, 0 14px 24px -10px rgba(0,0,0,0.35); }
.btn.purple:active { box-shadow: 0 1px 0 #4f17c2; }
.btn.green { background: var(--green); color: #fff; box-shadow: 0 6px 0 #0a8a63, 0 14px 24px -10px rgba(0,0,0,0.35); }
.btn.green:active { box-shadow: 0 1px 0 #0a8a63; }
.btn.white { background: #fff; color: var(--purple); box-shadow: 0 6px 0 #d8c9ff, 0 14px 24px -10px rgba(0,0,0,0.3); }
.btn.white:active { box-shadow: 0 1px 0 #d8c9ff; }
.btn.ghost { background: rgba(255,255,255,0.18); color: #fff; box-shadow: none; border: 2px solid rgba(255,255,255,0.45); min-height: 54px; font-size: 1.08rem; }
.btn.ghost:active { transform: scale(0.97); }
.btn.small { min-height: 46px; font-size: 1rem; border-radius: 16px; padding: 10px 14px; width: auto; }
.btn[disabled] { filter: grayscale(0.5) opacity(0.65); pointer-events: none; }
.btn .spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid currentColor; border-right-color: transparent; animation: rot 0.7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

.linkbtn { background: none; border: 0; color: #fff; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 1rem; padding: 10px; opacity: 0.9; }

/* ---------- Inputs ---------- */
.input {
  width: 100%; min-height: 64px; border-radius: 20px;
  border: 3px solid var(--line); background: var(--paper-2);
  padding: 12px 18px; font-size: 1.5rem; font-weight: 600; text-align: center;
  outline: none; transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.input:focus { border-color: var(--purple); box-shadow: 0 0 0 6px rgba(123, 60, 255, 0.15); background: #fff; }
.input.code { letter-spacing: 0.35em; text-transform: uppercase; font-size: 1.9rem; padding-left: calc(18px + 0.35em); }
.input.shake { animation: shake 0.42s; border-color: var(--pink); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.divider { display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,0.85); font-weight: 600; margin: 4px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 2px; background: rgba(255,255,255,0.35); border-radius: 2px; }

/* ---------- Header im Spiel ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: #fff; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  background: rgba(255,255,255,0.2); border: 2px solid rgba(255,255,255,0.3); font-weight: 600; font-size: 0.95rem; color: #fff;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.pill.score { background: #fff; color: var(--purple); border-color: #fff; }
.pill b { font-weight: 700; }

.progress { display: flex; gap: 6px; justify-content: center; }
.progress i { width: 100%; max-width: 34px; height: 8px; border-radius: 8px; background: rgba(255,255,255,0.28); transition: background 0.4s; }
.progress i.done { background: #fff; }
.progress i.now { background: var(--yellow); animation: pulse 1.2s ease-in-out infinite; }
.progress i.perfect { background: var(--green); }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- Spieler ---------- */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.player {
  background: #fff; border-radius: 22px; padding: 12px 10px; text-align: center; position: relative;
  box-shadow: var(--shadow); border: 3px solid transparent; transition: border-color 0.3s, transform 0.3s var(--ease-bounce);
}
.player.me { border-color: var(--c, var(--purple)); }
.player .avatar {
  width: 54px; height: 54px; margin: 0 auto 6px; border-radius: 50%;
  display: grid; place-items: center; font-size: 30px;
  background: var(--c, var(--purple));
  box-shadow: inset 0 -5px 0 rgba(0,0,0,0.15);
}
.player .pname { font-weight: 600; font-size: 0.95rem; line-height: 1.15; word-break: break-word; hyphens: auto; }
.player .ptag { font-size: 0.75rem; color: var(--ink-soft); margin-top: 2px; }
.player .status {
  position: absolute; top: 8px; right: 8px; font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: #eee; color: #555;
}
.player .status.ok { background: #d9fbe9; color: #0a7a55; }
.player .status.wait { background: #fff3cc; color: #8a6200; }
.player .status.off { background: #ffe0e8; color: #c4245f; }
.player.empty { background: rgba(255,255,255,0.15); color: #fff; box-shadow: none; border: 3px dashed rgba(255,255,255,0.5); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.player.empty .avatar { background: rgba(255,255,255,0.2); animation: wobble 2s ease-in-out infinite; box-shadow: none; }
.online-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #14c38e; margin-right: 4px; vertical-align: middle; box-shadow: 0 0 0 3px rgba(20,195,142,0.25); }
.online-dot.off { background: #ff4d8d; box-shadow: 0 0 0 3px rgba(255,77,141,0.25); }

/* ---------- Lobby ---------- */
.code-big {
  font-size: clamp(2.6rem, 14vw, 3.6rem); font-weight: 700; letter-spacing: 0.18em; text-align: center;
  color: var(--purple); line-height: 1; padding-left: 0.18em; margin: 6px 0;
}
.qr { width: 190px; height: 190px; margin: 6px auto; padding: 10px; background: #fff; border-radius: 20px; border: 3px solid var(--paper-2); }
.qr svg, .qr img { width: 100%; height: 100%; display: block; }
.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.waiting { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; color: #fff; font-size: 1.1rem; text-align: center; }
.dots span { display: inline-block; animation: bounce 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-8px); } }

/* ---------- Frage ---------- */
.question-card { text-align: center; padding: 26px 20px 24px; overflow: hidden; }
.question-card .qlabel {
  display: inline-block; font-size: 0.82rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: #fff; background: var(--pink); padding: 5px 12px; border-radius: 999px; margin-bottom: 12px;
}
.question-card .qtext { font-size: clamp(1.45rem, 6.4vw, 1.9rem); font-weight: 600; line-height: 1.2; margin: 0; }
.question-card.compact { padding: 16px 18px; }
.question-card.compact .qlabel { margin-bottom: 8px; font-size: 0.74rem; }
.question-card.compact .qtext { font-size: clamp(1.1rem, 4.8vw, 1.35rem); }
.question-card.pop { animation: pop 0.6s var(--ease-bounce) both; }
@keyframes pop { 0% { transform: scale(0.6) rotate(-4deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
.hint { font-size: 0.85rem; color: var(--ink-soft); text-align: center; margin-top: 2px; }
.answer-form { display: flex; flex-direction: column; gap: 12px; }

.sealed {
  text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.envelope { font-size: 64px; animation: wobble 2.4s ease-in-out infinite; }
.sealed .mine { font-size: 0.95rem; color: var(--ink-soft); }
.sealed .mine b { color: var(--ink); }

/* ---------- Lade-Gehirn ---------- */
.brain-loader { position: relative; width: 120px; height: 120px; display: grid; place-items: center; margin: 0 auto; }
.brain-loader span { font-size: 76px; animation: think 1.4s ease-in-out infinite; filter: drop-shadow(0 8px 14px rgba(0,0,0,0.25)); }
.brain-loader::before, .brain-loader::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%; border: 4px dashed rgba(255,255,255,0.6); animation: rot 6s linear infinite;
}
.brain-loader::after { inset: 14px; border-style: dotted; animation-duration: 3.5s; animation-direction: reverse; }
@keyframes think { 0%, 100% { transform: scale(1) rotate(-4deg); } 50% { transform: scale(1.12) rotate(4deg); } }
.loading-text { color: #fff; font-size: 1.25rem; font-weight: 600; margin: 16px 0 4px; min-height: 1.6em; }

/* ---------- Aufdeckung ---------- */
.stage { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; perspective: 1000px; }
.flip { height: 150px; position: relative; transform-style: preserve-3d; transition: transform 0.9s var(--ease-bounce); }
.flip.flipped { transform: rotateY(180deg); }
.flip .face {
  position: absolute; inset: 0; border-radius: 24px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px 8px; text-align: center;
  box-shadow: var(--shadow);
}
.flip .back {
  background: repeating-linear-gradient(45deg, #2b1360 0 14px, #34197a 14px 28px); color: #fff; font-size: 48px;
  border: 4px solid rgba(255,255,255,0.85);
}
.flip .front { background: #fff; transform: rotateY(180deg); border: 4px solid var(--c, var(--purple)); }
.flip .who { font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; display: flex; align-items: center; gap: 4px; max-width: 100%; }
.flip .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flip .word { font-size: clamp(1.25rem, 6.5vw, 1.8rem); font-weight: 700; margin-top: 6px; word-break: break-word; line-height: 1.1; color: var(--c, var(--ink)); }
.stage.shake .flip:not(.flipped) { animation: jiggle 0.25s ease-in-out infinite; }
.stage.shake .flip:nth-child(2):not(.flipped) { animation-delay: 0.1s; }
@keyframes jiggle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg) translateY(-3px); } }
.stage.match .front { animation: matchGlow 1.2s ease-in-out infinite; }
@keyframes matchGlow { 50% { box-shadow: 0 0 0 8px rgba(255, 204, 51, 0.7), var(--shadow); } }

.countdown {
  font-size: 5rem; font-weight: 700; color: #fff; text-align: center; height: 5.5rem; line-height: 5.5rem;
  text-shadow: 0 6px 0 rgba(60,10,120,0.35);
}
.countdown.tick { animation: tick 0.9s ease-out both; }
@keyframes tick { 0% { transform: scale(2.2); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.8); opacity: 0.2; } }

.result { text-align: center; }
.score-num { font-size: 4.4rem; font-weight: 700; line-height: 1; color: var(--purple); }
.score-num small { font-size: 1.6rem; color: var(--ink-soft); }
.meter { height: 18px; border-radius: 12px; background: var(--paper-2); overflow: hidden; margin: 12px 0 4px; box-shadow: inset 0 2px 4px rgba(0,0,0,0.08); }
.meter i { display: block; height: 100%; width: 0; border-radius: 12px; background: linear-gradient(90deg, var(--pink), var(--orange), var(--yellow), var(--green)); background-size: 100vw 100%; transition: width 1.1s var(--ease-bounce); }
.meter-scale { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--ink-soft); font-weight: 600; }
.verdict { font-size: 1.15rem; font-weight: 700; margin-top: 10px; }
.bubble {
  margin-top: 14px; background: var(--paper-2); border-radius: 20px; padding: 14px 16px; font-size: 1.08rem; position: relative; text-align: left;
  display: flex; gap: 10px; align-items: flex-start;
}
.bubble .bot { font-size: 26px; line-height: 1; }
.result-reveal { opacity: 0; transform: translateY(16px) scale(0.96); transition: opacity 0.5s, transform 0.6s var(--ease-bounce); }
.result-reveal.on { opacity: 1; transform: none; }
.banner {
  text-align: center; font-size: clamp(1.7rem, 8.5vw, 2.4rem); font-weight: 700; color: var(--yellow);
  text-shadow: 0 4px 0 rgba(60,10,120,0.45); animation: banner 0.9s var(--ease-bounce) both; line-height: 1.05;
}
@keyframes banner { 0% { transform: scale(0.2) rotate(-10deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
.src-note { font-size: 0.72rem; color: var(--ink-soft); margin-top: 8px; text-align: center; }

/* ---------- Ende ---------- */
.final-total { font-size: clamp(4rem, 22vw, 6rem); font-weight: 700; color: #fff; line-height: 1; text-align: center; text-shadow: 0 6px 0 rgba(60,10,120,0.35); }
.final-total small { font-size: 0.35em; opacity: 0.85; }
.trophy { font-size: 72px; text-align: center; animation: wobble 2.4s ease-in-out infinite; }
.title-card { text-align: center; background: linear-gradient(135deg, #fff 0%, #fff6d6 100%); }
.title-card .label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; color: var(--pink); }
.title-card h2 { margin: 6px 0; font-size: clamp(1.6rem, 7.5vw, 2.2rem); line-height: 1.1; color: var(--purple); }
.title-card p { margin: 0; color: var(--ink-soft); font-size: 1.02rem; }
.recap { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.recap li { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 16px; background: var(--paper-2); }
.recap .rn { font-weight: 700; color: var(--ink-soft); text-align: center; }
.recap .rq { font-size: 0.82rem; color: var(--ink-soft); line-height: 1.2; }
.recap .ra { font-weight: 600; font-size: 0.98rem; word-break: break-word; }
.recap .rs { font-weight: 700; font-size: 1.1rem; min-width: 46px; text-align: center; border-radius: 12px; padding: 6px 8px; background: #fff; }
.recap .rs.perfect { background: var(--green); color: #fff; }

/* ---------- Regeln ---------- */
.rules { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.rules li { display: flex; gap: 12px; align-items: flex-start; }
.rules .ri { font-size: 24px; line-height: 1.2; }

/* ---------- Statusleisten ---------- */
.netbar {
  position: fixed; top: calc(10px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 50;
  background: #23123f; color: #fff; padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 0.92rem;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.35); width: max-content; max-width: calc(100% - 32px);
  animation: dropIn 0.35s var(--ease-bounce);
}
.netbar-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--yellow); animation: pulse 0.9s infinite; flex: none; }
@keyframes dropIn { from { transform: translate(-50%, -30px); opacity: 0; } }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60;
  background: #fff; color: var(--ink); padding: 14px 18px; border-radius: 18px; font-weight: 600; box-shadow: 0 16px 40px rgba(0,0,0,0.35);
  width: max-content; max-width: calc(100% - 32px); text-align: center; animation: toastIn 0.35s var(--ease-bounce);
}
.toast.err { background: var(--pink); color: #fff; }
@keyframes toastIn { from { transform: translate(-50%, 30px); opacity: 0; } }
.notice { background: #fff3cc; color: #6b4b00; border-radius: 16px; padding: 10px 14px; font-size: 0.92rem; font-weight: 500; text-align: center; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; width: 100%; height: 100%; }

@media (min-width: 640px) {
  .app { padding-top: calc(32px + var(--safe-top)); }
  .flip { height: 190px; }
}

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