/* เถ้าแก่ไทคูน — mobile-first, ไม่มี dependency */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0f1420; --panel: #1a2233; --panel2: #212b42; --line: #2c3852;
  --text: #e8edf7; --muted: #8b97b0; --accent: #ffb020; --accent2: #4f8dff;
  --good: #3ecf72; --bad: #ff5d6c; --gold: #ffcf4d;
}
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'Segoe UI', 'Sukhumvit Set', 'Noto Sans Thai', system-ui, sans-serif;
  font-size: 15px; line-height: 1.45; min-height: 100vh;
}
.hidden { display: none !important; }
.w-full { width: 100%; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input {
  font: inherit; width: 100%; padding: 11px 14px; margin-bottom: 10px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
}
input:focus { outline: 2px solid var(--accent2); border-color: transparent; }

.btn { display: inline-block; padding: 10px 16px; border-radius: 10px; font-weight: 600; transition: opacity .15s; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent2); color: #fff; }
.btn.gold { background: linear-gradient(135deg, #f8b500, #ffcf4d); color: #4a3000; }
.btn.ghost { border: 1px solid var(--line); color: var(--muted); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn.link { color: var(--accent2); padding: 8px; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

/* ── auth ── */
.auth-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.auth-box h1 { font-size: 26px; margin-bottom: 6px; text-align: center; }
.tagline { color: var(--muted); text-align: center; margin-bottom: 20px; font-size: 14px; }
.note { color: var(--muted); font-size: 12px; text-align: center; margin-top: 14px; }
.error-msg { background: rgba(255,93,108,.12); border: 1px solid var(--bad); color: var(--bad); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }

/* ── layout เกม ── */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.co span { font-weight: 700; }
.co small { display: block; color: var(--muted); font-size: 12px; }
.co small b { color: var(--accent); }
.gold-pill {
  display: flex; align-items: center; gap: 5px; padding: 7px 12px; border-radius: 999px;
  background: linear-gradient(135deg, #3a2d00, #574400); border: 1px solid #8a6d00; color: var(--gold); font-weight: 700;
}
.gold-pill .plus { background: var(--gold); color: #4a3000; border-radius: 50%; width: 18px; height: 18px; line-height: 18px; text-align: center; font-size: 14px; }

.resbar {
  position: sticky; top: 53px; z-index: 19; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--panel); border-bottom: 1px solid var(--line); padding: 6px 8px; gap: 4px;
}
.res { text-align: center; font-size: 13px; }
.res .ic { font-size: 14px; }
.res b { display: block; font-size: 14px; }
.res small { color: var(--muted); font-size: 10.5px; display: block; }
.res.full b { color: var(--bad); }

main { padding: 14px 14px 84px; max-width: 760px; margin: 0 auto; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex;
  background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { flex: 1; padding: 8px 0 9px; font-size: 20px; color: var(--muted); position: relative; }
.tabbar button span { display: block; font-size: 11px; margin-top: 1px; }
.tabbar button.active { color: var(--accent); }
.dot { position: absolute; top: 4px; margin-left: 2px; width: 8px; height: 8px; background: var(--bad); border-radius: 50%; display: inline-block; }

/* ── การ์ด/section ── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h3 { font-size: 15px; margin-bottom: 10px; }
.section-title { font-size: 13px; color: var(--muted); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .4px; }

/* ── คิวก่อสร้าง ── */
.queue-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.queue-item:last-child { border-bottom: 0; padding-bottom: 0; }
.queue-item .info { flex: 1; }
.queue-item .info b { font-size: 14px; }
.queue-item .timer { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
.progress { height: 5px; background: var(--panel2); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.progress i { display: block; height: 100%; background: var(--accent2); border-radius: 3px; transition: width 1s linear; }

/* ── ตารางอาคาร ── */
.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 10px; }
.bcard { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.bcard .head { display: flex; align-items: center; gap: 8px; }
.bcard .head .icon { font-size: 26px; }
.bcard .head b { font-size: 13.5px; display: block; }
.bcard .head small { color: var(--muted); font-size: 11.5px; }
.bcard .prod { font-size: 12px; color: var(--good); min-height: 16px; }
.bcard .btn { margin-top: auto; font-size: 12.5px; padding: 8px; }
.bcard.locked { opacity: .55; }
.cost { font-size: 12px; color: var(--muted); }
.cost .no { color: var(--bad); }

/* ── modal ── */
#modal-root .overlay { position: fixed; inset: 0; background: rgba(5,8,15,.7); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
#modal-root .modal {
  width: 100%; max-width: 480px; max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 18px;
}
@media (min-width: 520px) { #modal-root .overlay { align-items: center; } #modal-root .modal { border-radius: 18px; } }
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.modal .row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.modal .actions { display: flex; gap: 10px; margin-top: 16px; }
.modal .actions .btn { flex: 1; text-align: center; }

/* ── ตลาด/โรงงาน ── */
.prow { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px dashed var(--line); }
.prow:last-child { border-bottom: 0; }
.prow .icon { font-size: 26px; }
.prow .info { flex: 1; min-width: 0; }
.prow .info b { font-size: 14px; }
.prow .info small { display: block; color: var(--muted); font-size: 12px; }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.pill.up { color: var(--good); } .pill.down { color: var(--bad); }
.qty-line { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.qty-line input { margin: 0; flex: 1; }

/* ── quests ── */
.quest { padding: 11px 0; border-bottom: 1px dashed var(--line); }
.quest:last-child { border-bottom: 0; }
.quest .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.quest b { font-size: 14px; }
.quest small { color: var(--muted); }
.tutorial-card { border: 1px solid var(--accent); background: linear-gradient(160deg, #2a2410, var(--panel)); }

/* ── leaderboard ── */
.lb-row { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.lb-row .rank { width: 34px; text-align: center; font-weight: 700; color: var(--muted); }
.lb-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .val { font-variant-numeric: tabular-nums; }
.lb-row.me { background: rgba(79,141,255,.12); border-radius: 8px; }
.lb-row .mv { font-size: 11px; width: 30px; text-align: right; }
.mv.up { color: var(--good); } .mv.down { color: var(--bad); }

/* ── gold store ── */
.pkg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pkg { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: center; position: relative; }
.pkg .amt { font-size: 20px; font-weight: 800; color: var(--gold); }
.pkg .price { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.pkg .badge { position: absolute; top: -8px; right: 8px; background: var(--bad); color: #fff; font-size: 10.5px; padding: 2px 8px; border-radius: 999px; }
.bonus-banner { background: linear-gradient(135deg, #3a2d00, #574400); border: 1px solid #8a6d00; color: var(--gold); padding: 10px 14px; border-radius: 12px; text-align: center; font-weight: 700; margin-bottom: 12px; }

/* ── toast ── */
#toast-root { position: fixed; top: 14px; left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 18px;
  font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.45); animation: pop .2s ease-out;
}
.toast.err { border-color: var(--bad); color: var(--bad); }
.toast.ok { border-color: var(--good); }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 12px; }
