:root {
  --bg: #f6f3ff;
  --card: #ffffff;
  --text: #1d1636;
  --muted: #6b6485;
  --line: #e6e0f5;
  --brand: #6d4aff;
  --brand-2: #ff4f8b;
  --brand-soft: #efeaff;
  --good: #14a36b;
  --good-soft: #e3f7ee;
  --bad: #e0445a;
  --bad-soft: #fde8eb;
  --shadow: 0 10px 30px rgba(60, 30, 140, .10);
  --radius: 18px;
  /* Player colors: player 1 = purple, player 2 = pink */
  --p0: #6d4aff;
  --p0-soft: #efeaff;
  --p1: #e8367a;
  --p1-soft: #ffe8f1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #120e22;
    --card: #1d1833;
    --text: #f1eefc;
    --muted: #a59fc0;
    --line: #2f2850;
    --brand: #8b6dff;
    --brand-soft: #2a2250;
    --good-soft: #0f3326;
    --bad-soft: #3a1720;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --p0: #9b82ff;
    --p0-soft: #2a2250;
    --p1: #ff6fa3;
    --p1-soft: #3a1a2b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  background-image: radial-gradient(circle at 10% 0%, rgba(109, 74, 255, .14), transparent 45%),
                    radial-gradient(circle at 90% 10%, rgba(255, 79, 139, .12), transparent 40%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.top {
  max-width: 560px; margin: 0 auto; padding: 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand {
  font-weight: 800; font-size: 1.1rem; text-decoration: none;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lang {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-weight: 600; cursor: pointer;
}

main { max-width: 560px; margin: 0 auto; padding: 0 16px 48px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; margin-bottom: 16px;
  animation: pop .25s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.center { text-align: center; }

h1 { font-size: 1.6rem; margin: 0 0 8px; line-height: 1.3; }
h2 { font-size: 1.25rem; margin: 0 0 12px; line-height: 1.4; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.hero-emoji { font-size: 3rem; line-height: 1; margin-bottom: 8px; }

label { display: block; font-weight: 600; margin: 16px 0 6px; }
input[type=text] {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text);
}
input[type=text]:focus { outline: none; border-color: var(--brand); }

.hint { font-size: .85rem; color: var(--muted); margin: 6px 0 0; }
.code-row { display: flex; gap: 8px; }
.code-input {
  direction: ltr; text-align: center; text-transform: uppercase;
  letter-spacing: .2em; font-weight: 800; font-size: 1.2rem;
}
.dice {
  flex: 0 0 52px; font-size: 1.4rem; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--bg);
}
.bigcode {
  direction: ltr; font-size: 2.2rem; font-weight: 800; letter-spacing: .25em;
  padding: 10px 0 10px .25em; margin: 8px 0; border-radius: 14px;
  background: var(--brand-soft); color: var(--brand);
}

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; font: inherit; font-weight: 600; padding: 10px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text);
}
.seg button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

.btn {
  display: block; width: 100%; margin-top: 20px; padding: 14px; border: 0; border-radius: 14px;
  font: inherit; font-weight: 800; font-size: 1.05rem; color: #fff; cursor: pointer;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 18px rgba(109, 74, 255, .3);
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); box-shadow: none; }
.row { display: flex; gap: 8px; }
.row .btn { margin-top: 12px; }

.linkbox {
  direction: ltr; text-align: left; font-family: ui-monospace, monospace; font-size: .9rem;
  background: var(--bg); border: 1px dashed var(--line); border-radius: 12px; padding: 12px;
  word-break: break-all; margin-top: 12px;
}

/* Quiz */
.progress { height: 8px; background: var(--brand-soft); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .25s; }
.step { font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.phase-tag {
  display: inline-block; font-size: .8rem; font-weight: 800; padding: 2px 10px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); margin-bottom: 8px;
}
.options { display: grid; gap: 10px; margin-top: 12px; }
.opt {
  font: inherit; text-align: start; padding: 14px 16px; border-radius: 14px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text); font-weight: 600;
  transition: transform .08s, border-color .15s;
}
.opt:active { transform: scale(.98); }
.opt.on { border-color: var(--brand); background: var(--brand-soft); }
.back { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; margin-top: 12px; padding: 4px 0; }

/* Waiting */
.status { list-style: none; padding: 0; margin: 16px 0 0; text-align: start; }
.status li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.status li:last-child { border: 0; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%; margin: 12px auto;
  border: 4px solid var(--brand-soft); border-top-color: var(--brand); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results */
.scores { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 4px; }
.score { border-radius: 16px; padding: 16px 8px; background: var(--bg); border: 2px solid var(--line); }
.score.win { border-color: var(--brand); background: var(--brand-soft); }
.score .n { font-size: 2.2rem; font-weight: 800; line-height: 1.1; }
.score .who { font-weight: 700; }
.crown { font-size: 1.4rem; }

.qres { padding: 14px 0; border-bottom: 1px solid var(--line); }
.qres:last-child { border: 0; }
.qres .q { font-weight: 800; margin-bottom: 6px; }
.pair { display: flex; justify-content: space-between; gap: 8px; font-size: .92rem; padding: 6px 10px; border-radius: 10px; margin-top: 6px; }
.pair.ok { background: var(--good-soft); }
.pair.no { background: var(--bad-soft); }
.pair b { font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: .2s; font-weight: 600; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- v2: players, rounds, reveal ---------- */
a.btn { text-decoration: none; text-align: center; }
.hidden { display: none; }
.small { font-size: .85rem; }

.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.how div { background: var(--bg); border-radius: 14px; padding: 10px 6px; font-size: .85rem; font-weight: 600; line-height: 1.4; }
.how span { display: block; font-size: 1.7rem; margin-bottom: 4px; }

.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatar {
  font-size: 1.7rem; aspect-ratio: 1; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--line); background: var(--bg); padding: 0;
}
.avatar.on { border-color: var(--brand); background: var(--brand-soft); transform: scale(1.08); }

/* Player colors */
.c0 { --pc: var(--p0); --pcs: var(--p0-soft); }
.c1 { --pc: var(--p1); --pcs: var(--p1-soft); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px 2px 4px; border-radius: 999px;
  background: var(--pcs); color: var(--pc); font-weight: 800; font-size: .92rem; white-space: nowrap;
}
[dir=rtl] .chip { padding: 2px 4px 2px 10px; }
.chip .av { font-size: 1.1rem; }
.big-avatar {
  position: relative; width: 72px; height: 72px; margin: 0 auto 6px; border-radius: 50%;
  display: grid; place-items: center; font-size: 2.4rem;
  background: var(--pcs, var(--bg)); border: 3px solid var(--pc, var(--line));
}
.big-avatar.huge { width: 104px; height: 104px; font-size: 3.4rem; }
.crown { position: absolute; top: -22px; font-size: 1.6rem; }

.players { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 12px 0; }
.pslot { flex: 1; max-width: 160px; }
.pslot.empty { opacity: .6; }
.pname { font-weight: 800; overflow-wrap: anywhere; }
.pslot .score { font-weight: 800; color: var(--muted); }
.vs { font-weight: 800; color: var(--muted); font-size: 1.1rem; }

/* 3-step bar */
.stepper { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 0 0 14px; }
.st { display: flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 700; color: var(--muted); }
.st span {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); border: 2px solid var(--line); font-size: .95rem;
}
.st.now { color: var(--brand); }
.st.now span { border-color: var(--brand); background: var(--brand-soft); transform: scale(1.12); }
.st.done span { background: var(--good); border-color: var(--good); color: #fff; }
.st-line { width: 18px; height: 2px; background: var(--line); }

/* Question card */
.qtop { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.tag {
  display: inline-block; font-size: .88rem; font-weight: 800; padding: 4px 12px; border-radius: 999px;
  background: var(--pcs, var(--brand-soft)); color: var(--pc, var(--brand));
}
.tag.likely { background: #fff3d6; color: #a86700; }
@media (prefers-color-scheme: dark) { .tag.likely { background: #3a2c0c; color: #ffc34d; } }
.count { font-size: .85rem; color: var(--muted); font-weight: 700; }
.qemoji { font-size: 2.6rem; text-align: center; line-height: 1.2; margin-top: 4px; }
.qtext { text-align: center; }
.qtext b { color: var(--pc, var(--brand)); }
.options.two { grid-template-columns: 1fr 1fr; }
.opt.who { text-align: center; padding: 18px 8px; border-color: var(--pc); background: var(--pcs); }
.opt.who .av { display: block; font-size: 2rem; }
.opt.who.on { outline: 3px solid var(--pc); }
.intro h1 { margin-top: 8px; }

/* Lobby: own questions */
#customCard input[type=text] { margin-top: 8px; }
.cq {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px;
  background: var(--bg); border-radius: 12px; margin-top: 8px;
}
.x { background: none; border: 0; font-size: 1rem; color: var(--muted); cursor: pointer; padding: 6px; }
.copt { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.copt input[type=text] { margin-top: 0 !important; }
.tick {
  flex: 0 0 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: var(--bg);
  color: var(--muted); font-weight: 800; cursor: pointer;
}
.tick.on { background: var(--good); border-color: var(--good); color: #fff; }

/* Reveal & results */
.reveal .count { margin-bottom: 6px; }
.apair { background: var(--bg); border-radius: 14px; padding: 8px 12px; margin-top: 10px; text-align: start; }
.aline { padding: 5px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.badge { display: inline-block; margin-top: 10px; padding: 4px 12px; border-radius: 999px; font-weight: 800; }
.badge.good { background: var(--good-soft); color: var(--good); }
.react { font-size: 1.2rem; font-weight: 800; margin-top: 12px; }

.love {
  font-size: 4.2rem; font-weight: 800; line-height: 1.1;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.winner { font-weight: 800; font-size: 1.05rem; }
.meters { text-align: start; margin-top: 12px; }
.meter { margin-top: 10px; }
.mlabel { display: flex; justify-content: space-between; font-size: .9rem; font-weight: 700; }
.mbar { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.mbar > div { height: 100%; border-radius: 999px; }
.mbar .mm { background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.mbar .c0bg { background: var(--p0); }
.mbar .c1bg { background: var(--p1); }
.dcard { border-top: 1px solid var(--line); padding: 14px 0; text-align: center; }
.dcard:first-of-type { border-top: 0; }
.dcard .qemoji { font-size: 1.6rem; }
.dcard .qtext { font-size: 1.05rem; }
.dcard .react { font-size: 1rem; }

@media (max-width: 380px) {
  .st { font-size: .75rem; }
  .st-line { width: 8px; }
  .big-avatar { width: 60px; height: 60px; font-size: 2rem; }
}
