:root {
  --bg: #14112b;
  --bg2: #1d1840;
  --surface: #251f4d;
  --surface2: #30296164;
  --line: #3b3470;
  --text: #f4f1ff;
  --muted: #a59fcf;
  --accent: #ffc93c;
  --accent-ink: #2a1d00;
  --me: #2ed3b7;
  --them: #ff6b6b;
  --radius: 16px;
  --font: 'Tajawal', system-ui, 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 600px at 80% -10%, #2c2468 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 110%, #3a1d4f 0%, transparent 55%), var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

#app { max-width: 1180px; margin: 0 auto; padding-inline: 16px; padding-block: 16px 140px; }

/* ---------- shared bits ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: 999px; font-weight: 700; font-size: 16px;
  background: var(--surface); border: 1px solid var(--line); transition: transform .12s, filter .12s;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.me { background: var(--me); color: #002a24; border-color: transparent; }
.btn.danger { background: var(--them); color: #2b0000; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.field {
  width: 100%; padding: 14px 16px; border-radius: 14px; background: var(--bg2);
  border: 1px solid var(--line); font-size: 17px; outline: none;
}
.field:focus { border-color: var(--accent); }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* ---------- home ---------- */
.home { min-height: 80vh; display: grid; place-items: center; }
.home-card { width: 100%; max-width: 420px; text-align: center; }
.logo { font-size: clamp(44px, 12vw, 64px); font-weight: 800; margin: 0; line-height: 1.1; letter-spacing: -1px; }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); margin: 8px 0 28px; font-size: 17px; }
.home-card .field { margin-bottom: 12px; text-align: center; }
.home-card .btn { width: 100%; padding-block: 15px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 18px 0; font-size: 14px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 10px; }
.join-row .field { margin: 0; letter-spacing: 6px; text-transform: uppercase; font-weight: 800; }
.join-row .btn { width: auto; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.code-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px dashed var(--accent); font-weight: 800; letter-spacing: 3px;
}
.code-chip small { letter-spacing: 0; color: var(--muted); font-weight: 500; }
.score { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; font-weight: 800; }
.pill { padding: 6px 12px; border-radius: 999px; background: var(--surface); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.pill.me { box-shadow: inset 0 0 0 2px var(--me); }
.pill.them { box-shadow: inset 0 0 0 2px var(--them); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #6b6699; }
.dot.on { background: #43e97b; }

/* ---------- lobby ---------- */
.panel { background: var(--surface2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.lobby-head { text-align: center; margin: 10px 0 22px; }
.lobby-head h2 { margin: 0 0 6px; font-size: 26px; }
.big-code { font-size: 44px; font-weight: 800; letter-spacing: 10px; color: var(--accent); margin: 6px 0 12px; }
.group-title { margin: 22px 4px 10px; font-size: 15px; color: var(--muted); font-weight: 700; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.cat {
  position: relative; overflow: hidden; border-radius: var(--radius); aspect-ratio: 4 / 3;
  background: var(--surface); border: 1px solid var(--line); text-align: start; padding: 0;
  transition: transform .15s, border-color .15s;
}
.cat:hover { transform: translateY(-2px); border-color: var(--accent); }
.cat .mosaic { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; opacity: .55; }
.cat .mosaic img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.cat .cat-label {
  position: absolute; inset: auto 0 0 0; padding: 26px 12px 10px; font-weight: 800; font-size: 17px;
  background: linear-gradient(transparent, rgba(12, 9, 30, .95));
}
.cat .cat-label small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.cat[disabled] { opacity: .5; }

/* ---------- board ---------- */
.stage { display: grid; gap: 16px; }
@media (min-width: 980px) { .stage { grid-template-columns: 1fr 300px; align-items: start; } }
.status {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface2); border: 1px solid var(--line); margin-bottom: 12px;
}
.status .turn { font-weight: 800; font-size: 18px; }
.status .turn.me { color: var(--me); }
.status .turn.them { color: var(--them); }
.secret-mini { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; background: none; padding: 0; }
.secret-mini img { width: 42px; height: 52px; object-fit: cover; object-position: top; border-radius: 8px; border: 2px solid var(--me); }
.secret-mini span { font-size: 12px; color: var(--muted); text-align: start; line-height: 1.3; }
.secret-mini b { display: block; color: var(--text); font-size: 14px; }

.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 8px; }
@media (max-width: 699px) { .board .face .name { font-size: 12px; padding-inline: 2px; } }
@media (min-width: 700px) { .board { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; } }
.card { perspective: 800px; aspect-ratio: 3 / 4; background: none; padding: 0; }
.card-inner { position: relative; width: 100%; height: 100%; transition: transform .45s cubic-bezier(.3, 1.4, .5, 1); transform-style: preserve-3d; }
.card.down .card-inner { transform: rotateX(-180deg); }
.face, .back {
  position: absolute; inset: 0; border-radius: 12px; overflow: hidden; backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face { background: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); }
.face img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.fit-contain .face { background: #eef0f6; }
.fit-contain .face img { object-fit: contain; object-position: center; padding: 14px 8px 30px; }
.face .name {
  position: absolute; inset: auto 0 0 0; padding: 18px 4px 6px; font-size: 13px; font-weight: 700; text-align: center;
  color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .85)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.back {
  transform: rotateX(180deg); display: grid; place-items: center; font-size: 34px; font-weight: 800; color: #ffffff30;
  background: repeating-linear-gradient(45deg, #2b2360 0 10px, #251e55 10px 20px); border: 2px solid #3d3580;
}
.card.selected .face { outline: 4px solid var(--accent); outline-offset: 2px; }
.card.is-secret .face::after {
  content: 'شخصيتك'; position: absolute; top: 6px; inset-inline-start: 6px; background: var(--me); color: #002a24;
  font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px;
}
.guessing .card:not(.down) .face { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px var(--accent), 0 4px 14px rgba(0, 0, 0, .35); } }

/* ---------- log ---------- */
.log { max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.log h3 { margin: 0 0 4px; font-size: 15px; color: var(--muted); }
.msg { padding: 9px 12px; border-radius: 14px; background: var(--surface); max-width: 92%; font-size: 15px; line-height: 1.5; }
.msg.mine { align-self: flex-start; border-start-start-radius: 4px; box-shadow: inset 3px 0 0 var(--me); }
.msg.theirs { align-self: flex-end; border-start-end-radius: 4px; box-shadow: inset -3px 0 0 var(--them); }
.msg.sys { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 2px; }
.ans { font-weight: 800; }
.ans.yes { color: #43e97b; }
.ans.no { color: var(--them); }
.ans.maybe { color: var(--accent); }
.log-toggle { display: inline-flex; }
@media (min-width: 980px) { .log-toggle { display: none; } }
.aside { position: sticky; top: 16px; }
@media (max-width: 979px) {
  .aside { position: fixed; inset: auto 0 0 0; z-index: 30; max-height: 70vh; border-radius: 22px 22px 0 0; transform: translateY(105%); transition: transform .25s; }
  .aside.open { transform: none; }
}

/* ---------- dock ---------- */
.dock {
  position: fixed; inset: auto 0 0 0; z-index: 20; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(20, 17, 43, .88); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.dock-inner { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.question { font-size: 18px; font-weight: 700; text-align: center; }
.answers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.answers .btn { padding-block: 14px; }
.ask-row { display: flex; gap: 8px; }
.ask-row .field { padding-block: 12px; }
.waiting { text-align: center; color: var(--muted); padding: 6px; }
.waiting b { color: var(--text); }

/* ---------- modal / toast / result ---------- */
#modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(8, 6, 20, .7); padding: 16px; }
.modal-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 22px; padding: 22px; width: 100%; max-width: 380px; text-align: center; }
.modal-card img { width: 160px; aspect-ratio: 3 / 4; object-fit: cover; object-position: top; border-radius: 14px; margin: 6px auto 12px; }
.modal-card h3 { margin: 0 0 6px; font-size: 22px; }
.modal-card .row { justify-content: center; margin-top: 16px; }
#toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 60; padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-weight: 700; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); max-width: calc(100vw - 32px);
}
.result { text-align: center; margin: 8px 0 20px; }
.result h2 { font-size: clamp(30px, 8vw, 44px); margin: 4px 0; }
.reveal { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; margin: 18px 0; }
.reveal figure { margin: 0; width: 140px; }
.reveal img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: top; border-radius: 14px; }
.reveal figcaption { margin-top: 6px; font-size: 14px; color: var(--muted); }
.reveal figcaption b { display: block; color: var(--text); font-size: 16px; }
.fit-contain.reveal img, .fit-contain .modal-img { object-fit: contain; background: #eef0f6; padding: 10px; }
