/* ساند — الواجهة. ليلٌ صحراويّ دافئ فوق مدينة تحت الرمال. */
:root {
  --bg: #1d150e; --bg2: #2a1f15; --card: #33271b; --card2: #3d2f21; --line: #564330;
  --ink: #f6ead4; --muted: #bfa987; --sand: #e2b76a; --sand2: #c9954f; --gold: #f0c24a;
  --power: #ffd23f; --water: #53b8e0; --food: #8fcf5a; --red: #e45b4f; --ok: #7cc46f; --blue: #6aa8e0; --purple: #b58ae6;
  --r0: #cfc2ad; --r1: #6ab0ff; --r2: #ffb13b;
  --radius: 14px; --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Tajawal", system-ui, sans-serif; background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.55; -webkit-tap-highlight-color: transparent; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--ink); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--sand); outline-offset: 0; }
textarea { min-height: 90px; resize: vertical; }
[hidden] { display: none !important; }
a { color: var(--sand); }

.btn { border: 0; border-radius: 11px; padding: 9px 15px; background: var(--card2); font-weight: 700; display: inline-flex; gap: 6px; align-items: center; justify-content: center; }
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
.btn.pri { background: linear-gradient(180deg, #f0c24a, #d39a2c); color: #2a1a08; }
.btn.ok { background: #4f8f45; color: #fff; }
.btn.bad { background: #a4372f; color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--bg2); font-size: 12px; color: var(--muted); }
.r0 { color: var(--r0); } .r1 { color: var(--r1); } .r2 { color: var(--r2); }
h2, h3 { margin: 0 0 8px; }
h3 { font-size: 16px; }

/* ── الدخول ── */
.auth { position: fixed; inset: 0; overflow: auto; display: grid; place-items: center; padding: 20px 16px;
  background: radial-gradient(ellipse at 50% 120%, #c9954f 0%, #7c5530 30%, #2a1d12 62%, #0c1024 100%); }
.auth .box { width: min(420px, 100%); background: rgba(35, 26, 17, .92); border: 1px solid var(--line); border-radius: 20px; padding: 26px 22px; box-shadow: var(--shadow); }
.logo { text-align: center; margin-bottom: 18px; }
.logo .t { font-size: 44px; font-weight: 800; letter-spacing: 1px; color: var(--sand); text-shadow: 0 3px 0 #5a3a18; line-height: 1.1; }
.logo .s { color: var(--muted); }
.tabs { display: flex; gap: 6px; background: var(--bg2); border-radius: 12px; padding: 4px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 9px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--card2); color: var(--ink); }
.field { margin-bottom: 11px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ── اللعبة ── */
#game { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; }
#cv { width: 100%; height: 100%; display: block; touch-action: none; }
.stage { position: relative; min-height: 0; }
.hud { display: flex; gap: 6px; align-items: center; padding: 7px 10px calc(7px) 10px; background: linear-gradient(180deg, #2a1f15, #1d150e); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.hud::-webkit-scrollbar { display: none; }
.res { flex: none; display: flex; align-items: center; gap: 5px; background: var(--bg2); border-radius: 99px; padding: 3px 9px 3px 4px; min-width: 0; white-space: nowrap; font-weight: 700; font-size: 13px; }
.res .ic { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: #0003; font-size: 14px; }
.res .bar { width: 46px; height: 6px; border-radius: 3px; background: #0006; overflow: hidden; }
.res .bar i { display: block; height: 100%; border-radius: 3px; }
.res.low { animation: pulse 1s infinite; }
@keyframes pulse { 50% { background: #6a2520; } }
.hud .sp { flex: 1; }
.iconbtn { position: relative; border: 0; background: var(--bg2); width: 36px; height: 36px; border-radius: 50%; font-size: 17px; flex: none; }
.badge { position: absolute; top: -3px; left: -3px; background: var(--red); color: #fff; font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 3px; font-weight: 800; }
.nav { display: flex; background: #1a120b; border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav button { flex: 1; min-width: 0; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 2px; border-radius: 10px; font-size: 11.5px; color: var(--muted); font-weight: 700; }
.nav button .e { font-size: 21px; line-height: 1.1; }
.nav button.on, .nav button:hover { background: var(--card); color: var(--ink); }
.nav button .badge { top: 1px; left: 8px; }
.nav button { position: relative; }
.zoom { position: absolute; left: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: rgba(30, 22, 14, .85); font-size: 20px; font-weight: 700; }
.banner { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: rgba(20, 14, 8, .88); border: 1px solid var(--sand2); color: var(--ink); padding: 7px 14px; border-radius: 99px; font-weight: 700; font-size: 13.5px; display: flex; gap: 10px; align-items: center; max-width: calc(100% - 24px); white-space: nowrap; overflow: hidden; }
.banner.warn { border-color: var(--red); }
.ann { position: absolute; top: 8px; right: 10px; left: 10px; background: linear-gradient(90deg, rgba(90, 60, 20, .95), rgba(60, 40, 14, .95)); border: 1px solid var(--gold); border-radius: 12px; padding: 8px 12px; font-size: 13.5px; display: flex; gap: 8px; align-items: flex-start; }
.ann b { color: var(--gold); white-space: nowrap; }
.ann .x { margin-inline-start: auto; background: none; border: 0; color: var(--muted); font-size: 16px; }

/* ── النوافذ ── */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--card); width: min(720px, 100%); max-height: 88vh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column; box-shadow: var(--shadow); animation: up .2s; border: 1px solid var(--line); border-bottom: 0; }
@keyframes up { from { transform: translateY(40px); } }
.sheet.full { max-height: 96vh; height: 96vh; }
@media (min-width: 760px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 20px; border-bottom: 1px solid var(--line); } }
.sheet .hd { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.sheet .hd h2 { font-size: 18px; margin: 0; flex: 1; }
.sheet .hd .x { border: 0; background: var(--bg2); width: 34px; height: 34px; border-radius: 50%; font-size: 16px; }
.sheet .bd { overflow-y: auto; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.card { background: var(--bg2); border-radius: 12px; padding: 11px 12px; margin-bottom: 9px; }
.list .it { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px; background: var(--bg2); margin-bottom: 7px; cursor: pointer; }
.list .it:hover { background: var(--card2); }
.list .it .nm { font-weight: 700; }
.pbar { height: 8px; background: #0006; border-radius: 4px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: var(--gold); border-radius: 4px; transition: width .3s; }
.pbar.hp i { background: var(--ok); } .pbar.pois i { background: var(--purple); } .pbar.xp i { background: var(--blue); }
.stats7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; text-align: center; }
.stats7 .s { background: var(--bg2); border-radius: 10px; padding: 6px 2px; }
.stats7 .s b { display: block; font-size: 18px; }
.stats7 .s small { font-size: 10.5px; color: var(--muted); }
.stats7 .s.hi { outline: 2px solid var(--gold); }
.statbars { display: grid; gap: 5px; }
.statbars .l { display: grid; grid-template-columns: 70px 1fr 42px; gap: 8px; align-items: center; font-size: 13px; }
.statbars .l .pbar { height: 10px; }
.statbars .l .pbar i { background: linear-gradient(90deg, #c9954f, #f0c24a); }
.portrait { width: 86px; height: 110px; border-radius: 14px; background: radial-gradient(circle at 50% 30%, #5a4430, #2a1f15); flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg2); border-radius: 99px; padding: 5px 12px; font-weight: 700; }
.chip.on { background: var(--sand); color: #2a1a08; border-color: var(--sand); }
.logl { font-size: 13.5px; padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; }
.logl .tm { color: var(--muted); font-size: 12px; white-space: nowrap; }
.logl.good { color: #cdeec4; } .logl.bad { color: #ffc2bb; } .logl.warn { color: #ffe1a3; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* الصناديق */
.crates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.crate { background: var(--bg2); border-radius: 14px; padding: 12px 8px; text-align: center; }
.crate .ico { font-size: 42px; line-height: 1.2; }
.crate.wood .ico { filter: sepia(.6); }
.crate .n { font-weight: 800; font-size: 20px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; perspective: 800px; margin: 10px 0; }
@media (max-width: 520px) { .cards { grid-template-columns: repeat(2, 1fr); } }
.cardx { height: 150px; position: relative; transform-style: preserve-3d; transition: transform .6s; cursor: pointer; }
.cardx.flip { transform: rotateY(180deg); }
.cardx > div { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px; text-align: center; }
.cardx .back { background: repeating-linear-gradient(45deg, #6b4a2a, #6b4a2a 8px, #5a3d22 8px, #5a3d22 16px); border: 2px solid #c9954f; font-size: 36px; }
.cardx .front { transform: rotateY(180deg); background: var(--card2); border: 2px solid var(--line); }
.cardx .front.r1 { border-color: var(--r1); box-shadow: 0 0 18px rgba(106, 176, 255, .35) inset; }
.cardx .front.r2 { border-color: var(--r2); box-shadow: 0 0 24px rgba(255, 177, 59, .5) inset; }
.cardx .front .e { font-size: 34px; }
.cardx .front b { font-size: 13.5px; }
.shake { animation: shake .5s 2; }
@keyframes shake { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }

.toast { position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%); background: #2f4a2a; color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 50; box-shadow: var(--shadow); font-weight: 700; max-width: calc(100% - 32px); text-align: center; animation: fade .2s; }
.toast.err { background: #7a2a24; }
.buildbar { position: absolute; bottom: 10px; right: 50%; transform: translateX(50%); background: rgba(20, 14, 8, .92); border: 1px solid var(--ok); border-radius: 99px; padding: 6px 8px 6px 14px; display: flex; gap: 10px; align-items: center; font-weight: 700; white-space: nowrap; }
.spin { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--sand); border-radius: 50%; animation: sp 1s linear infinite; margin: auto; }
@keyframes sp { to { transform: rotate(360deg); } }
.av { width: 54px; height: 54px; border-radius: 50%; background: var(--bg2); display: grid; place-items: center; font-size: 30px; flex: none; }
.avs { display: flex; flex-wrap: wrap; gap: 8px; }
.avs button { width: 48px; height: 48px; border-radius: 50%; border: 2px solid transparent; background: var(--bg2); font-size: 26px; }
.avs button.on { border-color: var(--sand); }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th, table.t td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.t th { color: var(--muted); font-weight: 700; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover { background: var(--card2); }
.msg { white-space: pre-wrap; }

@media (max-width: 560px) {
  .hud { flex-wrap: wrap; row-gap: 5px; padding: 6px 8px; }
  .hud .sp { display: none; }
  .res { font-size: 12px; padding: 2px 7px 2px 3px; gap: 4px; }
  .res .ic { width: 20px; height: 20px; font-size: 12px; }
  .res .bar { width: 26px; }
  .iconbtn { width: 32px; height: 32px; font-size: 15px; }
  .nav button { font-size: 10.5px; padding: 4px 0; }
  .nav button .e { font-size: 19px; }
  .ann { font-size: 12.5px; top: 6px; }
}

/* البطاقة السريعة للساكن */
.qcard { position: absolute; left: 10px; right: 10px; bottom: 10px; margin: 0 auto; max-width: 560px; background: rgba(35, 26, 17, .96); border: 1px solid var(--sand2); border-radius: 16px; padding: 11px 12px; box-shadow: var(--shadow); }
.qcard .stats7 .s { padding: 4px 1px; } .qcard .stats7 .s b { font-size: 16px; }
.eqc .card { margin: 0; cursor: pointer; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px; }
.eqc .card b { font-size: 13px; }
.list .it svg { width: 44px; height: 44px; }
.cardx .front .e svg { width: 56px; height: 56px; }
