/* ══ حرب الغاز — نظام التصميم ══ */
:root {
  --bg: #0b1220;
  --bg-2: #0f1729;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #15803d;
  --primary-lit: #22c55e;
  --accent: #d97706;
  --accent-lit: #f59e0b;
  --enemy: #dc2626;
  --enemy-lit: #f87171;
  --sq-light: #2a3448;
  --sq-dark: #1a2232;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 6px 28px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 54px rgba(0, 0, 0, 0.55);
  --font: 'Noto Sans Arabic', ui-sans-serif, system-ui, sans-serif;
  --font-head: 'Noto Naskh Arabic', 'Noto Sans Arabic', serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.glow {
  position: fixed;
  inset: -30% -10% auto -10%;
  height: 65vh;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(21, 128, 61, 0.32), transparent 60%),
    radial-gradient(ellipse at 75% 5%, rgba(217, 119, 6, 0.18), transparent 55%);
  z-index: 0;
}

#app { position: relative; z-index: 1; display: flex; flex-direction: column; min-height: 100dvh; }

button { font-family: inherit; }
.hidden { display: none !important; }
/* ══ الهيكل العام ══ */
.hud {
  position: sticky;
  top: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 1.25rem;
  background: rgba(11, 18, 32, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.hud-center { text-align: center; }
.logo { font-family: var(--font-head); font-size: clamp(1.2rem, 2.4vw, 1.7rem); font-weight: 700; letter-spacing: -0.01em; }
.logo span { color: var(--accent-lit); }
.logo-sub { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.22em; margin-top: -0.15rem; }

.turn-pill {
  display: inline-block;
  margin-top: 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.22rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
}
.turn-pill.mine { color: var(--primary-lit); border-color: rgba(34, 197, 94, 0.4); background: rgba(21, 128, 61, 0.15); }
.turn-pill.foe { color: var(--enemy-lit); border-color: rgba(248, 113, 113, 0.35); background: rgba(220, 38, 38, 0.12); }

.hud-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  transition: border-color 0.25s, background 0.25s, transform 0.25s;
}
.hud-card.active { border-color: rgba(217, 119, 6, 0.5); background: var(--panel-2); }
.hud-a { text-align: left; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.hud-name { font-weight: 700; font-size: 0.95rem; }
.hud-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.hud-a .hud-dot { background: var(--enemy); }
.hud-p .hud-dot { background: var(--primary-lit); }
.hud-card.active .hud-dot { box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.22); }

.gas-line { display: flex; align-items: baseline; gap: 0.25rem; }
.gas-num { font-family: var(--font-head); font-size: 1.35rem; font-weight: 700; color: var(--accent-lit); }
.gas-cap { font-size: 0.7rem; color: var(--muted); }
.gas-bar { height: 5px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin: 0.25rem 0 0.4rem; }
.gas-bar b { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-lit)); transition: width 0.35s ease; }
.hud-stats { display: flex; gap: 0.6rem; font-size: 0.68rem; color: var(--muted); flex-wrap: wrap; }
/* ══ المسرح ══ */
.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 1.25rem;
  padding: 1.25rem;
  align-items: start;
  max-width: 1320px;
  margin: 0 auto;
  width: 100%;
}

.board-col { display: flex; flex-direction: column; gap: 0.85rem; }

.board-frame {
  position: relative;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, rgba(217, 119, 6, 0.16), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(217, 119, 6, 0.32);
  box-shadow: var(--shadow-lg);
  width: min(100%, 62vh, 660px);
  margin: 0 auto;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  direction: ltr;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.5), inset 0 0 40px rgba(0, 0, 0, 0.45);
}

.sq { position: relative; background: var(--sq-dark); transition: background 0.18s, box-shadow 0.18s; }
.sq.light { background: var(--sq-light); }
.sq.zone-p { box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.12); }
.sq.zone-a { box-shadow: inset 0 0 0 1px rgba(248, 113, 113, 0.12); }

.sq.last { background: rgba(217, 119, 6, 0.22); }
.sq.sel { background: rgba(245, 158, 11, 0.35) !important; box-shadow: inset 0 0 0 2px var(--accent-lit); }

.sq.move::after, .sq.attack::after, .sq.deployable::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(34, 197, 94, 0.85);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.7);
  animation: pulse 1.6s ease-in-out infinite;
}

.sq.attack::after {
  width: 58%;
  border-radius: 8px;
  background: transparent;
  border: 2px dashed rgba(248, 113, 113, 0.95);
  box-shadow: 0 0 14px rgba(220, 38, 38, 0.55);
}

.sq.deployable { background: rgba(34, 197, 94, 0.16) !important; box-shadow: inset 0 0 0 2px rgba(34, 197, 94, 0.55); }
.sq.deployable::after { width: 20%; background: rgba(34, 197, 94, 0.7); box-shadow: none; }
.sq.threat { box-shadow: inset 0 0 0 2px rgba(248, 113, 113, 0.65); }

@keyframes pulse { 0%, 100% { transform: scale(0.85); opacity: 0.75; } 50% { transform: scale(1.05); opacity: 1; } }

.board-hint { font-size: 0.82rem; color: var(--muted); text-align: center; }
.board-hint.danger { color: var(--enemy-lit); font-weight: 600; }
/* ══ بطاقات الرقعة ══ */
.pieces, .fx { position: absolute; inset: 12px; pointer-events: none; direction: ltr; }
.pieces { z-index: 3; }
.fx { z-index: 6; }

.pc {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  display: grid;
  place-items: center;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.pc::before {
  content: '';
  position: absolute;
  inset: 8%;
  border-radius: 12px;
  background: linear-gradient(160deg, #1a7a42, #0d5228);
  border: 1px solid rgba(245, 158, 11, 0.45);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.2s, transform 0.2s, filter 0.25s;
}
.pc-a::before { background: linear-gradient(160deg, #9f1239, #b91c1c); border-color: rgba(248, 113, 113, 0.5); }
.pc-glyph { position: relative; font-size: calc(var(--cell, 60px) * 0.5); line-height: 1; color: #ecfdf5; text-shadow: 0 2px 7px rgba(0, 0, 0, 0.55); z-index: 2; }
.pc-a .pc-glyph { color: #fee2e2; }
.pc-name { position: absolute; bottom: 7%; font-size: calc(var(--cell, 60px) * 0.17); color: rgba(255, 255, 255, 0.75); z-index: 2; }
.pc-badge { position: absolute; font-size: calc(var(--cell, 60px) * 0.2); font-weight: 700; line-height: 1.4; padding: 0 3px; border-radius: 6px; z-index: 3; }
.pc-badge.atk { top: 3%; inset-inline-start: 5%; background: rgba(185, 28, 28, 0.9); color: #fff; }
.pc-badge.def { top: 3%; inset-inline-end: 5%; background: rgba(148, 163, 184, 0.9); color: #0b1220; }

.pc.sel::before { box-shadow: 0 0 0 3px var(--accent-lit), 0 10px 24px rgba(0, 0, 0, 0.55); transform: scale(1.04); }
.pc.threat::before { box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.9), 0 6px 16px rgba(0, 0, 0, 0.45); }
.pc.spent { filter: grayscale(0.4) brightness(0.82); }
.pc.spawn { animation: pop 0.3s ease-out; }
.pc.dying { animation: die 0.4s ease-in forwards; z-index: 1; }

@keyframes pop { from { opacity: 0; } }
@keyframes die { to { opacity: 0; filter: blur(2px); } }
@keyframes burst { from { transform: scale(0.4); opacity: 1; } to { transform: scale(2); opacity: 0; } }
/* ══ اللوحة الجانبية ══ */
.panel { display: flex; flex-direction: column; gap: 1rem; }
.panel-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  backdrop-filter: blur(12px);
}
.panel-title { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.14em; color: var(--muted); margin-bottom: 0.6rem; }
.actions { display: flex; flex-direction: column; gap: 0.5rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.2s, opacity 0.2s, border-color 0.2s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: linear-gradient(135deg, #15803d, #22c55e); color: #04240f; box-shadow: 0 6px 22px rgba(34, 197, 94, 0.28); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(34, 197, 94, 0.4); }
.btn-ghost { background: rgba(255, 255, 255, 0.04); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--panel-2); transform: translateY(-2px); }

.log { display: flex; flex-direction: column; gap: 0.35rem; max-height: 220px; overflow-y: auto; }
.log-row {
  font-size: 0.78rem;
  padding: 0.35rem 0.55rem;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  border-inline-start: 3px solid var(--border-strong);
  animation: fadeUp 0.25s ease;
}
.log-row.tone-good { border-color: var(--primary-lit); color: #bbf7d0; }
.log-row.tone-bad { border-color: var(--enemy); color: #fecaca; }
.log-row.tone-warn { border-color: var(--accent-lit); color: #fde68a; }
.log-row.tone-gold { border-color: var(--accent); color: #fcd34d; font-weight: 600; }

.enemy-hand { display: flex; gap: 0.3rem; flex-wrap: wrap; min-height: 34px; }
.back-card {
  width: 22px;
  height: 32px;
  border-radius: 6px;
  background: repeating-linear-gradient(45deg, #7f1d1d 0 4px, #991b1b 4px 8px);
  border: 1px solid rgba(248, 113, 113, 0.4);
}
.empty-mini { font-size: 0.75rem; color: var(--muted); }
/* ══ شريط اليد والبطاقات ══ */
.handbar {
  position: sticky;
  bottom: 0;
  z-index: 11;
  background: rgba(11, 18, 32, 0.86);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 0.7rem 1.25rem 0.9rem;
}
.handbar-head { display: flex; align-items: center; gap: 0.75rem; justify-content: space-between; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.5rem; }
.handbar-head span { font-weight: 700; color: var(--text); letter-spacing: 0.1em; }
.hand { display: flex; gap: 0.6rem; overflow-x: auto; padding-bottom: 0.3rem; }

.hcard {
  flex: 0 0 auto;
  width: 106px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.5rem 0.45rem 0.45rem;
  background: linear-gradient(165deg, rgba(21, 128, 61, 0.34), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(34, 197, 94, 0.35);
  border-radius: 14px;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.2s, opacity 0.2s;
}
.hcard:hover { transform: translateY(-4px); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45); border-color: var(--accent-lit); }
.hcard.selected { border-color: var(--accent-lit); box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.5), 0 12px 30px rgba(0, 0, 0, 0.5); }
.hcard.disabled { opacity: 0.4; cursor: not-allowed; }
.hcard-glyph { font-size: 1.7rem; line-height: 1.1; }
.hcard-name { font-size: 0.8rem; font-weight: 600; }
.hcard-stats { display: flex; gap: 0.3rem; font-size: 0.68rem; font-weight: 700; }
.hcard-stats em { font-style: normal; padding: 0.05rem 0.35rem; border-radius: 6px; }
.s-gas { background: rgba(217, 119, 6, 0.25); color: #fcd34d; }
.s-atk { background: rgba(220, 38, 38, 0.22); color: #fecaca; }
.s-def { background: rgba(148, 163, 184, 0.2); color: #e2e8f0; }
.empty { font-size: 0.82rem; color: var(--muted); padding: 0.8rem 1rem; border: 1px dashed var(--border); border-radius: 12px; }
/* ══ مؤثرات القتال ══ */
.burst { position: absolute; top: 0; left: 0; width: 12.5%; height: 12.5%; }
.burst::after { content: ''; position: absolute; inset: 12%; border-radius: 50%; animation: burst 0.65s ease-out forwards; }
.burst.capture::after { background: radial-gradient(circle, rgba(245, 158, 11, 0.95), rgba(220, 38, 38, 0.15) 70%); }
.burst.clash::after { background: radial-gradient(circle, rgba(248, 113, 113, 0.95), rgba(120, 20, 20, 0.12) 70%); }
.burst.repelled::after { background: radial-gradient(circle, rgba(148, 163, 184, 0.85), transparent 70%); }
.burst.deploy::after { background: radial-gradient(circle, rgba(34, 197, 94, 0.9), transparent 70%); }

.banner {
  position: absolute;
  inset-inline: 8%;
  top: 50%;
  transform: translateY(-50%) scale(0.96);
  text-align: center;
  font-family: var(--font-head);
  font-size: clamp(0.95rem, 2.2vw, 1.4rem);
  font-weight: 700;
  color: #fff;
  background: rgba(11, 18, 32, 0.74);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 8;
}
.banner.show { opacity: 1; transform: translateY(-50%) scale(1); }

.toast-wrap {
  position: fixed;
  bottom: 1.25rem;
  inset-inline-start: 1.25rem;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(92vw, 390px);
}
.toast {
  padding: 0.6rem 1rem;
  border-radius: 12px;
  font-size: 0.85rem;
  background: rgba(15, 23, 41, 0.96);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  animation: fadeUp 0.25s ease;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.out { opacity: 0; transform: translateY(10px); }
.toast.success { border-color: rgba(34, 197, 94, 0.5); color: #bbf7d0; }
.toast.error { border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }
.toast.warn { border-color: rgba(245, 158, 11, 0.5); color: #fde68a; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
/* ══ النوافذ ══ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(4, 8, 16, 0.72);
  backdrop-filter: blur(6px);
  animation: fadeUp 0.2s ease;
  overflow-y: auto;
}
.modal {
  width: 100%;
  max-width: 560px;
  background: linear-gradient(170deg, #101a2e, #0c1424);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.6rem;
  max-height: 92dvh;
  overflow-y: auto;
}
.modal-head h2 { font-family: var(--font-head); font-size: clamp(1.5rem, 4vw, 2.1rem); font-weight: 700; margin-bottom: 0.5rem; }
.modal-head h2.win { color: var(--accent-lit); }
.modal-head h2.lose { color: var(--enemy-lit); }
.modal-head p { font-size: 0.88rem; color: var(--muted); }
.modal-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--accent-lit);
  background: rgba(217, 119, 6, 0.12);
  border: 1px solid rgba(217, 119, 6, 0.3);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  margin-bottom: 0.7rem;
}
.modal-foot { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1.1rem; }

.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.6rem; margin-top: 1.1rem; }
.mode-card {
  text-align: start;
  padding: 0.8rem 0.9rem;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.mode-card b { display: block; font-size: 0.95rem; }
.mode-card span { font-size: 0.75rem; color: var(--muted); }
.mode-card:hover { transform: translateY(-3px); border-color: var(--accent-lit); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4); }
.mode-card.primary { background: linear-gradient(150deg, rgba(21, 128, 61, 0.32), rgba(255, 255, 255, 0.05)); border-color: rgba(34, 197, 94, 0.45); }

.rules-list { margin: 0.6rem 0 0.9rem; padding-inline-start: 1.1rem; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.84rem; color: #dbe4f0; }
.cards-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.cards-table th, .cards-table td { padding: 0.42rem 0.5rem; text-align: start; border-bottom: 1px solid var(--border); }
.cards-table th { color: var(--muted); font-size: 0.7rem; letter-spacing: 0.1em; }
.cards-table tbody tr:hover { background: var(--panel); }
.mini-glyph { font-size: 1rem; color: var(--accent-lit); }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin-top: 1rem; }
.stat-block { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem; }
.stat-block h4 { font-size: 0.82rem; margin-bottom: 0.4rem; }
.stat-row { display: flex; gap: 0.4rem; }
.stat-cell { flex: 1; text-align: center; }
.stat-cell b { display: block; font-family: var(--font-head); font-size: 1.15rem; color: var(--accent-lit); }
.stat-cell span { font-size: 0.66rem; color: var(--muted); }

/* ══ الاستجابة ══ */
@media (max-width: 1040px) {
  .stage { grid-template-columns: 1fr; padding: 1rem; }
  .panel { order: 2; }
  .board-frame { width: min(100%, 620px); }
  .log { max-height: 150px; }
}
@media (max-width: 640px) {
  .hud { grid-template-columns: 1fr; gap: 0.5rem; padding: 0.6rem 0.8rem; }
  .hud-center { order: -1; }
  .hud-side { display: flex; gap: 0.5rem; }
  .hud-card { flex: 1; padding: 0.45rem 0.6rem; }
  .hud-stats { font-size: 0.62rem; }
  .pc-name { display: none; }
  .stage { padding: 0.75rem; gap: 0.85rem; }
  .handbar { padding: 0.55rem 0.8rem 0.7rem; }
  .hcard { width: 92px; }
  .stats-grid { grid-template-columns: 1fr; }
  .toast-wrap { inset-inline: 0.75rem; bottom: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.05s !important; }
}