/* ============================================================
   تك تك — نظام التصميم
   ألوان الهوية:
   أحمر #E74236 · أصفر #FADE6B · بيج #E2C9AF
   بني #915238 · أسود #282827 · أزرق فاتح #BDDDE7
   ============================================================ */

:root {
  --red: #E74236;
  --red-deep: #C93227;
  --yellow: #FADE6B;
  --yellow-soft: #FDEFB5;
  --beige: #E2C9AF;
  --beige-soft: #F1E4D3;
  --brown: #915238;
  --brown-line: #A96A4C;
  --ink: #282827;
  --sky: #BDDDE7;
  --sky-soft: #DCEEF4;
  --paper: #FFFDF6;

  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow-card: 0 4px 0 rgba(145, 82, 56, .25);
  --shadow-pop: 0 10px 30px rgba(40, 40, 39, .18);
  --font: 'Baloo Bhaijaan 2', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--yellow);
  /* نقش ورقي خفيف مثل كرتون العلبة */
  background-image: radial-gradient(rgba(145, 82, 56, .07) 1.2px, transparent 1.3px);
  background-size: 22px 22px;
  color: var(--ink);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  border-radius: 6px;
}

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* ============ الشاشة الرئيسية ============ */

.home-head {
  text-align: center;
  padding: clamp(20px, 4vw, 44px) 16px 6px;
}

.home-logo {
  width: clamp(110px, 22vw, 170px);
  height: auto;
  filter: drop-shadow(0 4px 0 rgba(145, 82, 56, .25));
  animation: logo-in .7s cubic-bezier(.2, 1.4, .4, 1) both;
}

@keyframes logo-in {
  from { transform: scale(.6) rotate(-6deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

.home-tag {
  font-size: clamp(1.15rem, 3.4vw, 1.6rem);
  font-weight: 800;
  color: var(--ink);
  margin: 10px auto 2px;
  max-width: 26ch;
  line-height: 1.5;
}

.home-sub {
  font-size: clamp(.9rem, 2.4vw, 1.05rem);
  font-weight: 500;
  color: var(--brown);
  margin: 0 0 8px;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(168px, 44vw), 1fr));
  gap: clamp(10px, 2.2vw, 18px);
  padding: clamp(12px, 3vw, 28px);
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.game-card {
  background: var(--sky);
  border-radius: var(--radius-lg);
  border: 2.5px solid var(--ink);
  box-shadow: var(--shadow-card);
  padding: 12px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  transition: transform .15s ease, box-shadow .15s ease;
}

.game-card:hover, .game-card:focus-visible {
  transform: translateY(-3px) rotate(-.4deg);
  box-shadow: 0 7px 0 rgba(145, 82, 56, .3);
}

.game-card:active { transform: translateY(1px) scale(.99); }

.gc-pill {
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: clamp(1rem, 2.6vw, 1.15rem);
  border-radius: 999px;
  padding: 3px 18px 5px;
  line-height: 1.4;
  border: 2px solid var(--ink);
  min-width: 70%;
}

.gc-en {
  display: block;
  font-size: .68em;
  font-weight: 600;
  opacity: .92;
  letter-spacing: .4px;
}

.gc-preview {
  width: min(120px, 30vw);
  height: auto;
  display: block;
  filter: drop-shadow(0 2px 0 rgba(145, 82, 56, .3));
}

.gc-goal {
  font-size: .84rem;
  font-weight: 500;
  color: var(--ink);
  margin: 0;
  line-height: 1.55;
  min-height: 2.6em;
}

.gc-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.board-chip {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  padding: 0 10px 1px;
  color: var(--brown);
  direction: ltr;
}

.home-foot {
  text-align: center;
  padding: 18px;
  font-size: .8rem;
  color: var(--brown);
  font-weight: 600;
}

/* ============ شاشة اللعب ============ */

.game-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 6px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.hbtn {
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 3px 0 rgba(145, 82, 56, .3);
  width: 44px;
  height: 44px;
  font-size: 1.15rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  transition: transform .1s ease;
}

.hbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(145, 82, 56, .3); }
.hbtn[disabled] { opacity: .35; pointer-events: none; }

.game-title-pill {
  background: var(--red);
  color: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(145, 82, 56, .3);
  font-weight: 800;
  font-size: clamp(1rem, 3vw, 1.25rem);
  padding: 4px 16px 6px;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.game-title-pill .board-chip { flex: 0 0 auto; }
#game-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.head-actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* شريط الحالة */

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 860px;
  width: 100%;
  margin: 4px auto 0;
  padding: 6px 12px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 3px 12px 4px;
  font-weight: 800;
  font-size: .95rem;
  opacity: .55;
  transition: opacity .2s, transform .2s, box-shadow .2s;
}

.player-chip .dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  flex: 0 0 auto;
}

.player-chip.red .dot { background: var(--red); }
.player-chip.black .dot { background: var(--ink); }

.player-chip.active {
  opacity: 1;
  transform: scale(1.06);
  box-shadow: 0 3px 0 rgba(145, 82, 56, .35);
}

.player-chip .score {
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 999px;
  min-width: 24px;
  text-align: center;
  font-size: .8rem;
  padding: 0 6px;
}

.status-msg {
  font-weight: 700;
  font-size: clamp(.9rem, 2.8vw, 1.1rem);
  text-align: center;
  color: var(--ink);
  flex: 1;
  min-width: 0;
  line-height: 1.4;
}

/* منطقة اللعب */

.play-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.5vh, 14px);
  padding: 8px 10px calc(14px + env(safe-area-inset-bottom));
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.tray:empty { display: none; }

/* اللوح */

.board-host {
  width: min(94vw, 62dvh, 560px);
  flex: 0 0 auto;
  position: relative;
}

.board {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  background: var(--beige);
  border: 4px solid var(--brown);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 0 rgba(145, 82, 56, .35), var(--shadow-pop);
  padding: 6px;
  gap: 0;
  position: relative;
}

.cell {
  position: relative;
  border: 1.5px solid var(--brown-line);
  display: grid;
  grid-template: 1fr / 1fr;
  place-items: center;
  padding: 7%;
  min-width: 0;
  min-height: 0;
}

.board.checker .cell.dark { background: rgba(145, 82, 56, .22); }

.cell.goal-mark::after {
  content: '';
  position: absolute;
  inset: 18%;
  border: 2.5px dashed var(--red);
  border-radius: 50%;
  opacity: .55;
  pointer-events: none;
}

/* تظليلات التفاعل */

.cell.sel { background: rgba(250, 222, 107, .75); }
.cell.sel::before {
  content: '';
  position: absolute;
  inset: 4%;
  border: 3px solid var(--red);
  border-radius: 14%;
  pointer-events: none;
  animation: sel-pulse 1.2s ease-in-out infinite;
}

@keyframes sel-pulse {
  50% { transform: scale(.96); }
}

.cell.hint::after {
  content: '';
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(231, 66, 54, .45);
  border: 2px solid rgba(231, 66, 54, .8);
  pointer-events: none;
}

.cell.cap::after {
  content: '';
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  border: 4px dashed var(--red);
  background: rgba(231, 66, 54, .12);
  pointer-events: none;
}

.cell.last { background: rgba(189, 221, 231, .55); }

.cell.winline { animation: win-glow 1s ease-in-out infinite alternate; }

@keyframes win-glow {
  from { background: rgba(250, 222, 107, .5); }
  to   { background: rgba(231, 66, 54, .45); }
}

/* القطع */

.pc {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.pc svg { width: 100%; height: 100%; display: block; }

.pc.pop { animation: pc-pop .3s cubic-bezier(.2, 1.6, .4, 1) both; }

@keyframes pc-pop {
  from { transform: scale(.3); }
  to   { transform: scale(1); }
}

.ghost-pc {
  position: absolute;
  pointer-events: none;
  z-index: 30;
  display: grid;
  place-items: center;
  transition: transform .28s cubic-bezier(.3, 1.2, .4, 1);
  will-change: transform;
}

/* خانات الاحتياط (أدراج القطع) */

.slot {
  background: var(--beige-soft);
  border: 2.5px solid var(--brown);
  border-radius: var(--radius-sm);
  width: clamp(44px, 11vw, 60px);
  height: clamp(44px, 11vw, 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6%;
  position: relative;
  transition: transform .12s ease;
}

.slot .pc { pointer-events: none; position: absolute; inset: 8%; width: auto; height: auto; }
.slot.sel { background: var(--yellow); box-shadow: 0 0 0 3px var(--red); }
.slot.empty { opacity: .35; }
.slot:active { transform: scale(.94); }

.slot .count {
  position: absolute;
  bottom: -8px;
  inset-inline-end: -8px;
  background: var(--red);
  color: #fff;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 800;
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  z-index: 2;
}

.tray-label {
  width: 100%;
  text-align: center;
  font-size: .8rem;
  font-weight: 700;
  color: var(--brown);
  margin: 0;
}

/* ============ النوافذ ============ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(40, 40, 39, .55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 18px;
  overflow-y: auto;
}

.modal[hidden] { display: none; }

.modal-card {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 0 rgba(145, 82, 56, .4);
  max-width: 520px;
  width: 100%;
  padding: 22px 22px 20px;
  animation: card-in .3s cubic-bezier(.2, 1.4, .4, 1) both;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
}

@keyframes card-in {
  from { transform: translateY(24px) scale(.94); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.modal-title {
  background: var(--red);
  color: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 800;
  padding: 4px 20px 6px;
  margin: 0 auto 14px;
  width: fit-content;
}

.rules-goal {
  background: var(--yellow-soft);
  border: 2px dashed var(--brown);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.7;
}

.rules-list {
  margin: 0;
  padding: 0 4px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rules-list li {
  position: relative;
  padding-inline-start: 26px;
  line-height: 1.8;
  font-weight: 500;
  font-size: .95rem;
}

.rules-list li::before {
  content: '';
  position: absolute;
  inset-inline-start: 4px;
  top: .62em;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--sky);
  border: 2.5px solid var(--ink);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}

.btn {
  border-radius: 999px;
  border: 2.5px solid var(--ink);
  font-weight: 800;
  font-size: 1rem;
  padding: 8px 26px 10px;
  text-decoration: none;
  text-align: center;
  transition: transform .1s ease;
  display: inline-block;
}

.btn:active { transform: translateY(2px); }
.btn.solid { background: var(--red); color: #fff; box-shadow: 0 4px 0 rgba(145, 82, 56, .4); }
.btn.ghost { background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 rgba(145, 82, 56, .25); }

/* نافذة الفوز */

.win-card { text-align: center; position: relative; overflow: visible; }

.win-title {
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 800;
  margin: 6px 0 2px;
}

.win-title.red-win { color: var(--red); }
.win-title.black-win { color: var(--ink); }

.win-sub { font-weight: 600; color: var(--brown); margin: 0 0 6px; min-height: 1.4em; }

.win-burst {
  font-size: clamp(2.6rem, 10vw, 3.6rem);
  line-height: 1.2;
  animation: burst-bounce .7s cubic-bezier(.2, 1.6, .4, 1) both;
}

@keyframes burst-bounce {
  from { transform: scale(0) rotate(-20deg); }
  to   { transform: scale(1) rotate(0); }
}

/* قصاصات الاحتفال */

#confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  overflow: hidden;
}

.confetto {
  position: absolute;
  top: -4vh;
  width: 12px;
  height: 12px;
  animation: confetti-fall linear both;
}

@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); }
}

/* ============ تجاوب ============ */

@media (max-width: 480px) {
  .player-chip .pname { display: none; }
  .player-chip { padding: 5px 9px 6px; }
  .hbtn { width: 40px; height: 40px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .board-host { width: min(58dvh, 420px); }
  .game-head { padding-top: 6px; }
}

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

/* ---------- شاشة الإعداد ---------- */
.setup-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px 16px; text-align: center; }
.setup-preview { width: 190px; max-width: 60vw; }
.setup-preview svg { width: 100%; height: auto; }
.setup-q { font-size: 1.35rem; color: var(--brown); margin: 0; }
.setup-q.sub { font-size: 1.05rem; opacity: .85; }
.setup-spacer { visibility: hidden; }
.seg { display: inline-flex; gap: 8px; background: var(--beige); padding: 6px; border-radius: 18px; box-shadow: inset 0 2px 5px rgba(145,82,56,.25); flex-wrap: wrap; justify-content: center; }
.seg-btn { font-family: var(--font); font-size: 1.05rem; border: none; cursor: pointer; padding: 10px 18px; border-radius: 13px; background: transparent; color: var(--ink); transition: transform .08s, background .15s; }
.seg-btn[aria-pressed="true"] { background: var(--red); color: #fff; box-shadow: 0 3px 0 rgba(145,82,56,.4); }
.seg-btn:active { transform: translateY(2px); }
.setup-diff-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.setup-start { min-width: 180px; font-size: 1.2rem; }

.gc-badge {
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 800;
  padding: 0 9px 1px;
  white-space: nowrap;
}
.gc-badge.soon { background: var(--yellow); color: var(--ink); }
.gc-badge.local { background: var(--sky); color: var(--ink); }

/* ============================================================
   الاشتراكات — نافذة الدخول/التفعيل
   ============================================================ */
.subs-card {
  max-width: 420px; width: min(92vw, 420px); text-align: right;
  max-height: 88vh; overflow-y: auto;
}
.subs-title { margin: 0 0 12px; text-align: center; }
.subs-tabs { width: 100%; margin-bottom: 14px; }
.subs-form { display: flex; flex-direction: column; gap: 10px; }
.subs-label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: .95rem; }
.subs-input {
  border: 2px solid #915238; border-radius: 12px; padding: 10px 12px;
  font: inherit; background: #fff; direction: ltr; text-align: center;
}
.subs-input:focus { outline: 3px solid #FADE6B; }
.subs-submit { margin-top: 4px; }
.subs-error {
  background: #BD362C; color: #fff; border-radius: 10px;
  padding: 8px 12px; margin: 10px 0 0; font-weight: 700; text-align: center;
}
.subs-msg { font-weight: 700; margin: 0 0 8px; }
.subs-devices-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.subs-device-btn {
  border: 2px solid #915238; background: #E2C9AF; border-radius: 12px;
  padding: 10px; font: inherit; font-weight: 700; cursor: pointer; text-align: right;
}
.subs-device-btn small { display: block; font-weight: 400; }
.subs-buy {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 14px; border-top: 2px dashed #E2C9AF; padding-top: 12px;
}

/* ============================================================
   لوحة التحكم
   ============================================================ */
.admin-body { background: #E2C9AF; min-height: 100vh; }
.admin-wrap { max-width: 720px; margin: 0 auto; padding: 20px 14px 60px; }
.admin-title { text-align: center; margin: 8px 0 18px; }
.admin-card {
  background: #fff; border: 2px solid #915238; border-radius: 16px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px;
}
.admin-tabs { width: 100%; margin-bottom: 14px; }
.admin-msg {
  position: fixed; bottom: 14px; right: 50%; transform: translateX(50%);
  background: #282827; color: #FADE6B; padding: 10px 18px;
  border-radius: 12px; font-weight: 700; z-index: 50;
}
.gen-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.gen-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #FDF6EC; border-radius: 10px; padding: 6px 10px;
}
.gen-list code { font-size: 1.1rem; font-weight: 700; letter-spacing: 1px; direction: ltr; }
.admin-table { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: #FDF6EC; border-radius: 10px; padding: 8px 10px; font-size: .95rem;
}
.admin-row code { font-weight: 700; direction: ltr; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-devs { display: flex; flex-wrap: wrap; gap: 6px; }
