:root {
  --ink: #2a160c;
  --ink-2: #3d2213;
  --sand: #e9c98f;
  --sand-2: #d9ad68;
  --gold: #f2c14e;
  --gold-2: #c98a1b;
  --teal: #1f8a8a;
  --cream: #fff4dc;
  --red: #c0392b;
  --ok: #2e9e5b;
  --panel: rgba(42, 22, 12, 0.92);
  --line: rgba(242, 193, 78, 0.35);
  --font: "Cairo", system-ui, sans-serif;
  --display: "Reem Kufi", "Cairo", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--ink);
  color: var(--cream);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- splash ---------- */
.splash {
  position: fixed; inset: 0;
  display: grid; place-items: end center;
  background: #1a0d06 url("assets/loading_wide.webp") center top / cover no-repeat;
}
@media (max-aspect-ratio: 3/4) {
  .splash { background-image: url("assets/loading_screen.webp"); }
}
.splash::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(20, 9, 4, 0.95) 0%, rgba(20, 9, 4, 0.55) 30%, transparent 60%);
}
.splash-inner {
  position: relative; z-index: 1;
  width: min(440px, 100% - 32px);
  padding-bottom: max(40px, env(safe-area-inset-bottom));
  text-align: center;
}
.logo {
  font-family: var(--display);
  font-size: clamp(48px, 12vw, 76px);
  margin: 0;
  color: var(--gold);
  text-shadow: 0 3px 0 #6b3d0a, 0 8px 24px rgba(0, 0, 0, 0.7);
}
.tagline { margin: 4px 0 22px; font-weight: 600; opacity: 0.9; }
.bar { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; width: 5%; background: linear-gradient(90deg, var(--gold-2), var(--gold)); transition: width 0.4s; }
.splash-status { font-size: 14px; opacity: 0.8; min-height: 1.5em; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 22px;
  font-weight: 800; font-size: 16px;
  transition: transform 0.1s, filter 0.2s;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn[disabled] { filter: grayscale(0.8) brightness(0.7); cursor: not-allowed; }
.btn-gold {
  background: linear-gradient(180deg, #ffd977, var(--gold-2));
  color: #3a1c04;
  box-shadow: 0 4px 0 #7a4a08, 0 8px 18px rgba(0, 0, 0, 0.4);
}
.btn-teal { background: linear-gradient(180deg, #33b3a8, #146a6a); box-shadow: 0 4px 0 #0b3f3f; color: #fff; }

/* ---------- HUD ---------- */
.game { position: fixed; inset: 0; }
.hud {
  position: absolute; inset: 0 0 auto 0; z-index: 5;
  display: flex; gap: 10px; align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(to bottom, rgba(26, 12, 5, 0.95), rgba(26, 12, 5, 0.6) 75%, transparent);
}
.profile {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 40px;
  padding: 3px 3px 3px 14px; flex-shrink: 0;
}
.avatar { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--gold); object-fit: cover; }
.profile-text { display: grid; text-align: start; line-height: 1.2; }
.player-name { font-weight: 800; font-size: 14px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.power { font-size: 12px; color: var(--gold); }
.resources { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; flex: 1; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; }
.res {
  display: flex; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 2px 10px 2px 4px; min-width: 0;
}
.res img { width: 28px; height: 28px; object-fit: contain; }
.res-val { display: grid; line-height: 1.1; }
.res-val b { font-size: 14px; font-variant-numeric: tabular-nums; }
.res-val small { font-size: 10px; opacity: 0.75; }
.res.full b { color: #ff9a7a; }

/* ---------- city ---------- */
.city-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; background: #3b2410; }
.city-viewport canvas { display: block; }

.pad-editor {
  position: fixed; z-index: 30; inset-inline-start: 10px; bottom: 80px; width: 280px;
  background: var(--panel); border: 1px solid var(--gold); border-radius: 12px; padding: 10px;
  display: grid; gap: 6px; font-size: 13px; user-select: text;
}
.pad-editor select, .pad-editor input, .pad-editor textarea { width: 100%; background: rgba(0,0,0,0.3); color: var(--cream); border: 1px solid var(--line); border-radius: 6px; padding: 4px; font: 12px monospace; direction: ltr; }

/* ---------- queue strip ---------- */
.queue-strip { position: absolute; z-index: 4; inset-inline-start: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 64px); display: grid; gap: 6px; }
.queue-item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; font-size: 13px; min-width: 190px; }
.queue-item b { color: var(--gold); }
.queue-item .bar { height: 6px; margin-top: 4px; }

/* ---------- tabs ---------- */
.tabs {
  position: absolute; inset: auto 0 0 0; z-index: 5;
  display: flex; justify-content: center; gap: 8px;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(26, 12, 5, 0.95), transparent);
}
.tab {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 22px; font-weight: 800; min-width: 96px;
}
.tab.active { background: linear-gradient(180deg, #ffd977, var(--gold-2)); color: #3a1c04; border-color: transparent; }

/* ---------- sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 10; display: grid; place-items: end center; background: rgba(10, 4, 0, 0.45); }
.sheet-card {
  position: relative; width: min(560px, 100%); max-height: 82vh; overflow-y: auto;
  background: linear-gradient(180deg, #4a2915, #2a160c);
  border: 1px solid var(--gold-2); border-bottom: 0; border-radius: 22px 22px 0 0;
  padding: 18px 18px max(18px, env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet-close { position: absolute; inset-inline-end: 12px; top: 8px; background: none; border: 0; font-size: 30px; line-height: 1; opacity: 0.7; }
.sheet h2 { font-family: var(--display); color: var(--gold); margin: 0 0 4px; font-size: 26px; }
.sheet .sub { margin: 0 0 14px; opacity: 0.85; font-size: 14px; }
.sheet-hero { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.sheet-hero img, .sheet-hero svg { width: 120px; flex-shrink: 0; filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.5)); }
.costs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; padding: 0; list-style: none; }
.cost { display: flex; align-items: center; gap: 4px; background: rgba(0, 0, 0, 0.25); border-radius: 10px; padding: 4px 10px 4px 6px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cost img { width: 24px; height: 24px; object-fit: contain; }
.cost.short { color: #ff8f73; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.note { font-size: 13px; color: #ffcf9a; margin: 6px 0; }

.units { display: grid; gap: 10px; }
.unit { background: rgba(0, 0, 0, 0.22); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.unit.locked { opacity: 0.55; }
.unit h3 { margin: 0; font-size: 17px; }
.unit .stats { font-size: 12px; opacity: 0.8; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper input { width: 70px; text-align: center; border-radius: 8px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); color: var(--cream); padding: 6px; font: inherit; font-weight: 700; }

.rank-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.rank-list li { display: flex; gap: 10px; align-items: center; background: rgba(0, 0, 0, 0.22); border-radius: 12px; padding: 8px 12px; }
.rank-list li.me { outline: 2px solid var(--gold); }
.rank-no { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--ink-2); font-weight: 800; color: var(--gold); }
.rank-name { flex: 1; font-weight: 700; }
.field { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); color: var(--cream); font: inherit; font-size: 16px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 20; left: 50%; top: 90px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--gold); border-radius: 12px;
  padding: 10px 18px; font-weight: 700; max-width: calc(100% - 32px); text-align: center;
  animation: rise 0.2s ease-out;
}
.toast.err { border-color: var(--red); }

@media (max-width: 640px) {
  .hud { flex-wrap: wrap; }
  .resources { order: 2; width: 100%; flex-basis: 100%; justify-content: space-between; }
  .res { padding-inline-end: 6px; }
  .res img { width: 22px; height: 22px; }
  .res-val b { font-size: 12px; }
  .queue-strip { top: calc(max(8px, env(safe-area-inset-top)) + 106px); }
  .tab { padding: 9px 14px; min-width: 0; flex: 1; }
}
