/* ============ Game of Life — styling ============ */
:root {
  --bg: #0d1020;
  --panel: #161a2e;
  --panel-2: #1d2240;
  --panel-3: #252b4f;
  --border: #2c3358;
  --text: #e8eaf6;
  --muted: #9aa3c7;
  --accent: #7c5cff;
  --accent-2: #00d4ff;
  --good: #4ade80;
  --bad: #f87171;
  --gold: #fbbf24;
  --pink: #f472b6;
  --grad: linear-gradient(135deg, #7c5cff, #00d4ff);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% -10%, rgba(124,92,255,.15), transparent 50%),
                    radial-gradient(ellipse at 90% 110%, rgba(0,212,255,.10), transparent 50%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
button:disabled { opacity: .38; cursor: not-allowed; }

/* ---------- Top bar ---------- */
#topbar {
  height: 62px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: rgba(22,26,46,.9);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 50;
}

.brand { font-size: 20px; font-weight: 800; letter-spacing: .5px; white-space: nowrap; }
.brand-grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-dice { display: inline-block; }

#hud { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; align-items: center; }

.hud-chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
.hud-chip .lbl { color: var(--muted); font-weight: 500; margin-right: 4px; }
.hud-chip.money { color: var(--gold); }
.hud-chip.energy { color: var(--accent-2); }

.top-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 17px;
  transition: transform .1s, background .15s;
}
.icon-btn:hover { background: var(--panel-3); transform: translateY(-1px); }

.age-btn {
  background: var(--grad);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 22px;
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: .3px;
  box-shadow: 0 4px 18px rgba(124,92,255,.45);
  transition: transform .1s, box-shadow .15s;
}
.age-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(124,92,255,.6); }
.age-btn:active:not(:disabled) { transform: translateY(0); }

.menu-dropdown {
  position: absolute;
  top: 60px; right: 110px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.menu-dropdown.hidden { display: none; }
.menu-dropdown button {
  background: none; border: none; color: var(--text);
  padding: 9px 14px; border-radius: 8px; text-align: left; font-size: 14px;
}
.menu-dropdown button:hover { background: var(--panel-3); }

/* ---------- Layout ---------- */
#app {
  display: grid;
  grid-template-columns: 295px 1fr 385px;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 62px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow-y: auto;
  overflow-x: hidden;
}
.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 4px; }

#left { padding: 18px; }
#center { padding: 0; display: flex; flex-direction: column; }
#right { padding: 0; display: flex; flex-direction: column; }

/* ---------- Left: profile & stats ---------- */
#profile { text-align: center; margin-bottom: 14px; }
.avatar { font-size: 52px; line-height: 1.1; }
.pname { font-size: 19px; font-weight: 800; margin-top: 4px; }
.psub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.gen-badge {
  display: inline-block; margin-top: 6px;
  background: var(--panel-3); border: 1px solid var(--border);
  border-radius: 12px; padding: 2px 10px; font-size: 11.5px; color: var(--accent-2); font-weight: 700;
}

.statrow { margin-bottom: 9px; }
.statrow .stat-top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.statrow .stat-name { color: var(--muted); font-weight: 600; }
.statrow .stat-val { font-weight: 700; }
.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .35s ease; }

#snapshot { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.snap-line { display: flex; gap: 8px; font-size: 13px; padding: 4px 0; color: var(--muted); align-items: baseline; }
.snap-line b { color: var(--text); font-weight: 600; }
.snap-line .ic { width: 20px; text-align: center; flex-shrink: 0; }

/* ---------- Center: log ---------- */
#log { padding: 16px 20px; flex: 1; }
.log-age-header {
  font-size: 13px; font-weight: 800; color: var(--accent-2);
  letter-spacing: 1px; text-transform: uppercase;
  margin: 16px 0 6px; padding-bottom: 4px;
  border-bottom: 1px dashed var(--border);
}
.log-age-header:first-child { margin-top: 0; }
.log-entry { padding: 3.5px 0; font-size: 14.5px; line-height: 1.45; color: #c9cfeb; }
.log-entry.good { color: var(--good); }
.log-entry.bad { color: var(--bad); }
.log-entry.money { color: var(--gold); }
.log-entry.love { color: var(--pink); }
.log-entry.milestone { color: #c4b5fd; font-weight: 700; }

/* ---------- Right: tabs & actions ---------- */
#tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.tab-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 9px; padding: 6px 11px; font-size: 13px; font-weight: 600;
  transition: all .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--grad); color: #fff; border-color: transparent; }

#tabContent { padding: 14px; flex: 1; overflow-y: auto; }
#tabContent::-webkit-scrollbar { width: 8px; }
#tabContent::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 4px; }

.section-title { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 14px 0 8px; }
.section-title:first-child { margin-top: 0; }

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  margin-bottom: 8px;
}
.card .card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card .card-title { font-weight: 700; font-size: 14px; }
.card .card-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; line-height: 1.4; }
.card .card-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.card.locked { opacity: .55; }
.card.owned { border-color: rgba(74,222,128,.4); }

.btn {
  background: var(--panel-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  transition: all .12s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.btn.primary { background: var(--grad); border: none; color: #fff; }
.btn.danger { background: rgba(248,113,113,.12); border-color: rgba(248,113,113,.4); color: var(--bad); }
.btn.gold { background: rgba(251,191,36,.12); border-color: rgba(251,191,36,.4); color: var(--gold); }
.btn.small { padding: 4px 9px; font-size: 12px; }

.price { color: var(--gold); font-weight: 700; font-size: 13px; white-space: nowrap; }
.time-cost { color: var(--accent-2); font-weight: 700; font-size: 12px; white-space: nowrap; }

.empty-note { color: var(--muted); font-size: 13.5px; padding: 8px 2px; line-height: 1.5; }

.minibar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.minibar .bar-fill { height: 100%; }

.invest-row { display: flex; justify-content: space-between; align-items: center; }
.invest-btns { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 7px; }

/* ---------- Modals ---------- */
#modal-root:empty { display: none; }
.overlay {
  position: fixed; inset: 0;
  background: rgba(5,7,18,.78);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px;
  width: min(560px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
  animation: popIn .22s cubic-bezier(.2,1.4,.4,1);
}
@keyframes popIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal.wide { width: min(780px, 94vw); }

.modal h2 { font-size: 21px; margin-bottom: 6px; }
.modal .modal-icon { font-size: 46px; text-align: center; margin-bottom: 8px; }
.modal .modal-text { color: #c9cfeb; line-height: 1.55; font-size: 15px; margin: 10px 0 4px; }
.modal .choices { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.choice-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 11px; padding: 12px 15px; font-size: 14px; font-weight: 600;
  text-align: left; transition: all .12s;
}
.choice-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--panel-3); }
.choice-btn .choice-cost { color: var(--gold); font-size: 12.5px; margin-left: 6px; }

.modal-footer { display: flex; gap: 8px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }

/* New life form */
.form-row { margin: 12px 0; }
.form-row label { display: block; color: var(--muted); font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; margin-bottom: 6px; }
.text-input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 13px; font-size: 15px; width: 100%;
  font-family: inherit;
}
.text-input:focus { outline: none; border-color: var(--accent); }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 10px; padding: 9px; font-size: 14px; font-weight: 600;
}
.seg button.sel { background: var(--grad); color: #fff; border-color: transparent; }

/* Death screen */
.death-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.death-stat { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.death-stat .ds-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; font-weight: 700; }
.death-stat .ds-value { font-size: 17px; font-weight: 800; margin-top: 2px; }
.score-banner {
  background: var(--grad); border-radius: 12px; padding: 14px; text-align: center;
  font-size: 16px; font-weight: 800; color: #fff; margin: 12px 0;
}

/* Perk / achievement grids */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ach-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px; padding: 10px 12px; }
.ach-card.unlocked { border-color: rgba(251,191,36,.45); }
.ach-card.locked-ach { opacity: .42; filter: grayscale(.7); }
.ach-card .ach-name { font-weight: 700; font-size: 13.5px; }
.ach-card .ach-desc { color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.35; }

/* Start screen */
.start-title { font-size: 34px; font-weight: 900; text-align: center; margin-bottom: 4px; }
.start-sub { text-align: center; color: var(--muted); margin-bottom: 18px; font-size: 14.5px; line-height: 1.5; }
.meta-strip { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }

/* Toasts */
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--panel-3); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 10px 18px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: toastIn .25s ease, toastOut .4s ease 2.8s forwards;
}
.toast.ach-toast { background: linear-gradient(135deg, #92400e, #b45309); border-color: var(--gold); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Expansion: effects ---------- */
.confetti-piece {
  position: fixed;
  top: -14px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  z-index: 300;
  pointer-events: none;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(106vh) rotate(720deg); opacity: .65; }
}

.hud-chip.prison { color: var(--bad); border-color: rgba(248,113,113,.55); }

.hud-chip.money.flash-up { animation: flashUp .9s ease; }
.hud-chip.money.flash-down { animation: flashDown .9s ease; }
@keyframes flashUp {
  25% { box-shadow: 0 0 16px rgba(74,222,128,.85); border-color: rgba(74,222,128,.8); }
}
@keyframes flashDown {
  25% { box-shadow: 0 0 16px rgba(248,113,113,.85); border-color: rgba(248,113,113,.8); }
}

/* Responsive */
@media (max-width: 1180px) {
  body { overflow: auto; }
  #app { grid-template-columns: 1fr 1fr; height: auto; }
  #center { grid-column: 1 / -1; order: 3; min-height: 320px; }
  .panel { max-height: 70vh; }
}
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  #hud { order: 3; width: 100%; }
}
