/* ── Design tokens ── */
:root {
  --bg: #0F172A;
  --bg-2: #0B1220;
  --felt: #1A7A46;
  --felt-2: #14603A;
  --primary: #15803D;
  --primary-2: #166534;
  --accent: #D97706;
  --accent-2: #F59E0B;
  --text: #F8FAFC;
  --muted: #94A3B8;
  --border: rgba(255, 255, 255, .08);
  --border-2: rgba(255, 255, 255, .18);
  --card: rgba(255, 255, 255, .05);
  --card-2: rgba(255, 255, 255, .09);
  --me: #22C55E;
  --ai: #F87171;
  --danger: #DC2626;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 60px rgba(0, 0, 0, .55);
  font-family: 'Noto Sans Arabic', ui-sans-serif, system-ui, sans-serif;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.glow {
  position: fixed; inset: -30% -15% auto -15%; height: 62vh; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(21, 128, 61, .35), transparent 62%),
              radial-gradient(ellipse at 88% 6%, rgba(217, 119, 6, .18), transparent 55%);
}
h1, h2, h3 { font-family: 'Noto Naskh Arabic', serif; font-weight: 700; letter-spacing: 0; }
button { font-family: inherit; }
/* ── Topbar ── */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1.4rem; background: rgba(11, 18, 32, .84); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .75rem; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: linear-gradient(140deg, var(--primary), var(--primary-2)); border: 1px solid rgba(255, 255, 255, .2); box-shadow: var(--shadow); color: #fff; }
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-family: 'Cinzel', serif; font-size: 1.05rem; letter-spacing: .1em; }
.brand-text b span { color: var(--accent-2); }
.brand-text i { font-style: normal; font-size: .72rem; color: var(--muted); }
.topbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .55rem 1.1rem; border-radius: 999px; font-size: .86rem; font-weight: 600; cursor: pointer; border: none; transition: transform .16s ease, box-shadow .16s ease, background .16s ease, opacity .16s; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 6px 22px rgba(21, 128, 61, .35); }
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 34px rgba(21, 128, 61, .5); }
.btn-accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a1206; }
.btn-accent:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(217, 119, 6, .45); }
.btn-ghost { background: rgba(255, 255, 255, .04); border: 1px solid var(--border-2); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--card-2); transform: translateY(-2px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: .42rem .85rem; font-size: .78rem; }

/* ── Layout & panels ── */
.layout { position: relative; z-index: 1; max-width: 1220px; margin: 0 auto; padding: 1.2rem 1.2rem 3rem; display: grid; gap: 1.1rem; grid-template-columns: minmax(320px, 1.35fr) minmax(300px, 1fr); align-items: start; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); backdrop-filter: blur(12px); box-shadow: var(--shadow); padding: 1rem 1.1rem; animation: fadeUp .4s ease; }
.panel + .panel { margin-top: 1rem; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .7rem; }
.panel-head h2 { font-size: 1rem; }
.hint { font-size: .74rem; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 600; padding: .18rem .6rem; border-radius: 999px; background: rgba(21, 128, 61, .18); color: #86efac; }
.badge.ai { background: rgba(248, 113, 113, .15); color: #fca5a5; }
.badge.gold { background: rgba(217, 119, 6, .18); color: var(--accent-2); }
.turn-line { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.turn-who { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.turn-who .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--me); box-shadow: 0 0 0 4px rgba(34, 197, 94, .16); }
.turn-who.ai .dot { background: var(--ai); box-shadow: 0 0 0 4px rgba(248, 113, 113, .16); }
.meta-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; font-size: .78rem; color: var(--muted); }
.action-text { font-size: .86rem; color: #cbd5e1; }
.action-text b { color: var(--accent-2); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: .5rem; margin-top: .7rem; }
.stat-cell { padding: .5rem .6rem; border-radius: 10px; background: rgba(255, 255, 255, .04); border: 1px solid var(--border); text-align: center; }
.stat-cell b { display: block; font-size: 1rem; color: var(--accent-2); }
.stat-cell span { font-size: .68rem; color: var(--muted); }
/* ── Board ── */
.board-col { display: flex; flex-direction: column; gap: .6rem; min-width: 0; }
.board-frame { position: relative; border-radius: 20px; padding: .6rem; background: linear-gradient(160deg, rgba(217, 119, 6, .4), rgba(21, 128, 61, .3)); border: 1px solid var(--border-2); box-shadow: var(--shadow-lg); }
.board-wrap { position: relative; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); border-radius: 14px; overflow: hidden; aspect-ratio: 1 / 1; background: var(--felt-2); }
.sq { position: relative; display: grid; place-items: center; background: var(--felt); transition: background .18s ease, box-shadow .18s ease; }
.sq.dark { background: var(--felt-2); }
.sq.playable { cursor: pointer; }
.sq.playable:hover { background: #1f8c51; }
.sq.sel { box-shadow: inset 0 0 0 3px var(--accent-2); }
.sq.mv::before { content: ''; position: absolute; inset: 0; margin: auto; width: 26%; height: 26%; border-radius: 50%; background: rgba(255, 255, 255, .65); box-shadow: 0 0 14px rgba(255, 255, 255, .55); }
.sq.atk::before { content: ''; position: absolute; inset: 0; margin: auto; width: 66%; height: 66%; border-radius: 50%; border: 3px dashed rgba(248, 113, 113, .95); }
.sq.dep { box-shadow: inset 0 0 0 2px rgba(217, 119, 6, .8); cursor: pointer; }
.sq.dep:hover { background: #1f8c51; }
.sq.last { box-shadow: inset 0 0 0 3px rgba(217, 119, 6, .5); }
.sq.danger::after { content: ''; position: absolute; top: 4px; inset-inline-start: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 8px rgba(220, 38, 38, .9); }
.board-veil { position: absolute; inset: 0; display: none; place-items: center; border-radius: 14px; background: rgba(11, 18, 32, .6); backdrop-filter: blur(2px); font-weight: 700; letter-spacing: .04em; }
.board-veil.on { display: grid; }

/* ── Pieces ── */
.piece { width: 86%; height: 86%; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: linear-gradient(165deg, rgba(255, 255, 255, .12), rgba(0, 0, 0, .3)); border: 1px solid var(--border-2); box-shadow: 0 6px 16px rgba(0, 0, 0, .4); animation: pop .22s ease; }
.piece.me { border-color: rgba(34, 197, 94, .8); box-shadow: 0 6px 16px rgba(0, 0, 0, .4), inset 0 0 0 1px rgba(34, 197, 94, .3); }
.piece.ai { border-color: rgba(248, 113, 113, .8); box-shadow: 0 6px 16px rgba(0, 0, 0, .4), inset 0 0 0 1px rgba(248, 113, 113, .3); }
.piece.me .em { color: #86efac; }
.piece.ai .em { color: #fca5a5; }
.piece .em svg { width: clamp(15px, 3.4vw, 25px); height: clamp(15px, 3.4vw, 25px); }
.piece .nm { font-size: clamp(.52rem, 1.4vw, .72rem); font-weight: 700; line-height: 1; }
.piece .st { display: flex; gap: 3px; font-size: clamp(.48rem, 1.25vw, .6rem); font-weight: 700; }
.piece .st i { font-style: normal; padding: 0 3px; border-radius: 5px; background: rgba(0, 0, 0, .45); }
.piece .st i.a { color: #fde68a; }
.piece .st i.d { color: #93c5fd; }
.piece.rest { opacity: .7; }
.piece.shake { animation: shake .3s ease; }
/* ── Seats & gas gauges ── */
.seat { display: flex; align-items: center; gap: .8rem; padding: .5rem .8rem; border-radius: 14px; background: var(--card); border: 1px solid var(--border); }
.seat-name { font-weight: 700; display: flex; align-items: center; gap: .45rem; white-space: nowrap; font-size: .88rem; }
.seat-name .pips { display: flex; gap: 3px; }
.seat-name .pips i { width: 7px; height: 7px; border-radius: 2px; background: var(--border-2); }
.seat-name .pips i.on { background: var(--accent-2); }
.gauge { flex: 1; min-width: 120px; }
.gauge-top { display: flex; justify-content: space-between; gap: .5rem; font-size: .72rem; color: var(--muted); margin-bottom: .25rem; }
.gauge-top em { font-style: normal; color: var(--accent-2); font-weight: 700; }
.gauge-bar { height: 9px; border-radius: 999px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.gauge-bar b { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }
.seat-ai .gauge-bar b { background: linear-gradient(90deg, #b91c1c, #f87171); }

/* ── Hand cards ── */
.hand { display: flex; gap: .55rem; overflow-x: auto; padding: .95rem .1rem .5rem; }
.cardc { position: relative; flex: 0 0 auto; width: 106px; padding: .6rem .5rem .5rem; border-radius: 12px; background: linear-gradient(170deg, rgba(255, 255, 255, .09), rgba(0, 0, 0, .32)); border: 1px solid var(--border-2); color: var(--text); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: .3rem; transition: transform .16s ease, box-shadow .16s ease, border-color .16s; }
.cardc:hover:not(:disabled) { transform: translateY(-4px); border-color: var(--accent-2); box-shadow: 0 14px 30px rgba(217, 119, 6, .25); }
.cardc.on { border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(217, 119, 6, .55); }
.cardc:disabled { opacity: .42; cursor: not-allowed; }
.cardc-cost { position: absolute; top: -9px; inset-inline-start: -8px; width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; font-size: .74rem; font-weight: 700; background: linear-gradient(140deg, var(--accent), var(--accent-2)); color: #1a1206; border: 1px solid rgba(0, 0, 0, .35); }
.cardc-em svg { width: 22px; height: 22px; color: var(--accent-2); }
.cardc-nm { font-weight: 700; font-size: .84rem; line-height: 1.1; }
.cardc-st { display: flex; gap: .3rem; font-size: .62rem; }
.cardc-st i { font-style: normal; padding: 1px 5px; border-radius: 6px; background: rgba(0, 0, 0, .4); }
.cardc-st i.a { color: #fde68a; }
.cardc-st i.d { color: #93c5fd; }
.cardc-mv { font-size: .6rem; color: var(--muted); text-align: center; line-height: 1.35; }
/* ── Battle log ── */
.log { list-style: none; max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; font-size: .8rem; }
.log li { padding: .38rem .6rem; border-radius: 9px; background: rgba(255, 255, 255, .04); border-inline-start: 3px solid var(--border-2); color: #cbd5e1; animation: fadeUp .3s ease; }
.log li.me { border-inline-start-color: var(--me); }
.log li.ai { border-inline-start-color: var(--ai); }
.log li.gold { border-inline-start-color: var(--accent-2); color: #fde68a; }

/* ── Modals ── */
.overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1rem; background: rgba(3, 7, 18, .74); backdrop-filter: blur(5px); animation: fade .2s ease; }
.modal { width: min(640px, 100%); max-height: 88vh; overflow-y: auto; background: linear-gradient(170deg, #101a2e, #0b1220); border: 1px solid var(--border-2); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 1.4rem 1.5rem; animation: pop .24s ease; }
.modal h2 { font-size: 1.3rem; margin-bottom: .45rem; display: flex; align-items: center; gap: .5rem; }
.modal p { color: #cbd5e1; font-size: .9rem; }
.modal .row { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.1rem; flex-wrap: wrap; }
.rules-grid { display: grid; gap: .55rem; margin: .9rem 0; }
.rule { display: flex; gap: .7rem; padding: .55rem .75rem; border-radius: 12px; background: rgba(255, 255, 255, .04); border: 1px solid var(--border); }
.rule b { min-width: 78px; color: var(--accent-2); font-size: .84rem; }
.rule span { font-size: .84rem; color: #cbd5e1; }
.opts { display: grid; gap: .5rem; margin: 1rem 0 .3rem; }
.opt { padding: .7rem .9rem; border-radius: 12px; text-align: start; background: rgba(255, 255, 255, .05); border: 1px solid var(--border-2); color: var(--text); cursor: pointer; font-size: .92rem; transition: transform .16s, border-color .16s, background .16s; }
.opt:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--accent-2); background: rgba(217, 119, 6, .12); }
.opt.right { border-color: var(--me); background: rgba(34, 197, 94, .16); }
.opt.wrong { border-color: var(--danger); background: rgba(220, 38, 38, .16); }

/* ── Toasts ── */
.toast-wrap { position: fixed; bottom: 1.2rem; inset-inline-end: 1.2rem; z-index: 90; display: flex; flex-direction: column; gap: .5rem; max-width: 330px; }
.toast { padding: .6rem 1rem; border-radius: 12px; font-size: .84rem; font-weight: 600; background: rgba(15, 23, 42, .96); border: 1px solid var(--border-2); box-shadow: var(--shadow); animation: pop .2s ease; }
.toast.gold { border-color: rgba(217, 119, 6, .6); color: var(--accent-2); }
.toast.red { border-color: rgba(220, 38, 38, .6); color: #fca5a5; }
.toast.green { border-color: rgba(34, 197, 94, .6); color: #86efac; }

/* ── Animations & footer ── */
@keyframes pop { from { opacity: 0; transform: scale(.94) } to { opacity: 1; transform: none } }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes shake { 0%, 100% { transform: none } 25% { transform: translateX(-3px) } 75% { transform: translateX(3px) } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }
.foot { position: relative; z-index: 1; text-align: center; font-size: .74rem; color: var(--muted); padding: 0 1rem 2rem; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ── Responsive ── */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .board-col { order: -1; }
}
@media (max-width: 620px) {
  .topbar { padding: .6rem .7rem; flex-direction: column; align-items: stretch; }
  .topbar-actions { justify-content: space-between; }
  .brand-text b { font-size: .95rem; }
  .layout { padding: .8rem .7rem 2rem; }
  .panel { padding: .8rem .85rem; }
  .seat { flex-wrap: wrap; gap: .5rem; }
  .cardc { width: 94px; }
  .rule { flex-direction: column; gap: .15rem; }
  .log { max-height: 170px; }
}
