:root {
  --night: #120c1c;
  --night2: #1c1430;
  --panel: #231a36;
  --panel2: #2e2346;
  --edge: #0a0612;
  --line: #4a3a6a;
  --text: #f0e4d0;
  --dim: #9a8cb0;
  --gold: #ffcf4a;
  --gold-dark: #8a6410;
  --pink: #ff8fb8;
  --blue: #6fc3ff;
  --green: #78e05a;
  --red: #ff5a5a;
  --pixel: "VT323", ui-monospace, monospace;
  --pixel-bold: "Press Start 2P", "VT323", monospace;
}

* { box-sizing: border-box; }

html { background: var(--night); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(ellipse at 50% -10%, var(--night2), var(--night) 70%) fixed var(--night);
  font-family: var(--pixel);
  font-size: 20px;
  letter-spacing: .06em;
  overflow-x: hidden;
  padding-bottom: 110px;
}

img { image-rendering: pixelated; }

[hidden] { display: none !important; }

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, .16) 0 1px, transparent 1px 3px);
}

.stars {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1.5px 1.5px at 10% 20%, #fff8, transparent),
    radial-gradient(1px 1px at 30% 70%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 55% 30%, #fff7, transparent),
    radial-gradient(1px 1px at 75% 85%, #fff5, transparent),
    radial-gradient(1.5px 1.5px at 90% 15%, #fff6, transparent);
  background-size: 260px 260px;
  animation: twinkle 4s steps(2) infinite;
}
@keyframes twinkle { 50% { opacity: .5; } }

/* ---------- Pixel panels & buttons ---------- */

.panel {
  background: var(--panel);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 3px var(--line), 4px 4px 0 var(--edge);
  padding: 14px 16px;
}

.px-btn {
  font-family: var(--pixel-bold);
  font-size: 11px;
  color: var(--text);
  background: var(--panel2);
  border: 3px solid var(--edge);
  box-shadow: inset -3px -3px 0 #0006, inset 3px 3px 0 #fff2, 3px 3px 0 var(--edge);
  padding: 10px 12px;
  cursor: pointer;
  letter-spacing: .05em;
  line-height: 1.4;
}
.px-btn:hover { background: var(--line); }
.px-btn:active { transform: translate(2px, 2px); box-shadow: inset 3px 3px 0 #0006, 1px 1px 0 var(--edge); }
.px-btn:disabled { opacity: .5; cursor: wait; }
.px-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  font-family: var(--pixel);
  font-size: 22px;
}
.icon-btn.off { opacity: .45; }

.gold { color: var(--gold); }
.pink { color: var(--pink); }
.blue { color: var(--blue); }
.dim { color: var(--dim); }

h1, h2 { font-family: var(--pixel-bold); font-weight: normal; margin: 0; }
h2 { font-size: 12px; color: var(--gold); letter-spacing: .1em; }

/* ---------- Header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}
.logo h1 {
  font-size: 26px;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--ember, #c2401c), 6px 6px 0 var(--edge);
}
.logo p { margin: 6px 0 0; font-size: 16px; color: var(--dim); letter-spacing: .3em; }
.top-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Game ---------- */

.game { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  align-items: baseline;
}
.stat { display: flex; flex-direction: column; min-width: 70px; }
.stat b { font-family: var(--pixel-bold); font-size: 14px; font-weight: normal; margin-top: 4px; }
.stat span { font-size: 16px; color: var(--dim); }
.stat.lead b { font-size: 20px; color: var(--gold); }
.stat .ok { color: var(--green); }
.stat .gone { color: var(--red); }

.colony-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 2px 10px; }
.sort { color: var(--dim); font-size: 18px; }
.sort select {
  font-family: var(--pixel);
  font-size: 18px;
  background: var(--panel2);
  color: var(--text);
  border: 3px solid var(--edge);
  padding: 2px 6px;
}

.colony {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.cat-card {
  position: relative;
  background: var(--panel);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 3px var(--line), 3px 3px 0 var(--edge);
  padding: 10px 10px 8px;
  text-align: center;
  cursor: pointer;
  transition: transform .15s;
}
.cat-card:hover { transform: translateY(-3px); }
.cat-card.founder { box-shadow: inset 0 0 0 3px var(--gold), 3px 3px 0 var(--edge); }
.cat-card.none { opacity: .82; }

.cc-sprite { height: 72px; display: flex; align-items: flex-end; justify-content: center; position: relative; }
.cc-sprite img { display: block; transition: width .5s steps(5), height .5s steps(5); }

.st-kitten { width: 40px; height: 40px; }
.st-young { width: 54px; height: 54px; }
.st-adult, .st-senior, .st-elder { width: 64px; height: 64px; }
.st-elder { filter: saturate(.7) brightness(.92); }

.cc-name { font-size: 20px; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-meta { font-size: 15px; color: var(--dim); line-height: 1.1; min-height: 34px; }
.sex-F { color: var(--pink); }
.sex-M { color: var(--blue); }

.dna-bar {
  position: relative;
  height: 14px;
  margin-top: 6px;
  background: #0a0612;
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 1px var(--line);
}
.dna-bar i {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: repeating-linear-gradient(90deg, var(--gold) 0 4px, #e8b030 4px 6px);
  transition: width .6s steps(8);
}
.dna-bar span {
  position: absolute;
  inset: 0;
  font-size: 14px;
  line-height: 10px;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}
.badges { font-size: 14px; color: var(--dim); min-height: 18px; margin-top: 4px; }
.badges b { font-weight: normal; color: var(--gold); }

.crown {
  position: absolute;
  top: 2px;
  left: 6px;
  font-size: 18px;
}

/* --- Aging, birth, death animations --- */

.cat-card.aging { animation: hop .7s steps(6); }
@keyframes hop {
  0%, 100% { transform: none; }
  30% { transform: translateY(-10px) scale(1.04); }
  60% { transform: translateY(0) scale(.98); }
}

.plus1 {
  position: absolute;
  left: 50%;
  top: 20px;
  font-family: var(--pixel-bold);
  font-size: 13px;
  color: var(--green);
  text-shadow: 2px 2px 0 var(--edge);
  pointer-events: none;
  animation: rise 1.1s steps(10) forwards;
  z-index: 5;
}
.plus1.grow { color: var(--gold); top: 4px; font-size: 10px; white-space: nowrap; }
@keyframes rise {
  from { transform: translate(-50%, 0); opacity: 1; }
  to { transform: translate(-50%, -40px); opacity: 0; }
}

.cat-card.dying { animation: fade 1.5s steps(8) forwards; pointer-events: none; }
.cat-card.dying img { filter: grayscale(1) brightness(1.4); }
@keyframes fade {
  0%, 40% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: scale(.85); }
}
.ghost {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 64px;
  height: 64px;
  margin-left: -32px;
  opacity: .8;
  filter: grayscale(1) brightness(2.2);
  animation: haunt 1.6s steps(12) forwards;
  pointer-events: none;
}
.ghost::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 22px;
  top: -6px;
  height: 6px;
  border: 2px solid var(--gold);
  border-radius: 50%;
}
@keyframes haunt {
  from { transform: translateY(0); opacity: .9; }
  to { transform: translateY(-80px); opacity: 0; }
}

.cat-card.born { animation: born .7s steps(7) backwards; }
@keyframes born {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}
.heart {
  position: absolute;
  font-size: 16px;
  color: var(--pink);
  pointer-events: none;
  animation: rise 1.2s steps(10) forwards;
}

/* ---------- Year log ---------- */

.yearlog { margin-top: 22px; }
.yearlog ul, .chron ul { list-style: none; margin: 10px 0 0; padding: 0; font-size: 18px; line-height: 1.25; }
.yearlog li, .chron li { padding: 2px 0; }
.ev-birth::before { content: "\2665  "; color: var(--pink); }
.ev-death::before { content: "\271D  "; color: var(--dim); }
.ev-info::before { content: "\2605  "; color: var(--gold); }
.ev-death { color: var(--dim); }

/* ---------- Footer ---------- */

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--night) 60%, transparent);
}
.age-btn {
  font-size: 14px;
  padding: 16px 22px;
  background: #3a6a2a;
  box-shadow: inset -4px -4px 0 #0005, inset 4px 4px 0 #fff3, 4px 4px 0 var(--edge);
}
.age-btn:hover { background: #4a8a36; }
.age-btn .cake { font-family: var(--pixel); font-size: 22px; vertical-align: -3px; }
.small-btn { font-size: 9px; padding: 10px 8px; }
#auto-btn.on { background: #8a6410; color: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { box-shadow: inset 0 0 0 3px var(--gold), 3px 3px 0 var(--edge); } }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 4, 14, .86);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.splash { z-index: 70; overflow-y: auto; align-items: flex-start; }
.splash-box { max-width: 860px; width: 100%; margin: auto; text-align: center; }
.big {
  font-size: 34px;
  color: var(--gold);
  text-shadow: 4px 4px 0 #c2401c, 8px 8px 0 var(--edge);
  margin-top: 10px;
}
.subtitle { font-family: var(--pixel-bold); font-size: 12px; color: var(--pink); margin: 18px 0 8px; }
.hint { color: var(--dim); max-width: 620px; margin: 8px auto 16px; line-height: 1.15; }

.founders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.founder-card {
  font-family: var(--pixel);
  color: var(--text);
  background: var(--panel2);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 3px var(--line), 3px 3px 0 var(--edge);
  padding: 12px;
  cursor: pointer;
  text-align: center;
}
.founder-card:hover, .founder-card:focus-visible { box-shadow: inset 0 0 0 3px var(--gold), 3px 3px 0 var(--edge); outline: none; }
.founder-card img { width: 80px; height: 80px; animation: idle 1.6s steps(2) infinite; }
.founder-card:nth-child(2) img { animation-delay: -.4s; }
.founder-card:nth-child(3) img { animation-delay: -.8s; }
@keyframes idle { 50% { transform: translateY(-3px); } }
.founder-card .fname { font-size: 24px; margin-top: 6px; }
.founder-card .fdesc { font-size: 16px; color: var(--dim); line-height: 1.1; }
.founder-card .fpick { font-family: var(--pixel-bold); font-size: 9px; color: var(--gold); margin-top: 10px; }
.splash-actions { margin-top: 16px; }

/* Year animation */
.yearfx {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(8, 4, 14, .35);
  animation: fxin 1.6s steps(8) forwards;
}
@keyframes fxin {
  0% { opacity: 0; }
  12%, 80% { opacity: 1; }
  100% { opacity: 0; }
}
.yearfx-box { text-align: center; padding: 18px 30px; }
.yearfx-label { font-family: var(--pixel-bold); font-size: 12px; color: var(--dim); }
.flip {
  position: relative;
  height: 64px;
  width: 160px;
  margin: 10px auto;
  overflow: hidden;
  font-family: var(--pixel-bold);
  font-size: 44px;
  color: var(--gold);
  text-shadow: 4px 4px 0 var(--edge);
}
.flip span { position: absolute; left: 0; right: 0; top: 8px; }
.flip-old { animation: flipout .5s steps(5) .55s forwards; }
.flip-new { transform: translateY(70px); animation: flipin .5s steps(5) .55s forwards; }
@keyframes flipout { to { transform: translateY(-70px); } }
@keyframes flipin { to { transform: translateY(0); } }
.months { display: flex; gap: 4px; justify-content: center; }
.months i {
  width: 12px;
  height: 12px;
  background: var(--edge);
  box-shadow: inset 0 0 0 2px var(--line);
  animation: month .1s steps(1) forwards;
}
@keyframes month { to { background: var(--green); } }

/* Modal */
.modal { overflow-y: auto; align-items: flex-start; z-index: 68; }
.modal-box { position: relative; max-width: 720px; width: 100%; margin: auto; }
.modal-x { position: absolute; right: 10px; top: 10px; }
.modal-box h2 { margin-right: 52px; }
.modal-box p, .modal-box li { line-height: 1.2; }

.detail-head { display: flex; gap: 16px; align-items: center; margin-right: 50px; flex-wrap: wrap; }
.detail-head img { width: 112px; height: 112px; background: var(--panel2); border: 3px solid var(--edge); }
.detail-head.dead img { filter: grayscale(1); }
.detail-name { font-size: 32px; }
.detail-sub { color: var(--dim); font-size: 18px; line-height: 1.15; }
.detail-dna { margin: 14px 0; }
.detail-dna .dna-bar { height: 20px; }
.detail-dna .dna-bar span { font-size: 18px; line-height: 16px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-size: 18px; }
.detail-grid > div > span { color: var(--dim); display: block; font-size: 15px; }
.link { color: var(--blue); cursor: pointer; text-decoration: underline dotted; }
.link:hover { color: var(--gold); }
.kids { display: flex; flex-wrap: wrap; gap: 4px 10px; }

.karyo {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 6px 10px;
}
.chr { font-size: 14px; color: var(--dim); }
.chr-row { display: flex; height: 7px; margin-top: 2px; }
.chr-row i { flex: 1; background: #3a3050; border-right: 1px solid var(--edge); }
.chr-row i.o { background: var(--gold); }
.chr-row.y i { flex: none; width: calc(100% / 12); }
.karyo-key { font-size: 15px; color: var(--dim); margin-top: 8px; }

.help h3, .end h3 { font-family: var(--pixel-bold); font-size: 11px; color: var(--pink); margin: 18px 0 6px; font-weight: normal; }
.help ul { padding-left: 18px; margin: 0; }
.end { text-align: center; }
.end .big { font-size: 22px; }
.end-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 18px 0; }
.end-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* ---------- Tree ---------- */

.tree { flex-direction: column; align-items: stretch; justify-content: flex-start; padding: 12px; gap: 10px; z-index: 65; }
.tree-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 8px 12px; }
.tree-sum { color: var(--dim); font-size: 18px; flex: 1; }
.tree-tools { display: flex; gap: 6px; }
.tree-scroll {
  flex: 1;
  overflow: auto;
  background: var(--night);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 3px var(--line);
}
.tree-inner { position: relative; transform-origin: 0 0; }
.tree-inner svg { position: absolute; left: 0; top: 0; overflow: visible; }
.gen-label {
  position: absolute;
  left: 8px;
  font-family: var(--pixel-bold);
  font-size: 9px;
  color: var(--line);
}
.tnode {
  position: absolute;
  width: 72px;
  text-align: center;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.tnode img {
  width: 44px;
  height: 44px;
  background: var(--panel);
  border: 2px solid var(--edge);
  box-shadow: 0 0 0 2px var(--line);
}
.tnode.carrier img { box-shadow: 0 0 0 2px var(--gold); }
.tnode.founder img { box-shadow: 0 0 0 3px var(--gold), 0 0 12px var(--gold); }
.tnode.dead img { filter: grayscale(1) brightness(.75); }
.tnode b { display: block; font-weight: normal; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tnode small { font-size: 14px; color: var(--dim); }
.tnode.carrier small { color: var(--gold); }
.tnode:hover b { color: var(--gold); }
.tree-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 16px; color: var(--dim); }
.lg { display: inline-block; width: 12px; height: 12px; vertical-align: -1px; border: 2px solid var(--edge); }
.lg.gold { background: var(--gold); }
.lg.none { background: var(--line); }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 2px var(--line), 3px 3px 0 var(--edge);
  padding: 6px 12px;
  font-size: 18px;
  animation: toast 2.6s steps(6) forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translateY(-10px); }
  10%, 85% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

@media (max-width: 560px) {
  body { font-size: 18px; }
  .logo h1 { font-size: 18px; }
  .logo p { font-size: 13px; }
  .icon-btn { width: 38px; height: 38px; font-size: 18px; }
  .colony { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
  .age-btn { font-size: 11px; padding: 14px 12px; }
  .detail-grid { grid-template-columns: 1fr; }
  .big { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; animation-delay: 0s !important; transition: none !important; }
}
