/* ديرة — الواجهة. رمل وبحر ونخيل. */
:root {
  --bg: #efe4cf;
  --bg2: #e6d6b8;
  --card: #fbf6ec;
  --line: #d8c6a3;
  --ink: #2b2118;
  --muted: #7a6a55;
  --sea: #1f6f78;
  --sea2: #16545b;
  --palm: #4c7a34;
  --clay: #a4623a;
  --iron: #6b7078;
  --dates: #8a4b1f;
  --gold: #c9a227;
  --red: #b33a3a;
  --ok: #3f7d3a;
  --shadow: 0 1px 2px rgba(60, 40, 10, .12), 0 4px 14px rgba(60, 40, 10, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1812; --bg2: #25201a; --card: #2a241c; --line: #3d3428; --ink: #f1e7d6; --muted: #b3a38b;
    --sea: #4fb3bd; --sea2: #7fcfd6; --palm: #8cbf6c; --clay: #d88f63; --iron: #a9afb7; --dates: #d9954f;
    --gold: #e2bd45; --red: #e0716f; --ok: #7cc46f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1812; --bg2: #25201a; --card: #2a241c; --line: #3d3428; --ink: #f1e7d6; --muted: #b3a38b;
  --sea: #4fb3bd; --sea2: #7fcfd6; --palm: #8cbf6c; --clay: #d88f63; --iron: #a9afb7; --dates: #d9954f;
  --gold: #e2bd45; --red: #e0716f; --ok: #7cc46f; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
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; min-height: 100vh;
  background-image: radial-gradient(circle at 20% 0%, rgba(201,162,39,.10), transparent 40%), radial-gradient(circle at 100% 100%, rgba(31,111,120,.08), transparent 45%);
  background-attachment: fixed;
}
a { color: var(--sea); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.3; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ── الترويسة ── */
.top {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.top-row { display: flex; align-items: center; gap: 10px; padding: 6px 12px; max-width: 1180px; margin: 0 auto; }
.brand { font-weight: 800; font-size: 1.25rem; color: var(--sea2); display: flex; align-items: center; gap: 6px; }
.brand svg { width: 26px; height: 26px; }
.clock { margin-inline-start: auto; text-align: left; font-size: .8rem; color: var(--muted); line-height: 1.25; }
.clock b { color: var(--ink); font-size: .95rem; }
.goldpill { display: inline-flex; align-items: center; gap: 4px; background: color-mix(in srgb, var(--gold) 18%, var(--card)); border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent); padding: 2px 10px; border-radius: 99px; font-weight: 700; cursor: pointer; }
.res-row { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 6px; padding: 4px 12px 8px; max-width: 1180px; margin: 0 auto; }
.res { background: var(--bg2); border-radius: 10px; padding: 4px 8px; position: relative; overflow: hidden; min-width: 0; }
.res .bar { position: absolute; inset-inline-start: 0; bottom: 0; height: 3px; background: currentColor; opacity: .7; }
.res .v { font-weight: 700; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.res .r { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.res.full .v { color: var(--red); }
.res svg { width: 16px; height: 16px; flex: none; }
.upk { font-size: .72rem; color: var(--muted); align-self: center; text-align: center; line-height: 1.2; }

/* ── التخطيط ── */
.wrap { max-width: 1180px; margin: 0 auto; padding: 12px; display: grid; grid-template-columns: 1fr 300px; gap: 14px; }
.main { min-width: 0; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
@media (max-width: 900px) {
  .wrap { grid-template-columns: 1fr; padding: 10px 10px 90px; }
  .side { order: 2; }
  .res-row { grid-template-columns: repeat(4, 1fr); }
  .upk { display: none; }
  .clock .lbl { display: none; }
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card h3 { display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; background: var(--bg2); font-size: .8rem; }
.pill.red { background: color-mix(in srgb, var(--red) 18%, var(--card)); color: var(--red); }
.pill.green { background: color-mix(in srgb, var(--ok) 18%, var(--card)); color: var(--ok); }
.pill.sea { background: color-mix(in srgb, var(--sea) 16%, var(--card)); color: var(--sea2); }
.pill.gold { background: color-mix(in srgb, var(--gold) 22%, var(--card)); color: var(--dates); }

/* ── الأزرار والحقول ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; background: var(--sea); color: #fff; padding: 7px 16px; border-radius: 10px; font-weight: 700; cursor: pointer; min-height: 38px; transition: filter .15s, transform .05s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--sea2); border-color: var(--line); }
.btn.gold { background: var(--gold); color: #2b2118; }
.btn.red { background: var(--red); }
.btn.sm { padding: 3px 10px; min-height: 30px; font-size: .85rem; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 7px 10px; min-height: 38px; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--sea) 50%, transparent); border-color: var(--sea); }
input.n { width: 76px; text-align: center; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { border: 1px solid var(--line); background: var(--card); padding: 5px 12px; border-radius: 99px; cursor: pointer; font-size: .9rem; }
.tabs button.on { background: var(--sea); color: #fff; border-color: var(--sea); }

/* ── الجداول ── */
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th, table.t td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
table.t th { font-size: .8rem; color: var(--muted); font-weight: 600; }
table.t tr.unread td { font-weight: 700; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--bg2); }
.tscroll { overflow-x: auto; }
table.units { width: 100%; border-collapse: collapse; font-size: .82rem; text-align: center; }
table.units th, table.units td { border: 1px solid var(--line); padding: 3px 2px; }
table.units th { background: var(--bg2); font-weight: 600; font-size: .72rem; }
table.units td.dead { color: var(--red); }

/* ── الكلفة ── */
.cost { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .88rem; }
.cost span { display: inline-flex; align-items: center; gap: 3px; }
.cost span.lack { color: var(--red); font-weight: 700; }
.cost svg { width: 15px; height: 15px; }

/* ── القرية ── */
.vtitle { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.vtitle h2 { margin: 0; }
.scene { position: relative; width: 100%; max-width: 640px; margin: 0 auto; aspect-ratio: 1 / .82; }
.scene svg.bgart { position: absolute; inset: 0; width: 100%; height: 100%; }
.slot { position: absolute; transform: translate(-50%, -50%); width: 13%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; cursor: pointer; border: 2px solid rgba(0,0,0,.18); box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform .12s; }
.slot:hover { transform: translate(-50%, -50%) scale(1.08); z-index: 2; }
.slot svg { width: 58%; height: 58%; }
.slot .lv { position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 99px; font-size: .72rem; font-weight: 800; padding: 0 6px; min-width: 22px; text-align: center; }
.slot.busy .lv { background: var(--gold); color: #2b2118; }
.slot.can { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 60%, transparent), 0 2px 6px rgba(0,0,0,.2); }
.slot.wood { background: #6f9a4a; } .slot.clay { background: #b57746; } .slot.iron { background: #8a8f96; } .slot.dates { background: #c9933b; }
.slot.b { border-radius: 14px; background: var(--card); width: 11%; }
.slot.b.empty { background: color-mix(in srgb, var(--card) 45%, transparent); border-style: dashed; }
.slot.b.empty svg { opacity: .35; }
.slot.center { width: 20%; background: radial-gradient(circle, #e9d6ad, #c8a86e); }
.legend { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 10px; font-size: .82rem; color: var(--muted); }

/* ── الخريطة ── */
.map { display: grid; gap: 2px; background: var(--line); border: 2px solid var(--line); border-radius: 10px; overflow: hidden; direction: ltr; user-select: none; }
.tile { aspect-ratio: 1; background: #e3cf9f; position: relative; cursor: pointer; display: grid; place-items: center; font-size: .6rem; overflow: hidden; }
:root[data-theme="dark"] .tile, :root:not([data-theme="light"]) .tile { }
.tile:hover { outline: 2px solid var(--sea); z-index: 1; }
.tile.oasis { background: #9fbf7a; }
.tile.v { background: #c9a36a; }
.tile.v.me { background: var(--sea); color: #fff; }
.tile.v.ally { background: var(--palm); color: #fff; }
.tile.v.other { background: #a8573b; color: #fff; }
.tile.c9 { box-shadow: inset 0 0 0 3px #d49a2a; }
.tile.c15 { box-shadow: inset 0 0 0 3px #e4572e; }
.tile .tl { position: absolute; bottom: 1px; left: 2px; font-size: .55rem; opacity: .7; }
.tile svg { width: 60%; height: 60%; }
.tile.sel { outline: 3px solid var(--gold); z-index: 2; }
.maptools { display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 34px); gap: 4px; }
.maptools button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; cursor: pointer; font-size: 1.1rem; }

/* ── الجانب ── */
.qitem { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: .88rem; }
.qitem:last-child { border-bottom: 0; }
.move-in-attack { color: var(--red); font-weight: 700; }
.vlist a { display: flex; justify-content: space-between; padding: 5px 8px; border-radius: 8px; color: var(--ink); }
.vlist a.on { background: color-mix(in srgb, var(--sea) 15%, transparent); font-weight: 700; }
.vlist a:hover { background: var(--bg2); }
.troop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px 10px; font-size: .88rem; }

/* ── التنقل السفلي (جوال) ── */
.nav { display: flex; gap: 2px; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--ink); font-weight: 600; font-size: .92rem; display: flex; align-items: center; gap: 5px; position: relative; }
.nav a.on { background: color-mix(in srgb, var(--sea) 16%, transparent); color: var(--sea2); }
.nav a svg { width: 20px; height: 20px; }
.nav .dot { position: absolute; top: 1px; inset-inline-end: 1px; background: var(--red); color: #fff; font-size: .62rem; border-radius: 99px; min-width: 16px; height: 16px; display: grid; place-items: center; padding: 0 4px; }
.navbar { max-width: 1180px; margin: 0 auto; padding: 8px 12px 0; }
@media (max-width: 900px) {
  .navbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); max-width: none; box-shadow: 0 -4px 14px rgba(0,0,0,.08); }
  .nav { justify-content: space-around; }
  .nav a { flex-direction: column; gap: 0; font-size: .7rem; padding: 4px 6px; }
  .nav a .lbl-long { display: none; }
}

/* ── النوافذ والتنبيهات ── */
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; font-weight: 600; }
.toast.err { background: var(--red); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: rgba(20, 14, 6, .5); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; width: min(560px, 100%); max-height: 88vh; overflow: auto; padding: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.banner { background: color-mix(in srgb, var(--gold) 20%, var(--card)); border: 1px solid color-mix(in srgb, var(--gold) 55%, transparent); border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; }
.banner.red { background: color-mix(in srgb, var(--red) 14%, var(--card)); border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.banner.sea { background: color-mix(in srgb, var(--sea) 12%, var(--card)); border-color: color-mix(in srgb, var(--sea) 40%, transparent); }

/* ── الدخول ── */
.auth { max-width: 980px; margin: 0 auto; padding: 24px 16px 60px; }
.hero-art { text-align: center; padding: 16px 0 6px; }
.hero-art h1 { font-size: 2.6rem; color: var(--sea2); margin: 0; letter-spacing: .5px; }
.hero-art p { color: var(--muted); margin: 4px 0 0; }
.tribes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.tribe { border: 2px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer; background: var(--card); }
.tribe.on { border-color: var(--sea); box-shadow: 0 0 0 3px color-mix(in srgb, var(--sea) 25%, transparent); }
.tribe b { font-size: 1.1rem; }
.auth-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
@media (max-width: 760px) { .auth-grid { grid-template-columns: 1fr; } }

.hp { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; }
.hp > i { display: block; height: 100%; background: var(--ok); }
.xp > i { background: var(--gold); }
.statline { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.chat { max-height: 320px; overflow: auto; background: var(--bg); border-radius: 10px; padding: 8px; font-size: .9rem; }
.chat div { padding: 3px 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--sea); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.bld-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.bld-icon { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; background: var(--bg2); flex: none; }
.bld-icon svg { width: 36px; height: 36px; }
.unitrow { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); align-items: center; }
.unitrow:last-child { border-bottom: 0; }
.stats { font-size: .78rem; color: var(--muted); }

/* أحجام الأيقونات داخل العناوين والأزرار */
h2 svg, h3 svg, h4 svg, .btn svg, .goldpill svg, .vlist svg, .legend svg { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.legend svg { width: 1.3em; height: 1.3em; }

table svg, .cost svg, .res svg { width: 16px; height: 16px; flex: none; vertical-align: -3px; }

/* ── تحسين المشاهد (2026-09-19) ── */
.scene { max-width: 760px; aspect-ratio: 1 / .9; }
.slot { width: 10.5%; border-width: 2px; }
.slot.wood, .slot.clay, .slot.iron, .slot.dates { background: radial-gradient(circle at 50% 35%, #f3e3bd, #d9bd85); border-color: rgba(90, 60, 20, .35); }
.slot.wood { box-shadow: 0 0 0 2px #5f8f3a55, 0 3px 8px rgba(0,0,0,.2); }
.slot.clay { box-shadow: 0 0 0 2px #b8703f55, 0 3px 8px rgba(0,0,0,.2); }
.slot.iron { box-shadow: 0 0 0 2px #7d838b55, 0 3px 8px rgba(0,0,0,.2); }
.slot.dates { box-shadow: 0 0 0 2px #c9933b66, 0 3px 8px rgba(0,0,0,.2); }
.slot.can { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 75%, transparent), 0 3px 8px rgba(0,0,0,.2) !important; }
.slot svg { width: 78%; height: 78%; }
.slot.b svg { width: 60%; height: 60%; }
.slot.b { width: 9.5%; border-radius: 22%; background: linear-gradient(160deg, #fbf3e0, #e5cfa3); border-color: rgba(120, 85, 35, .35); }
.slot.b:not(.empty) span:first-child { color: #16545b !important; }
.slot.b.empty { background: rgba(255, 248, 230, .28); border: 2px dashed rgba(120, 85, 35, .35); box-shadow: none; }
.slot.center { width: 16%; }
.slot .lv { font-size: .68rem; min-width: 20px; }
.scene-card { padding: 8px; }
.mapwrap { display: flex; gap: 12px; align-items: flex-start; }
.mapwrap .map { flex: 1; max-width: 720px; }
@media (max-width: 900px) {
  .scene-card { margin-inline: -10px; border-radius: 0; border-inline: 0; padding: 4px 0; }
  .scene { max-width: none; }
  .slot { width: 12.5%; }
  .slot.b { width: 11.5%; }
  .slot .lv { font-size: .62rem; bottom: -7px; padding: 0 4px; }
  .mapwrap { flex-direction: column; align-items: center; }
  .mapwrap .map { width: 100%; max-width: none; }
  .tile .tl { display: none; }
}
