/* ============================================================
   EggWorld — estilo (mobile first)
   A fazenda é um canvas em tela cheia; HUD, controles e painéis
   ficam por cima.
   ============================================================ */
:root {
  --bg: #2b2350;
  --card: #ffffff;
  --card2: #f5f1ff;
  --ink: #2a2440;
  --muted: #7a7294;
  --line: #e4ddf5;
  --good: #2eb872;
  --bad: #ff5a6e;
  --warn: #ffb020;
  --gold: #ffc233;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: 'Baloo 2', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; }

#app {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  height: 100dvh;
  overflow: hidden;
}
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }

/* ---------------- HUD (topo) ---------------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5;
  padding: calc(8px + var(--safe-t)) 12px 6px;
  pointer-events: none;
}
#hud button { pointer-events: auto; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hud-row + .hud-row { margin-top: 6px; }
.hud-money {
  background: rgba(30, 18, 60, .55); color: #fff; border-radius: 16px; padding: 4px 12px 5px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.hud-money .m { font-size: 26px; font-weight: 800; line-height: 1.05; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.hud-money .inc { font-size: 13px; font-weight: 800; color: #b9f6ca; line-height: 1; }
.world-pill, .egg-pill, .chip {
  background: rgba(30, 18, 60, .55); color: #fff; border-radius: 99px; font-weight: 800; font-size: 12px;
  padding: 4px 10px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.world-pill { max-width: 55%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; align-self: flex-start; }
.egg-pill { white-space: nowrap; min-width: 0; overflow: hidden; display: flex; align-items: center; gap: 6px; font-size: 14px; padding: 3px 12px 3px 6px; }
.egg-pill b { opacity: .7; }
.chips { display: flex; gap: 6px; flex: none; }
.chip { white-space: nowrap; }
.chip { transition: background .2s; }
.chip.bad { background: rgba(255, 90, 110, .92); animation: pulse 1.2s infinite; }
.chip.warn { background: rgba(255, 176, 32, .9); }

/* ---------------- Controles (base) ---------------- */
#controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 0 8px calc(8px + var(--safe-b));
  display: flex; align-items: flex-end; justify-content: space-between; gap: 6px;
  pointer-events: none;
}
#controls > * { pointer-events: auto; }
.ctl-side { display: flex; gap: 6px; }
.ctl {
  position: relative; width: 62px; height: 62px; border-radius: 18px;
  background: #fff; box-shadow: 0 4px 0 rgba(40, 20, 70, .35);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 800; color: var(--ink); line-height: 1.1;
}
.ctl .i { font-size: 24px; line-height: 1.1; }
.ctl:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(40, 20, 70, .35); }
.dot {
  position: absolute; top: -3px; right: -3px; width: 14px; height: 14px; border-radius: 99px;
  background: var(--bad); border: 2px solid #fff; animation: pulse 1.4s infinite;
}
.dot[hidden] { display: none; }
.hatch-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 2px; }
.species-chip {
  background: rgba(30, 18, 60, .7); color: #fff; font-size: 12px; font-weight: 800; border-radius: 99px; padding: 2px 10px;
  white-space: nowrap;
}
.hatch-btn {
  width: 96px; height: 116px; position: relative;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 35% 28%, #fff 0 10%, #ffe9a8 35%, #ffb020 100%);
  box-shadow: inset -6px -8px 0 rgba(0,0,0,.1), 0 6px 0 #c47f00, 0 10px 18px rgba(0,0,0,.3);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; color: #6b3f00; line-height: 1.05; touch-action: none;
  transition: transform .06s;
}
.hatch-btn .chick { font-size: 32px; }
.hatch-btn .lbl { font-size: 15px; }
.hatch-btn .n { font-size: 12px; opacity: .8; }
.hatch-btn.pressed { transform: translateY(4px) scale(.96); box-shadow: inset -6px -8px 0 rgba(0,0,0,.1), 0 2px 0 #c47f00, 0 4px 10px rgba(0,0,0,.3); }
.hatch-btn.full { filter: grayscale(.7); }

/* ---------------- Painel deslizante ---------------- */
#sheet { position: absolute; inset: 0; z-index: 20; }
#sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 8, 35, 0); transition: background .2s; }
#sheet.open .sheet-backdrop { background: rgba(15, 8, 35, .35); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; height: 74%;
  background: #2f2658; border-radius: 26px 26px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2,.9,.3,1.1);
}
#sheet.open .sheet-panel { transform: none; }
.sheet-grab { width: 44px; height: 5px; border-radius: 9px; background: rgba(255,255,255,.35); margin: 8px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 14px 8px; color: #fff; flex: none; }
.sheet-title { font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-x { width: 36px; height: 36px; border-radius: 12px; background: rgba(255,255,255,.14); color: #fff; font-size: 16px; font-weight: 800; flex: none; }
.sheet-body {
  flex: 1; overflow-y: auto; padding: 2px 12px calc(20px + var(--safe-b));
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.sheet-tools { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.sub-title { color: #fff; font-size: 15px; font-weight: 800; margin: 12px 4px 6px; display: flex; justify-content: space-between; align-items: center; }
.sub-title small { font-size: 12px; opacity: .7; }

/* ---------------- Cartões ---------------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px;
  box-shadow: 0 4px 0 rgba(0,0,0,.22);
}
.card.soft { background: var(--card2); }
.card.done { background: #e3fbe9; }
.card.locked { opacity: .6; }
.card.current { outline: 3px solid var(--gold); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; justify-content: space-between; gap: 6px; font-weight: 700; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.hint { background: rgba(255,255,255,.1); color: #fff; border-radius: 14px; padding: 8px 12px; font-size: 13px; margin: 0 0 8px; line-height: 1.3; }

.up { display: flex; align-items: center; gap: 10px; }
.up .ico { font-size: 26px; width: 42px; height: 42px; border-radius: 12px; background: var(--card2); display: grid; place-items: center; flex: none; }
.up .name { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 15px; line-height: 1.15; }
.up .name > span:first-child { min-width: 0; }
.up .eff { font-size: 13px; font-weight: 800; color: var(--good); line-height: 1.2; }
.up .desc { font-size: 11.5px; color: var(--muted); line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.up .own { font-size: 12px; font-weight: 800; margin-top: 2px; }
.lvl { flex: none; white-space: nowrap; font-size: 11px; font-weight: 800; background: var(--card2); border-radius: 99px; padding: 0 7px; color: var(--muted); }
.pips { display: flex; gap: 2px; margin-top: 4px; }
.pips i { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.pips i.on { background: var(--good); }
.cost-line { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; font-weight: 800; color: var(--ink); margin-top: 2px; }
.cost-line small { color: var(--muted); font-weight: 700; }
.cost-line .no { color: var(--bad); }
.summary .bar { margin: 4px 0; }
.summary .name { font-weight: 800; }
.summary .desc { font-size: 13px; color: var(--muted); }

/* ---------------- Botões ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 1px; flex-direction: column;
  background: var(--good); color: #fff; font-weight: 800;
  border-radius: 14px; padding: 6px 10px; min-height: 46px; min-width: 88px; flex: none;
  box-shadow: 0 4px 0 #1f8a54; line-height: 1.05; font-size: 15px;
  transition: transform .05s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #1f8a54; }
.btn:disabled { background: #cfc8e2; box-shadow: 0 4px 0 #aaa1c4; color: #fff; cursor: default; }
.btn.blue { background: #3d8bff; box-shadow: 0 4px 0 #2560c4; }
.btn.purple { background: #8a5cff; box-shadow: 0 4px 0 #5b36c4; }
.btn.gold, .btn.gold:disabled.keep { background: #ffb020; box-shadow: 0 4px 0 #c47f00; }
.btn.red { background: var(--bad); box-shadow: 0 4px 0 #c43347; }
.btn.ghost { background: rgba(255,255,255,.14); color: #fff; box-shadow: none; }
.btn.wide { width: 100%; margin-top: 4px; }
.btn .sub { font-size: 11px; font-weight: 700; opacity: .92; }
.btn.maxed { background: #8a5cff; box-shadow: 0 4px 0 #5b36c4; }
.sheet-body .btn.ghost.wide { margin: 8px 0; }

.seg { display: flex; background: rgba(0,0,0,.28); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { color: #fff; font-weight: 800; font-size: 13px; padding: 3px 12px; border-radius: 9px; }
.seg button.on { background: #fff; color: var(--ink); }

/* ---------------- Ovos (arte em CSS) ---------------- */
.egg {
  --c1: #f3e2c7; --c2: #d9b98b;
  width: 30px; height: 38px; flex: none;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 35% 28%, #fff 0 8%, var(--c1) 30%, var(--c2) 100%);
  box-shadow: inset -3px -4px 0 rgba(0,0,0,.08), 0 2px 0 rgba(0,0,0,.15);
  position: relative;
}
.egg.spots::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background:
    radial-gradient(circle at 60% 40%, var(--c2) 0 6%, transparent 7%),
    radial-gradient(circle at 30% 62%, var(--c2) 0 5%, transparent 6%),
    radial-gradient(circle at 68% 72%, var(--c2) 0 4%, transparent 5%);
  opacity: .8;
}
.egg.sm { width: 20px; height: 26px; }
.egg.xs { width: 14px; height: 18px; }
.egg.locked { filter: grayscale(1) brightness(.6); }
.egg-row { display: flex; gap: 4px; margin-top: 4px; }
.planet { background: radial-gradient(circle at 35% 30%, #fff 0 6%, var(--w1) 30%, var(--w2) 100%) !important; border-radius: 50% !important; }

/* ---------------- Raças ---------------- */
.species-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.sp-chip {
  display: flex; align-items: center; gap: 4px; background: rgba(255,255,255,.14); color: #fff;
  padding: 4px 12px 4px 8px; border-radius: 99px; font-size: 13px; font-weight: 800; border: 2px solid transparent;
}
.sp-chip.on { background: #fff; color: var(--ink); border-color: var(--gold); }
.chick-ico { display: inline-block; }
.sp-card .big-ico { font-size: 36px; width: 46px; text-align: center; flex: none; }
.traits { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; }
.trait { font-size: 11px; font-weight: 800; padding: 0 7px; border-radius: 99px; background: var(--card2); }
.trait.up { background: #dcf7e8; color: #13794a; }
.trait.down { background: #ffe4e8; color: #b3263a; }

/* ---------------- Recursos ---------------- */
.res-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.res-pill {
  display: flex; align-items: center; gap: 4px; background: rgba(255,255,255,.12); color: #fff;
  border-radius: 99px; padding: 2px 10px 2px 6px; font-weight: 800; font-size: 14px;
}
.res-pill small { font-size: 10.5px; opacity: .7; font-weight: 700; }

/* ---------------- Naves ---------------- */
.ship-hero {
  background: linear-gradient(160deg, #4a36a0, #1c1538); color: #fff; border-radius: 22px;
  padding: 14px; margin-bottom: 8px; position: relative; overflow: hidden; box-shadow: 0 4px 0 rgba(0,0,0,.25);
}
.ship-hero .rocket { font-size: 50px; position: absolute; right: 12px; top: 6px; animation: bob 2s ease-in-out infinite; }
.ship-hero h3 { margin: 0 0 2px; font-size: 19px; }
.colony-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.colony-row .bar { background: rgba(255,255,255,.18); }
.expedition .ico, .mission .ico { font-size: 28px; }
.expedition { display: flex; align-items: center; gap: 10px; }
.expedition .ico { width: 42px; text-align: center; }
.reward-list { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; }
.reward { font-size: 12px; font-weight: 800; background: var(--card2); border-radius: 99px; padding: 0 8px; }

/* ---------------- Barras ---------------- */
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.bar > i { display: block; height: 100%; background: var(--good); border-radius: 99px; transition: width .3s; }
.bar.gold > i { background: linear-gradient(90deg, #ffb020, #ffd86e); }

/* ---------------- Menu ---------------- */
.menu-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 4px; }
.menu-item {
  position: relative; background: #fff; border-radius: 16px; padding: 8px 2px; font-size: 11.5px; font-weight: 800;
  display: flex; flex-direction: column; align-items: center; gap: 2px; box-shadow: 0 4px 0 rgba(0,0,0,.22);
}
.menu-item .i { font-size: 26px; }
.toggle { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-weight: 800; }
.toggle input { width: 22px; height: 22px; accent-color: var(--good); }
.menu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); font-weight: 700; }
.kv:last-child { border: 0; }

/* ---------------- Toasts e modais ---------------- */
#toasts {
  position: absolute; left: 12px; right: 12px; bottom: calc(150px + var(--safe-b));
  display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; z-index: 40;
}
.toast {
  background: rgba(28,21,56,.9); color: #fff; padding: 6px 12px; border-radius: 12px;
  font-weight: 700; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.3); text-align: center;
  animation: toastin .25s ease-out;
}
#modal {
  position: absolute; inset: 0; background: rgba(10,6,25,.6); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#modal[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 24px; padding: 18px; width: 100%; max-width: 420px;
  max-height: 85dvh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.4);
  animation: toastin .2s ease-out;
}
.modal-box h2 { margin: 0 0 6px; font-size: 22px; }
.modal-box .emoji { font-size: 54px; text-align: center; }
.modal-box textarea { width: 100%; min-height: 110px; border-radius: 12px; border: 2px solid var(--line); padding: 8px; font-size: 12px; font-family: monospace; user-select: text; -webkit-user-select: text; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }
.modal-box .kv span:last-child { text-align: right; }

@keyframes toastin { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

@media (max-width: 380px) {
  #controls { padding-left: 6px; padding-right: 6px; gap: 4px; }
  .ctl-side { gap: 4px; }
  .ctl { width: 50px; height: 54px; font-size: 9px; border-radius: 15px; }
  .ctl .i { font-size: 20px; }
  .hatch-btn { width: 82px; height: 100px; }
  .hatch-btn .chick { font-size: 26px; }
  .hud-money .m { font-size: 22px; }
  .egg-pill { font-size: 12px; }
  .chip { font-size: 11px; padding: 3px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; }
}
/* com um painel aberto, os avisos ficam logo acima dele */
#sheet.open ~ #toasts { bottom: calc(74% + 10px); }
