:root {
  --bg: #f6ecd9; --card: #fffaf0; --ink: #2a2218; --muted: #7a6a55; --line: #e6d6b8;
  --gold: #d9a521; --gold-ink: #5a4100; --dark: #2a2218; --red: #b3261e; --green: #1e6b3a;
  --shadow: 0 6px 24px rgba(60, 40, 10, .14);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: 'Cairo', system-ui, sans-serif; color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; border: 0; }
input { font: inherit; }
a { color: inherit; }
.btn { background: var(--dark); color: #fff; border-radius: 12px; padding: 8px 14px; font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn.gold { background: var(--gold); color: var(--gold-ink); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- map page ---------- */
body.map { overflow: hidden; }
#scene { position: fixed; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }
.topbar { position: fixed; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; z-index: 5; }
.brand { background: var(--dark); color: #fff; border-radius: 14px; padding: 8px 14px; font-weight: 800; font-size: 18px; white-space: nowrap; box-shadow: var(--shadow); }
.brand small { font-weight: 600; opacity: .7; font-size: 12px; margin-inline-start: 6px; }
.search { flex: 1; display: flex; background: #fff; border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; min-width: 0; max-width: 460px; }
.search input { flex: 1; border: 0; padding: 10px 14px; outline: none; min-width: 0; direction: ltr; text-align: right; }
.search input::placeholder { direction: rtl; }
.search button { background: var(--gold); color: var(--gold-ink); padding: 0 16px; font-weight: 800; }
.topbar .spacer { flex: 1; }
.topbar .btn { box-shadow: var(--shadow); padding: 10px 14px; border-radius: 14px; }

.toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); background: var(--dark); color: #fff; border-radius: 12px; padding: 10px 16px; z-index: 20; box-shadow: var(--shadow); display: none; max-width: calc(100% - 32px); }
.toast.show { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }

.panel { position: fixed; z-index: 6; background: var(--card); border-radius: 18px; box-shadow: var(--shadow); }
#info { right: 12px; top: 72px; width: 300px; padding: 16px; display: none; }
#info.show { display: block; }
#info .close { position: absolute; left: 10px; top: 8px; background: none; font-size: 20px; color: var(--muted); }
#info h2 { margin: 0; font-size: 20px; direction: ltr; text-align: right; }
.sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.power { display: inline-block; margin-top: 8px; background: #fff3cf; color: var(--gold-ink); border-radius: 10px; padding: 3px 10px; font-weight: 800; }
.units { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 0; }
.units div { background: #fff; border: 1px solid var(--line); border-radius: 10px; text-align: center; padding: 6px 2px; font-size: 12px; color: var(--muted); }
.units b { display: block; font-size: 17px; color: var(--ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1; justify-content: center; }

#board { left: 12px; top: 72px; width: 250px; padding: 12px 14px; }
#board h3 { margin: 0 0 6px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
#board h3 button { background: none; font-size: 14px; color: var(--muted); }
#board ol { margin: 0; padding: 0; list-style: none; }
#board li { display: flex; gap: 8px; align-items: center; padding: 5px 4px; border-radius: 8px; cursor: pointer; font-size: 14px; }
#board li:hover { background: #fff3cf; }
#board li .n { width: 22px; text-align: center; font-weight: 800; color: var(--muted); }
#board li .nm { flex: 1; direction: ltr; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board li .p { font-weight: 700; color: var(--gold-ink); }
#board.collapsed ol { display: none; }

.hint { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); background: rgba(42, 34, 24, .78); color: #fff; border-radius: 12px; padding: 6px 14px; font-size: 13px; z-index: 4; white-space: nowrap; }
#loading { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-size: 20px; font-weight: 800; }
#loading.hide { display: none; }
#loading .bar { width: 200px; height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 30%; background: var(--gold); animation: load 1.2s infinite ease-in-out; }
@keyframes load { 0% { margin-inline-start: -30%; } 100% { margin-inline-start: 100%; } }

.battlebar { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); z-index: 5; background: rgba(30, 22, 12, .9); color: #fff; border-radius: 16px; padding: 8px 14px; text-align: center; box-shadow: var(--shadow); min-width: 300px; }
.battlebar .vs { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 16px; direction: rtl; }
.battlebar .side b { font-weight: 800; }
.battlebar .side em { font-style: normal; background: rgba(255, 255, 255, .15); border-radius: 8px; padding: 0 8px; font-weight: 700; }
.battlebar .side.a b { color: #ff8a80; }
.battlebar .side.b b { color: #8fe3a8; }
.battlebar .when { font-size: 14px; margin-top: 2px; color: #ffe08a; font-weight: 700; }
.battlebar.live .when { color: #ff6b5b; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .55; } }
.battlebar .meta { display: flex; gap: 10px; justify-content: center; align-items: center; font-size: 12px; opacity: .9; margin-top: 2px; flex-wrap: wrap; }
.battlebar .meta button { background: rgba(255, 255, 255, .14); color: #fff; border-radius: 8px; padding: 2px 10px; font-size: 12px; }
.result { position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%); z-index: 8; font-size: 34px; font-weight: 800; color: #fff; background: rgba(30, 22, 12, .85); padding: 14px 26px; border-radius: 20px; display: none; text-align: center; box-shadow: var(--shadow); }
.result.show { display: block; animation: pop .5s ease-out; }
.result small { display: block; font-size: 15px; font-weight: 600; opacity: .8; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }
.fate { margin-top: 8px; font-weight: 700; background: #fff3cf; color: var(--gold-ink); border-radius: 10px; padding: 6px 10px; font-size: 14px; }
.toast .btn { padding: 4px 12px; }

@media (max-width: 720px) {
  .brand small { display: none; }
  .battlebar { top: 112px; min-width: 0; width: calc(100% - 24px); padding: 6px 10px; }
  .battlebar .vs { font-size: 14px; }
  .result { font-size: 24px; width: calc(100% - 40px); }
  .topbar { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  #board { top: auto; bottom: 52px; left: 12px; width: auto; right: 12px; }
  #board:not(.collapsed) ol { max-height: 30vh; overflow: auto; }
  #info { left: 12px; right: 12px; width: auto; top: auto; bottom: 52px; z-index: 7; }
  .hint { font-size: 11px; }
}

/* ---------- shop page ---------- */
body.shop { min-height: 100%; }
.shop-wrap { max-width: 860px; margin: 0 auto; padding: 16px; }
.shop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; }
.shop-head h1 { margin: 0; font-size: 20px; }
.me { background: var(--dark); color: #fff; border-radius: 18px; padding: 16px; display: flex; align-items: center; gap: 12px; }
.me .av { width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; font-size: 28px; flex: none; }
.me .who { flex: 1; min-width: 0; }
.me .who b { display: block; font-size: 18px; direction: ltr; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.me .who span { font-size: 13px; opacity: .75; }
.me .btn { background: #fff3cf; color: var(--gold-ink); }
.login { background: var(--card); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.login h2 { margin: 0 0 4px; font-size: 18px; }
.login form { display: flex; gap: 8px; margin-top: 10px; }
.login input { flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; direction: ltr; min-width: 0; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 6px; scrollbar-width: none; }
.tabs button { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; white-space: nowrap; font-weight: 700; color: var(--ink); }
.tabs button.on { background: var(--dark); color: #fff; border-color: var(--dark); }
.gift-to { background: #fff3cf; border-radius: 14px; padding: 12px; margin: 6px 0 4px; display: none; }
.gift-to.show { display: block; }
.gift-to input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; direction: ltr; margin-top: 6px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 10px; }
.item { background: #fff; border-radius: 16px; padding: 10px; box-shadow: 0 2px 10px rgba(60, 40, 10, .07); display: flex; flex-direction: column; gap: 6px; }
.item .pic { aspect-ratio: 1.25; border-radius: 12px; background: linear-gradient(#f4e6c8, #ead6ae); display: grid; place-items: center; font-size: 44px; overflow: hidden; }
.item .pic img { width: 100%; height: 100%; object-fit: contain; }
.item h4 { margin: 2px 0 0; font-size: 15px; }
.item p { margin: 0; font-size: 12px; color: var(--muted); flex: 1; }
.item .row { display: flex; justify-content: space-between; align-items: center; }
.item .price { font-weight: 800; font-size: 17px; }
.item .tag { font-size: 12px; color: var(--green); font-weight: 700; }
.note { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0 8px; }
.modal { position: fixed; inset: 0; background: rgba(20, 14, 6, .5); display: none; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal.show { display: flex; }
.modal .box { background: var(--card); border-radius: 18px; padding: 20px; max-width: 360px; width: 100%; text-align: center; }
.modal h3 { margin: 0 0 6px; }
.modal .test { background: #fff3cf; color: var(--gold-ink); border-radius: 10px; padding: 6px 10px; font-size: 13px; margin: 10px 0; }
.modal .actions { margin-top: 12px; }
@media (max-width: 640px) { .grid { grid-template-columns: repeat(2, 1fr); } }
