/* Good Genes live world, 3D. Cozy chrome over the Polyworld world: the
   world's own cream pills, plum ink, coral, butter, leaf and sky; Fredoka,
   big round targets. Phone first, portrait and landscape. */
@font-face { font-family: Fredoka; src: url(Fredoka.ttf) format("truetype"); font-weight: 300 700; font-display: swap; }
:root {
  --cream: #fff8ec;
  --cream2: #fffdf6;
  --sand: #ebdcc6;
  --plum: #4a3b52;
  --plum-soft: #7b6a80;
  --coral: #e0675a;
  --coral-deep: #b9473c;
  --butter: #f2d7a0;
  --leaf: #4fae7f;
  --leaf-deep: #2f8a5e;
  --mint: #dcf3e3;
  --sky: #7fb8f0;
  --shadow: 0 8px 24px rgba(74, 59, 82, 0.22);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #cfe9d4; color: var(--plum);
  font: 16px/1.35 Fredoka, ui-rounded, system-ui, sans-serif; -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
canvas#canvas {
  position: fixed; inset: 0; display: block; width: 100%; height: 100%; outline: none;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
b { font-weight: 600; }
.muted { color: var(--plum-soft); }
.small { font-size: 14px; }
.err { color: var(--coral-deep); font-weight: 500; }
.msg { color: var(--leaf-deep); font-weight: 500; }

/* ---- splash ---- */
#splash {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(180deg, rgba(191, 227, 255, 0.82) 0%, rgba(207, 236, 205, 0.78) 62%, rgba(243, 226, 190, 0.9) 100%),
    #cfe9d4 url(splash-backdrop.jpg) 50% 40% / cover no-repeat;
  transition: opacity 0.7s ease;
}
#splash.done { opacity: 0; pointer-events: none; }
.splash-card {
  width: min(420px, 100%); text-align: center; padding: 26px 22px 22px; border-radius: 30px;
  background: rgba(255, 248, 236, 0.94); box-shadow: 0 18px 50px rgba(74, 59, 82, 0.25), inset 0 0 0 3px #fff;
}
.brand { margin: 6px 0 4px; font-size: 40px; font-weight: 700; letter-spacing: 0.01em; color: var(--leaf-deep); line-height: 1; }
.brand span { color: var(--coral); }
.tagline { margin: 6px 4px 18px; color: var(--plum-soft); font-size: 16px; }
.egg { width: 64px; height: 78px; margin: 0 auto; position: relative; animation: wobble 2.2s ease-in-out infinite; transform-origin: 50% 90%; }
.egg::before { content: ""; position: absolute; inset: 0; border-radius: 50% 50% 46% 46% / 58% 58% 42% 42%;
  background: radial-gradient(circle at 35% 30%, #fff 0 14%, #fde9c4 15% 100%); box-shadow: inset -6px -8px 0 rgba(224, 103, 90, 0.18), 0 6px 0 rgba(74, 59, 82, 0.12); }
.egg span { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: #f7b9a8; left: 18px; top: 34px; box-shadow: 22px 10px 0 -2px #a8d9b8, 8px 22px 0 -3px #9cc9f2; }
@keyframes wobble { 0%, 60%, 100% { transform: rotate(0); } 70% { transform: rotate(-7deg); } 80% { transform: rotate(6deg); } 90% { transform: rotate(-3deg); } }
.bar { height: 14px; border-radius: 99px; background: #f1e4cf; overflow: hidden; box-shadow: inset 0 2px 3px rgba(74, 59, 82, 0.15); }
#fill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #8fd4a6, var(--leaf) 60%, #f2c66d); transition: width 0.3s ease-out; }
#stage { margin: 10px 0 0; color: var(--plum-soft); font-size: 15px; min-height: 1.4em; }
#splash.error .bar, #splash.error #stage, #splash.error .tagline { display: none; }
#splashErr p { margin: 10px 0 14px; font-size: 18px; }
.splash-actions { display: flex; flex-direction: column; gap: 10px; }
#splashErr details { margin-top: 14px; color: var(--plum-soft); font-size: 13px; text-align: left; }
#splashErr pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; margin: 6px 0 0; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 10px 18px;
  border-radius: 999px; border: 0; background: var(--butter); color: var(--plum); font-weight: 600; font-size: 17px;
  text-decoration: none; box-shadow: 0 3px 0 rgba(74, 59, 82, 0.18);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(74, 59, 82, 0.18); }
.btn.primary { background: var(--leaf); color: #fff; box-shadow: 0 4px 0 var(--leaf-deep); }
.btn.primary:disabled { opacity: 0.55; }
.btn.green { background: var(--mint); color: #23704f; }
.btn.small { min-height: 40px; padding: 7px 14px; font-size: 15px; }
.btn.on { background: #ffe39c; }
.btn.wide { width: 100%; justify-content: flex-start; padding-left: 18px; }
.btn small { font-weight: 400; color: var(--plum-soft); font-size: 13.5px; margin-left: 4px; }
.round {
  width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--cream); color: var(--plum); font-size: 20px; box-shadow: var(--shadow);
}

/* ---- overlay layer ---- */
#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#ui > *, .bottom > * { pointer-events: auto; }
.bottom { pointer-events: none !important; }

.top {
  position: absolute; top: calc(var(--safe-t) + 10px); left: calc(var(--safe-l) + 10px); right: calc(var(--safe-r) + 10px);
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "pill menu" "chips chips"; gap: 6px 8px; align-items: center;
  pointer-events: none !important;
}
.top > * { pointer-events: auto; }
#pill { grid-area: pill; justify-self: start; }
#menuBtn { grid-area: menu; }
.chips { grid-area: chips; display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 15px; border-radius: 999px; white-space: nowrap;
  font-size: 15px; font-weight: 600; box-shadow: var(--shadow); max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.pill .dot { width: 11px; height: 11px; flex: none; border-radius: 50%; background: #a3a0a6; }
.pill.on { background: #e5f7ea; color: #23704f; }
.pill.on .dot { background: #3cc97a; animation: pulse 2s infinite; }
.pill.off { background: #eeeaee; color: #7d7883; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(60, 201, 122, 0.65); } 70% { box-shadow: 0 0 0 9px rgba(60, 201, 122, 0); } 100% { box-shadow: 0 0 0 0 rgba(60, 201, 122, 0); } }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 11px; border-radius: 999px;
  background: rgba(255, 248, 236, 0.9); color: var(--plum); font-size: 13.5px; box-shadow: 0 3px 10px rgba(74, 59, 82, 0.14);
}
.chip b { color: var(--coral-deep); }
.chip.wide-only { display: none; }

#toasts {
  position: absolute; top: calc(var(--safe-t) + 104px); left: 50%; transform: translateX(-50%);
  width: min(440px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none !important;
}
.toast {
  padding: 9px 15px; border-radius: 18px; background: rgba(255, 248, 236, 0.96); box-shadow: var(--shadow);
  font-size: 15px; text-align: center; animation: drop 0.35s ease-out; transition: opacity 0.4s, transform 0.4s;
}
.toast.mine { background: #fff1c9; box-shadow: var(--shadow), inset 0 0 0 2px #f2c66d; font-weight: 500; }
.toast.bye { opacity: 0; transform: translateY(-8px); }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } }

.hint {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); width: min(330px, calc(100% - 40px));
  padding: 14px 18px; border-radius: 22px; background: rgba(74, 59, 82, 0.82); color: #fff; text-align: center;
  font-size: 16px; line-height: 1.6; pointer-events: none !important; animation: drop 0.4s ease-out;
}
.hint b { color: #ffe39c; }

.bottom {
  position: absolute; left: calc(var(--safe-l) + 10px); right: calc(var(--safe-r) + 10px); bottom: calc(var(--safe-b) + 10px);
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
}
.dock {
  display: flex; gap: 4px; padding: 5px; border-radius: 26px; background: rgba(255, 248, 236, 0.96); box-shadow: var(--shadow);
  max-width: 520px; width: 100%; align-self: center;
}
.dock button {
  flex: 1 1 0; min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; border: 0; border-radius: 21px; background: transparent; padding: 4px 2px;
}
.dock .ico { font-size: 22px; line-height: 1.1; }
.dock .lbl { font-size: 13px; font-weight: 600; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock button.on, .dock button:active { background: var(--butter); }
#dockPlay { background: var(--coral); color: #fff; }
#dockPlay.on { background: var(--coral-deep); }

.caption {
  align-self: center; max-width: min(520px, 100%); padding: 8px 14px; border-radius: 16px; background: rgba(74, 59, 82, 0.72); color: #fff;
  font-size: 14.5px; text-align: center; opacity: 0; transform: translateY(6px); transition: opacity 0.45s, transform 0.45s; pointer-events: none !important;
}
.caption.on { opacity: 1; transform: none; }
.caption.mine { background: rgba(224, 103, 90, 0.9); }
body:has(#card:not([hidden])) .caption { display: none; }
/* A portrait sheet covers the bottom of the screen: the card and dock wait under it. */
@media (orientation: portrait) and (max-width: 699px) {
  body.sheet-open .bottom { z-index: 25; }
  body.sheet-open .bottom > :not(.dock) { visibility: hidden; }
  .sheet { max-height: min(80vh, 80dvh); padding-bottom: calc(var(--safe-b) + 92px); }
}

/* the critter card */
.crit {
  position: relative; align-self: center; width: 100%; max-width: 420px; padding: 12px 14px 12px; border-radius: 24px;
  background: var(--cream); box-shadow: var(--shadow), inset 0 0 0 2px #fff; animation: drop 0.25s ease-out;
}
.crit .x { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: #f3e7d4; font-size: 16px; }
.crit-head { display: flex; gap: 12px; align-items: center; padding-right: 36px; }
.crit .art { flex: none; width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; background: #fff; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.8); }
.crit-title { min-width: 0; }
.crit h3 { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crit .who { color: var(--plum-soft); font-size: 14.5px; }
.crit-stats { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin: 10px 0 2px; font-size: 14.5px; }
.stat b { color: var(--coral-deep); }
.energy { display: inline-flex; align-items: center; gap: 5px; }
.meter { display: inline-block; width: 74px; height: 10px; border-radius: 99px; background: #efe2cd; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 99px; }
.crit-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.crit-actions:empty { display: none; }

/* camera menu */
.pop {
  position: absolute; right: 0; bottom: 76px; width: min(330px, 100%); padding: 8px; border-radius: 24px;
  background: var(--cream); box-shadow: 0 14px 40px rgba(74, 59, 82, 0.3); display: flex; flex-direction: column; gap: 4px; animation: drop 0.2s ease-out;
}
.pop button { display: flex; gap: 12px; align-items: center; text-align: left; min-height: 56px; padding: 8px 12px; border: 0; border-radius: 18px; background: transparent; }
.pop button:active, .pop button:hover { background: #f6ead6; }
.pop .ico { font-size: 24px; }
.pop small { display: block; color: var(--plum-soft); font-size: 13px; }

/* ---- sheets ---- */
.sheet {
  position: absolute; z-index: 20; left: 0; right: 0; bottom: 0; max-height: min(74vh, 74dvh); overflow: auto; overscroll-behavior: contain;
  padding: 6px calc(var(--safe-r) + 18px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 18px);
  border-radius: 28px 28px 0 0; background: var(--cream); box-shadow: 0 -12px 40px rgba(74, 59, 82, 0.28);
  animation: up 0.28s ease-out; transition: transform 0.2s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 46px; height: 5px; border-radius: 3px; background: #e3d2b8; margin: 4px auto 6px; }
.sheet-head { position: sticky; top: -6px; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0 6px; background: var(--cream); }
.sheet-head h2 { margin: 0; font-size: 23px; font-weight: 600; }
.sheet-head .x { width: 40px; height: 40px; box-shadow: none; background: #f3e7d4; font-size: 17px; }
.lede { margin: 2px 0 10px; color: var(--plum-soft); font-size: 16px; }
h3.sub { margin: 14px 0 2px; font-size: 18px; font-weight: 600; }
.row { display: flex; gap: 10px; margin: 12px 0 6px; }
input {
  flex: 1; min-width: 0; min-height: 52px; padding: 10px 16px; border-radius: 18px; border: 2px solid var(--sand);
  background: #fff; color: var(--plum); font: inherit; font-size: 18px; -webkit-appearance: none; appearance: none;
}
input:focus { outline: none; border-color: var(--leaf); }

.starters { display: grid; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 10px; margin: 8px 0; }
.starter {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 3px; padding: 10px 8px 12px;
  border-radius: 22px; border: 2px solid var(--sand); background: var(--cream2);
}
.starter b { font-size: 18px; }
.starter span { color: var(--plum-soft); font-size: 13px; line-height: 1.3; }
.starter.on { border-color: var(--leaf); background: #eef8e8; box-shadow: 0 0 0 3px rgba(79, 174, 127, 0.25); }
.lvl { font-style: normal; font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: #e7f4e0; color: #2e6b45; }
.lvl.medium { background: #fbefd2; color: #7a5410; }
.lvl.hard { background: #f8e0dc; color: #a2433a; }
.hues { display: flex; flex-wrap: wrap; gap: 9px; margin: 10px 0 4px; }
.hue { width: 42px; height: 42px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--sand); padding: 0; }
.hue.on { box-shadow: 0 0 0 3px var(--plum); transform: scale(1.08); }

.fam { background: var(--cream2); border-radius: 22px; padding: 12px 14px; margin: 10px 0; box-shadow: inset 0 0 0 2px var(--sand); }
.fam-head { display: flex; align-items: center; gap: 12px; }
.fam .art, .listrow .art { flex: none; display: grid; place-items: center; background: #fff; box-shadow: inset 0 0 0 2px var(--sand); }
.fam .art { width: 62px; height: 62px; border-radius: 18px; }
.fam .title { flex: 1; min-width: 0; }
.fam h3 { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.15; }
.fam .who { color: var(--plum-soft); font-size: 14px; }
.stars { margin-top: 3px; font-size: 20px; letter-spacing: 2px; color: #f2b84b; }
.stars .off { color: #e6dccb; }
.status { display: inline-block; margin-top: 3px; font-size: 14px; font-weight: 600; padding: 3px 11px; border-radius: 999px; }
.status.alive { background: var(--mint); color: #23704f; }
.status.gone { background: #f8e0dc; color: #a2433a; }
.status.wait { background: #fbefd2; color: #8a6418; }
.fate { margin: 8px 0 4px; font-size: 16px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 2px; }
.badge { display: inline-flex; gap: 5px; padding: 5px 10px; border-radius: 999px; background: #fff; box-shadow: inset 0 0 0 2px var(--sand); font-size: 14px; }
.fam-foot { display: flex; gap: 8px; margin-top: 8px; }
.fam-foot:empty { display: none; }
.listrow { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 2px dashed var(--sand); }
.listrow:last-child { border-bottom: 0; }
.listrow .art { width: 48px; height: 48px; border-radius: 15px; }
.listrow .who { flex: 1; min-width: 0; font-size: 16px; }
.listrow .who small { display: block; color: var(--plum-soft); font-size: 13.5px; }
.row-btns { display: flex; gap: 6px; flex: none; }
.tag { font-size: 12.5px; padding: 1px 8px; border-radius: 99px; background: #fff1c9; white-space: nowrap; }
.empty { text-align: center; padding: 16px 8px 8px; color: var(--plum-soft); font-size: 16px; }
.empty .big { font-size: 44px; display: block; }
.menu-list { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 12px; }
.about { margin: 4px 2px; }
#buildStamp { font-size: 12px; opacity: 0.7; }

/* ---- bigger screens ---- */
@media (min-width: 700px) {
  .top { grid-template-columns: auto 1fr auto; grid-template-areas: "pill chips menu"; }
  .chip.wide-only { display: inline-flex; }
  #toasts { top: calc(var(--safe-t) + 70px); }
  .sheet { left: auto; right: 12px; top: calc(var(--safe-t) + 70px); bottom: 12px; width: 420px; max-height: none; border-radius: 28px; padding-bottom: 20px; }
  .grab { display: none; }
}

/* ---- phone held sideways: the sheet becomes a side panel, the dock a slim bar ---- */
@media (orientation: landscape) and (max-height: 520px) {
  .top { grid-template-columns: auto 1fr auto; grid-template-areas: "pill chips menu"; top: calc(var(--safe-t) + 8px); }
  .pill { padding: 7px 13px; font-size: 14px; }
  .round { width: 42px; height: 42px; }
  #toasts { top: calc(var(--safe-t) + 58px); left: calc(var(--safe-l) + 10px); transform: none; width: min(400px, 50%); align-items: flex-start; }
  .bottom { left: calc(var(--safe-l) + 10px); right: auto; width: min(400px, 52%); bottom: calc(var(--safe-b) + 8px); gap: 6px; }
  .dock { align-self: stretch; }
  .dock button { min-height: 48px; flex-direction: row; gap: 5px; }
  .dock .ico { font-size: 19px; }
  .dock .lbl { font-size: 12.5px; }
  .dock button:not(#dockPlay):not(#camBtn) .lbl { display: none; }
  .crit { padding: 9px 12px; }
  .crit .art { width: 52px; height: 52px; }
  .crit-stats { margin-top: 6px; }
  .crit-actions { margin-top: 6px; }
  .sheet { left: auto; top: calc(var(--safe-t) + 58px); bottom: calc(var(--safe-b) + 8px); right: calc(var(--safe-r) + 8px);
    width: min(400px, 50vw); max-height: none; border-radius: 26px; padding: 6px 16px 16px; }
  .grab { display: none; }
  .hint { top: 50%; }
  .pop { bottom: 60px; left: 0; right: auto; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
