/* ============================================================
   جاكارو النادي — نادٍ خشبي دافئ، جوخ أخضر، ونحاس مصقول
   ============================================================ */
*,
*::before,
*::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; margin: 0; }

body {
  font-family: 'Noto Naskh Arabic', 'Segoe UI', Tahoma, sans-serif;
  color: #EFE6CE;
  background:
    radial-gradient(120% 85% at 8% -14%, rgba(255, 213, 146, .22), rgba(255, 213, 146, 0) 52%),
    radial-gradient(95% 75% at 106% 118%, rgba(0, 0, 0, .66), rgba(0, 0, 0, 0) 60%),
    radial-gradient(85% 65% at 50% 42%, rgba(0, 0, 0, 0) 36%, rgba(0, 0, 0, .52) 100%),
    #0E2A1E;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

button { font-family: inherit; }

/* ------------------------------------------------------------
   SETUP
   ------------------------------------------------------------ */
.setup {
  position: fixed;
  inset: 0;
  z-index: 6;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 22px 16px 34px;
}

.setup-inner {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setup-head { text-align: center; }

.orn {
  height: 1px;
  width: 100%;
  max-width: 210px;
  margin: 12px auto;
  position: relative;
  background: linear-gradient(90deg, rgba(201,162,39,0), rgba(201,162,39,.8), rgba(201,162,39,0));
}
.orn::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 7px; height: 7px;
  background: #C9A227;
  transform: translate(-50%, -50%) rotate(45deg);
  box-shadow: 0 0 10px rgba(201,162,39,.8);
}

.logo {
  font-family: 'Amiri', Georgia, serif;
  font-size: 54px;
  font-weight: 700;
  line-height: 1.05;
  margin: 0;
  color: #F3EAD3;
  text-shadow: 0 2px 0 rgba(0,0,0,.55), 0 0 30px rgba(201,162,39,.35);
}

.tag { margin: 6px 0 0; font-size: 14px; color: rgba(239,230,206,.66); }

.panel {
  background: linear-gradient(180deg, #F8F1E1, #EFE6CE);
  border-radius: 18px;
  padding: 18px;
  color: #17241C;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow:
    0 24px 46px -18px rgba(0,0,0,.9),
    0 0 0 1px rgba(201,162,39,.62),
    inset 0 1px 0 rgba(255,255,255,.7);
}

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; font-weight: 600; color: rgba(23,36,28,.58); }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  background: rgba(23,36,28,.08);
  padding: 5px;
  border-radius: 999px;
}
.seg button {
  border: none;
  background: transparent;
  color: #17241C;
  font-size: 16px;
  font-weight: 700;
  padding: 9px 0;
  border-radius: 999px;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, box-shadow .16s ease;
}
.seg button.active {
  background: #17241C;
  color: #F3EAD3;
  box-shadow: 0 3px 9px rgba(0,0,0,.35);
}
.seg button:focus-visible { outline: 2px solid #C9A227; outline-offset: 2px; }

.seats { display: flex; flex-direction: column; gap: 10px; }

.seat {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(23,36,28,.055);
  border: 1px solid rgba(23,36,28,.1);
  border-radius: 14px;
  padding: 8px 10px;
}

.dots { display: flex; gap: 4px; flex: none; }
.dotbtn {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--c);
  padding: 0;
  cursor: pointer;
  opacity: .38;
  transition: opacity .15s ease, transform .15s ease, box-shadow .15s ease;
}
.dotbtn.on {
  opacity: 1;
  transform: scale(1.14);
  box-shadow: 0 0 0 2px #F8F1E1, 0 0 0 3.5px #17241C;
}
.dotbtn:disabled { opacity: .12; cursor: not-allowed; }
.dotbtn:focus-visible { outline: 2px solid #C9A227; outline-offset: 2px; }

.nameinput {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid rgba(23,36,28,.18);
  background: #FFFBF0;
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 15px;
  color: #17241C;
}
.nameinput:focus {
  outline: none;
  border-color: #C9A227;
  box-shadow: 0 0 0 3px rgba(201,162,39,.25);
}

.aibtn {
  flex: none;
  border: 1px solid rgba(23,36,28,.22);
  background: #FFFBF0;
  color: #17241C;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 10px;
  border-radius: 10px;
  min-width: 54px;
  min-height: 36px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.aibtn.on { background: #17241C; border-color: #17241C; color: #F3EAD3; }

.hint { margin: 0; font-size: 12.5px; line-height: 1.6; color: rgba(23,36,28,.55); text-align: center; }

/* ------------------------------------------------------------
   BUTTONS
   ------------------------------------------------------------ */
.btn {
  border: none;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
  min-height: 46px;
  font-size: 16px;
  padding: 12px 20px;
  transition: transform .1s ease, box-shadow .14s ease, background .16s ease, opacity .16s ease;
}
.btn.primary {
  background: linear-gradient(180deg, #DBB742, #B78F1C);
  color: #2a1e05;
  box-shadow: 0 4px 0 #8a6c14, 0 12px 22px -12px rgba(0,0,0,.9);
}
.btn.primary:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #8a6c14; }
.btn.primary:disabled { opacity: .42; cursor: default; }
.btn.big { width: 100%; min-height: 54px; font-size: 18px; }
.btn.ghost {
  background: transparent;
  color: #17241C;
  box-shadow: inset 0 0 0 1.5px rgba(23,36,28,.35);
}
.btn:focus-visible { outline: 3px solid #C9A227; outline-offset: 2px; }

.iconbtn {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: #FBF5E7;
  color: #17241C;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: inset 0 0 0 1.5px rgba(201,162,39,.75), 0 2px 6px rgba(0,0,0,.16);
  transition: transform .1s ease, background .15s ease;
}
.iconbtn:active { transform: scale(.94); background: #F0E5CB; }
.iconbtn:focus-visible { outline: 3px solid #C9A227; outline-offset: 2px; }

/* ------------------------------------------------------------
   GAME LAYOUT
   ------------------------------------------------------------ */
.game {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
}

/* ---------- status bar ---------- */
.statusbar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas:
    "turn card deck"
    "chips chips chips";
  gap: 8px 10px;
  align-items: center;
  padding: 8px 12px 9px;
  background: linear-gradient(180deg, #F8F1E1, #EFE6CE);
  color: #17241C;
  border-bottom: 2px solid #C9A227;
  box-shadow: 0 8px 20px -8px rgba(0,0,0,.7);
}

.turnbox {
  grid-area: turn;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px 5px 8px;
  border-radius: 11px;
  background: #FFFCF2;
  border: 2px solid var(--pc, #C9A227);
  box-shadow: 0 2px 6px rgba(0,0,0,.14);
  min-width: 0;
  max-width: 100%;
}
.gemdot {
  flex: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #C9A227;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,.35), 0 0 0 1px rgba(0,0,0,.18);
}
.turnmeta { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.turnmeta .k { font-size: 9.5px; color: rgba(23,36,28,.55); font-weight: 600; }
.turnmeta b {
  font-size: 13.5px;
  font-weight: 700;
  color: #17241C;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 108px;
}

.cardwrap { grid-area: card; display: grid; place-items: center; }

.deckinfo {
  grid-area: deck;
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  padding: 4px 8px;
  border-radius: 9px;
  background: rgba(23,36,28,.06);
}
.deckinfo .k { font-size: 9.5px; color: rgba(23,36,28,.55); font-weight: 600; }
.deckinfo b { font-size: 14px; color: #17241C; font-variant-numeric: tabular-nums; }

.chips {
  grid-area: chips;
  display: flex;
  gap: 5px;
  justify-content: center;
  flex-wrap: nowrap;
  overflow: hidden;
}

.chip {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(23,36,28,.07);
  font-size: 11px;
  line-height: 1.5;
  color: #17241C;
  transition: background .2s ease, box-shadow .2s ease;
}
.chip .gdot {
  flex: none;
  width: 8px; height: 8px;
  border-radius: 50%;
  box-shadow: inset 0 -1px 2px rgba(0,0,0,.35);
}
.chip .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 58px;
  font-weight: 600;
}
.chip .ct {
  flex: none;
  font-weight: 700;
  font-size: 10px;
  color: #FBF5E7;
  background: #17241C;
  border-radius: 999px;
  padding: 0 5px;
  min-width: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.chip.active { background: rgba(201,162,39,.26); box-shadow: inset 0 0 0 1.5px #C9A227; }

/* ---------- card ---------- */
.card {
  width: clamp(46px, 12.5vw, 60px);
  aspect-ratio: 5 / 7;
  perspective: 620px;
}
.card-inner {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .48s cubic-bezier(.4,.1,.3,1);
  transform: rotateY(180deg);
}
.card-inner.flipped { transform: rotateY(0deg); }
.card-inner.noflip { transition: none; }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 8px rgba(0,0,0,.35), inset 0 0 0 1.5px rgba(201,162,39,.75);
}
.card-front {
  background: linear-gradient(170deg, #FBF5E7, #F3EAD3 60%, #E9DDC0);
  color: #17241C;
  grid-template-areas: "r" "s" "b";
  gap: 0;
  padding: 3px;
}
.card-front .cr { grid-area: r; font-size: 12px; font-weight: 700; line-height: 1; font-family: 'Noto Naskh Arabic', serif; }
.card-front .cs { grid-area: s; font-size: 15px; line-height: 1; }
.card-front .br { grid-area: b; transform: rotate(180deg); opacity: .55; }

.card-back {
  background:
    repeating-linear-gradient(45deg, rgba(201,162,39,.14) 0 3px, rgba(201,162,39,0) 3px 7px),
    linear-gradient(150deg, #1d4c34, #123423);
  transform: rotateY(180deg);
}
.card-back .backmark { color: rgba(201,162,39,.9); font-size: 15px; }

/* ---------- stage ---------- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 8px;
}

.board-area {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.board-wrap {
  position: relative;
  border-radius: 16px;
  padding: 10px;
  background:
    repeating-linear-gradient(112deg, rgba(0,0,0,.18) 0 3px, rgba(255,255,255,.05) 3px 7px),
    linear-gradient(150deg, #6d4729, #472c17 54%, #5f3d22);
  box-shadow:
    0 26px 48px -16px rgba(0,0,0,.9),
    0 0 0 1.5px rgba(201,162,39,.62),
    inset 0 0 0 3px rgba(0,0,0,.28);
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: #16412C;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(201,162,39,.55),
    inset 0 0 34px rgba(0,0,0,.55);
}

.grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  direction: ltr;
}

.cell { position: relative; }

.cell.track {
  background: rgba(239,230,206,.085);
  border-radius: 22%;
  box-shadow: inset 0 0 0 1px rgba(201,162,39,.2);
}

.cell.track.start { box-shadow: inset 0 0 0 1.6px var(--c, #C9A227); }

.cell.track.safe::after {
  content: '';
  position: absolute;
  inset: 21%;
  background: #C9A227;
  opacity: .85;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.cell.home {
  background: var(--c, #C9A227);
  opacity: .6;
  border-radius: 22%;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.3);
}

/* ---------- bases ---------- */
.bases { position: absolute; inset: 0; pointer-events: none; }

.basepanel {
  position: absolute;
  border-radius: 11px;
  background:
    linear-gradient(160deg, rgba(255,255,255,.16), rgba(0,0,0,.28)),
    var(--c, #C9A227);
  box-shadow:
    inset 0 0 0 2px rgba(201,162,39,.6),
    inset 0 0 26px rgba(0,0,0,.5),
    0 0 0 1px rgba(0,0,0,.35);
}
.basepanel .slot {
  position: absolute;
  width: 18%;
  height: 18%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(0,0,0,.34);
  box-shadow: inset 0 2px 5px rgba(0,0,0,.65), 0 0 0 1px rgba(255,255,255,.14);
}

/* ---------- center ---------- */
.centerpiece {
  position: absolute;
  left: 40%; top: 40%;
  width: 20%; height: 20%;
  border-radius: 9px;
  background:
    radial-gradient(circle at 50% 50%, rgba(0,0,0,.42), rgba(0,0,0,.06) 72%),
    conic-gradient(from -45deg,
      #B14A3A 0 25%,
      #3E7A55 25% 50%,
      #E0A32E 50% 75%,
      #2F6FA8 75% 100%);
  box-shadow:
    inset 0 0 0 2px rgba(201,162,39,.8),
    0 0 20px rgba(0,0,0,.5);
}

/* ---------- pieces ---------- */
.pieces { position: absolute; inset: 0; pointer-events: none; }

.piece {
  position: absolute;
  width: 5.2%;
  height: 5.2%;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 27%, #FFFDF7 0%, #F8F1DE 20%, #EFE6CE 48%, #CFC3A2 75%, #988C6D 100%);
  box-shadow:
    0 0 0 2px var(--pc, #C9A227),
    0 3px 6px rgba(0,0,0,.55),
    inset -1px -2px 3px rgba(0,0,0,.2);
  pointer-events: none;
  z-index: 3;
  transition: left .13s ease-in-out, top .13s ease-in-out, transform .22s cubic-bezier(.34,1.56,.64,1);
}
.piece::before {
  content: '';
  position: absolute;
  left: 21%; top: 15%;
  width: 32%; height: 25%;
  border-radius: 50%;
  background: rgba(255,255,255,.9);
  filter: blur(.6px);
}
.piece.movable { pointer-events: auto; cursor: pointer; z-index: 7; }
.piece.movable::after {
  content: '';
  position: absolute;
  inset: -26%;
  border-radius: 50%;
  border: 2px solid rgba(201,162,39,.95);
  animation: pulse 1.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulse {
  0%, 100% { transform: scale(.88); opacity: .42; }
  50%      { transform: scale(1.06); opacity: 1; }
}
.piece.done { transform: scale(.58); }
.piece.hit { transform: scale(1.4); z-index: 9; }

/* ---------- action bar ---------- */
.actionbar {
  flex: none;
  margin-top: 8px;
  padding: 9px 12px 10px;
  border-radius: 16px;
  background: linear-gradient(180deg, #F8F1E1, #EFE6CE);
  color: #17241C;
  border-top: 2px solid #C9A227;
  box-shadow: 0 -6px 20px -10px rgba(0,0,0,.8), inset 0 1px 0 rgba(255,255,255,.6);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  min-height: 20px;
  color: #17241C;
  font-weight: 600;
}

.row { display: flex; align-items: center; gap: 10px; }
.row .btn.primary { flex: 1 1 auto; min-width: 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(23,36,28,.94);
  color: #F3EAD3;
  border: 1px solid rgba(201,162,39,.7);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity .22s ease, transform .22s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------------
   OVERLAYS
   ------------------------------------------------------------ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px 16px;
  background: rgba(6,18,12,.72);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  overflow-y: auto;
}

.sheet {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, #F8F1E1, #EFE6CE);
  color: #17241C;
  border-radius: 20px;
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow:
    0 30px 60px -20px rgba(0,0,0,.95),
    0 0 0 1px rgba(201,162,39,.7),
    inset 0 1px 0 rgba(255,255,255,.7);
  animation: sheetIn .3s cubic-bezier(.22,1,.36,1) both;
}
@keyframes sheetIn {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.sheet h2 {
  margin: 0;
  font-family: 'Amiri', Georgia, serif;
  font-size: 26px;
  line-height: 1.25;
  text-align: center;
  color: #17241C;
}

.sheet-actions { display: flex; flex-direction: column; gap: 8px; }

.end-sheet { text-align: center; }

.medal {
  width: 66px; height: 66px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #3c2c06;
  background: radial-gradient(circle at 35% 30%, #F6DE86, #C9A227 62%, #90701a 100%);
  box-shadow: 0 8px 20px -6px rgba(0,0,0,.7), inset 0 0 0 2px rgba(255,255,255,.35);
}

.end-sub { margin: 0; font-size: 14px; color: rgba(23,36,28,.66); }

.rank {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.rank li {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(23,36,28,.06);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
}
.rank li.first { background: rgba(201,162,39,.24); box-shadow: inset 0 0 0 1.5px rgba(201,162,39,.75); }
.rank .pos {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #17241C;
  color: #F3EAD3;
  font-size: 11px;
  font-weight: 700;
}
.rank .nm { flex: 1 1 auto; text-align: start; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .hm { flex: none; font-size: 12px; color: rgba(23,36,28,.6); font-variant-numeric: tabular-nums; }
.rank .sw { flex: none; width: 11px; height: 11px; border-radius: 50%; box-shadow: inset 0 -1px 2px rgba(0,0,0,.35); }

.rules {
  margin: 0;
  padding: 0 18px 0 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 13.5px;
  line-height: 1.65;
  color: #1d2a22;
  max-height: 52vh;
  overflow-y: auto;
}
.rules li::marker { color: #C9A227; }
.rules b { color: #17241C; }

/* ------------------------------------------------------------
   SHORT / LANDSCAPE
   ------------------------------------------------------------ */
@media (orientation: landscape) and (max-height: 560px) {
  .game { flex-direction: row; }

  .statusbar {
    width: 168px;
    flex: none;
    grid-template-columns: 1fr;
    grid-template-areas: "turn" "card" "deck" "chips";
    align-content: start;
    gap: 8px;
    padding: 8px;
    border-bottom: none;
    border-inline-start: 2px solid #C9A227;
    overflow-y: auto;
  }
  .turnbox { justify-self: stretch; }
  .turnmeta b { max-width: none; }
  .deckinfo { justify-self: stretch; }
  .chips { flex-wrap: wrap; justify-content: flex-start; }
  .chip .nm { max-width: 64px; }

  .stage { padding: 6px 8px; }
  .actionbar { margin-top: 6px; padding: 6px 10px 7px; gap: 5px; }
  .msg { font-size: 12.5px; min-height: 17px; }
  .row .btn.primary { min-height: 42px; font-size: 14.5px; }
  .iconbtn { width: 42px; height: 42px; }
  .btn { min-height: 42px; }
}

@media (max-width: 360px) {
  .chip .nm { max-width: 42px; font-size: 10px; }
  .turnmeta b { max-width: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  .piece.movable::after { animation: none; opacity: .85; }
  .sheet { animation: none; }
  .card-inner { transition-duration: .01s; }
}