/* ==========================================================
   style.css  ·  ظاهر بازی
   چیدمان: نوار بالا (پول، روز، سرعت) / نقشه / نوار پایین؛ پنل‌ها روی نقشه باز می‌شوند.
   ========================================================== */
:root {
  --ink: #17233d;
  --ink2: #223158;
  --ink3: #33466f;
  --paper: #eef2f8;
  --card: #ffffff;
  --line: #d6deea;
  --mute: #55627e;
  --gold: #f2b134;
  --gold-d: #b97f00;
  --teal: #12776c;
  --good: #11784a;
  --bad: #c0392b;
  --warn: #9c6100;
  --grass: #7fb867;
  --on-ink: #ffffff;
  --on-ink-mute: #aebbd8;
  --font: 'Vazirmatn', Tahoma, 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ink); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.6;
  overflow: hidden; -webkit-tap-highlight-color: transparent;
}
button, input { font-family: inherit; }
*, *::before, *::after { box-sizing: border-box; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
small { font-size: 12px; }
h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

#app { height: 100%; display: flex; flex-direction: column; position: relative; overflow: hidden; }

/* ---------- نوار بالا ---------- */
#hud {
  background: var(--ink); color: var(--on-ink); display: flex; flex-direction: column; gap: 8px;
  padding-block: 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  z-index: 5;
}
.hud-row { display: flex; gap: 8px; align-items: stretch; }
.icon-btn {
  width: 48px; min-height: 48px; flex: none; border: 0; border-radius: 14px; background: var(--ink2); color: var(--on-ink);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn.sm { width: 44px; min-height: 44px; border-radius: 12px; background: rgba(23, 35, 61, .9); box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }
.chip {
  display: flex; align-items: center; gap: 10px; background: var(--ink2); color: var(--on-ink); border-radius: 14px; padding: 4px 12px; min-height: 48px; min-width: 0;
}
#chip-cash { flex: 1; }
.chip .ci { color: var(--gold); display: inline-flex; }
.chip > span:last-child { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.lbl { font-size: 12px; color: var(--mute); display: block; }
.chip .lbl { color: var(--on-ink-mute); }
.val { font-weight: 800; font-size: 15px; white-space: nowrap; }
.val small { font-weight: 500; color: var(--on-ink-mute); }
.val.neg { color: #ff9a8b; }
.chip-sm { background: rgba(23, 35, 61, .92); min-height: 44px; flex-direction: column; align-items: flex-start; gap: 0; padding: 4px 14px; justify-content: center; }
.chip-sm .lbl { color: var(--on-ink-mute); line-height: 1.3; }

.hud-2 { align-items: center; }
#factory-info { flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr; gap: 1px; font-size: 12px; }
.fname { font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flevel { color: var(--gold); font-weight: 700; }
.fnext { color: var(--on-ink-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#speed { display: flex; gap: 4px; flex: none; }
#speed button {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 12px; background: var(--ink2); color: var(--on-ink); padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 3px; font-weight: 700; font-size: 12px; cursor: pointer;
}
#speed button[aria-pressed="true"] { background: var(--gold); color: var(--ink); }

/* ---------- نقشه ---------- */
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--grass); }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#checklist {
  position: absolute; top: 10px; right: 12px; width: min(268px, calc(100% - 84px)); background: rgba(255, 255, 255, .96); border-radius: 16px;
  padding: 10px 12px; box-shadow: 0 3px 0 rgba(10, 16, 48, .22); z-index: 4;
}
.cl-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 13px; }
.cl-toggle { min-height: 36px; border: 0; background: none; color: var(--mute); font-size: 13px; display: inline-flex; align-items: center; gap: 2px; cursor: pointer; padding: 0 4px; }
.cl-next { margin-top: 4px; }
.cl-next .cl-item { font-weight: 700; }
#checklist ul { margin-top: 8px; display: grid; gap: 2px; }
.cl-item {
  width: 100%; min-height: 40px; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0 4px; border-radius: 10px;
  font-size: 13px; color: var(--ink); text-align: right; cursor: pointer;
}
.cl-item:hover { background: var(--paper); }
.cl-item.done { color: var(--mute); text-decoration: line-through; cursor: default; }
.cl-box { width: 22px; height: 22px; flex: none; border-radius: 7px; border: 2px solid var(--ink3); display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.cl-item.done .cl-box { background: var(--good); border-color: var(--good); }
#zoomctl { position: absolute; top: 10px; left: 12px; display: grid; gap: 6px; z-index: 4; }
#floatbar { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; z-index: 4; }
#actionbar {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 6; background: #fff; border-radius: 18px; padding: 10px 12px;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 0 rgba(10, 16, 48, .25);
}
.ab-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.5; }
.ab-text span { font-size: 12px; color: var(--mute); }
.warnt { color: var(--warn) !important; }

/* ---------- نوار پایین ---------- */
#nav {
  background: var(--ink); display: flex; gap: 2px; padding-block: 6px 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); border-radius: 20px 20px 0 0; z-index: 5;
}
#nav button {
  flex: 1; min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: none;
  color: var(--on-ink); font-size: 12px; font-weight: 500; border-radius: 12px; cursor: pointer; padding: 0 2px;
}
#nav button[aria-pressed="true"] { background: var(--ink2); color: var(--gold); }

/* ---------- کشوی پنل‌ها ---------- */
#sheet { position: absolute; z-index: 8; background: var(--paper); display: flex; flex-direction: column; box-shadow: 0 -4px 24px rgba(10, 16, 48, .35); left: 0; right: 0; bottom: 0; max-height: 74%; border-radius: 20px 20px 0 0; }
#sheet > header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; }
#sheet > header h2 { font-size: 18px; font-weight: 800; }
#sheet-body { overflow-y: auto; padding: 4px 16px 20px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
@media (min-width: 860px) {
  /* روی صفحه بزرگ، نوار بالا یک ردیف می‌شود */
  #hud { flex-direction: row; align-items: center; gap: 10px; }
  .hud-row { display: contents; }
  #chip-cash { flex: 0 0 auto; min-width: 210px; }
  #factory-info { flex: 1; max-width: 420px; margin-inline: 8px; }
  #speed { margin-inline-start: auto; }
  #sheet { top: 12px; bottom: 12px; left: 12px; right: auto; width: 420px; max-height: none; border-radius: 20px; box-shadow: 0 6px 28px rgba(10, 16, 48, .4); }
  #zoomctl { left: auto; right: 12px; top: auto; bottom: 76px; }
  #checklist { right: 12px; top: 10px; }
}

/* ---------- اجزای مشترک ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.card h3, .sec { font-size: 14px; font-weight: 800; }
.sec { margin-top: 6px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-width: 0; }
.row > span:first-child { min-width: 0; }
.row.sm { font-size: 12px; color: var(--mute); }
.row.sm b { color: inherit; }
.row.total { border-top: 1px solid var(--line); padding-top: 6px; font-weight: 800; }
.row.th { color: var(--mute); font-size: 12px; }
.r-end { display: flex; align-items: center; gap: 8px; flex: none; }
.tbl { display: flex; flex-direction: column; gap: 6px; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.hint { font-size: 12px; color: var(--mute); }
.empty { color: var(--mute); text-align: center; padding: 12px 4px; font-size: 13px; }
.meta { font-size: 12px; color: var(--mute); }
.lbl + b, .st-mid b { display: block; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 > div { min-width: 0; display: flex; flex-direction: column; }
.grid2 small { color: var(--mute); }
.dots { color: var(--gold-d); letter-spacing: 1px; font-size: 11px; }
.dots .off { color: var(--line); }
.tr { display: inline-flex; align-items: center; font-size: 12px; font-weight: 700; }
.tr.good { color: var(--good); } .tr.bad { color: var(--bad); } .tr.flat { color: var(--mute); }
.chip-e { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-inline-end: 4px; }
.chip-e.good { background: #d9f1e4; color: var(--good); } .chip-e.bad { background: #fadfda; color: var(--bad); }
.pill { font-size: 12px; font-weight: 700; padding: 1px 10px; border-radius: 999px; background: #e3e9f3; color: var(--ink); }
.pill.good { background: #d9f1e4; color: var(--good); } .pill.warn { background: #fbecc8; color: var(--warn); } .pill.bad { background: #fadfda; color: var(--bad); }
.lockt { display: inline-flex; align-items: center; gap: 4px; }
.bar { height: 8px; border-radius: 4px; background: #dfe6f1; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ink3); border-radius: 4px; }
.bar.gold i { background: var(--gold); } .bar.teal i { background: var(--teal); } .bar.warn i { background: #d98b00; } .bar.bad i { background: var(--bad); }
#factory-info .bar { background: rgba(255, 255, 255, .18); height: 6px; margin: 2px 0; }
.spark { flex: none; }
.netbars { width: 100%; height: auto; display: block; }

.btn {
  min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 700; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 var(--gold-d); }
.btn.ghost { background: #e1e8f3; color: var(--ink); }
.btn.danger { background: var(--bad); }
.btn.sq { width: 44px; padding: 0; flex: none; }
.btn.tiny { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.big { min-height: 52px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--paper); border-radius: 12px; padding: 6px; }
.stepper.sm { background: none; padding: 0; }
.st-mid { flex: 1; text-align: center; display: flex; flex-direction: column; line-height: 1.4; }
.st-mid small { color: var(--mute); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #dfe6f1; border-radius: 12px; padding: 4px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: none; color: var(--ink); font-weight: 700; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button[aria-disabled="true"] { color: var(--mute); }
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; border: 0; background: none; padding: 0; font-size: 13px; color: var(--ink); text-align: right; cursor: pointer; }
.knob { width: 44px; height: 26px; flex: none; border-radius: 13px; background: #aab6cc; position: relative; transition: background .15s; }
.knob::after { content: ""; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch[aria-checked="true"] .knob { background: var(--teal); }
.switch[aria-checked="true"] .knob::after { transform: translateX(-18px); }
.switch[aria-disabled="true"] { color: var(--mute); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: #dfe6f1; border-radius: 12px; padding: 4px; }
.tabs button { min-height: 40px; border: 0; border-radius: 9px; background: none; color: var(--ink); font-weight: 700; font-size: 13px; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
.eff { display: flex; flex-direction: column; gap: 2px; font-size: 13px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.eff:last-child { border-bottom: 0; padding-bottom: 0; }
.eff small { color: var(--mute); }
.news-i { display: flex; flex-direction: column; font-size: 13px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.news-i:last-child { border-bottom: 0; }
.news-i small { color: var(--mute); }
.lv { display: flex; gap: 10px; align-items: flex-start; color: var(--mute); }
.lv small { display: block; }
.lv-ic { width: 26px; height: 26px; flex: none; border-radius: 50%; background: #e3e9f3; display: inline-flex; align-items: center; justify-content: center; }
.lv.on { color: var(--ink); } .lv.on .lv-ic { background: var(--good); color: #fff; }
.worker .meta, .cand .meta { margin-top: -4px; }
.build-i { flex-direction: row; align-items: center; gap: 10px; }
.thumb { width: 84px; height: 72px; flex: none; border-radius: 12px; background: #cfe3c3; display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.bi-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bi-txt small { color: var(--mute); }
.bi-txt .price { font-weight: 800; }

/* ---------- پنجره‌ها ---------- */
#modal { position: absolute; inset: 0; z-index: 60; background: rgba(10, 16, 40, .68); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal-card { width: min(460px, 100%); max-height: 100%; overflow-y: auto; background: #fff; color: var(--ink); border-radius: 22px; padding: 18px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, .4); }
.m-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.m-head h2 { font-size: 20px; font-weight: 800; line-height: 1.4; }
.m-head p { color: var(--mute); font-size: 13px; }
.m-head.day, .m-head.night { padding: 12px; border-radius: 14px; justify-content: flex-start; color: #fff; }
.m-head.day { background: var(--ink3); } .m-head.night { background: var(--ink); }
.m-head.day p, .m-head.night p { color: var(--on-ink-mute); }
.m-head .ci { color: var(--gold); display: inline-flex; }
label { font-weight: 700; font-size: 13px; }
.inp { width: 100%; min-height: 48px; border: 2px solid var(--line); border-radius: 12px; padding: 0 14px; font-size: 16px; color: var(--ink); background: #fff; margin-top: 4px; }
.inp:focus { border-color: var(--ink3); outline: 3px solid rgba(242, 177, 52, .5); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
legend { font-weight: 700; font-size: 13px; padding: 0; margin-bottom: 6px; float: right; width: 100%; }
.prods { grid-template-columns: 1fr 1fr; } .prods legend { grid-column: 1 / -1; }
.prod { position: relative; display: block; cursor: pointer; font-weight: 400; }
.prod input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.pc { display: flex; flex-direction: column; border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; min-height: 72px; }
.pc small { color: var(--mute); line-height: 1.4; }
.prod input:checked + .pc { border-color: var(--ink); background: #fff7e0; box-shadow: 0 0 0 2px var(--gold); }
.prod input:focus-visible + .pc { outline: 3px solid var(--gold); outline-offset: 2px; }
.news-big { background: var(--paper); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.news-big small { color: var(--mute); display: inline-flex; align-items: center; gap: 4px; }
.news-big b { font-size: 17px; line-height: 1.5; }
.news-big p { color: var(--ink2); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.bigline { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 14px; border-radius: 14px; background: var(--paper); font-size: 14px; }
.bigline b { font-size: 20px; }
.bigline.good { background: #d9f1e4; } .bigline.bad { background: #fadfda; }
.events { display: flex; flex-direction: column; gap: 4px; font-size: 13px; background: #fbf3dc; border-radius: 12px; padding: 10px 12px; }
.events li::before { content: "• "; }
.banner { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; font-weight: 700; font-size: 13px; }
.banner.good { background: #d9f1e4; color: var(--good); } .banner.bad { background: #fadfda; color: var(--bad); }
.help { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink2); padding-inline-start: 18px; list-style: disc; }

/* ---------- پیام کوتاه ---------- */
#toasts { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 6px; align-items: center; width: calc(100% - 32px); max-width: 440px; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 12px; font-size: 13px; font-weight: 700; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); animation: tin .22s ease-out; border: 2px solid transparent; }
.toast.good { border-color: #2fb878; } .toast.bad { border-color: #ff7a66; }
.toast.out { opacity: 0; transition: opacity .35s; }
@keyframes tin { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } .knob, .knob::after { transition: none; } }
