:root {
  --grass: #8fc94f;
  --ink: #3b2a1c;
  --ink-soft: #7a6553;
  --card: #fffaf0;
  --line: #ecdfc8;
  --green: #5cc13b;
  --green-dark: #3d8f24;
  --orange: #f6a23a;
  --orange-dark: #c4741a;
  --blue: #4aa8e8;
  --blue-dark: #2a77b3;
  --red: #e8574a;
  --gold: #ffcc33;
  --display: "Lilita One", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --body: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--grass);
  color: var(--ink);
  font-family: var(--body);
  font-weight: 800;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }

#app {
  height: 100%;
  display: flex;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
#world {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#world.pointer { cursor: pointer; }

/* ---- HUD ---------------------------------------------------------------- */
#hud {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: rgba(40, 28, 18, 0.55);
  color: #fff;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.pill.cash { font-family: var(--display); font-size: 26px; line-height: 1; padding-right: 16px; }
.pill.cash small { font-family: var(--body); font-size: 13px; font-weight: 900; color: #c8f59a; }
#cash { min-width: 3ch; font-variant-numeric: tabular-nums; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
.pill.cash.bump #cash { animation: bump 0.25s ease-out; }
@keyframes bump { 40% { transform: scale(1.12); } }
.coin {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff4b0 0 18%, #ffd23f 19% 62%, #e8a910 63%);
  box-shadow: inset 0 -2px 0 #c88a00;
  flex: none;
}
.guide {
  margin: 0 10px 10px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 8px 14px 10px;
  border: 0; border-radius: 16px;
  background: #fffaf0;
  box-shadow: 0 3px 0 #e2c995, 0 0 0 2px #f6c36a inset;
  text-align: left;
  color: var(--ink);
  flex: none;
}
.guide-kicker { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; color: #c4741a; }
.guide b { font-family: var(--display); font-weight: 400; font-size: 19px; line-height: 1.15; }
.guide span:last-child { font-size: 13px; color: var(--ink-soft); line-height: 1.3; }
.guide.can { box-shadow: 0 4px 0 var(--green-dark), 0 0 0 3px var(--green) inset; }
.guide.can .guide-kicker::after { content: "  · tap to do it"; color: var(--green-dark); }
.guide:active { transform: translateY(2px); }
.earn { margin: 0 10px 10px; padding: 8px 14px 10px; border-radius: 16px; background: #fffaf0; box-shadow: 0 3px 0 var(--line); flex: none; }
.earn-kicker { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); }
.earn p { margin: 2px 0 0; font-size: 13.5px; line-height: 1.4; }
.earn p b { font-weight: 900; }

.toast {
  position: absolute;
  left: 50%; bottom: 18px;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 14px;
  background: rgba(40, 28, 18, 0.82);
  color: #fff;
  font-size: 15px;
  width: max-content; max-width: calc(100% - 24px);
  text-align: center; line-height: 1.3;
  pointer-events: none;
  animation: toast-in 0.25s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* rush horn and stars */
.pill[hidden] { display: none; }
.pill.stars { font-family: var(--display); font-size: 18px; color: #ffd23f; padding: 6px 14px; }
.pill.rush {
  position: relative; overflow: hidden;
  border: 0; font: inherit; color: #fff; cursor: pointer;
  padding: 8px 14px; gap: 6px;
  background: linear-gradient(#ffc066, var(--orange)); box-shadow: 0 3px 0 var(--orange-dark);
}
.pill.rush b { font-family: var(--display); font-weight: 400; font-size: 18px; position: relative; }
.pill.rush small { font-size: 12px; font-weight: 900; position: relative; }
.pill.rush i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(255,255,255,0.35); }
.pill.rush.wait { background: rgba(40, 28, 18, 0.55); box-shadow: none; cursor: default; }
.pill.rush.on { background: linear-gradient(#7fd85a, var(--green)); box-shadow: 0 3px 0 var(--green-dark); }
.pill.rush:not(.wait):active { transform: translateY(2px); }

/* contracts */
.deals { margin: 0 10px 10px; padding: 8px 12px 10px; border-radius: 16px; background: #fffaf0; box-shadow: 0 3px 0 #e2c995, 0 0 0 2px #f6c36a inset; flex: none; }
.deals[hidden] { display: none; }
.deals .kick { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; color: #c4741a; display: flex; justify-content: space-between; align-items: center; }
.deal { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.deal canvas { width: 30px; height: 30px; flex: none; }
.deal .what { flex: 1; font-size: 14px; line-height: 1.2; }
.deal .what small { display: block; font-size: 12px; color: var(--green-dark); font-weight: 900; }
.deal button, .deals .drop {
  border: 0; border-radius: 10px; padding: 6px 12px; font-family: var(--display); font-size: 15px; color: #fff;
  background: linear-gradient(#ffc066, var(--orange)); box-shadow: 0 2px 0 var(--orange-dark);
}
.deals .drop { background: #fff; color: var(--ink-soft); box-shadow: 0 2px 0 var(--line); font-family: var(--body); font-weight: 900; font-size: 12px; padding: 3px 10px; }
.deal button:disabled { background: #d9ccb4; box-shadow: 0 2px 0 #bfae90; }
.bar { height: 10px; border-radius: 5px; background: #efe3cb; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #7fd85a, var(--green)); border-radius: 5px; transition: width 0.3s; }
.deals .tip { margin: 6px 0 0; font-size: 12.5px; line-height: 1.35; color: var(--ink); }
.deals .tip button { border: 0; border-radius: 8px; padding: 2px 8px; margin-left: 4px; background: var(--red); color: #fff; font-weight: 900; font-size: 12px; }

/* a new valley */
.valley { margin: 0 10px 10px; padding: 8px 14px 10px; border-radius: 16px; background: #eef6ff; box-shadow: 0 3px 0 #c9dcf0; flex: none; }
.valley[hidden] { display: none; }
.valley .kick { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; color: var(--blue-dark); }
.valley p { margin: 2px 0 6px; font-size: 13.5px; line-height: 1.4; }
.valley button {
  border: 0; border-radius: 12px; padding: 8px 14px; font-family: var(--display); font-size: 16px; color: #fff;
  background: linear-gradient(#7cc2f2, var(--blue)); box-shadow: 0 3px 0 var(--blue-dark);
}
.valley button:disabled { background: #c9d4de; box-shadow: 0 3px 0 #aab7c4; }
.valley button.armed { background: var(--red); box-shadow: 0 3px 0 #a8342b; }

/* machine cards: on/off and milestones */
.tog {
  margin-left: auto; flex: none; align-self: flex-start;
  border: 0; border-radius: 999px; padding: 4px 12px; font-family: var(--display); font-size: 14px; color: #fff;
  background: var(--green); box-shadow: 0 2px 0 var(--green-dark);
}
.tog.off { background: #8a7a62; box-shadow: 0 2px 0 #6b5d49; }
.card .ms { font-size: 12px; font-weight: 900; color: var(--blue-dark); margin-top: 2px; }
.hint-btn {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 0;
  background: #fff3dc; box-shadow: 0 2px 0 #ecd3a3; font-size: 13px; font-weight: 900; color: #c4741a;
}
.hint-btn[hidden], .guide[hidden] { display: none; }

/* ---- panel -------------------------------------------------------------- */
#panel {
  flex: none;
  width: 370px;
  display: flex;
  flex-direction: column;
  background: #f6ead3;
  box-shadow: -4px 0 16px rgba(60, 40, 10, 0.18);
  z-index: 1;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 8px;
}
.panel-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 22px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.restart-btn {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 0;
  background: #fff; box-shadow: 0 2px 0 var(--line); font-size: 13px; font-weight: 900; color: var(--ink-soft);
}
.help-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: #fff; box-shadow: 0 2px 0 var(--line); font-family: var(--display); font-size: 18px;
}
#rows {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 2px 10px 12px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.card {
  margin-bottom: 10px;
  padding: 10px 12px 12px;
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 3px 0 var(--line);
}
.card.sel { box-shadow: 0 3px 0 var(--line), 0 0 0 3px #f6a23a inset; }
.card.next { background: #fff3dc; box-shadow: 0 3px 0 #ecd3a3, 0 0 0 2px #f6c36a inset; }
.card .head { display: flex; gap: 10px; align-items: flex-start; }
.card .icon { width: 46px; height: 46px; border-radius: 12px; flex: none; }
.card .kicker { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; color: #c4741a; }
.card .name { font-family: var(--display); font-size: 19px; line-height: 1.1; }
.card p { margin: 3px 0 0; font-size: 13.5px; line-height: 1.35; color: var(--ink); font-weight: 700; }
.card p b { font-weight: 900; }
.status { margin: 8px 0 0; padding: 4px 10px; border-radius: 10px; font-size: 12.5px; font-weight: 900; }
.status.ok { background: #e3f4d4; color: #2f7a1a; }
.status.idle { background: #efe8da; color: var(--ink-soft); }
.status.mid { background: #fdecc8; color: #9a5b00; }
.status.bad { background: #fde0dc; color: #b8352d; }
.btns { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.opt {
  flex: 1 1 0;
  min-width: 96px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "label cost" "change change" "gain gain";
  align-items: baseline;
  gap: 1px 6px;
  padding: 6px 10px 7px;
  border: 0; border-radius: 12px;
  background: linear-gradient(#7fd85a, var(--green));
  box-shadow: 0 3px 0 var(--green-dark);
  color: #fff;
  text-align: left;
  text-shadow: 0 1px 0 rgba(0, 60, 0, 0.3);
}
.opt b { grid-area: label; font-family: var(--display); font-weight: 400; font-size: 15px; }
.opt em { grid-area: cost; font-style: normal; font-family: var(--display); font-size: 15px; }
.opt span { grid-area: change; font-size: 12px; font-weight: 900; }
.opt small { grid-area: gain; font-size: 11px; font-weight: 900; opacity: 0.95; }
.opt small:empty { display: none; }
.opt .nogain { opacity: 0.8; }
.opt.build, .opt.hire { background: linear-gradient(#ffc066, var(--orange)); box-shadow: 0 3px 0 var(--orange-dark); }
.opt:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--green-dark); }
.opt:disabled { background: #d9ccb4; box-shadow: 0 3px 0 #bfae90; color: #fffaf0; text-shadow: none; cursor: default; }
.why { margin-top: 6px; font-size: 12px; font-weight: 800; color: #b8352d; }
.why:empty { display: none; }

/* ---- overlays ----------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: var(--mc-top, 0) 0 0 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(60, 90, 30, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 5;
  overflow-y: auto;
}
.overlay[hidden] { display: none; }
.card-pop {
  width: min(460px, 100%);
  padding: 24px 24px 22px;
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 6px 0 var(--line), 0 20px 40px rgba(40, 30, 10, 0.3);
  text-align: center;
  font-weight: 700;
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.card-pop.wide { width: min(560px, 100%); text-align: left; }
.card-pop.wide h2 { text-align: center; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.card-pop h2 { margin: 0 0 8px; font-family: var(--display); font-weight: 400; font-size: 30px; }
.logo {
  font-family: var(--display);
  font-size: 54px;
  line-height: 1;
  color: #ffb43a;
  -webkit-text-stroke: 3px #7a3e0e;
  paint-order: stroke fill;
  text-shadow: 0 5px 0 #7a3e0e;
  margin-bottom: 10px;
}
.lede { font-size: 16px; line-height: 1.4; }
.legend { text-align: left; padding-left: 20px; font-size: 14px; line-height: 1.45; color: var(--ink); }
.legend li { margin-bottom: 6px; }
.legend b { font-weight: 900; }
.promise { font-size: 13px; color: var(--green-dark); }
.small { font-size: 13px; color: var(--ink-soft); line-height: 1.4; }
.kicker { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-soft); }
.big-money { font-family: var(--display); font-size: 46px; color: var(--green-dark); margin: 4px 0; }
.big-stars { font-family: var(--display); font-size: 44px; color: #e3a21a; margin: 4px 0; }
.primary {
  margin-top: 8px;
  padding: 12px 34px;
  border: 0; border-radius: 16px;
  background: linear-gradient(#7fd85a, var(--green));
  box-shadow: 0 5px 0 var(--green-dark);
  color: #fff;
  font-family: var(--display); font-size: 22px;
  text-shadow: 0 2px 0 rgba(0, 60, 0, 0.35);
}
.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--green-dark); }
.secondary {
  margin-top: 8px; padding: 12px 22px; border: 0; border-radius: 16px;
  background: #fff; box-shadow: 0 5px 0 var(--line); font-family: var(--display); font-size: 20px;
}
.link { border: 0; background: none; padding: 0; text-decoration: underline; color: var(--red); font-weight: 800; }

/* ---- narrow / portrait: the panel becomes a bottom sheet ------------------- */
/* Closed, the sheet shows only its header and the Next step card, so the world
   gets most of the screen; the selected station's upgrades float over it there.
   "Stations" opens the sheet over the world with every card. */
.sheet-btn, .back-btn { display: none; }
.restart-btn.armed, .link.armed { background: var(--red); color: #fff; box-shadow: 0 2px 0 #a8342b; }
.link.armed { padding: 4px 10px; border-radius: 999px; text-decoration: none; }
@media (max-width: 760px), (orientation: portrait) and (max-width: 1000px) {
  #app { display: block; position: relative; }
  #stage { position: absolute; top: 0; left: 0; right: 0; bottom: var(--sheet, 130px); }
  #panel {
    position: absolute;
    left: env(safe-area-inset-left); right: env(safe-area-inset-right); bottom: 0;
    width: auto;
    max-height: 82%;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 16px rgba(60, 40, 10, 0.18);
    border-radius: 18px 18px 0 0;
  }
  .panel-head { padding: 8px 10px 6px 14px; }
  .panel-head h2 { font-size: 19px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sheet-btn {
    display: block;
    height: 32px; padding: 0 12px; border-radius: 999px; border: 0;
    background: var(--orange); box-shadow: 0 2px 0 var(--orange-dark); color: #fff;
    font-family: var(--display); font-size: 15px;
  }
  .sheet-btn::after { content: " ▲"; font-size: 11px; }
  #panel.open .sheet-btn { background: #fff; color: var(--ink); box-shadow: 0 2px 0 var(--line); }
  #panel.open .sheet-btn::after { content: " ▼"; }
  #panel:not(.open) .restart-btn, #panel:not(.open) .earn, #panel:not(.open) #rows, #panel:not(.open) .valley { display: none; }
  #panel.focus:not(.open) .deals { display: none; }
  #rows { flex: 1 1 auto; min-height: 0; }
  /* A station tapped in the world: its card replaces the Next step card. */
  .back-btn {
    height: 32px; padding: 0 12px; border-radius: 999px; border: 0;
    background: #fff; box-shadow: 0 2px 0 var(--line); font-size: 13px; font-weight: 900; color: var(--ink-soft);
  }
  #panel.focus:not(.open) .back-btn { display: block; }
  #panel.focus:not(.open) .guide { display: none; }
  #panel.focus:not(.open) #rows { display: block; overflow: visible; padding-bottom: 0; }
  #panel.focus:not(.open) #rows .card:not(.sel) { display: none; }
  #panel.focus:not(.open) .card.sel { box-shadow: 0 3px 0 var(--line); }
  #panel.focus:not(.open) .card .head { align-items: center; }
  #panel.focus:not(.open) .card .head p { display: none; }
  #panel.focus:not(.open) .card .icon { width: 34px; height: 34px; border-radius: 9px; }
  #panel.focus:not(.open) .btns { display: grid; grid-template-columns: 1fr 1fr; }
  .pill.cash { font-size: 22px; }
  .guide { margin-bottom: 8px; padding: 6px 12px 8px; }
  .guide b { font-size: 17px; }
  .guide span:last-child {
    font-size: 12px;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  }
  .earn { margin-bottom: 8px; padding: 6px 12px 8px; }
  .earn p span { display: none; }
  .deals { margin-bottom: 8px; padding: 6px 12px 8px; }
  .deal { margin-top: 3px; }
  .deal canvas { width: 24px; height: 24px; }
  .deal .what { font-size: 13px; }
  .deal .what small { font-size: 11.5px; }
  .deal button { padding: 4px 12px; font-size: 14px; }
  .deals .tip { font-size: 12px; margin-top: 4px; }
}
