:root {
  /* Crafted brand palette (from craftedup.com) */
  --page: #f3f4f6;
  --panel: #ffffff;
  --ink: #272727;
  --muted: #696969;
  --line: #e2e4e8;
  --accent: #3b5bf8;
  --good: #489e96;
  --human: #272727;
  --ai: #3b5bf8;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Rubik', Helvetica, system-ui, sans-serif;
  background: var(--page);
  color: var(--ink);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; }
.icon { display: block; flex: none; }

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
  min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 19px; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.brand .logo { height: 26px; width: auto; display: block; }
.brand .game-name { padding-left: 12px; border-left: 2px solid var(--line); line-height: 26px; }
.stat { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.stat .v { font-size: 18px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.bar { width: 140px; height: 6px; border-radius: 99px; background: rgba(43, 42, 40, .1); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--ink); border-radius: 99px; transition: width .3s; }
.happy .bar > div { background: var(--good); }
.controls { margin-left: auto; display: flex; gap: 6px; }
.controls button {
  width: 36px; height: 36px; border-radius: 50%; border: none; display: grid; place-items: center;
  background: var(--panel); cursor: pointer; font-weight: 700; font-size: 14px;
  box-shadow: 0 0 0 1px var(--line);
}
.controls button:hover { box-shadow: 0 0 0 2px var(--ink); }

/* ---------- Stage ---------- */
#stage { position: relative; min-height: 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 8px 16px; border-radius: 99px; font-size: 14px; font-weight: 500;
  max-width: calc(100% - 32px); width: max-content; text-align: center; pointer-events: none;
}
#hint:empty { display: none; }
#toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%) translateY(-6px);
  background: #fff; color: var(--ink); padding: 9px 16px; border-radius: 99px;
  font-size: 14px; font-weight: 600; opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none; max-width: calc(100% - 32px); width: max-content; text-align: center;
  box-shadow: 0 0 0 2px var(--ink);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#rotateTip {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; border-radius: 99px;
  background: #fff; box-shadow: 0 0 0 2px var(--ink); font-size: 13px; font-weight: 600;
  white-space: nowrap; animation: drop-in .3s ease-out;
}
#rotateTip .rot-ic { display: grid; animation: tilt 2.4s ease-in-out infinite; }
#rotateTip button {
  width: 26px; height: 26px; border-radius: 50%; border: none; background: var(--page);
  display: grid; place-items: center; cursor: pointer;
}
@keyframes drop-in { from { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes tilt { 0%, 55%, 100% { transform: rotate(-90deg); } 70%, 90% { transform: rotate(0deg); } }

/* ---------- Toolbar ---------- */
#toolbar {
  display: flex; gap: 24px; padding: 10px 16px 14px;
  flex-wrap: wrap; align-items: flex-end; touch-action: none;
  transition: background .15s;
}
.group { display: flex; flex-direction: column; gap: 6px; }
.legend { margin-left: auto; }
.glabel { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.items { display: flex; gap: 8px; flex-wrap: wrap; }
.tool {
  --c: var(--ink); --t: #fff;
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 8px 6px 7px;
  border-radius: 99px; font-weight: 600; font-size: 14px; cursor: grab;
  background: #fff; box-shadow: 0 0 0 2px var(--c); color: var(--ink);
  transition: transform .12s, box-shadow .12s;
}
.tool .ic {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--t); color: var(--c);
}
.tool:hover { transform: translateY(-2px); }
.tool .n {
  background: var(--c); color: #fff; border-radius: 99px; padding: 1px 7px; font-size: 12px; min-width: 22px; text-align: center;
}
.tool.worker { box-shadow: 0 0 0 1px var(--line); }
.tool.worker .n { background: var(--ink); }
.tool.empty { opacity: .4; cursor: not-allowed; transform: none; }
.tool.locked { --c: #c9c2b6; --t: #f1ede6; box-shadow: 0 0 0 2px #d9d2c6 inset; background: transparent; color: var(--muted); }
.worker-ic { display: inline-grid; place-items: center; color: #fff; flex: none; }
.worker-ic.human { background: var(--human); border-radius: 50%; }
.worker-ic.ai { background: var(--ai); border-radius: 30%; }
.legend .items { gap: 10px; }
.legend .items span { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.legend svg { width: 15px; height: 15px; fill: var(--ink); stroke: none; }
.legend .fuzzy svg { fill: #fff; stroke: var(--ink); stroke-width: 1.6; stroke-dasharray: 2.4 1.8; }
#toolbar.drop { background: rgba(218, 121, 101, .12); }
#toolbar.drop::after {
  content: 'Drop here to put the station away'; font-weight: 700; color: #b5523d; align-self: center;
}

/* ---------- Overlay ---------- */
#overlay {
  position: fixed; inset: 0; background: rgba(43, 42, 40, .28); display: flex;
  align-items: center; justify-content: center; z-index: 40; padding: 16px;
  animation: fade .2s ease-out;
}
.card {
  background: var(--panel); border-radius: 24px; padding: 28px 30px; width: 100%; max-width: 580px;
  max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 0 0 3px var(--ink), 0 24px 60px rgba(39, 39, 39, .18);
  user-select: text; -webkit-user-select: text;
  animation: rise .28s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.card h1 { margin: 0 0 6px; font-size: 34px; font-weight: 800; letter-spacing: -0.03em; }
.card h2 { margin: 2px 0 8px; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.card h3 { font-weight: 700; }
.card p { line-height: 1.55; }
.eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.muted { color: var(--muted); }
.steps { padding-left: 0; list-style: none; margin: 18px 0 24px; display: grid; gap: 12px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.6; }
.steps .num {
  flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; margin-top: 1px;
}
.chip {
  --c: var(--ink); --t: #fff;
  display: inline-flex; align-items: center; gap: 5px; vertical-align: -5px;
  padding: 1px 9px 1px 4px; border-radius: 99px; font-weight: 600; font-size: 14px;
  box-shadow: 0 0 0 2px var(--c); background: #fff; color: var(--ink); margin: 0 2px;
}
.chip > .icon { color: var(--c); }
.btn {
  border: none; background: var(--accent); color: #fff; font-weight: 700; padding: 12px 22px;
  border-radius: 99px; cursor: pointer; font-size: 15px; text-decoration: none; display: inline-block;
  transition: transform .12s;
}
.btn:hover { transform: translateY(-1px); }
.btn.secondary { background: #fff; color: var(--ink); box-shadow: 0 0 0 2px var(--ink) inset; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.upgrades { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.upgrade {
  text-align: left; background: #fff; border: none; border-radius: 18px; padding: 18px;
  cursor: pointer; transition: transform .12s, box-shadow .12s; box-shadow: 0 0 0 2px var(--line);
}
.upgrade:hover { transform: translateY(-3px); box-shadow: 0 0 0 3px var(--ink); }
.uicon { width: 40px; height: 40px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; }
.utitle { font-weight: 700; font-size: 17px; margin: 10px 0 4px; }
.utext { font-size: 14px; color: var(--muted); line-height: 1.45; }

.arch {
  display: flex; gap: 16px; align-items: center; background: #fff;
  border-radius: 18px; padding: 18px; margin: 16px 0; box-shadow: 0 0 0 2px var(--line);
}
.arch .big { flex: none; width: 60px; height: 60px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; }
.arch h3 { margin: 0 0 4px; font-size: 21px; }
.arch p { margin: 0; font-size: 14.5px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.stats div { background: #fff; border-radius: 14px; padding: 10px 12px; box-shadow: 0 0 0 1px var(--line); }
.stats b { display: block; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); font-weight: 600; }
.insight { background: #fff; border-radius: 14px; padding: 12px 16px; margin: 10px 0; font-size: 14.5px; line-height: 1.55; box-shadow: 0 0 0 1px var(--line); }
.lead { border-top: 2px dashed var(--line); margin-top: 18px; padding-top: 16px; }

#ghost { position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -50%); }
.ghost-station {
  --c: var(--ink);
  width: 54px; height: 54px; border-radius: 50%; background: #fff; color: var(--c);
  box-shadow: 0 0 0 5px var(--c), 0 8px 18px rgba(43, 42, 40, .2); display: grid; place-items: center;
}
.hidden { display: none !important; }

/* ---------- Narrow screens ---------- */
@media (max-width: 1180px) {
  .legend { display: none; }
}
@media (max-width: 720px) {
  #topbar { gap: 14px; padding: 8px 12px; }
  .brand { font-size: 0; gap: 0; }
  .bar { width: 72px; }
  .stat .k { font-size: 11px; }
  #toolbar { gap: 14px; padding: 8px 12px 12px; }
  .glabel { display: none; }
  .tool { font-size: 13px; padding: 5px 7px 5px 6px; gap: 5px; }
  .tool .ic { width: 22px; height: 22px; }
  .upgrades { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 22px 20px; }
  #hint { font-size: 13px; }
}
@media (max-width: 480px) {
  #topbar { gap: 10px; padding: 8px 10px; min-height: 48px; }
  .brand .logo { height: 22px; }
  .bar { width: 64px; }
  .stat .v { font-size: 16px; }
  .controls { gap: 4px; }
  .controls button { width: 32px; height: 32px; }
  #toolbar { flex-direction: column; align-items: stretch; gap: 8px; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .items { gap: 6px; }
  .tool { font-size: 12.5px; padding: 4px 7px 4px 4px; }
  .tool .n { padding: 0 6px; min-width: 18px; }
  #hint { bottom: 8px; padding: 6px 12px; font-size: 12.5px; }
  .card { padding: 20px 18px; border-radius: 20px; }
  .card h1 { font-size: 28px; }
}
@media (max-width: 480px) {
  /* Counts become corner badges so all four stations fit on one row */
  .tool { position: relative; padding: 4px 9px 4px 4px; gap: 5px; }
  .tool .ic { width: 22px; height: 22px; }
  .tool .n { position: absolute; top: -7px; right: -7px; font-size: 11px; line-height: 16px; min-width: 18px; padding: 0 5px; box-shadow: 0 0 0 2px var(--page); }
  .items { gap: 9px; }
  #toolbar { padding-top: 12px; }
}
/* Phones held sideways: squeeze the chrome so the map gets the height */
@media (max-height: 500px) and (orientation: landscape) {
  #topbar { min-height: 0; padding: 4px 12px; gap: 16px; }
  .brand { font-size: 15px; }
  .stat { flex-direction: row; align-items: center; gap: 6px; }
  .stat .v { font-size: 15px; }
  .controls button { width: 30px; height: 30px; }
  #toolbar { padding: 4px 12px 6px; gap: 14px; flex-wrap: nowrap; }
  .glabel, .legend { display: none; }
  .tool { font-size: 12.5px; padding: 3px 7px 3px 3px; }
  .tool .ic { width: 20px; height: 20px; }
  #hint { bottom: 4px; padding: 4px 12px; font-size: 12px; }
}

/* ---------- Lead capture, full report, share card ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.btn:disabled { opacity: .6; cursor: progress; transform: none; }
.lead h3 { margin: 0 0 4px; font-size: 19px; }
.lead > .muted { margin: 0 0 12px; font-size: 14.5px; }
.lead form { display: grid; gap: 10px; margin: 0; }
.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
.field i { font-style: normal; font-weight: 500; color: var(--muted); }
.field input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: none;
  font: inherit; font-size: 15px; font-weight: 500; background: #fff; box-shadow: 0 0 0 2px var(--line) inset;
}
.field input:focus { outline: none; box-shadow: 0 0 0 2px var(--ink) inset; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lead form .btn { justify-self: start; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.error { margin: 0; color: #b5523d; font-size: 13.5px; font-weight: 600; }
.fine { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.lead.unlocked { border-top: none; background: #fff; border-radius: 18px; padding: 18px; box-shadow: 0 0 0 2px var(--ink); }
.sent { margin: 4px 0 12px; font-size: 14px; color: var(--muted); }
.recs { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 12px; }
.recs li { display: flex; gap: 12px; align-items: flex-start; }
.recs .num {
  flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; margin-top: 1px;
}
.recs b { font-size: 15.5px; }
.recs p { margin: 2px 0 0; font-size: 14.5px; line-height: 1.5; }
.next { border-top: 2px dashed var(--line); padding-top: 14px; }
.next p { margin: 0 0 12px; font-size: 14.5px; }
.share { margin-top: 18px; display: grid; gap: 10px; }
.share img { width: 100%; aspect-ratio: 1200 / 630; border-radius: 14px; background: #fff; box-shadow: 0 0 0 1px var(--line); }
.end-actions { margin-top: 16px; }
@media (max-width: 480px) {
  .field-row { grid-template-columns: 1fr; }
}

/* ---------- Crafted credits ---------- */
.credit { display: flex; align-items: center; gap: 10px; margin: 18px 0 0; font-size: 13.5px; color: var(--muted); }
.credit img { height: 20px; width: auto; }
.credit a { color: var(--ink); font-weight: 600; }

/* ---------- Coaching ---------- */
#toolbar { position: relative; z-index: 2; }
.tool.coach { position: relative; animation: coach-pulse 1.3s ease-in-out infinite; }
.tool.coach.bubble::after {
  content: attr(data-bubble); position: absolute; left: 0; bottom: calc(100% + 12px);
  white-space: nowrap; pointer-events: none;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700;
  padding: 5px 11px; border-radius: 99px; animation: coach-bob 1.3s ease-in-out infinite;
}
.tool.coach.bubble::before {
  content: ''; position: absolute; left: 18px; bottom: calc(100% + 6px);
  border: 6px solid transparent; border-top-color: var(--accent); border-bottom: 0;
  animation: coach-bob 1.3s ease-in-out infinite; pointer-events: none;
}
@keyframes coach-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--c, var(--ink)), 0 0 0 0 rgba(59, 91, 248, .45); }
  50% { box-shadow: 0 0 0 2px var(--c, var(--ink)), 0 0 0 8px rgba(59, 91, 248, 0); }
}
@keyframes coach-bob { 0%, 100% { margin-bottom: 0; } 50% { margin-bottom: 5px; } }
#hint.setup { background: var(--accent); font-weight: 600; }
