:root {
  --bg: var(--tg-theme-bg-color, #15171c);
  --bg2: var(--tg-theme-secondary-bg-color, #1e2128);
  --text: var(--tg-theme-text-color, #eceef2);
  --hint: var(--tg-theme-hint-color, #8b919e);
  --accent: var(--tg-theme-button-color, #d29b3a);
  --accent-text: var(--tg-theme-button-text-color, #1a1306);
  --danger: #e0574f;
  --ok: #4caf7a;
  --line: rgba(127, 127, 127, 0.18);
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 14px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
h2 { font-size: 18px; margin: 0 0 8px; }
p { margin: 6px 0; }

.loading { display: grid; place-items: center; height: 100vh; color: var(--hint); }
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.content { flex: 1; overflow-y: auto; padding: 10px 10px 16px; }
.muted { color: var(--hint); font-weight: normal; }
.small { font-size: 12px; }
.tiny { font-size: 11px; margin-top: 10px; }
.warn { color: var(--danger); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.label { margin: 14px 0 6px; font-weight: 600; font-size: 13px; }
.section-title { font-weight: 600; margin-bottom: 6px; display: flex; justify-content: space-between; }

/* Resources */
.resources { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px 10px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.res-top { display: flex; align-items: center; gap: 4px; font-weight: 700; font-variant-numeric: tabular-nums; }
.res-icon { font-size: 15px; }
.res-bar { height: 3px; background: var(--line); border-radius: 2px; margin: 4px 0 3px; overflow: hidden; }
.res-fill { height: 100%; background: var(--accent); transition: width 0.4s; }
.res.full .res-fill { background: var(--danger); }
.res.full .res-amount { color: var(--danger); }
.res-sub { font-size: 10.5px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.speed-badge { text-align: center; font-size: 12px; background: var(--accent); color: var(--accent-text); padding: 2px; }

/* Queue */
.queue { background: var(--bg2); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.queue-empty { color: var(--hint); font-size: 13px; }
.job { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.job:first-of-type { border-top: none; }
.job-icon { font-size: 20px; }
.job-body { flex: 1; min-width: 0; }
.job-name { font-size: 13px; }
.job-progress { height: 4px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.job-fill { height: 100%; background: var(--ok); }
.job-time { font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; text-align: right; }
.job:not(.running) { opacity: 0.65; }

/* City grid */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { position: relative; aspect-ratio: 1; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px; cursor: pointer; }
.tile:active { transform: scale(0.96); }
.tile.empty { border-style: dashed; background: transparent; }
.tile-plus { font-size: 26px; color: var(--hint); }
.tile-icon { font-size: 26px; }
.tile-name { font-size: 10.5px; text-align: center; line-height: 1.1; color: var(--hint); }
.tile-level { position: absolute; top: 4px; right: 6px; font-size: 11px; font-weight: 700; }
.tile-badge { position: absolute; top: 3px; left: 4px; font-size: 13px; }
.tile.busy { border-color: var(--ok); }
.tile.kind-wood { background: rgba(76, 140, 74, 0.16); }
.tile.kind-stone { background: rgba(150, 140, 120, 0.16); }
.tile.kind-iron { background: rgba(110, 120, 150, 0.18); }
.tile.kind-food { background: rgba(214, 178, 72, 0.16); }
.tile.empty.kind-wood, .tile.empty.kind-stone, .tile.empty.kind-iron, .tile.empty.kind-food { border-style: dashed; }
.tile-icon.terrain { opacity: 0.55; }

/* Bottom tabs */
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); background: var(--bg2); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { background: none; border: none; padding: 7px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 1px; color: var(--hint); cursor: pointer; }
.tab.active { color: var(--accent); }
.tab:disabled { opacity: 0.4; cursor: default; }
.tab-icon { font-size: 19px; }
.tab-label { font-size: 10.5px; }

/* Buttons */
.btn { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.wide { width: 100%; margin-top: 10px; padding: 11px; }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; z-index: 10; animation: fade 0.15s; }
.sheet { position: relative; width: 100%; max-height: 82vh; overflow-y: auto; background: var(--bg); border-radius: 16px 16px 0 0; padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); animation: up 0.18s ease-out; }
.sheet-close { position: absolute; top: 10px; right: 10px; background: var(--bg2); border: none; border-radius: 50%; width: 30px; height: 30px; cursor: pointer; }
@keyframes up { from { transform: translateY(30px); opacity: 0.5; } }
@keyframes fade { from { opacity: 0; } }

.options { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.option { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--bg2); border-radius: var(--radius); }
.option.locked { opacity: 0.55; }
.option-icon { font-size: 26px; }
.option-body { flex: 1; min-width: 0; }
.option-name { font-weight: 600; }
.option-effect { font-size: 12px; color: var(--hint); }
.cost { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12.5px; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.cost .lack { color: var(--danger); }
.effect-row { margin: 4px 0; }
.upgrade { background: var(--bg2); border-radius: var(--radius); padding: 10px; margin: 10px 0; }
.upgrade .btn { margin-top: 8px; width: 100%; }
.demolish { margin-top: 12px; }

/* Market */
.panel { background: var(--bg2); border-radius: var(--radius); padding: 14px; }
.res-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; text-align: left; }
.chip.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.slider { width: 100%; accent-color: var(--accent); }
.exchange-preview { font-size: 18px; font-weight: 700; margin-top: 12px; text-align: center; }
.paid { margin-top: 16px; padding: 10px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); padding: 9px 14px; border-radius: 10px; font-size: 13px; z-index: 20; max-width: 90%; text-align: center; animation: fade 0.15s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
