@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800;900&display=swap');

/* ===================================================
   MODERN DESIGN SYSTEM & TOKENS
   ثيم داكن متناسق ومضغوط لشاشات الهواتف
   =================================================== */
:root {
  --bg-dark: #0b1118;
  --bg-surface: #131c26;
  --bg-surface-elevated: #1a2634;
  --bg-surface-glass: rgba(19, 28, 38, 0.92);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-active: rgba(255, 255, 255, 0.18);

  --primary: #00d2aa;
  --primary-glow: rgba(0, 210, 170, 0.25);
  --primary-dark: #00a888;
  
  --accent-gold: #ffb703;
  --accent-gold-glow: rgba(255, 183, 3, 0.25);
  
  --danger: #ef476f;
  --danger-glow: rgba(239, 71, 111, 0.25);
  
  --info-blue: #3a86ff;
  
  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --radius-xl: 18px;
  --radius-lg: 12px;
  --radius-md: 9px;
  --radius-pill: 50px;

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

/* ===================================================
   RESET & BASE
   =================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body, button, input, textarea, select {
  font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.fa, .fas, .far, .fal, .fad, .fab, .fa-solid, .fa-regular, .fa-brands {
  font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands" !important;
}

.fa-regular { font-weight: 400 !important; }
.fa-solid { font-weight: 900 !important; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed; /* يمنع ارتداد الشاشة والتمرير خارج إطار التطبيق */
  direction: rtl;
  background-color: var(--bg-dark);
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: 
    radial-gradient(ellipse at 50% 0%, rgba(0, 210, 170, 0.1) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(255, 183, 3, 0.06) 0%, transparent 50%);
}

/* ===================================================
   APP WRAPPER - إطار يملأ الشاشة بدقة 100dvh
   =================================================== */
.app-wrapper {
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  background: var(--bg-surface-glass);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

@media (min-width: 500px) {
  .app-wrapper {
    height: calc(100dvh - 32px);
    max-height: 850px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  }
}

/* ===================================================
   HEADER
   =================================================== */
.app-header {
  padding: max(var(--safe-top), 6px) 12px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(11, 17, 24, 0.85);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  min-height: 48px;
  z-index: 20;
}

.header-side {
  flex: 1;
  display: flex;
  align-items: center;
}

.header-side.end {
  justify-content: flex-end;
}

.header-center {
  display: flex;
  justify-content: center;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.brand-icon {
  width: 26px;
  height: 26px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #0b1118;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  box-shadow: 0 0 10px var(--primary-glow);
}

.brand-name {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: var(--text-main);
}

.header-action-btn {
  background: rgba(239, 71, 111, 0.12);
  border: 1px solid rgba(239, 71, 111, 0.3);
  color: var(--danger);
  border-radius: var(--radius-pill);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.header-action-btn:active {
  transform: scale(0.95);
}

.room-pill {
  background: rgba(255, 183, 3, 0.12);
  border: 1px solid rgba(255, 183, 3, 0.3);
  color: var(--accent-gold);
  border-radius: var(--radius-pill);
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.room-pill .pill-label {
  color: var(--text-muted);
  font-size: 10px;
}

.room-pill strong {
  letter-spacing: 0.8px;
}

/* ===================================================
   MAIN APP BODY & SCREENS
   =================================================== */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.screen {
  display: none;
  flex: 1;
  padding: 10px 14px max(var(--safe-bottom), 10px);
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
  animation: slideFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===================================================
   CARDS & CONTAINERS
   =================================================== */
.card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px;
}

.glass-banner {
  background: rgba(26, 38, 52, 0.85);
  border: 1px solid rgba(0, 210, 170, 0.3);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.banner-content {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
}

.banner-icon {
  width: 28px;
  height: 28px;
  background: var(--primary-glow);
  color: var(--primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.banner-title {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-main);
}

.banner-sub {
  display: block;
  font-size: 10.5px;
  color: var(--primary);
  font-weight: 700;
}

/* ===================================================
   HERO & TYPOGRAPHY
   =================================================== */
.hero-section {
  text-align: center;
  margin: 6px 0 10px;
}

.game-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(0, 210, 170, 0.12);
  border: 1px solid rgba(0, 210, 170, 0.25);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 6px;
}

.game-tag.danger {
  background: rgba(239, 71, 111, 0.12);
  border-color: rgba(239, 71, 111, 0.3);
  color: var(--danger);
}

.game-tag.success {
  background: rgba(0, 210, 170, 0.15);
  color: var(--primary);
}

.hero-title {
  font-size: 21px;
  font-weight: 900;
  color: var(--text-main);
  line-height: 1.2;
  margin-bottom: 2px;
}

.hero-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

.screen-header-info {
  text-align: center;
  margin-bottom: 8px;
}

.section-title {
  font-size: 18px;
  font-weight: 900;
  color: var(--text-main);
  margin-bottom: 1px;
}

.section-subtitle {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.section-block {
  margin-bottom: 8px;
}

.section-block.flex-grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 80px;
}

.block-label {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--text-secondary);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* ===================================================
   TABS & INPUTS
   =================================================== */
.segmented-tabs {
  display: flex;
  background: var(--bg-dark);
  padding: 3px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  gap: 3px;
  border: 1px solid var(--border-color);
}

.tab-item {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 6px;
  font-size: 12.5px;
  font-weight: 800;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.tab-item.active {
  background: var(--bg-surface-elevated);
  color: var(--primary);
}

.input-field-group {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-field-group label {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--text-secondary);
}

.input-wrapper input {
  width: 100%;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 700;
  outline: none;
  transition: border-color 0.15s;
}

.input-wrapper input:focus {
  border-color: var(--primary);
}

/* ===================================================
   BUTTONS
   =================================================== */
.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-block { width: 100%; }

.btn-lg {
  padding: 11px 16px;
  font-size: 14px;
  border-radius: var(--radius-md);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11.5px;
  border-radius: 6px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #0b1118;
}

.btn-primary:active { transform: scale(0.98); }

.btn-accent {
  background: linear-gradient(135deg, var(--accent-gold), #e09f00);
  color: #0b1118;
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #d9385d);
  color: #ffffff;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.screen-bottom-bar {
  margin-top: auto;
  padding-top: 6px;
  flex-shrink: 0;
}

/* ===================================================
   MODES LIST
   =================================================== */
.modes-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mode-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-card.selected {
  background: rgba(0, 210, 170, 0.08);
  border: 1.5px solid var(--primary);
}

.mode-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.mode-icon.q-icon { background: rgba(0, 210, 170, 0.15); color: var(--primary); }
.mode-icon.w-icon { background: rgba(58, 134, 255, 0.15); color: var(--info-blue); }
.mode-icon.a-icon { background: rgba(255, 183, 3, 0.15); color: var(--accent-gold); }

.mode-details { flex: 1; min-width: 0; }

.mode-name {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 5px;
}

.mode-desc {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  font-size: 9px;
  background: var(--primary);
  color: #0b1118;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 800;
}

/* ===================================================
   PLAYERS LIST
   =================================================== */
.players-scroll-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  max-height: 140px;
  overflow-y: auto;
}

.player-item-row {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.player-info-side {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
}

.player-num {
  width: 20px;
  height: 20px;
  background: var(--bg-dark);
  color: var(--text-secondary);
  border-radius: 5px;
  font-size: 11px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.player-num.host { background: var(--accent-gold); color: #0b1118; }

.player-name-val {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-color-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.player-score-side {
  text-align: left;
  flex-shrink: 0;
}

.score-digits {
  font-size: 13px;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
}

.score-unit {
  font-size: 9px;
  color: var(--text-muted);
}

.waiting-box {
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  padding: 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ===================================================
   QUESTION & REVEAL BOXES
   =================================================== */
.highlight-box {
  background: rgba(255, 183, 3, 0.08);
  border: 1px solid rgba(255, 183, 3, 0.3);
  border-radius: var(--radius-md);
  padding: 8px;
  text-align: center;
  margin-bottom: 8px;
}

.secret-label {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--accent-gold);
}

.secret-word-text {
  font-size: 19px;
  font-weight: 900;
  color: var(--text-main);
  margin-top: 1px;
}

.impostor-hint-text {
  font-size: 10.5px;
  color: var(--accent-gold);
  font-weight: 700;
  margin-top: 2px;
}

.question-card {
  padding: 12px;
  text-align: center;
  margin-bottom: 8px;
}

.question-content {
  font-size: 14.5px;
  font-weight: 900;
  color: var(--text-main);
  line-height: 1.45;
}

.success-card {
  text-align: center;
  padding: 12px;
  border-color: rgba(0, 210, 170, 0.3);
  background: rgba(0, 210, 170, 0.05);
}

.success-icon {
  font-size: 26px;
  color: var(--primary);
  margin-bottom: 4px;
}

.success-card h3 {
  font-size: 14px;
  font-weight: 900;
  color: var(--text-main);
}

.success-card p {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ===================================================
   PROGRESS GRID
   =================================================== */
.progress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 5px;
}

.progress-chip {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.progress-chip.ready {
  border-color: rgba(0, 210, 170, 0.4);
  background: rgba(0, 210, 170, 0.06);
}

.chip-name {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-status {
  font-size: 8.5px;
  font-weight: 700;
  color: var(--text-muted);
}

#screen-drawing {
  display: none;
}

#screen-drawing.active {
  display: flex;
  flex-direction: column;
}

.canvas-card {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 2px;
  position: relative;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 240px;
  margin-bottom: 6px;
}

#drawingCanvas {
  background: #ffffff;
  border-radius: 8px 8px 0 0;
  cursor: crosshair;
  touch-action: none;
  width: 100%;
  flex: 1;
  display: block;
}

.canvas-footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 2px;
  background: var(--bg-surface-elevated);
  border-radius: 0 0 8px 8px;
  gap: 6px;
}

.turn-badge {
  background: var(--primary);
  color: #0b1118;
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 10.5px;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cycle-tag {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-secondary);
}

/* ===================================================
   DISCUSSION & CHAT
   =================================================== */
.topic-card {
  padding: 8px 10px;
  margin-bottom: 6px;
}

.topic-header {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
  display: block;
  margin-bottom: 1px;
}

.topic-body {
  font-size: 13.5px;
  font-weight: 900;
  color: var(--text-main);
}

.chat-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  height: 110px;
  overflow: hidden;
}

.chat-log {
  flex: 1;
  padding: 6px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11.5px;
}

.chat-entry {
  background: rgba(255, 255, 255, 0.04);
  padding: 3px 6px;
  border-radius: 5px;
  line-height: 1.3;
}

.chat-entry .sender-name {
  font-weight: 900;
  color: var(--primary);
  margin-left: 3px;
}

.chat-bar {
  display: flex;
  padding: 3px;
  background: var(--bg-dark);
  gap: 3px;
  border-top: 1px solid var(--border-color);
}

.chat-bar input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 5px 8px;
  font-size: 11.5px;
  outline: none;
}

.btn-send {
  background: var(--primary);
  color: #0b1118;
  border: none;
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 11px;
  cursor: pointer;
}

/* ===================================================
   VOTING GRID
   =================================================== */
.voting-selection-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 6px 0;
}

.candidate-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 9px 6px;
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 42px;
}

.candidate-card.selected {
  background: rgba(239, 71, 111, 0.12);
  border: 1.5px solid var(--danger);
  color: var(--danger);
}

/* ===================================================
   MODAL & TOAST
   =================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 17, 24, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 300px;
  padding: 16px;
  text-align: center;
}

.modal-icon {
  width: 38px;
  height: 38px;
  background: rgba(239, 71, 111, 0.15);
  color: var(--danger);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  margin: 0 auto 8px;
}

.modal-title {
  font-size: 15px;
  font-weight: 900;
  color: var(--text-main);
  margin-bottom: 3px;
}

.modal-msg {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 14px;
  line-height: 1.35;
}

.modal-actions {
  display: flex;
  gap: 6px;
}

.modal-actions .btn { flex: 1; }

.toast {
  position: fixed;
  top: max(var(--safe-top), 10px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color-active);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 800;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
