:root {
  --ink: #241c16;
  --muted: #74685c;
  --paper: #f3ecdf;
  --card: #fffaf3;
  --line: #e6d8c4;
  --red: #c23a2e;
  --red-dark: #8e241c;
  --gold: #b8860b;
  --pine: #1f6b4a;
  --cbd: #1e4f86;
  --neon: #d63a78;
  --shadow: 0 18px 50px rgba(48, 28, 12, 0.16);
  --safe-b: env(safe-area-inset-bottom);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #d9c7a6; color: var(--ink); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { height: 100%; }

.top {
  position: fixed;
  z-index: 5;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 10px;
  align-items: stretch;
  pointer-events: none;
}
.brand, .stats, .hud {
  pointer-events: auto;
  background: rgba(255, 250, 243, 0.94);
  border: 1px solid rgba(255,255,255,.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.brand {
  border-radius: 18px;
  padding: 8px 14px 9px;
  min-width: 148px;
}
.brand b { display: block; font-size: 18px; letter-spacing: 0.08em; }
.brand span { color: var(--muted); font-size: 12px; }
.stats {
  margin-left: auto;
  border-radius: 18px;
  padding: 8px 12px;
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 13px;
}
.stats strong { display: block; font-size: 15px; }
.dot { width: 8px; height: 8px; border-radius: 99px; background: #2ea36a; display: inline-block; margin-right: 4px; }

.hud {
  position: fixed;
  z-index: 5;
  left: 12px;
  top: 78px;
  width: min(280px, calc(100% - 24px));
  border-radius: 18px;
  padding: 10px 12px 12px;
}
.who { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.who b { font-size: 16px; }
.cash { color: var(--red-dark); font-variant-numeric: tabular-nums; font-weight: 700; }
.meters { display: grid; gap: 5px; margin-top: 8px; }
.meter { display: grid; grid-template-columns: 32px 1fr 28px; gap: 6px; align-items: center; font-size: 11px; color: var(--muted); }
.bar { height: 7px; background: #efe4d4; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.bar.hunger i { background: #d8892d; }
.bar.energy i { background: #2f8f62; }
.bar.mood i { background: #d63a78; }
.bar.face i { background: #1e4f86; }
.bar.social i { background: #7a5af8; }

#viewport {
  position: relative;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(circle at 50% 45%, rgba(255,248,230,.5), transparent 42%),
    linear-gradient(180deg, #efe2c6 0%, #e7d3ae 100%);
  cursor: grab;
}
#viewport.drag { cursor: grabbing; }
#world { position: absolute; width: 1400px; height: 980px; transform-origin: 0 0; }
#world svg { width: 100%; height: 100%; display: block; }
.ring { fill: none; stroke: rgba(194, 58, 46, 0.28); stroke-width: 8; }
.ring.inner { stroke: rgba(30, 79, 134, 0.25); }
.avenue { stroke: #c6a15a; stroke-width: 10; stroke-linecap: round; }
.district { font: 700 22px "PingFang SC", "Microsoft YaHei", sans-serif; fill: rgba(36, 28, 22, 0.28); }
.block { stroke: rgba(255,255,255,.45); stroke-width: 2; }
.pin {
  position: absolute;
  transform: translate(-50%, -110%);
  border: 0;
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 9px 5px 6px;
  box-shadow: 0 8px 18px rgba(48, 28, 12, 0.16);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}
.pin em { font-style: normal; font-size: 16px; }
.pin.here { outline: 3px solid var(--red); }
.pin.ad {
  background: #1b1a22;
  color: #ffe08a;
  border-radius: 8px;
  transform: translate(-50%, -120%);
}
.pin small { display: block; font-weight: 500; color: var(--muted); font-size: 10px; }
.pin.ad small { color: #f3b6cb; }

.dock {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: calc(12px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 6px;
  background: rgba(255,250,243,.95);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.dock button {
  border: 0;
  background: transparent;
  border-radius: 14px;
  min-width: 72px;
  padding: 8px 10px 7px;
}
.dock button.on, .dock button:hover { background: #f6e2cf; }
.dock strong { display: block; font-size: 13px; }
.dock span { color: var(--muted); font-size: 11px; }

.zoom {
  position: fixed;
  z-index: 6;
  right: 12px;
  bottom: calc(84px + var(--safe-b));
  display: grid;
  gap: 6px;
}
.zoom button, .ghost, .primary, .choice, .mini button, .sheet header button {
  border: 0;
  border-radius: 12px;
}
.zoom button {
  width: 42px;
  height: 42px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 20px;
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: none;
  background: rgba(36, 22, 12, 0.28);
}
#overlay.show { display: block; }
.sheet, .full {
  background: var(--card);
  box-shadow: var(--shadow);
}
.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: min(86vh, 760px);
  overflow: auto;
  border-radius: 24px 24px 0 0;
  padding: 8px 16px calc(18px + var(--safe-b));
}
.sheet header, .full header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.sheet h2, .full h2 { margin: 8px 0 0; font-size: 24px; }
.kicker { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.blurb { line-height: 1.55; }
.close {
  margin-top: 8px;
  background: #f3e7d8;
  padding: 8px 12px;
}
.actions, .grid, .apps { display: grid; gap: 8px; }
.choice, .app, .job, .lead button, .primary {
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
}
.choice b, .app b, .job b { display: block; }
.choice small, .app small, .job small, .muted { color: var(--muted); }
.choice:disabled { opacity: 0.45; }
.primary { background: var(--red); color: white; border: 0; text-align: center; font-weight: 700; }
.ghost { background: transparent; color: var(--red-dark); padding: 10px; }

.full {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 22px 18px 40px;
  background:
    radial-gradient(circle at 80% 0%, #f6d7c6, transparent 36%),
    var(--paper);
}
.cards { display: grid; gap: 8px; }
.cards button, .origin {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.76);
  border-radius: 16px;
  padding: 12px;
}
.origin.on { border-color: var(--red); background: #fff4ea; }
.origin b, .origin small { display: block; }
.origin small { margin-top: 3px; }
label { display: grid; gap: 6px; margin: 14px 0; color: var(--muted); font-size: 13px; }
label input, .lead textarea { width: 100%; border: 1px solid var(--line); background: white; border-radius: 12px; padding: 12px; }
.name-row { display: flex; gap: 8px; }
.name-row input, .lead input, .lead textarea, .chat-row input {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 12px;
}
.phone {
  width: min(390px, 100%);
  margin: 0 auto;
  background: #16141a;
  color: #f7f1e8;
  border-radius: 28px;
  padding: 18px 14px 16px;
  min-height: 70vh;
}
.phone h2 { color: white; }
.apps { grid-template-columns: 1fr 1fr; }
.app { background: #26232c; color: #f7f1e8; border: 0; min-height: 84px; }
.screen { background: #fffaf3; color: var(--ink); border-radius: 18px; padding: 12px; }
.chat { display: grid; gap: 6px; max-height: 280px; overflow: auto; }
.chat p { margin: 0; background: white; border-radius: 12px; padding: 8px 10px; }
.chat-row { display: flex; gap: 6px; margin-top: 8px; }
.log p { margin: 0 0 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }

.mini {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: #141820;
  color: white;
}
.mini .panel { width: min(420px, 100%); text-align: center; }
.doors {
  margin: 18px 0;
  height: 140px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 800;
  background: #3a4254;
}
.doors.open { background: #2f8f62; }
.mini button { background: white; color: #141820; padding: 12px 18px; font-weight: 800; }

.share {
  width: min(420px, calc(100% - 32px));
  margin: 12vh auto;
  background: #1b1a22;
  color: #fff8ea;
  border-radius: 24px;
  padding: 22px;
}
.share em { color: #f0c36a; font-style: normal; }
.toast {
  position: fixed;
  z-index: 12;
  left: 50%;
  bottom: calc(92px + var(--safe-b));
  transform: translateX(-50%) translateY(12px);
  background: #241c16;
  color: white;
  padding: 12px 14px;
  border-radius: 14px;
  max-width: min(440px, calc(100% - 24px));
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 900px) {
  .sheet {
    left: auto;
    top: 88px;
    right: 18px;
    bottom: 18px;
    width: 420px;
    border-radius: 24px;
    max-height: none;
  }
  .hud { top: 86px; }
}
@media (max-width: 720px) {
  .stats span.label { display: none; }
  .hud { top: auto; bottom: calc(78px + var(--safe-b)); width: calc(100% - 24px); }
  .top { top: 8px; }
}
