/* Life Sim — mobile-first dark UI. The map is the app; chrome floats above. */

:root {
  --bg: #04101f;
  --panel: rgba(10, 22, 38, 0.94);
  --card: rgba(255, 255, 255, 0.06);
  --text: #e8eef5;
  --dim: #93a3b5;
  --accent: #ffd97a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

#map {
  position: fixed; inset: 0; width: 100%; height: 100%;
  touch-action: none; display: block;
}

.hidden { display: none !important; }
.dim { color: var(--dim); }
.gold { color: var(--accent); }
.small { font-size: 12px; }

/* ---- top bar ---- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  padding: calc(var(--safe-top) + 8px) 14px 8px;
  display: flex; gap: 10px; align-items: baseline;
  background: linear-gradient(rgba(4, 16, 31, 0.92), rgba(4, 16, 31, 0));
  font-size: 14px; font-weight: 600;
  pointer-events: none; z-index: 10;
}
#topbar .era { color: var(--accent); font-weight: 700; }
#statPop { margin-left: auto; }

/* ---- floating controls ---- */
#controls {
  position: fixed; right: 10px; bottom: calc(var(--safe-bottom) + 86px);
  display: flex; flex-direction: column; gap: 8px; z-index: 12;
}
#controls button {
  width: 48px; height: 44px; border-radius: 14px; border: none;
  background: var(--panel); color: var(--text);
  font-size: 15px; font-weight: 700;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}
#controls button:active { transform: scale(0.93); background: #1d3a5c; }

/* ---- fast-forward overlay ---- */
#ffOverlay {
  position: fixed; top: calc(var(--safe-top) + 46px); left: 50%;
  transform: translateX(-50%);
  background: var(--panel); border-radius: 20px; padding: 8px 16px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 600; z-index: 14;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--dim); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- tab bar ---- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; z-index: 15;
  background: var(--panel); backdrop-filter: blur(10px);
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.tab {
  flex: 1; padding: 9px 0 7px; border: none; background: none;
  color: var(--dim); font-size: 19px; line-height: 1.1;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.tab span { font-size: 10px; font-weight: 600; }
.tab.active { color: var(--accent); }

/* ---- slide-up panel ---- */
#panel {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 62px);
  max-height: 56vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--panel); backdrop-filter: blur(12px);
  border-radius: 18px 18px 0 0; padding: 14px 14px 18px;
  z-index: 11; box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.5);
  animation: rise 0.18s ease-out;
}
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }
#btnClosePanel {
  position: sticky; top: 0; float: right;
  background: var(--card); color: var(--dim); border: none;
  width: 30px; height: 30px; border-radius: 50%; font-size: 14px;
}

/* ---- cards ---- */
.card {
  background: var(--card); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; font-size: 13.5px;
}
.cardHead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14.5px; }
.row { margin-top: 4px; line-height: 1.45; }
.chip { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.rel { margin-right: 8px; white-space: nowrap; }
.mini {
  margin-left: auto; background: rgba(255, 255, 255, 0.1); border: none;
  color: var(--text); border-radius: 8px; padding: 4px 9px; font-size: 13px;
}
.cardHead .mini + .mini { margin-left: 6px; }
.bar {
  display: inline-block; width: 70px; height: 7px; vertical-align: middle;
  background: rgba(255, 255, 255, 0.12); border-radius: 4px; overflow: hidden;
}
.bar i { display: block; height: 100%; background: var(--accent); }
.traits { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.traits span {
  font-size: 11px; display: inline-flex; align-items: center; gap: 3px;
  background: rgba(255, 255, 255, 0.07); border-radius: 6px; padding: 2px 6px 2px 4px;
  min-width: 52px;
}
.traits span i {
  display: inline-block; height: 5px; max-width: 34px;
  background: #6fb3e8; border-radius: 3px;
}
.actions { display: flex; gap: 8px; margin-top: 9px; }
.actions button {
  flex: 1; padding: 9px; border: none; border-radius: 10px;
  background: rgba(255, 255, 255, 0.12); color: var(--text);
  font-size: 13.5px; font-weight: 600;
}
.actions button:active { background: #1d3a5c; }

/* ---- history ---- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chipBtn {
  border: none; border-radius: 14px; padding: 5px 11px; font-size: 12px;
  background: rgba(255, 255, 255, 0.08); color: var(--dim); font-weight: 600;
}
.chipBtn.on { background: var(--accent); color: #20242c; }
.timeline .event {
  display: flex; gap: 8px; align-items: baseline;
  padding: 6px 4px; font-size: 13px; line-height: 1.4;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.event .eyear { color: var(--dim); font-size: 11px; min-width: 38px; text-align: right; flex: none; }
.event .eicon { flex: none; }
.event .etext { flex: 1; }
.event.imp4 .etext, .event.imp5 .etext { color: var(--accent); font-weight: 600; }
.event .mini { padding: 2px 7px; }

/* ---- modals ---- */
.modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(2, 8, 16, 0.78); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 22px;
}
.modalBox {
  background: #0d1f33; border-radius: 18px; padding: 22px;
  width: 100%; max-width: 380px; max-height: 84vh; overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.modalBox h1 { margin: 0 0 6px; font-size: 30px; }
.modalBox h2 { margin: 0 0 14px; }
.modalBox p { line-height: 1.5; }
.modalBox input {
  width: 100%; padding: 11px; margin: 8px 0; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16); background: rgba(255, 255, 255, 0.06);
  color: var(--text); font-size: 15px;
}
.modalBox button {
  display: block; width: 100%; padding: 12px; margin-top: 9px;
  border: none; border-radius: 12px; font-size: 15px; font-weight: 600;
  background: rgba(255, 255, 255, 0.1); color: var(--text);
}
.modalBox button.primary { background: var(--accent); color: #20242c; }
.modalBox button.danger { background: rgba(224, 106, 106, 0.25); }
.modalBox button:active { transform: scale(0.98); }
.menuRow { display: flex; gap: 8px; }
.menuRow button { flex: 1; }
.modalBox hr { border: none; border-top: 1px solid rgba(255, 255, 255, 0.1); margin: 14px 0; }
.modalBox.start { text-align: center; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 130px);
  background: var(--panel); border-radius: 14px; padding: 10px 16px;
  font-size: 13.5px; font-weight: 600; max-width: 86vw;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5); z-index: 25;
  animation: rise 0.2s ease-out;
}

/* Larger screens: keep things centered and readable. */
@media (min-width: 700px) {
  #panel { left: auto; right: 12px; width: 400px; border-radius: 18px; }
  #controls { bottom: 100px; }
}
