:root {
  --ink: #34324d;
  --ink-soft: #5d5a7a;
  --cream: #fff1cf;
  --paper: #fffaf0;
  --pink: #f25c7a;
  --pink-soft: #f3a1cb;
  --lime: #b8e65a;
  --sky: #73d9e8;
  --gold: #f4c542;
  --peach: #f8a76d;
  --shadow: 0 4px 0 var(--ink);
  --radius: 14px;
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #4fb3e3; }
body { -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); font-weight: 500; }
.small { font-size: 12.5px; }
kbd { font: 600 11px 'Fredoka', sans-serif; background: #fff; border: 1.5px solid var(--ink); border-radius: 5px; padding: 0 4px; margin-left: 4px; }

#world { position: fixed; inset: 0; display: block; touch-action: none; cursor: grab; }
#world.dragging { cursor: grabbing; }

/* ---------- HUD ---------- */
.hud { position: fixed; z-index: 10; display: flex; gap: 10px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-tl { top: 16px; left: 16px; flex-direction: column; align-items: flex-start; }
.hud-tr { top: 16px; right: 16px; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - 260px); }
.hud-bl { bottom: 18px; left: 16px; }
.hud-bc { bottom: 22px; left: 50%; transform: translateX(-50%); }
.hud-br { bottom: 18px; right: 16px; align-items: flex-end; }

.chip {
  display: inline-flex; align-items: center; gap: 10px; padding: 7px 16px 7px 8px;
  background: rgba(52, 50, 77, 0.88); color: #fff; border: 2.5px solid var(--ink);
  border-radius: 999px; font-weight: 600; font-size: 17px; box-shadow: 0 3px 0 rgba(0,0,0,0.25);
  backdrop-filter: blur(4px);
}
.chip .muted { color: #c9c6e4; }
a.chip { text-decoration: none; }
.home-link { font-size: 15px; padding: 5px 14px 5px 6px; }
.home-link .chip-icon { width: 28px; height: 28px; font-weight: 700; }
button.chip:hover { transform: translateY(-1px); background: rgba(52, 50, 77, 0.96); }
button.chip:active { transform: translateY(1px); }
.chip.big { font-size: 18px; padding: 8px 18px 8px 8px; }
.chip-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--cream); border: 2px solid var(--ink); color: var(--ink); }
.chip-icon svg { width: 26px; height: 26px; }
.chip-icon.bag { background: #ffd6e0; }
.badge { min-width: 22px; height: 22px; border-radius: 11px; background: var(--lime); color: var(--ink); font-size: 13px; font-weight: 700; display: grid; place-items: center; padding: 0 6px; border: 2px solid var(--ink); }

.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 14px 5px 6px;
  background: var(--paper); border: 2.5px solid var(--ink); border-radius: 999px; box-shadow: var(--shadow);
  font-size: 17px; min-width: 92px;
}
.coin { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--gold); border: 2px solid var(--ink); }
.coin.vend { background: var(--pink-soft); }
.coin.parts { background: var(--sky); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 12px; border: 2.5px solid var(--ink); background: var(--lime);
  font-weight: 600; font-size: 15px; box-shadow: 0 3px 0 var(--ink); transition: transform .08s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.ghost { background: #fff; }
.btn.pink { background: var(--pink); color: #fff; }
.btn.sky { background: var(--sky); }
.btn.gold { background: var(--gold); }
.btn.wallet { background: var(--pink); color: #fff; font-size: 15px; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 10px; box-shadow: 0 2px 0 var(--ink); }
.btn.block { width: 100%; }

.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 2.5px solid var(--ink); background: var(--paper); font-size: 20px; font-weight: 700; box-shadow: 0 3px 0 var(--ink); display: grid; place-items: center; }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.zoom { display: flex; flex-direction: column; gap: 8px; }
#minimap { width: 200px; height: 110px; border-radius: 12px; border: 2.5px solid var(--ink); background: #4fb3e3; box-shadow: var(--shadow); cursor: pointer; }

.district-label {
  padding: 8px 26px; background: #262438; color: #fff; border: 3px solid #4d4a6b; border-radius: 10px;
  font-weight: 600; font-size: 17px; box-shadow: 0 0 0 2px #1a1828, 0 4px 0 rgba(0,0,0,.3); white-space: nowrap;
}
.district-label .tag { color: #c9c6e4; font-weight: 500; font-size: 13px; margin-left: 8px; }

/* ---------- Panels ---------- */
.panel {
  position: fixed; z-index: 20; background: var(--paper); border: 3px solid var(--ink); border-radius: 20px;
  box-shadow: 0 6px 0 var(--ink), 0 20px 50px rgba(30, 28, 60, .25);
}
.panel h2 { margin: 0; font-size: 22px; line-height: 1.15; }
.panel h3 { margin: 16px 0 8px; font-size: 14px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.panel-close { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 10px; border: 2px solid var(--ink); background: #fff; font-size: 18px; font-weight: 700; }

.inspector { top: 84px; right: 16px; width: 340px; max-height: calc(100vh - 110px); overflow: auto; padding: 18px; animation: slideIn .22s ease-out; }
.drawer { left: 16px; bottom: 84px; width: 380px; max-height: calc(100vh - 210px); overflow: auto; padding: 18px; animation: rise .2s ease-out; }
.popover { left: 16px; top: 262px; width: 340px; max-height: calc(100vh - 290px); overflow: auto; padding: 18px; animation: rise .2s ease-out; }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }

.portrait { display: flex; gap: 14px; align-items: center; }
.portrait img, .thumb { image-rendering: pixelated; border: 2.5px solid var(--ink); border-radius: 14px; background: #eee; }
.portrait img { width: 112px; height: 112px; }
.thumb { width: 56px; height: 56px; border-radius: 10px; }
.rarity { display: inline-block; padding: 2px 10px; border-radius: 999px; color: #fff; font-size: 12.5px; font-weight: 600; border: 2px solid var(--ink); }
.owner { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }

.traits { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.trait { background: #fff; border: 2px solid #e4dccb; border-radius: 10px; padding: 5px 8px; }
.trait span { display: block; font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.trait b { font-size: 14px; font-weight: 600; }
.trait a { color: inherit; }

.stat { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 7px 0; font-size: 15px; }
.bar { flex: 1; height: 12px; border-radius: 6px; background: #eadfca; border: 2px solid var(--ink); overflow: hidden; max-width: 150px; }
.bar > i { display: block; height: 100%; background: var(--lime); }
.bar.stock > i { background: var(--sky); }
.bar.low > i { background: var(--pink); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .cost { display: block; font-size: 11.5px; font-weight: 500; opacity: .85; }
.actions .btn { flex-direction: column; gap: 0; line-height: 1.15; padding: 8px 10px; }
.note { margin-top: 14px; font-size: 12px; color: var(--ink-soft); line-height: 1.4; background: #f5efe2; border-radius: 10px; padding: 8px 10px; }

.mlist { display: flex; flex-direction: column; gap: 10px; }
.mrow { display: flex; gap: 12px; align-items: center; background: #fff; border: 2px solid #e4dccb; border-radius: 14px; padding: 8px; }
.mrow .info { flex: 1; min-width: 0; }
.city-badge { width: 56px; height: 56px; flex: none; border-radius: 14px; border: 2.5px solid var(--ink); display: grid; place-items: center; font-size: 28px; }
#cityIcon { font-size: 20px; }
.mrow .info b { display: block; }
.mrow .info .muted { font-size: 13px; }
.mrow .row-actions { display: flex; flex-direction: column; gap: 6px; }
.balances { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.balances div { background: #fff; border: 2px solid #e4dccb; border-radius: 12px; padding: 6px 10px; }
.balances span { display: block; font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.balances b { font-size: 18px; }

.event { background: linear-gradient(135deg, #ffe0ea, #fff1cf); border: 2px solid var(--ink); border-radius: 14px; padding: 12px; }
.event b { font-size: 18px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-chip { padding: 3px 10px; border-radius: 999px; border: 2px solid var(--ink); background: #fff; font-size: 13px; font-weight: 600; }
.drow { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 10px; cursor: pointer; }
.drow:hover { background: #f5efe2; }
.drow .meter { flex: 1; }
.drow .ico { font-size: 20px; width: 28px; text-align: center; }

/* ---------- Banner, tooltip, toasts, modal ---------- */
.banner {
  position: fixed; z-index: 15; top: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 8px; background: var(--paper);
  border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink);
}
.banner img { width: 46px; height: 46px; image-rendering: pixelated; border-radius: 10px; border: 2px solid var(--ink); }
.tooltip {
  position: fixed; z-index: 30; pointer-events: none; background: #262438; color: #fff; padding: 9px 12px; border-radius: 12px;
  font-size: 13.5px; line-height: 1.4; border: 2px solid #4d4a6b; max-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.tooltip b { font-size: 15px; }
.tooltip .good { color: #b8e65a; } .tooltip .bad { color: #ff8fa6; }
.toasts { position: fixed; z-index: 50; top: 84px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--paper); border: 2.5px solid var(--ink); border-radius: 14px; padding: 8px 16px; font-weight: 600; box-shadow: 0 4px 0 var(--ink); animation: rise .2s ease-out; }
.toast.err { background: #ffe1e7; }
.toast.good { background: #eaffc7; }

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(38, 36, 56, .45); backdrop-filter: blur(3px); padding: 16px; }
.modal-card { width: min(480px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--paper); border: 3px solid var(--ink); border-radius: 24px; padding: 24px; box-shadow: 0 8px 0 var(--ink); position: relative; animation: rise .22s ease-out; }
.modal-card h1 { margin: 0 0 4px; font-size: 30px; }
.modal-card p { line-height: 1.5; margin: 8px 0; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.logo { display: inline-flex; gap: 2px; font-weight: 700; font-size: 34px; letter-spacing: .02em; }
.logo span:nth-child(odd) { color: var(--pink); } .logo span:nth-child(even) { color: #3e8de0; }
.hero-machines { display: flex; justify-content: center; gap: 8px; margin: 10px 0 6px; }
.hero-machines img { width: 72px; height: 72px; image-rendering: pixelated; border-radius: 12px; border: 2.5px solid var(--ink); }
.quote { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; background: #fff; border: 2px solid #e4dccb; border-radius: 14px; padding: 12px; margin: 12px 0; font-size: 15px; }
.quote .total { font-weight: 700; border-top: 2px dashed #e4dccb; padding-top: 6px; }

@media (max-width: 1100px) {
  .hud-bc { display: none; }
  .banner { top: 84px; }
  .toasts { top: 160px; }
}
@media (max-width: 720px) {
  .hud-tr { top: auto; bottom: 74px; left: 12px; right: auto; justify-content: flex-start; max-width: calc(100vw - 80px); gap: 6px; }
  .hud-tl { top: 12px; left: 12px; }
  .pill { min-width: 0; font-size: 15px; padding: 4px 10px 4px 5px; }
  .btn.wallet { position: fixed; top: 12px; right: 12px; }
  .hud-bc { display: none; }
  #minimap { display: none; }
  .hud-br { bottom: 12px; right: 12px; }
  .zoom { gap: 6px; }
  .hud-bl { bottom: 12px; left: 12px; }
  .chip { font-size: 15px; }
  .inspector, .drawer, .popover { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 72vh; border-radius: 22px 22px 0 0; animation: rise .2s ease-out; }
  .banner { top: auto; bottom: 140px; width: calc(100vw - 24px); }
}

/* ---------- Notifications, tutorial ---------- */
.bell { position: relative; font-size: 18px; }
.bell .badge { position: absolute; top: -8px; right: -8px; background: var(--pink); color: #fff; font-size: 11px; min-width: 20px; height: 20px; }
.notes { top: 84px; right: 16px; width: 360px; max-height: calc(100vh - 110px); overflow: auto; padding: 18px; animation: slideIn .22s ease-out; }
.note-row { display: flex; gap: 10px; padding: 10px 8px; border-radius: 12px; cursor: pointer; font-size: 14.5px; line-height: 1.35; }
.note-row:hover { background: #f5efe2; }
.note-row.unread { background: #fff3d6; }
.note-row > span { font-size: 20px; }
.note-row small { display: block; margin-top: 2px; }
.coach {
  position: fixed; z-index: 45; left: 50%; bottom: 96px; transform: translateX(-50%); width: min(440px, calc(100vw - 24px));
  background: var(--paper); border: 3px solid var(--ink); border-radius: 20px; padding: 16px 18px; box-shadow: 0 6px 0 var(--ink), 0 20px 50px rgba(30,28,60,.3);
  animation: rise .25s ease-out;
}
.coach p { margin: 6px 0 12px; line-height: 1.45; font-size: 15.5px; }
.coach-step { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--pink); }
.coach-actions { display: flex; justify-content: flex-end; gap: 8px; }
.coach-target { position: relative; z-index: 46; animation: coachPulse 1.2s ease-in-out infinite; }
@keyframes coachPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(242,92,122,.0), 0 3px 0 var(--ink); } 50% { box-shadow: 0 0 0 8px rgba(242,92,122,.45), 0 3px 0 var(--ink); } }
@media (prefers-reduced-motion: reduce) { .coach-target { animation: none; outline: 4px solid var(--pink); } }
@media (max-width: 720px) { .notes { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 72vh; border-radius: 22px 22px 0 0; } .coach { bottom: 150px; } }

/* Pixel art mode: the canvas renders at half resolution and is scaled up with hard edges */
#world.pixel { image-rendering: pixelated; image-rendering: crisp-edges; }
.icon-btn.on { background: var(--lime); }
.btn.soon, .btn.soon:hover { opacity: .6; cursor: not-allowed; transform: none; box-shadow: 0 3px 0 var(--ink); }
