:root {
  --ink: #17161a;
  --paper: #f3f1ea;
  --card: #fffdf8;
  --muted: #6f6b74;
  --line: #d9d4c8;
  --yellow: #f6d55c;
  --yellow-soft: #fff1b8;
  --red: #e2563f;
  --green: #8fdcb0;
  --head: "Bowlby One", "Arial Black", Impact, sans-serif;
  --ui: Rubik, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font-family: var(--ui); overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body { touch-action: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
canvas#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#world.tool-inspect { cursor: none; }
canvas#world.tool-place { cursor: crosshair; }
canvas#world.grab { cursor: grabbing; }

.screen { position: fixed; inset: 0; display: none; pointer-events: none; }
.screen.show { display: block; }
.screen.modal { display: none; place-items: center; padding: 16px; background: rgba(243, 241, 234, 0.55); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); pointer-events: auto; overflow-y: auto; }
.screen.modal.show { display: grid; }

/* ---------- buttons ---------- */
.btn { position: relative; min-width: 136px; padding: 13px 26px 12px; border: 3px solid var(--ink); border-radius: 999px; background: #fff; font-weight: 800; font-size: 16px; letter-spacing: 0.06em; box-shadow: 4px 5px 0 var(--ink); transition: transform .08s, box-shadow .08s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn svg { width: 16px; height: 16px; }
.btn.dark { background: var(--ink); color: #fff; box-shadow: 4px 5px 0 #8f8a80; }
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 6px 0 var(--ink); }
.btn.dark:hover { box-shadow: 5px 6px 0 #8f8a80; }
.btn:active { transform: translate(3px, 4px); box-shadow: 1px 1px 0 var(--ink); }
.btn:focus-visible, .tool:focus-visible, .round:focus-visible, .sq:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.btns { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.btns.col { flex-direction: column; align-items: center; }
.btns.col .btn { width: 220px; }

/* ---------- title ---------- */
#title { display: none; text-align: center; }
#title.show { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px 16px 64px; }
#title > * { pointer-events: auto; }
.logo { margin: 0; font-family: var(--head); font-weight: 400; line-height: 0.8; filter: url(#rough); display: flex; flex-direction: column; align-items: center; pointer-events: none !important; }
.logo .l1 { font-size: clamp(48px, 8.4vw, 116px); text-shadow: 0.03em 0.035em 0 #cfc9bb; letter-spacing: 0.02em; display: inline-flex; align-items: flex-start; transform: rotate(-3deg); }
.logo .l2 { font-size: clamp(96px, 19vw, 250px); letter-spacing: 0; margin-top: 0.04em; transform: rotate(1.5deg); text-shadow: 0.03em 0.035em 0 #cfc9bb; }
.candle { position: relative; display: inline-block; width: 0.15em; height: 0.36em; margin: 0.12em 0.06em 0; }
.candle::before { content: ""; position: absolute; left: 50%; top: -0.1em; bottom: -0.1em; width: 0.03em; background: var(--ink); transform: translateX(-50%); }
.candle b { position: absolute; inset: 0; background: var(--red); border: 0.025em solid var(--ink); border-radius: 0.02em; }
.offer { margin: 22px 0 22px; font-size: clamp(16px, 2.2vw, 22px); font-weight: 500; background: rgba(243,241,234,.8); padding: 2px 10px; border-radius: 8px; }
.offer b { font-weight: 800; }
.best { margin: 18px 0 0; min-height: 1em; font-size: 13px; font-weight: 700; letter-spacing: .08em; color: var(--muted); }
.foot { position: absolute; bottom: 14px; left: 0; right: 0; display: flex; gap: 8px; justify-content: center; align-items: center; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; padding: 0 16px; }
.xlink { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-weight: 700; text-decoration: none; border-bottom: 2px solid var(--ink); }
.xlink svg { width: 13px; height: 13px; }
.dot { opacity: .6; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 3px solid var(--ink); border-radius: 24px; box-shadow: 7px 8px 0 var(--ink); }
.modal .card { width: min(560px, 100%); padding: 22px 26px 26px; text-align: center; animation: pop .28s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.9) rotate(-1.5deg); opacity: 0; } to { transform: none; opacity: 1; } }
.card h2 { font-family: var(--head); font-weight: 400; font-size: clamp(26px, 4.4vw, 36px); line-height: 1.02; margin: 6px 0 10px; letter-spacing: .01em; }
.card .lead { margin: 0 auto 20px; max-width: 30em; font-size: 16.5px; line-height: 1.45; color: #4a4650; }
.step { margin: 14px 0 0; font-size: 12px; font-weight: 800; letter-spacing: .18em; color: var(--muted); }
.illo { position: relative; margin: 0 0 4px; border: 2.5px solid var(--ink); border-radius: 16px; background: #faf8f2; overflow: hidden; aspect-ratio: 5 / 3; }
.illo canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.illo-dom { position: absolute; inset: 0; display: none; }
.illo-dom.show { display: block; }

/* tutorial extras */
.legend { display: grid; gap: 4px; padding: 10px 14px; height: 100%; align-content: center; text-align: left; }
.legend .it { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; font-size: 14.5px; line-height: 1.3; }
.legend canvas { position: static; width: 52px; height: 52px; }
.legend b { font-weight: 800; }
.illo-tools { position: absolute; left: 0; right: 0; bottom: 10px; display: flex; justify-content: center; gap: 10px; }
.illo-tools span { width: 48px; height: 48px; border: 2.5px solid var(--ink); border-radius: 50%; background: #fff; display: grid; place-items: center; position: relative; box-shadow: 2px 3px 0 var(--ink); }
.illo-tools svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.illo-tools kbd { position: absolute; top: -7px; right: -7px; }
.illo-fee { position: absolute; left: 14px; right: 14px; bottom: 10px; display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; background: #fff; border: 2.5px solid var(--ink); border-radius: 14px; padding: 7px 12px; font-weight: 800; }
.illo-fee .feebar { margin: 0; }

/* launch */
.tick { display: flex; align-items: center; justify-content: center; gap: 2px; margin: 0 auto 14px; width: min(340px, 100%); border: 3px solid var(--ink); border-radius: 16px; background: #fff; padding: 6px 14px; box-shadow: 3px 4px 0 var(--ink); }
.tick span { font-family: var(--head); font-size: 34px; }
.tick input { width: 100%; border: 0; outline: 0; font-family: var(--head); font-size: 34px; text-transform: uppercase; background: transparent; color: var(--ink); padding: 4px 0; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 0 0 22px; }
.chips button { border: 2px solid var(--ink); background: #fff; border-radius: 999px; padding: 5px 11px; font-weight: 700; font-size: 13px; }
.chips button:hover { background: var(--yellow-soft); }

/* end */
.end-card .amount { font-family: var(--head); font-size: clamp(19px, 3.6vw, 28px); margin: 0 0 12px; }
.end-card .amount s { white-space: nowrap; }
.end-card .amount s { text-decoration-thickness: 4px; text-decoration-color: var(--red); }
.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 0 0 20px; }
.stats span { border: 2px solid var(--ink); border-radius: 10px; padding: 4px 10px; font-size: 13px; font-weight: 600; background: #fff; }
.stats b { font-weight: 800; }
.endx { margin-top: 18px; font-size: 13px; }
.small-card { width: min(420px, 100%) !important; }

/* ---------- HUD ---------- */
#hud.show { display: block; }
#hud .hud-tl, #hud .hud-tr, #hud .hud-bl, #hud .hud-br, #hud .toast, #hud .callout { pointer-events: auto; }
.lab { font-size: 11.5px; font-weight: 700; letter-spacing: .16em; color: var(--muted); }
.hud-tl { position: absolute; top: 18px; left: 22px; width: 290px; pointer-events: none !important; text-shadow: 0 0 3px var(--paper), 0 0 6px var(--paper), 0 0 10px var(--paper); }
.hud-tl .prog { box-shadow: 0 0 0 3px rgba(243,241,234,.9); }
#hCut { color: #6f7fd0; margin-left: 6px; }
.zoom { position: absolute; left: 20px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; pointer-events: auto; }
.zoom .round.small { box-shadow: 2px 3px 0 var(--ink); }
.tickrow { display: flex; gap: 8px; align-items: center; }
.ticker { font-weight: 900; font-size: 13px; letter-spacing: .06em; background: var(--ink); color: #fff; border-radius: 6px; padding: 2px 7px; }
.trend { font-size: 12px; font-weight: 900; }
.trend.up { color: #2a9a5e; } .trend.down { color: var(--red); }
.hud-tl .big { font-family: var(--head); font-size: 46px; line-height: 1.05; margin-top: 4px; letter-spacing: -.01em; }
.hud-tl .sub { white-space: nowrap; font-size: 13px; font-weight: 700; letter-spacing: .1em; color: #4a4650; }
.prog { height: 6px; border-radius: 9px; background: #e2ddd1; margin: 10px 0 8px; overflow: hidden; }
.prog i { display: block; height: 100%; width: 0; background: var(--ink); border-radius: 9px; transition: width .3s; }
.row { display: flex; gap: 10px; align-items: baseline; font-size: 13px; font-weight: 700; margin: 2px 0; }
.row .lab { width: 66px; }
.time { font-weight: 800; font-size: 20px; margin-top: 10px; }

.hud-tr { position: absolute; top: 18px; right: 20px; width: 300px; padding: 12px 16px 12px; border-radius: 20px; box-shadow: 5px 6px 0 var(--ink); transform: rotate(.6deg); }
.feetop { display: flex; justify-content: space-between; align-items: flex-start; }
.feetop b { display: block; font-family: var(--head); font-weight: 400; font-size: 34px; line-height: 1; }
.pm { display: flex; gap: 8px; }
.sq { width: 42px; height: 42px; border: 2.5px solid var(--ink); border-radius: 12px; background: #fff; font-size: 24px; font-weight: 800; line-height: 1; box-shadow: 2px 3px 0 var(--ink); }
.sq:active { transform: translate(2px, 3px); box-shadow: none; }
.sq:disabled { opacity: .35; cursor: default; }
.feebar { position: relative; height: 14px; margin: 10px 0 6px; border: 2.5px solid var(--ink); border-radius: 9px; background: #fff; overflow: visible; }
.feebar i { position: absolute; left: 0; top: 0; bottom: 0; width: 10%; background: var(--ink); border-radius: 6px 0 0 6px; transition: width .2s, background .2s; }
.feebar i.over { background: var(--red); }
.feebar em { position: absolute; top: -6px; bottom: -6px; width: 4px; margin-left: -2px; background: var(--red); border-radius: 2px; transition: left .4s; }
.carry { font-size: 13.5px; color: #4a4650; text-align: center; }
.carry b { color: var(--red); }

.hud-bl { position: absolute; left: 20px; bottom: 20px; display: flex; gap: 10px; align-items: center; }
.round { width: 54px; height: 54px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; display: grid; place-items: center; box-shadow: 3px 4px 0 var(--ink); }
.round.small { width: 42px; height: 42px; }
.round svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.round.small svg { width: 20px; height: 20px; }
.feetbar { position: relative; width: 300px; height: 50px; border: 3px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden; box-shadow: 4px 5px 0 var(--ink); }
.feetbar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--yellow); transition: width .25s, background .25s; }
.feetbar.hot i { background: #f0a24a; }
.feetbar.crit i { background: var(--red); }
.feetbar.crit { animation: shake .35s infinite; }
@keyframes shake { 25% { transform: translateX(-2px) rotate(-.5deg); } 75% { transform: translateX(2px) rotate(.5deg); } }
.feetbar span { position: relative; display: flex; align-items: baseline; gap: 6px; height: 100%; align-items: center; padding: 0 20px; font-weight: 800; font-size: 14px; letter-spacing: .12em; }
.feetbar b { font-size: 20px; letter-spacing: 0; }
.feetbar small { font-size: 12px; color: var(--muted); letter-spacing: 0; }

.hud-br { position: absolute; right: 18px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 14px; }
.tools { display: flex; gap: 10px; flex-wrap: nowrap; }
.tool { position: relative; flex: none; width: 60px; height: 60px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; display: grid; place-items: center; box-shadow: 3px 4px 0 var(--ink); margin-bottom: 18px; transition: transform .08s, background .15s; }
.tool svg { width: 30px; height: 30px; fill: none; stroke: var(--ink); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { transform: translateY(-2px); }
.tool.on { background: var(--ink); }
.tool.on svg { stroke: #fff; }
.tool.poor { background: #ebe7de; border-color: #9a948a; box-shadow: 3px 4px 0 #9a948a; }
.tool.poor svg { stroke: #9a948a; }
.tool .badge { position: absolute; top: -6px; left: -6px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: var(--red); color: #fff; font: 800 12px/18px var(--ui); border: 2px solid var(--paper); animation: blink 1s infinite; }
.tool .cost { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 6px; font-size: 11.5px; font-weight: 800; white-space: nowrap; }
.tool.poor .cost { color: var(--red); }
.tool .cd { position: absolute; inset: -3px; border-radius: 50%; background: conic-gradient(rgba(23,22,26,.35) var(--p, 0%), transparent 0); pointer-events: none; }
kbd { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font: 800 11px/22px var(--ui); text-align: center; border: 2px solid var(--paper); }

.callout { position: relative; max-width: 340px; background: var(--yellow); border: 3px solid var(--ink); border-radius: 18px; padding: 12px 16px 13px; box-shadow: 4px 5px 0 var(--ink); transform: rotate(-.8deg); cursor: pointer; animation: pop .3s cubic-bezier(.2,1.4,.4,1); }
.callout::after { content: ""; position: absolute; right: 44px; bottom: -12px; width: 16px; height: 16px; background: var(--yellow); border-right: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: rotate(45deg); }
.callout b { display: block; font-family: var(--head); font-weight: 400; font-size: 17px; margin-bottom: 3px; }
.callout span { font-size: 14px; line-height: 1.38; }

.toast { position: absolute; top: 16px; left: 50%; transform: translateX(-50%) rotate(-.5deg); width: min(430px, calc(100% - 680px)); min-width: 300px; background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 10px 16px 11px; box-shadow: 4px 5px 0 var(--ink); text-align: center; animation: drop .35s cubic-bezier(.2,1.4,.4,1); }
@keyframes drop { from { transform: translate(-50%, -30px); opacity: 0; } }
.toast b { display: block; font-family: var(--head); font-weight: 400; font-size: 18px; line-height: 1.1; margin-bottom: 3px; }
.toast span { font-size: 13.5px; line-height: 1.35; color: #4a4650; }
.toast.k-good { background: #e8f8ef; } .toast.k-warn { background: var(--yellow-soft); } .toast.k-bad { background: #fbe0da; } .toast.k-inf { background: #eaf0fb; } .toast.k-milestone { background: var(--ink); color: #fff; } .toast.k-milestone span { color: #ddd; }
.warn { position: absolute; left: 50%; bottom: 58px; transform: translateX(-50%); font-weight: 900; letter-spacing: .16em; font-size: 13px; color: var(--red); background: rgba(243,241,234,.85); padding: 3px 10px; border-radius: 6px; white-space: nowrap; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .45; } }
.toolhint { position: absolute; left: 50%; bottom: 88px; transform: translateX(-50%); background: var(--ink); color: #fff; font-weight: 700; font-size: 13.5px; padding: 7px 14px; border-radius: 999px; white-space: nowrap; }
.keys { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); font-size: 11px; font-weight: 700; letter-spacing: .14em; color: #8f8a94; white-space: nowrap; }

/* ---------- responsive ---------- */
@media (max-width: 1440px) { .keys { display: none; } }
@media (max-width: 1100px) {
  .hud-br .tool { width: 54px; height: 54px; }
  .hud-br .tool svg { width: 26px; height: 26px; }
  .toast { width: min(420px, calc(100% - 40px)); top: auto; bottom: 168px; min-width: 0; }
  .keys { display: none; }
}
@media (max-width: 760px) {
  .hud-tl { top: 10px; left: 12px; width: 52vw; }
  .hud-tl .big { font-size: 30px; }
  .hud-tl .sub { font-size: 11px; }
  .hud-tl .row { font-size: 11.5px; } .hud-tl .row .lab { width: 54px; }
  .hud-tl .time { font-size: 15px; margin-top: 4px; }
  .lab { font-size: 10px; }
  .hud-tr { top: 10px; right: 10px; width: 42vw; min-width: 150px; padding: 8px 10px 8px; border-radius: 16px; box-shadow: 3px 4px 0 var(--ink); }
  .feetop b { font-size: 24px; }
  .sq { width: 32px; height: 32px; font-size: 19px; border-radius: 9px; }
  .pm { gap: 5px; }
  .feebar { height: 11px; margin: 7px 0 4px; }
  .carry { font-size: 11.5px; }
  .hud-bl { left: 10px; bottom: 86px; gap: 7px; }
  .round { width: 42px; height: 42px; } .round.small { width: 36px; height: 36px; }
  .feetbar { width: calc(100vw - 120px); height: 40px; }
  .feetbar span { font-size: 12px; padding: 0 14px; }
  .hud-br { right: 0; left: 0; bottom: 8px; align-items: stretch; }
  .tools { justify-content: center; gap: 8px; }
  .hud-br .tool { width: 48px; height: 48px; margin-bottom: 16px; border-width: 2.5px; box-shadow: 2px 3px 0 var(--ink); }
  .hud-br .tool svg { width: 23px; height: 23px; }
  .tool .cost { font-size: 10.5px; }
  kbd { width: 18px; height: 18px; font-size: 10px; line-height: 18px; top: -5px; right: -5px; }
  .zoom { left: auto; right: 10px; top: 46%; transform: none; gap: 7px; }
  #hCut { display: block; margin: 0; }
  .toolhint { white-space: normal; width: calc(100% - 24px); text-align: center; border-radius: 14px; }
  .offer { font-size: 15px; }
  .callout { position: absolute; bottom: 146px; right: 12px; left: 12px; max-width: none; }
  .callout::after { display: none; }
  .toast { bottom: auto; top: 150px; padding: 8px 12px; border-radius: 14px; }
  .toast b { font-size: 15px; } .toast span { font-size: 12.5px; }
  .callout { padding: 9px 12px 10px; } .callout b { font-size: 15px; } .callout span { font-size: 13px; }
  .warn { bottom: 136px; font-size: 11px; }
  .toolhint { bottom: 136px; font-size: 12px; }
  .modal .card { padding: 16px 16px 20px; border-radius: 20px; box-shadow: 5px 6px 0 var(--ink); }
  .card .lead { font-size: 15px; margin-bottom: 16px; }
  .btn { min-width: 120px; padding: 11px 20px 10px; font-size: 15px; }
  .legend .it { font-size: 13px; grid-template-columns: 40px 1fr; }
  .legend canvas { width: 40px; height: 40px; }
  .illo-tools span { width: 40px; height: 40px; } .illo-tools svg { width: 20px; height: 20px; }
}
@media (max-height: 640px) and (min-width: 761px) {
  .illo { aspect-ratio: 2 / 1; }
  .modal .card { padding: 14px 20px 18px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- loader ---------- */
#loader { position: fixed; inset: 0; z-index: 50; background: var(--paper); display: grid; place-content: center; justify-items: center; gap: 18px; padding: 16px; transition: opacity .5s, visibility .5s; }
#loader.done { opacity: 0; visibility: hidden; }
.ld-chart { position: relative; width: 230px; height: 150px; border-left: 3px solid var(--ink); border-bottom: 3px solid var(--ink); }
.ld-chart i { position: absolute; top: var(--y); width: 18px; height: var(--h); background: var(--green); border: 2.5px solid var(--ink); border-radius: 3px; transform-origin: bottom; animation: candle 2.2s var(--d) infinite both cubic-bezier(.3,1.4,.5,1); }
.ld-chart i::before { content: ""; position: absolute; left: 50%; top: -10px; bottom: -10px; width: 2.5px; margin-left: -1.25px; background: var(--ink); z-index: -1; }
.ld-chart i:nth-child(1) { left: 14px; } .ld-chart i:nth-child(2) { left: 42px; } .ld-chart i:nth-child(3) { left: 70px; } .ld-chart i:nth-child(4) { left: 98px; } .ld-chart i:nth-child(5) { left: 126px; } .ld-chart i:nth-child(6) { left: 154px; } .ld-chart i:nth-child(7) { left: 182px; }
.ld-chart i.red { background: var(--red); transform-origin: top; animation-name: dump; }
@keyframes candle { 0% { transform: scaleY(0); opacity: 0; } 14% { opacity: 1; } 30%, 88% { transform: scaleY(1); opacity: 1; } 100% { transform: scaleY(1); opacity: 0; } }
@keyframes dump { 0%, 36% { transform: scaleY(0); opacity: 0; } 40% { opacity: 1; } 52%, 88% { transform: scaleY(1); opacity: 1; } 100% { opacity: 0; } }
.ld-title { font-family: var(--head); font-size: 40px; line-height: 1; }
.ld-bar { width: 260px; height: 16px; border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; background: #fff; }
.ld-bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .2s; }
.ld-text { font-size: 12px; font-weight: 800; letter-spacing: .14em; color: var(--muted); text-align: center; }
.ld-text b { color: var(--ink); }
.illo-names { position: absolute; left: 0; right: 0; bottom: 8px; display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; font-weight: 800; font-size: 12px; letter-spacing: .14em; }
