/* =============================================================
   مرسوم — نفس روح "بيننا واحد" (عتمة + خط Estedad + نفس المكوّنات:
   شريط الحساب، نوافذ الدخول/التفعيل، اللوبي) بلون هوية مختلف (وردي
   بدل كهرماني)، حتى يبان واضح إنه نفس عائلة تكية بدون ما يكون نفس
   اللعبة بالضبط.
   ============================================================= */

:root {
  --bg-void: #120e1b;
  --bg-panel: #1e1730;
  --bg-panel-raised: #271e3c;
  --line: #362a4f;
  --ink: #f2ece0;
  --ink-muted: #9c90b3;
  --ink-faint: #6c6285;

  --accent: #ff8fc0;
  --accent-soft: #ffb3d6;
  --crimson: #c8483d;
  --crimson-soft: #de6b5f;
  --success: #6fae7f;

  --font-display: "Estedad", "Arial Black", sans-serif;
  --font-body: "Estedad", "Tahoma", "Segoe UI", sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg-void); color: var(--ink); min-height: 100%; }
body {
  direction: rtl;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: #1a1220; }
button, input, select, textarea { font-family: inherit; }
button, a, [data-action] { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 800; margin: 0; text-wrap: balance; }

.room-code-chip, .player-row .score, .timer-label, .word-pattern, .score-row .total {
  font-weight: 800;
}

/* -------------------------------------------------------------
   الحاوية العامة (نفس أبعاد بيننا واحد بالضبط)
   ------------------------------------------------------------- */
.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(18px + var(--safe-top)) 18px calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
}
@media (min-width: 720px) {
  .app { max-width: 780px; padding-top: 48px; padding-bottom: 48px; gap: 26px; }
}
/* شاشة الرسم أوسع من بقية الشاشات (كانفاس + 3 أعمدة) */
.app.wide { max-width: 1100px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.center { text-align: center; }
.grow { flex: 1; }

.wordmark, .brand {
  text-align: center;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(2.3rem, 9.5vw, 3rem);
  color: var(--accent-soft);
  filter: drop-shadow(0 3px 0 rgba(26,18,32,0.35));
  margin-bottom: 4px;
}

.subtitle { text-align: center; color: var(--ink-muted); font-size: 0.95rem; margin-top: -10px; }
.subtitle.lg { font-size: 1.15rem; color: var(--ink); }

label.field-label, .field-label { font-size: 0.85rem; color: var(--ink-muted); }

input[type="text"], input[type="tel"], input[type="email"], input[type="password"] {
  width: 100%;
  background: var(--bg-void);
  border: 1.5px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1.05rem;
  min-height: 52px;
}
input[type="text"]:focus, input[type="tel"]:focus, input[type="email"]:focus, input[type="password"]:focus {
  border-color: var(--accent);
}

.card {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.btn {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 1rem;
  border: none;
  border-radius: 100px;
  padding: 15px 26px;
  min-height: 52px;
  cursor: pointer;
  width: 100%;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:not(:disabled):active { transform: scale(0.98) translateY(1px); }
@media (hover: hover) {
  .btn:not(:disabled):hover { transform: translateY(-3px); }
  .btn.primary:not(:disabled):hover { box-shadow: 0 16px 28px -12px rgba(255,143,192,0.75); }
  .btn.secondary:not(:disabled):hover { transform: translateY(-3px); box-shadow: 0 12px 22px -14px rgba(0,0,0,0.5); }
}
.btn.primary { background: linear-gradient(180deg, var(--accent-soft), var(--accent)); color: #300f22; box-shadow: 0 10px 22px -10px rgba(255,143,192,0.6); }
.btn.secondary { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.secondary:not(:disabled):hover { border-color: var(--accent); color: var(--accent-soft); }
.btn.danger { background: linear-gradient(180deg, var(--crimson-soft), var(--crimson)); color: #2a0c09; }
.btn.ghost { background: var(--bg-panel-raised); color: var(--ink-muted); border: 1px solid var(--line); }
.btn.auto { width: auto; }
.btn.sm { padding: 10px 18px; min-height: 40px; font-size: 0.88rem; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 700;
  color: var(--ink-faint); background: var(--bg-panel-raised);
  border: 1px solid var(--line); padding: 5px 13px; border-radius: 100px;
}
.pill.host { color: var(--accent-soft); border-color: rgba(255,143,192,0.45); }
.pill.correct { color: var(--success); border-color: rgba(111,174,127,0.5); }

.error-box {
  background: rgba(200,72,61,0.12);
  border: 1px solid rgba(200,72,61,0.4);
  color: var(--crimson-soft);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.9rem;
}
.hint { color: var(--ink-faint); font-size: 0.82rem; line-height: 1.6; margin: 0; }

/* -------------------------------------------------------------
   شريط علوي داخل الغرفة (كود الغرفة + زر الرجوع/الإغلاق)
   ------------------------------------------------------------- */
.top-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.top-bar > .icon-btn, .top-bar > .back-x-btn { justify-self: start; }
.top-bar > .room-code-chip { justify-self: end; }

.room-code-chip {
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  color: var(--accent-soft);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 16px;
}

.lang-toggle {
  display: flex; border: 1px solid var(--line); border-radius: 100px; overflow: hidden;
}
.lang-btn {
  background: var(--bg-panel-raised); color: var(--ink-muted); border: none;
  font-weight: 800; font-size: 0.8rem; padding: 9px 14px; min-height: 38px;
}
.lang-btn.active { background: var(--accent); color: #300f22; }

.icon-btn {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-panel); color: var(--ink-faint);
  font-size: 0.95rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { color: var(--crimson-soft); border-color: var(--crimson-soft); }

.back-x-btn {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
  color: var(--ink-muted);
  background: linear-gradient(180deg, var(--bg-panel-raised), var(--bg-panel));
  border: 1px solid var(--line);
  box-shadow: 0 5px 12px -5px rgba(0,0,0,0.65), inset 0 1px 0 rgba(255,255,255,0.07);
}
.back-x-btn:hover { color: var(--accent-soft); border-color: var(--accent); }
.back-x-btn.danger-x:hover { color: var(--crimson-soft); border-color: var(--crimson-soft); }

/* -------------------------------------------------------------
   الأفتار
   ------------------------------------------------------------- */
.avatar { border-radius: 50%; background: var(--bg-panel-raised); object-fit: cover; flex: 0 0 auto; }
.avatar.sz-sm { width: 34px; height: 34px; }
.avatar.sz-md { width: 46px; height: 46px; }
.avatar.sz-lg { width: 88px; height: 88px; }

.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.avatar-option {
  position: relative; background: var(--bg-void); border: 2px solid var(--line);
  border-radius: 16px; padding: 8px; display: flex; align-items: center; justify-content: center; aspect-ratio: 1;
}
.avatar-option img { width: 100%; height: 100%; border-radius: 12px; }
.avatar-option.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,143,192,0.25); }
.avatar-option.taken { opacity: 0.3; pointer-events: none; }
.avatar-option.taken::after {
  content: "مأخوذ"; position: absolute; inset: auto 0 6px 0; text-align: center;
  font-size: 0.62rem; color: var(--ink-faint);
}

.avatar-edit-btn { background: none; border: none; padding: 0; border-radius: 50%; position: relative; flex: 0 0 auto; }
.avatar-edit-btn .avatar { box-shadow: 0 0 0 2px var(--accent); }
.avatar-edit-btn::after {
  content: "✎"; position: absolute; inset: auto -2px -2px auto; width: 18px; height: 18px;
  border-radius: 50%; background: var(--accent); color: #300f22; font-size: 0.62rem;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg-panel-raised);
}

.player-list { display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex; align-items: center; gap: 10px; background: var(--bg-panel-raised);
  border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px;
}
.player-row .name { font-weight: 600; }
.player-row .meta { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.player-row .score { font-family: var(--font-display); color: var(--accent-soft); font-size: 1rem; }
.player-row.is-drawer { border-color: var(--accent); }
.player-row.has-guessed { opacity: 0.75; }

/* -------------------------------------------------------------
   شريط الحساب (فوق يمين) + نوافذ الدخول/التفعيل
   ------------------------------------------------------------- */
.account-bar { position: fixed; top: calc(14px + var(--safe-top)); right: 14px; z-index: 60; }
.room-bar { position: fixed; top: calc(14px + var(--safe-top)); right: 14px; z-index: 60; }
.account-cluster { position: relative; display: flex; align-items: center; gap: 8px; }

.account-btn {
  display: flex; align-items: center; gap: 8px; background: var(--bg-panel);
  border: 1px solid var(--line); color: var(--ink); border-radius: 100px; padding: 9px 16px;
  font-size: 0.88rem; font-weight: 700;
}
.account-btn.login { color: var(--accent-soft); border-color: rgba(255,143,192,0.4); }
.account-btn:hover { border-color: var(--accent); color: var(--accent-soft); }
.account-btn .avatar-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: 0 0 auto; }

.status-pill {
  display: flex; align-items: center; background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: 100px; padding: 9px 16px; font-size: 0.88rem; font-weight: 700;
}
.status-pill.active { color: var(--success); border-color: rgba(111,174,127,0.45); }
.status-pill.free { color: var(--ink-faint); }

.account-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 61;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 16px; padding: 8px;
  min-width: 180px;
}
.account-menu .who-email { color: var(--ink-faint); font-size: 0.76rem; padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 6px; word-break: break-all; }
.account-menu-item { width: 100%; text-align: right; background: none; border: none; color: var(--crimson-soft); font-weight: 700; font-size: 0.92rem; padding: 10px; border-radius: 10px; }
.account-menu-item:hover { background: var(--bg-panel-raised); }

.status-menu { min-width: 220px; padding: 14px; }
.status-detail-title { font-weight: 800; color: var(--accent-soft); font-size: 0.95rem; }
.status-detail-title.muted { color: var(--ink-faint); font-weight: 600; font-size: 0.88rem; }
.status-detail-dates { color: var(--ink-faint); font-size: 0.78rem; margin-top: 4px; }

.link-btn { background: none; border: none; color: var(--ink-faint); text-decoration: underline; font-size: 0.85rem; padding: 6px; }

.share-text-input {
  text-align: center;
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--accent-soft);
}

@keyframes mrsoom-fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(9, 6, 15, 0.72); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center; padding: 18px; z-index: 50;
  animation: mrsoom-fade-up 0.2s ease both;
}
.modal-card {
  width: 100%; max-width: 480px; max-height: 82dvh; overflow-y: auto;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 22px; padding: 20px;
}
@media (min-width: 640px) { .modal-overlay { align-items: center; } }

.auth-switch-note { text-align: center; color: var(--ink-faint); font-size: 0.85rem; }
.auth-switch-note button { background: none; border: none; color: var(--accent-soft); font-weight: 700; text-decoration: underline; padding: 0; }

.global-toast {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--bg-panel-raised); border: 1px solid var(--line); color: var(--ink);
  padding: 10px 18px; border-radius: 100px; font-size: 0.88rem; z-index: 70;
  animation: mrsoom-fade-up 0.2s ease both;
}

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; margin: 12px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.round-label { color: var(--ink-muted); font-weight: 700; }
.word-choices { display: flex; flex-direction: column; gap: 10px; }

/* -------------------------------------------------------------
   منصة التتويج — الأول بالنص وأعلى، الثاني يمين، الثالث يسار
   ------------------------------------------------------------- */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; width: 100%; margin: 6px 0 4px; }
.podium-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; min-width: 0; max-width: 140px; }
.podium-medal { font-size: 1.5rem; line-height: 1; }
.podium-slot .name { font-size: 0.9rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-score { font-family: var(--font-display); color: var(--accent-soft); font-weight: 800; font-size: 1.1rem; }
.podium-pedestal {
  width: 100%; border-radius: 10px 10px 0 0; background: var(--bg-panel-raised);
  border: 1px solid var(--line); border-bottom: none;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 6px;
  font-family: var(--font-display); font-weight: 900; color: var(--ink-faint);
}
.podium-slot.place-1 .podium-pedestal { height: 74px; background: linear-gradient(180deg, var(--accent-soft), var(--accent)); color: #300f22; }
.podium-slot.place-2 .podium-pedestal { height: 50px; }
.podium-slot.place-3 .podium-pedestal { height: 34px; }

/* -------------------------------------------------------------
   شاشة الرسم — 3 أعمدة معكوسة (RTL): أسماء يمين، رسمة نص، شات يسار
   ------------------------------------------------------------- */
.word-bar {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 16px;
}
.timer-label { font-family: var(--font-display); font-size: 1.4rem; color: var(--accent-soft); min-width: 3ch; text-align: center; }
.word-pattern { font-family: var(--font-display); font-size: 1.5rem; letter-spacing: 0.3em; }
.my-word { font-weight: 700; color: var(--accent-soft); }

.game-grid {
  display: grid;
  grid-template-columns: 200px 1fr 240px;
  /* يمين↔يسار بترتيب RTL طبيعي: أول عمود بالـgrid يظهر بأقصى اليمين */
  gap: 12px;
  align-items: start;
}

.players-col, .chat-col { display: flex; flex-direction: column; gap: 8px; }

.canvas-col { display: flex; flex-direction: column; gap: 10px; align-items: center; }
#draw-canvas {
  width: 100%;
  aspect-ratio: 800 / 500;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  touch-action: none;
  cursor: crosshair;
}

.toolbar {
  width: 100%; display: flex; flex-direction: column; gap: 10px;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
}
.colors { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.color-swatch { width: 100%; aspect-ratio: 1; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; }
.color-swatch.selected { outline: 2px solid var(--accent); outline-offset: 1px; }

.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }

.tool-icon {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-panel-raised); border: 1px solid var(--line);
  color: var(--ink); font-size: 1.1rem; line-height: 1;
}
.tool-icon:active { transform: scale(0.94); }
.tool-icon.active { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,143,192,0.25); }

.size-picker { position: relative; }
.size-dot { display: block; border-radius: 50%; background: var(--ink); }
.tool-icon .size-dot { background: var(--ink); }

.size-popup {
  position: absolute; bottom: calc(100% + 8px); right: 50%; transform: translateX(50%);
  background: var(--bg-panel-raised); border: 1px solid var(--line); border-radius: 100px;
  padding: 10px 8px; align-items: center; z-index: 40;
}
.size-option {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: none;
  display: flex; align-items: center; justify-content: center;
}
.size-option.selected { background: var(--accent); }
.size-option .size-dot { background: var(--ink); }
.size-option.selected .size-dot { background: #300f22; }

.chat-log {
  flex: 1; min-height: 260px; max-height: 420px; overflow-y: auto;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
  display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem;
}
.chat-line { padding: 4px 6px; border-radius: 8px; }
.chat-line.correct-line { color: var(--success); font-weight: 700; }
.guess-form { display: flex; }
.guess-form input { width: 100%; }

@media (max-width: 760px) {
  .game-grid { grid-template-columns: 1fr; }
  .players-col { flex-direction: row; overflow-x: auto; }
  .players-col .player-row { flex: 0 0 auto; }
  .chat-log { max-height: 200px; min-height: 140px; }
}

.home-btn {
  position: fixed; top: calc(14px + var(--safe-top)); left: 14px; z-index: 60;
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-panel, #1e1730); border: 1px solid var(--line, #362a4f); color: var(--ink-muted, #9c90b3);
  text-decoration: none;
}
.home-btn svg { width: 20px; height: 20px; }
.home-btn:hover { color: var(--accent-soft, #ffb3d6); border-color: var(--accent, #ff8fc0); }

/* لوقو مرسوم فوق العنوان بالصفحة الرئيسية */
.brand-logo { display: block; width: 132px; height: 132px; margin: 0 auto -6px; object-fit: contain; }

/* علامة X موحّدة (shared/icons.js) — بالنص تمامًا داخل أي زر */
.x-ico { display: block; width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 3.4; stroke-linecap: round; flex: 0 0 auto; }
.x-ico.inline { display: inline-block; width: 0.8em; height: 0.8em; vertical-align: -0.08em; }
.icon-btn, .back-x-btn, .kick-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0; line-height: 1; }
