/* Mogul Row — UI styles */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --panel: rgba(20, 26, 48, 0.92);
  --panel-light: rgba(38, 46, 78, 0.95);
  --accent: #2f80ff;
  --gold: #ffd75e;
  --text: #eef1f8;
  --muted: #9aa3bf;
  --danger: #e05b5b;
  --warn: #e8a33d;
  --ok: #4fc06a;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,0.45);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background: #182246;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#view { position: fixed; inset: 0; display: block; touch-action: none; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-light);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: transparent; font-weight: 600; }
button.danger { background: var(--danger); border-color: transparent; }
button.close { background: transparent; border: none; font-size: 18px; padding: 4px 8px; color: var(--muted); }

.hidden { display: none !important; }

/* --- HUD ------------------------------------------------------------- */

#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  background: linear-gradient(rgba(10,14,30,0.85), rgba(10,14,30,0.45) 80%, transparent);
  pointer-events: none;
  z-index: 20;
}
#hud > div { display: flex; align-items: center; gap: 8px; pointer-events: auto; }

#hud-logo {
  font-weight: 800; letter-spacing: 1px; font-size: 15px; line-height: 1;
  color: var(--gold);
}
#hud-logo span { color: var(--text); display: block; font-size: 10px; letter-spacing: 4px; }

.hud-stat {
  background: var(--panel); border-radius: 8px; padding: 5px 10px;
  font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px;
  border: 1px solid rgba(255,255,255,0.1);
}
#hud-cash::before  { content: '💰 '; font-size: 12px; }
#hud-worth::before { content: '📈 '; font-size: 12px; }
#hud-pop::before   { content: '👥 '; font-size: 12px; }
#hud-cash.negative { color: var(--danger); }

#hud-clock {
  display: flex; flex-direction: column; align-items: flex-end;
  font-size: 12px; color: var(--muted); line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
#hud-clock #hud-day { font-weight: 700; color: var(--text); }

#speed-controls { display: flex; gap: 2px; background: var(--panel); border-radius: 8px; padding: 2px; }
#speed-controls button {
  background: transparent; border: none; padding: 5px 8px; font-size: 11px; color: var(--muted);
}
#speed-controls button.active { background: var(--accent); border-radius: 6px; color: white; }

#btn-menu { font-size: 16px; padding: 6px 11px; }

/* --- Toolbar ----------------------------------------------------------- */

#toolbar {
  position: fixed; bottom: calc(10px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 20;
}
.tool-btn {
  background: var(--panel); box-shadow: var(--shadow);
  padding: 10px 16px; font-weight: 600; font-size: 14px; border-radius: 999px;
}
.tool-btn.active { background: var(--accent); }

/* --- Sheets (drawers/panels) ------------------------------------------- */

.sheet {
  position: fixed; z-index: 30;
  background: var(--panel); box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  max-height: 70vh;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sheet-head h2 { font-size: 15px; }

#build-drawer { left: 10px; bottom: 70px; width: 320px; }
#info-panel { right: 10px; bottom: 70px; width: 320px; }
#portfolio-panel { left: 10px; bottom: 70px; width: 360px; }
#bank-panel { left: 10px; bottom: 70px; width: 340px; }

#build-list, #info-body, #portfolio-body, #bank-body { overflow-y: auto; padding: 8px; }
#bank-body { padding: 8px 12px; }
.bank-note { font-size: 12px; color: var(--muted); line-height: 1.45; padding: 8px 6px 4px; }

.build-cat { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 8px 6px 4px; }
.build-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: none; border-radius: 8px; padding: 8px;
  text-align: left;
}
.build-item:hover, .build-item:focus { background: rgba(255,255,255,0.07); }
.build-item.disabled { opacity: 0.45; }
.build-item.locked { opacity: 0.5; }
.build-item.locked .build-cost { color: var(--muted); }
.build-swatch { width: 26px; height: 26px; border-radius: 6px; flex: none; border: 1px solid rgba(255,255,255,0.25); }
.build-name { font-weight: 600; font-size: 14px; }
.build-sub { font-size: 11px; color: var(--muted); }
.build-cost { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gold); }

/* --- Status chip (objective / demand event) ------------------------------ */

#status-chip {
  position: fixed; top: calc(52px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  background: var(--panel); box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px; padding: 6px 14px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  z-index: 15; max-width: calc(100vw - 20px); overflow: hidden; text-overflow: ellipsis;
}
#status-chip.shock-up   { border-color: var(--gold); color: var(--gold); }
#status-chip.shock-down { border-color: var(--danger); color: var(--danger); }

/* --- Placement hint ------------------------------------------------------ */

#place-hint {
  position: fixed; top: calc(60px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent);
  border-radius: 999px; padding: 8px 8px 8px 16px;
  display: flex; align-items: center; gap: 12px;
  z-index: 25; font-size: 13px; box-shadow: var(--shadow);
}
#place-cancel { padding: 5px 12px; border-radius: 999px; background: var(--danger); border: none; font-size: 12px; }

/* --- Info panel ---------------------------------------------------------- */

.info-row { display: flex; justify-content: space-between; padding: 5px 6px; font-size: 13px; }
.info-row .k { color: var(--muted); }
.info-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.info-owner { font-weight: 700; }
.info-actions { display: flex; gap: 8px; padding: 10px 6px 4px; flex-wrap: wrap; }
.info-actions button { flex: 1; font-size: 13px; padding: 8px 6px; }

.price-control { padding: 8px 6px; }
.price-control label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.price-control input[type=range] { width: 100%; margin-top: 6px; accent-color: var(--accent); }

.owner-chip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }

/* --- Portfolio ------------------------------------------------------------ */

.pf-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: transparent; border: none; border-bottom: 1px solid rgba(255,255,255,0.06);
  padding: 8px 6px; text-align: left; font-size: 13px;
}
.pf-item:hover { background: rgba(255,255,255,0.06); }
.pf-name { font-weight: 600; }
.pf-sub { font-size: 11px; color: var(--muted); }
.pf-profit { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.pf-profit.pos { color: var(--ok); }
.pf-profit.neg { color: var(--danger); }
.pf-empty { padding: 18px; color: var(--muted); font-size: 13px; text-align: center; }

/* --- Modals ---------------------------------------------------------------- */

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6, 9, 20, 0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--panel); border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: min(440px, 100%); max-height: 85vh; overflow-y: auto;
  padding: 16px;
}
.modal-box h2 { font-size: 17px; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions button { flex: 1; padding: 10px; }

.menu-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.menu-list button { text-align: left; padding: 12px; }
.menu-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* New-game option rows */
.opt-label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; margin: 12px 0 6px; }
.opt-row { display: flex; gap: 6px; }
.opt-row button { flex: 1; padding: 9px 4px; font-size: 13px; }
.opt-row button.active { border-color: var(--accent); background: rgba(47, 128, 255, 0.22); font-weight: 600; }

.help-body p { font-size: 13px; line-height: 1.55; margin-bottom: 8px; color: #d5dbee; }

/* Auction */
#auction-bid-row {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(255,255,255,0.05); border-radius: 10px; padding: 12px; margin: 10px 0;
  font-size: 12px; color: var(--muted);
}
#auction-bid { font-size: 28px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
#auction-leader { font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; min-height: 40px; margin-top: 4px; }
.auction-leader-name { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.auction-leader-tag { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* Tycoon portraits (rankings + auction). Falls back to a coloured initial. */
.tycoon-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  flex: none; border-radius: 50%; overflow: hidden; box-sizing: border-box;
  border: 2px solid; background: rgba(255,255,255,0.08); vertical-align: middle;
}
.tycoon-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tycoon-avatar--initial { color: #fff; font-weight: 700; font-size: 15px; }
#auction-log { font-size: 12px; color: var(--muted); min-height: 60px; padding: 4px 2px; }
#auction-log div { padding: 2px 0; }

/* Rankings */
.rank-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 6px; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 14px;
}
.rank-pos { width: 20px; color: var(--muted); font-weight: 700; }
.rank-name { font-weight: 600; }
.rank-sub { font-size: 11px; color: var(--muted); }
.rank-worth { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.rank-row.bankrupt { opacity: 0.4; text-decoration: line-through; }
.rank-bar-wrap { height: 4px; background: rgba(255,255,255,0.08); border-radius: 2px; margin: 2px 6px 8px; }
.rank-bar { height: 100%; border-radius: 2px; }
.rank-goal { font-size: 11px; color: var(--muted); text-align: center; padding: 8px 0 2px; }

/* Save slots */
.save-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 6px; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 13px;
}
.save-name { font-weight: 600; }
.save-sub { font-size: 11px; color: var(--muted); }
.save-actions { display: flex; gap: 6px; flex: none; }
.save-actions button { font-size: 12px; padding: 6px 10px; }

/* Endgame */
#endgame-box { text-align: center; }
#endgame-box h2 { font-size: 24px; }
#endgame-box p { color: var(--muted); font-size: 14px; margin-top: 6px; }

/* Minimap */
#minimap {
  position: fixed; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px; box-shadow: var(--shadow);
  z-index: 18; cursor: pointer;
}
@media (max-width: 640px) {
  #minimap { width: 110px; height: 72px; bottom: calc(64px + env(safe-area-inset-bottom)); }
}

/* Toasts */
#toasts {
  position: fixed; top: calc(58px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 40;
  pointer-events: none; width: min(360px, 92vw);
}
.toast {
  background: var(--panel); border: 1px solid rgba(255,255,255,0.15);
  border-left: 4px solid var(--accent);
  padding: 9px 12px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease-out;
}
.toast.gold { border-left-color: var(--gold); }
.toast.bad { border-left-color: var(--danger); }
.toast.quip { border-left-color: #9b59b6; font-style: italic; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* Tutorial banner */
#tutorial-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(64px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-light); border: 1px solid var(--accent);
  border-radius: 10px; padding: 9px 12px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 22;
  width: min(440px, 94vw);
}
.tut-count { font-size: 11px; color: var(--muted); font-weight: 700; flex: none; }
.tut-text { flex: 1; line-height: 1.35; }
.tut-actions { display: flex; gap: 6px; flex: none; }
.tut-actions button { font-size: 12px; padding: 5px 10px; }
#tut-skip { background: transparent; border-color: rgba(255,255,255,0.2); color: var(--muted); }

/* --- Mobile -------------------------------------------------------------- */

@media (max-width: 640px) {
  .hide-narrow { display: none; }
  #hud-logo { display: none; }
  .hud-stat { font-size: 12px; padding: 4px 8px; }
  #hud-clock { font-size: 11px; }
  #build-drawer, #info-panel, #portfolio-panel, #bank-panel {
    left: 0; right: 0; bottom: 0; width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 55vh;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #toolbar { bottom: calc(8px + env(safe-area-inset-bottom)); }
  .tool-btn { padding: 9px 12px; font-size: 13px; }
}

/* --- Endgame report --------------------------------------------------------- */

#endgame-report { margin: 10px 0 2px; }
#endgame-report:empty { display: none; }
.endgame-chart {
  display: block; width: 100%; margin-top: 8px;
  background: rgba(255,255,255,0.04); border-radius: 8px;
}

/* --- Shop management ----------------------------------------------------- */

.tool-btn { position: relative; }
.badge {
  position: absolute; top: -5px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px;
  border-radius: 999px; text-align: center;
}

#shops-box { width: min(1200px, 96vw); max-width: none; }
#shops-body { max-height: 70vh; overflow-y: auto; }

.shop-alert {
  margin: 10px 0; padding: 8px 12px; border-radius: 8px;
  background: rgba(224, 91, 91, 0.15); border: 1px solid var(--danger);
  color: var(--danger); font-size: 13px; font-weight: 600;
}
.shop-bulk {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 0; font-size: 13px;
}
.shop-check { display: flex; align-items: center; gap: 6px; color: var(--muted); }

.shop-table { overflow-x: auto; }
.shop-row {
  display: grid; align-items: center; gap: 6px;
  grid-template-columns: 26px minmax(132px, 1.4fr) 56px 62px 58px 62px 96px 60px 76px 84px 78px 64px 112px;
  padding: 7px 4px; font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  min-width: 1040px;
}
.shop-head {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel); color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid rgba(255,255,255,0.14);
}
.shop-h.sortable { cursor: pointer; }
.shop-h.sortable:hover { color: var(--text); }
.shop-h.active { color: var(--accent); }

.shop-row.out { background: rgba(224, 91, 91, 0.12); }
.shop-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.shop-sub { color: var(--muted); font-weight: 400; font-size: 11px; }
.shop-out { color: var(--danger); font-weight: 700; }
.shop-low { color: var(--warn); font-weight: 600; }
.shop-throttled { color: var(--warn); font-weight: 600; }
.shop-row .pos { color: var(--ok); }
.shop-row .neg { color: var(--danger); }
.shop-row select, .shop-bulk select {
  background: var(--panel-light); color: var(--text);
  border: 1px solid rgba(255,255,255,0.14); border-radius: 6px;
  padding: 4px 6px; font-size: 12px;
}
.shop-row select { width: 100%; }
.shop-bulk select { min-width: 130px; }
.shop-row button { padding: 5px 9px; font-size: 12px; white-space: nowrap; }

@media (max-width: 720px) {
  #shops-box { width: 96vw; }
}
