:root {
  --bg: #1a1033;
  --bg2: #2b1657;
  --panel: rgba(255, 255, 255, 0.07);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.14);
  --text: #fff8f0;
  --muted: #b9a8d9;
  --pink: #ff5d8f;
  --blue: #4cc9f0;
  --gold: #ffd60a;
  --green: #06d6a0;
  --red: #ff6b6b;
  --amber: #ffb347;
  --grey: #9b93ad;
  --radius: 20px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Fredoka", ui-rounded, system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 80% -10%, var(--bg2), transparent 60%), var(--bg);
  color: var(--text);
  font-size: 17px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

/* Floating blobs */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.sky i { position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.35; animation: drift 18s ease-in-out infinite alternate; }
.sky i:nth-child(1) { width: 420px; height: 420px; background: var(--pink); left: -120px; top: 40%; }
.sky i:nth-child(2) { width: 360px; height: 360px; background: var(--blue); right: -100px; top: -80px; animation-delay: -6s; }
.sky i:nth-child(3) { width: 300px; height: 300px; background: #7b2cbf; left: 40%; bottom: -140px; animation-delay: -12s; }
@keyframes drift { to { transform: translate(60px, -40px) scale(1.15); } }

.screen { position: relative; z-index: 1; max-width: 1100px; margin: 0 auto; padding: 16px; min-height: 100%; }

/* Buttons */
.btn {
  border: 0; border-radius: 14px; padding: 12px 18px; cursor: pointer; font-weight: 600;
  background: var(--panel-strong); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.08s, filter 0.15s, opacity 0.15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.25); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(180deg, #ff7aa5, var(--pink)); color: #2a0b1a; }
.btn.gold { background: linear-gradient(180deg, #ffe45c, var(--gold)); color: #3a2c00; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.btn.big { font-size: 1.2rem; padding: 16px 22px; width: 100%; }
.btn.small { padding: 8px 12px; font-size: 0.9rem; }
.icon-btn { background: var(--panel); border: 0; width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 1.1rem; }
.icon-btn:hover { background: var(--panel-strong); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; backdrop-filter: blur(8px); }
.panel h2 { margin: 0 0 14px; font-size: 1.25rem; }
.hint { color: var(--muted); text-align: center; margin: 10px 0 0; font-size: 0.95rem; }
.error { color: var(--red); min-height: 1.2em; margin: 10px 0 0; text-align: center; }

/* Home */
.back { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.back:hover { color: var(--text); }
.hero { text-align: center; margin: 24px 0 26px; }
.hero h1 { font-size: clamp(2.6rem, 9vw, 4.2rem); margin: 18px 0 6px; letter-spacing: -0.02em; text-shadow: 0 4px 0 rgba(0,0,0,.25); }
.hero .tag { color: var(--muted); margin: 0; line-height: 1.5; }
.hero-card {
  width: 110px; height: 150px; margin: 0 auto; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--pink), #7b2cbf); box-shadow: var(--shadow), inset 0 0 0 4px rgba(255,255,255,.25);
  animation: bob 3s ease-in-out infinite; transform: rotate(-6deg);
}
.hero-card span { font-size: 90px; font-weight: 700; text-shadow: 0 5px 0 rgba(0,0,0,.25); }
@keyframes bob { 50% { transform: rotate(6deg) translateY(-8px); } }
#home-form { max-width: 420px; margin: 0 auto; display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field span { color: var(--muted); font-size: 0.95rem; }
input {
  background: rgba(0, 0, 0, 0.25); border: 2px solid var(--line); border-radius: 14px; padding: 13px 15px; outline: none; width: 100%;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--blue); }
input::placeholder { color: rgba(255, 255, 255, 0.35); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 10px; }
#join-code { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.code-chip {
  display: flex; align-items: baseline; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 8px 14px; cursor: pointer; position: relative;
}
.code-chip small { color: var(--muted); font-size: 0.7rem; letter-spacing: 0.1em; }
.code-chip b { letter-spacing: 0.2em; font-size: 1.2rem; }
.code-chip em { position: absolute; left: 50%; top: 100%; transform: translate(-50%, 4px); font-style: normal; font-size: 0.8rem; color: var(--green); opacity: 0; transition: opacity 0.2s; white-space: nowrap; }
.code-chip.flash em { opacity: 1; }
.round { flex: 1; text-align: center; color: var(--muted); font-weight: 500; }
.top-actions { display: flex; gap: 8px; }

/* Players */
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 14px; background: rgba(0,0,0,.18); transition: background .2s, opacity .2s; }
.plist li.off { opacity: 0.4; }
.plist li.turn { background: rgba(255, 214, 10, 0.16); box-shadow: inset 0 0 0 2px var(--gold); }
.plist li.win { background: rgba(6, 214, 160, 0.18); box-shadow: inset 0 0 0 2px var(--green); }
.plist .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .pname small { color: var(--muted); margin-left: 4px; }
.plist .score { font-weight: 700; font-variant-numeric: tabular-nums; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; color: #1a1033; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
}
.count { color: var(--muted); font-weight: 400; }
.invite { width: 100%; margin-top: 14px; }

/* Lobby */
.lobby-grid { display: grid; grid-template-columns: 1fr 1.3fr; gap: 16px; }
.setting { margin-bottom: 16px; }
.setting > span { display: block; color: var(--muted); font-size: 0.95rem; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 0; border-radius: 999px; padding: 8px 14px; cursor: pointer; background: rgba(0,0,0,.25);
  box-shadow: inset 0 0 0 2px var(--line); font-weight: 500;
}
.chip.on { background: var(--blue); color: #0b2530; box-shadow: none; }
.chip:disabled { cursor: default; }
.chip:disabled:not(.on) { opacity: 0.5; }
.rules { margin-top: 16px; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ol { margin: 12px 0 0; padding-left: 20px; line-height: 1.7; color: var(--muted); }
.rules b, .rules i { color: var(--text); }

/* Game */
#game { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.side { display: grid; gap: 12px; position: sticky; top: 16px; }
.mystery { perspective: 900px; height: 230px; }
.mystery-inner { position: relative; width: 100%; height: 100%; transition: transform 0.9s cubic-bezier(.3,1.4,.5,1); transform-style: preserve-3d; }
.mystery.flipped .mystery-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; border-radius: var(--radius); display: flex; flex-direction: column; align-items: center; justify-content: center;
  backface-visibility: hidden; box-shadow: var(--shadow), inset 0 0 0 4px rgba(255,255,255,.2); padding: 16px; text-align: center;
}
.front { background: linear-gradient(145deg, var(--pink), #7b2cbf); }
.front .q { font-size: 120px; line-height: 1; font-weight: 700; text-shadow: 0 6px 0 rgba(0,0,0,.25); animation: wobble 4s ease-in-out infinite; }
.front .kind { margin-top: 8px; font-weight: 600; background: rgba(0,0,0,.25); padding: 6px 12px; border-radius: 999px; font-size: 0.95rem; }
@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
.back { background: linear-gradient(145deg, var(--green), #118ab2); transform: rotateY(180deg); }
.reveal-label { color: rgba(255,255,255,.8); font-size: 0.95rem; }
.reveal { font-size: 1.9rem; font-weight: 700; line-height: 1.15; margin-top: 4px; text-shadow: 0 3px 0 rgba(0,0,0,.2); }
.timer { height: 10px; border-radius: 99px; background: rgba(0,0,0,.3); overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: var(--green); border-radius: inherit; transition: background 0.3s; }
.timer.warn i { background: var(--amber); }
.timer.crit i { background: var(--red); }
.timer.off { visibility: hidden; }

.main { display: flex; flex-direction: column; min-height: calc(100vh - 100px); min-height: calc(100dvh - 100px); }
.feed { flex: 1; display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.feed-empty { color: var(--muted); text-align: center; padding: 40px 16px; border: 2px dashed var(--line); border-radius: var(--radius); }
.entry { display: flex; gap: 10px; align-items: flex-start; animation: slide-in 0.3s ease-out; }
@keyframes slide-in { from { opacity: 0; transform: translateY(10px); } }
.bubble { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px 18px 18px 18px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.bubble .who { font-size: 0.8rem; color: var(--muted); width: 100%; margin-bottom: -6px; }
.bubble .text { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.entry.guess .bubble { border-color: var(--gold); background: rgba(255, 214, 10, 0.08); }
.entry.skip .bubble { background: transparent; border-style: dashed; color: var(--muted); }
.entry.correct .bubble { border-color: var(--green); background: rgba(6, 214, 160, 0.15); }
.pill { font-weight: 700; border-radius: 999px; padding: 6px 14px; white-space: nowrap; animation: pop 0.45s cubic-bezier(.3,1.8,.5,1); }
@keyframes pop { from { transform: scale(0.2); opacity: 0; } }
.pill.yes { background: var(--green); color: #032b20; }
.pill.no { background: var(--red); color: #3a0808; }
.pill.sometimes { background: var(--amber); color: #3a2200; }
.pill.unknown { background: var(--grey); color: #1d1a24; }
.pill.correct { background: var(--gold); color: #3a2c00; }
.dots { display: inline-flex; gap: 4px; padding: 10px 14px; background: rgba(0,0,0,.25); border-radius: 999px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--text); animation: dot 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 50% { transform: translateY(-5px); opacity: .4; } }

.composer { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.turn-banner { text-align: center; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.turn-banner.mine { color: var(--gold); font-size: 1.15rem; font-weight: 700; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }
#ask-form { display: grid; gap: 10px; }
.ask-buttons { display: flex; gap: 8px; }
.ask-buttons #ask { flex: 1; }
#ask-form.idle { opacity: 0.45; pointer-events: none; filter: grayscale(.6); }
#question { font-size: 1.05rem; }

.emotes { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.emotes button { background: transparent; border: 0; font-size: 1.4rem; cursor: pointer; padding: 4px 6px; border-radius: 10px; transition: transform .1s; }
.emotes button:hover { transform: scale(1.25); background: var(--panel); }
.float-emote { position: fixed; z-index: 30; pointer-events: none; font-size: 2.2rem; animation: rise 2.2s ease-out forwards; text-align: center; }
.float-emote small { display: block; font-size: .75rem; color: var(--muted); }
@keyframes rise { to { transform: translateY(-260px) scale(1.4); opacity: 0; } }

/* Game over */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(10, 5, 25, 0.7); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 16px; animation: fade .3s; }
@keyframes fade { from { opacity: 0; } }
.over-card { width: min(440px, 100%); background: var(--bg2); border: 1px solid var(--line); border-radius: 24px; padding: 26px 22px; text-align: center; box-shadow: var(--shadow); animation: pop .5s cubic-bezier(.3,1.5,.5,1); max-height: 100%; overflow: auto; }
.over-emoji { font-size: 64px; line-height: 1; }
.over-card h2 { margin: 10px 0 6px; font-size: 1.8rem; }
.over-secret { color: var(--muted); margin: 0 0 18px; }
.over-secret b { color: var(--gold); font-size: 1.25rem; display: block; margin-top: 2px; }
.over-card .plist { text-align: left; margin-bottom: 18px; }
.over-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.over-actions .big { grid-column: 1 / -1; }

/* Toasts etc. */
.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -150%); z-index: 40; background: #fff; color: #1a1033;
  padding: 10px 18px; border-radius: 999px; font-weight: 600; box-shadow: var(--shadow); transition: transform .3s cubic-bezier(.3,1.4,.5,1);
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); }
.toast.big { background: var(--gold); font-size: 1.3rem; padding: 14px 26px; }
.conn { position: fixed; bottom: 16px; left: 16px; z-index: 40; background: var(--red); color: #fff; padding: 8px 14px; border-radius: 12px; font-weight: 600; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(900deg); } }

@media (max-width: 760px) {
  .screen { padding: 12px 16px; }
  .lobby-grid { grid-template-columns: 1fr; }
  #game { grid-template-columns: 1fr; gap: 12px; }
  .side { position: static; grid-template-columns: 110px 1fr; align-items: start; }
  .mystery { height: 140px; grid-row: span 3; }
  .front .q { font-size: 64px; }
  .front .kind { font-size: 0.75rem; padding: 4px 8px; }
  .reveal { font-size: 1.1rem; }
  .side .plist { grid-template-columns: 1fr 1fr; gap: 6px; }
  .side .plist li { padding: 5px 8px; gap: 6px; font-size: 0.9rem; }
  .side .plist .avatar { width: 24px; height: 24px; font-size: 0.75rem; }
  .main { min-height: calc(100dvh - 240px); }
  .round { font-size: 0.9rem; }
}

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