/* عاصفة الرافدين — HUD styles (DOM over canvas; RTL-first) */
:root {
  --bg: #0b0f14;
  --panel: #141c26e6;
  --line: #2a3644;
  --ink: #e8eef5;
  --dim: #8fa3b8;
  --gold: #f2c05a;
  --green: #2eff9e;
  --red: #ff5a5a;
  --uiScale: 1;
  font-size: calc(14px * var(--uiScale));
}
* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; -webkit-user-select: none; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg); overscroll-behavior: none; }
body { font-family: 'Changa', 'Segoe UI', Tahoma, sans-serif; color: var(--ink); }
#game { position: fixed; inset: 0; display: block; cursor: default; touch-action: none; -webkit-tap-highlight-color: transparent; }

/* loading */
#loading { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 100; }
#loading .logo { font-size: 34px; font-weight: 800; background: linear-gradient(100deg,#b8860b,#ffd700,#fffbe0,#ffd700,#b8860b); -webkit-background-clip: text; background-clip: text; color: transparent; }
#loading .sub { color: var(--dim); letter-spacing: 2px; font-size: 13px; }
#loading .bar { width: 260px; height: 8px; background: #1b2530; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
#loadFill { height: 100%; width: 0%; background: linear-gradient(90deg,#b8860b,#ffd700); transition: width .15s; }
#loadMsg { color: var(--dim); font-size: 12.5px; }

/* top bar */
#topbar { position: fixed; top: 0; inset-inline: 0; height: 44px; display: flex; align-items: center; gap: 16px; padding: 0 14px; background: linear-gradient(180deg, #101822f2, #101822cc); border-bottom: 1px solid var(--line); z-index: 20; }
#topbar .brand { font-weight: 800; font-size: 15px; color: var(--gold); }
#topbar .res { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 16px; min-width: 110px; }
#topbar .power { display: flex; align-items: center; gap: 8px; }
#topbar .plabel { color: var(--dim); font-size: 12px; }
#topbar .pbar { position: relative; width: 140px; height: 10px; background: #1b2530; border: 1px solid var(--line); border-radius: 5px; }
#powerFill { position: absolute; inset-block: 0; inset-inline-start: 0; background: linear-gradient(90deg,#1f8f4d,#2eff9e); border-radius: 5px; }
#powerNeedle { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #fff; }
#lowPowerWarn { display: none; color: var(--red); font-weight: 700; font-size: 13px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .35; } }
#hudClock { color: var(--dim); font-variant-numeric: tabular-nums; }
#muteBtn { background: none; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); font-size: 14px; padding: 3px 8px; cursor: pointer; }
#muteBtn:hover { border-color: #4d7cab; }

/* sidebar */
/* sidebar stays on the PHYSICAL RIGHT in both languages (classic RTS identity);
   text inside remains RTL/LTR per document dir */
#sidebar { position: fixed; top: 44px; bottom: 0; right: 0; width: 208px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 20; backdrop-filter: blur(4px); }
#minimap { width: 192px; height: 192px; margin: 8px auto 4px; border: 1px solid var(--line); border-radius: 4px; image-rendering: pixelated; cursor: pointer; background: #000; }
#tabs { display: flex; gap: 4px; padding: 6px 8px; }
#tabs .tab { flex: 1; padding: 6px 2px; background: #1b2530; color: var(--dim); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 12.5px; font-weight: 700; }
#tabs .tab.on { background: #24405a; color: var(--ink); border-color: #3d6389; }
/* build list: Red Alert-style cameo grid (2 columns of icon tiles) */
#buildList { flex: 1; overflow-y: auto; padding: 4px 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-content: start; }
#buildList::-webkit-scrollbar { width: 6px; }
#buildList::-webkit-scrollbar-thumb { background: #2a3644; border-radius: 3px; }
.bItem { position: relative; overflow: hidden; display: block; padding: 0; height: 74px;
  background: linear-gradient(160deg, #223245, #131c28 70%); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-family: inherit; }
.bItem:hover { border-color: #4d7cab; box-shadow: 0 0 0 1px #4d7cab inset; }
.bItem:active { transform: translateY(1px); }
.bItem.cantAfford { filter: grayscale(.8) brightness(.6); }
.bItem .bIcon { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 3px 3px 15px; box-sizing: border-box; pointer-events: none; image-rendering: auto; }
.bItem .bCost { position: absolute; top: 2px; inset-inline-end: 4px; color: var(--gold); font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; z-index: 2; }
.bItem .bCost::before { content: '$'; opacity: .8; margin-inline-end: 1px; }
.bItem .bCount { position: absolute; top: 2px; inset-inline-start: 4px; color: var(--green); font-size: 11px; font-weight: 800; text-shadow: 0 1px 2px #000; z-index: 2; }
.bItem .bName { position: absolute; inset-inline: 0; bottom: 0; text-align: center; font-size: 10.5px; font-weight: 700; line-height: 1.3; padding: 1px 2px 2px; background: rgba(5,9,14,.78); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 1; }
.bItem .prog { position: absolute; inset-inline: 0; bottom: 0; height: 0%; background: linear-gradient(180deg, rgba(46,255,158,.05), rgba(46,255,158,.28)); border-top: 1px solid rgba(46,255,158,.6); pointer-events: none; z-index: 1; }
.bItem .readyTag { display: none; position: absolute; inset-inline: 0; bottom: 0; text-align: center; font-size: 10px; font-weight: 800; color: #0a1a10; background: rgba(46,255,158,.92); padding: 2px; animation: blink 1.2s infinite; z-index: 3; }
.bItem .lockTag { display: none; position: absolute; top: 2px; inset-inline-start: 4px; font-size: 13px; z-index: 3; filter: drop-shadow(0 1px 2px #000); }
.bItem.locked { filter: grayscale(1) brightness(.5); }
.bItem.locked .lockTag { display: block; }
.bItem.locked .bCount { display: none; }

/* superweapon button */
#superBtn, #powerBtns button { display: block; width: calc(100% - 16px); margin: 4px 8px 0; padding: 7px 6px; font-family: inherit; font-size: 12px; font-weight: 800;
  background: #241626; color: #e0b8ff; border: 1px solid #5a3a6a; border-radius: 8px; cursor: default; }
#powerBtns button { background: #16211c; color: #9fe8c8; border-color: #2e5a48; }
#superBtn.superReady, #powerBtns button.superReady { background: #3a1420; color: #ffd24a; border-color: #f2c05a; cursor: pointer; animation: blink 1s infinite; }
#superBtn.superReady:hover, #powerBtns button.superReady:hover { filter: brightness(1.25); }
#alerts { padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; max-height: 130px; overflow: hidden; }
.alert { background: #24160f; border: 1px solid #4a2a1a; color: #ffb08a; font-size: 12px; padding: 5px 8px; border-radius: 6px; }

/* selection box */
#selbox { position: fixed; border: 1px solid var(--green); background: rgba(46,255,158,.08); display: none; pointer-events: none; z-index: 15; }

/* placement hint */
#placeHint { display: none; position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(50%); background: var(--panel); border: 1px solid var(--line); padding: 8px 16px; border-radius: 8px; color: var(--gold); font-size: 13px; z-index: 25; }
html[dir="ltr"] #placeHint { transform: translateX(-50%); }

/* end overlay */
#endOverlay { display: none; position: fixed; inset: 0; background: rgba(4,6,10,.7); z-index: 50; align-items: center; justify-content: center; }
.endBox { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 34px 60px; text-align: center; display: flex; flex-direction: column; gap: 18px; }
.endTitle { font-size: 34px; font-weight: 800; }
.endStats { display: flex; gap: 26px; justify-content: center; }
.endStats div { display: flex; flex-direction: column; gap: 2px; }
.endStats b { font-size: 22px; color: var(--ink); }
.endStats span { font-size: 11.5px; color: var(--dim); }
.endBox button { padding: 10px 26px; font-family: inherit; font-size: 15px; font-weight: 700; background: #24405a; color: var(--ink); border: 1px solid #3d6389; border-radius: 8px; cursor: pointer; }

/* profiler */
#profiler { position: fixed; top: 48px; inset-inline-start: 8px; background: rgba(0,0,0,.6); color: #9fe8ff; font: 11px monospace; padding: 4px 8px; border-radius: 4px; z-index: 40; direction: ltr; }

/* ---------- touch / mobile ---------- */
/* physically LEFT (over the battlefield) in both languages — the sidebar owns the right */
#touchBar { position: fixed; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: calc(12px + env(safe-area-inset-left, 0px)); display: flex; flex-direction: row; gap: 8px; z-index: 30; direction: ltr; }
#touchBar button { display: none; min-width: 54px; height: 54px; padding: 0 10px; border-radius: 14px; font-family: inherit; font-size: 24px; line-height: 1;
  background: rgba(13,20,29,.88); border: 1px solid #3b4b5e; color: var(--ink); backdrop-filter: blur(4px); }
#touchBar button:active { transform: scale(.94); }
#touchBar button.on { border-color: #f2c05a; color: #f2c05a; background: rgba(60,44,12,.9); }
#touchBar button.confirm { background: rgba(18,58,32,.92); border-color: #2eff9e; color: #2eff9e; font-size: 17px; font-weight: 800; }
#touchBar button.wide { min-width: 92px; }

#sideToggle { display: none; position: fixed; top: 50%; right: 208px; transform: translateY(-50%); z-index: 26;
  width: 26px; height: 74px; border-radius: 10px 0 0 10px; border: 1px solid var(--line); border-right: none;
  background: var(--panel); color: var(--dim); font-size: 13px; transition: right .25s; }
body.touch #sideToggle { display: block; }
body.sideHidden #sidebar { transform: translateX(103%); }
#sidebar { transition: transform .25s; }
body.sideHidden #sideToggle { right: 0; }

#rotateHint { display: none; position: fixed; inset-inline: 0; top: 46px; z-index: 60; text-align: center;
  background: rgba(20,28,38,.94); color: var(--gold); font-size: 14px; font-weight: 700; padding: 10px 16px;
  border-bottom: 1px solid var(--line); pointer-events: none; }

@media (pointer: coarse), (max-width: 920px) {
  :root { font-size: 13px; }
  #topbar { height: 40px; gap: 10px; padding: 0 8px; }
  #topbar .brand { display: none; }
  #topbar .pbar { width: 90px; }
  /* the whole sidebar scrolls; the minimap must never squash onto the build list */
  #sidebar { top: 40px; width: 186px; overflow-y: auto; }
  #sidebar > * { flex-shrink: 0; }
  #buildList { flex: 1 0 auto; min-height: 150px; overflow-y: visible; }
  #sideToggle { right: 186px; }
  #minimap { width: 170px; height: 170px; margin: 6px auto 2px; }
  #tabs { padding: 4px 6px; gap: 3px; }
  #tabs .tab { font-size: 11px; padding: 7px 1px; }
  .bItem { height: 68px; }
  .bItem .bName { font-size: 10px; }
  #alerts { max-height: 90px; }
  #placeHint { display: none !important; } /* the ✓ button replaces it */
  #profiler { display: none; }
}
@media (pointer: coarse) and (orientation: portrait) {
  #rotateHint { display: block; }
}
/* very short screens (landscape phones): shrink the radar so build buttons keep room */
@media (max-height: 520px) {
  #minimap { width: 128px; height: 128px; margin: 4px auto 2px; }
  #superBtn, #powerBtns button { padding: 5px 4px; font-size: 11px; }
  #alerts { max-height: 56px; }
}

/* ---------- main menu ---------- */
#menu { position: fixed; inset: 0; z-index: 90; overflow: hidden; background: #0b0f14; opacity: 1; transition: opacity .4s; }
#menu.mGo { opacity: 0; }
#menuBg, #menuBgImg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#menuInner { position: relative; z-index: 2; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; }
.mTitle { font-size: clamp(44px, 7vw, 84px); font-weight: 800; letter-spacing: 1px; line-height: 1.15;
  background: linear-gradient(175deg, #fff3c4 8%, #ffd24a 38%, #b8860b 62%, #ffe9a0 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.55)) drop-shadow(0 10px 24px rgba(0,0,0,.5));
  animation: titleIn .9s cubic-bezier(.2,.9,.25,1) both; }
.mSub { color: #e8d9b8; letter-spacing: 6px; font-size: clamp(11px, 1.4vw, 15px); text-transform: uppercase; opacity: .85; margin-top: -4px; text-shadow: 0 2px 6px #000; animation: titleIn 1.1s .1s cubic-bezier(.2,.9,.25,1) both; }
@keyframes titleIn { from { opacity: 0; transform: translateY(-18px) scale(.96); } to { opacity: 1; transform: none; } }
.mPanel { margin-top: 26px; display: flex; flex-direction: column; gap: 10px; width: min(340px, 86vw);
  background: rgba(10,14,20,.72); border: 1px solid #3b4b5e; border-radius: 14px; padding: 18px 20px 20px;
  backdrop-filter: blur(6px); box-shadow: 0 18px 50px rgba(0,0,0,.55); animation: titleIn .9s .2s cubic-bezier(.2,.9,.25,1) both; }
.mDiffLabel { color: var(--dim); font-size: 12.5px; text-align: center; }
.mFac { display: flex; gap: 8px; }
.mFac button { flex: 1; padding: 10px 6px; font-family: inherit; background: #1b2530; color: var(--dim); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; align-items: center; }
.mFac button b { font-size: 15px; font-weight: 800; color: var(--ink); }
.mFac button small { font-size: 10.5px; }
.mFac button.on { background: #2c2416; border-color: #f2c05a; }
.mFac button.on b { color: var(--gold); }
.mDiff { display: flex; gap: 6px; }
.mDiff button { flex: 1; padding: 8px 2px; font-family: inherit; font-size: 13.5px; font-weight: 700; background: #1b2530; color: var(--dim); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.mDiff button.on { background: #24405a; color: var(--ink); border-color: #4d7cab; }
.mBtn { padding: 12px; font-family: inherit; font-size: 16.5px; font-weight: 800; border-radius: 10px; cursor: pointer;
  background: linear-gradient(180deg, #e9b93f, #a8781f); border: 1px solid #f2c05a; color: #1a1206; }
.mBtn:hover { filter: brightness(1.1); }
.mBtn.sec { background: #1b2530; border: 1px solid var(--line); color: var(--ink); font-size: 14px; font-weight: 700; padding: 10px; }
.mBtn.sec:hover { border-color: #4d7cab; filter: none; }
.mFoot { position: absolute; bottom: 14px; color: rgba(232,238,245,.55); font-size: 12px; text-shadow: 0 1px 3px #000; }
.mHelpBack { display: none; position: fixed; inset: 0; z-index: 95; background: rgba(3,5,8,.72); align-items: center; justify-content: center; padding: 20px; }
.mHelp { width: min(560px, 92vw); max-height: 84vh; overflow-y: auto; background: #121a24; border: 1px solid #3b4b5e; border-radius: 14px; padding: 20px 24px; display: flex; flex-direction: column; gap: 12px; }
.mHelp h3 { color: var(--gold); font-size: 15px; margin-top: 6px; }
.mHelp p, .mHelp li { color: #cfdbe8; font-size: 13.5px; line-height: 1.8; }
.mHelp ul { padding-inline-start: 18px; }
.mHelp b { color: var(--ink); }
