:root {
  --bg: #10131A; --panel: #181C25; --raised: #1F2532; --line: #2A3140; --line-soft: #20262F;
  --text: #ECEAE4; --soft: #C9CED8; --muted: #9AA3B2;
  --gold: #F5C451; --gold-ink: #1B1606; --up: #7CC6F2; --up-strong: #5FB8F0; --down: #F4A766; --down-strong: #F2994A;
  --bot: #C7B8FF; --bot-bg: rgba(167,139,250,.16); --ok: #81C784; --danger: #F28B82;
  --tabbar: 72px; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
h1, h2, h3 { margin: 0; font-weight: 600; }
.display { font-family: 'Space Grotesk', Inter, sans-serif; letter-spacing: -0.01em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.soft { color: var(--soft); }
.up { color: var(--up); } .down { color: var(--down); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Layout */
.shell { min-height: 100dvh; display: flex; }
.rail { display: none; }
.main { flex: 1; min-width: 0; padding-bottom: calc(var(--tabbar) + var(--safe-b)); }
.page { max-width: 760px; margin: 0 auto; padding: 18px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.page.wide { max-width: 1100px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b); display: flex; justify-content: space-around; align-items: center; background: var(--bg); border-top: 1px solid #232A37; z-index: 20; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 60px; min-height: 48px; justify-content: center; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; }
.tab[aria-current="page"] { color: var(--gold); }
.tab svg, .navlink svg { width: 22px; height: 22px; }
@media (min-width: 900px) {
  .tabbar { display: none; }
  .main { padding-bottom: 0; }
  .rail { display: flex; flex-direction: column; gap: 4px; width: 220px; flex: none; padding: 20px 12px; border-right: 1px solid #232A37; position: sticky; top: 0; height: 100dvh; }
  .rail .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 19px; }
  .navlink { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: 10px; color: var(--soft); text-decoration: none; font-weight: 500; }
  .navlink[aria-current="page"] { background: rgba(245,196,81,.12); color: var(--gold); }
  .rail .foot { margin-top: auto; font-size: 11px; color: var(--muted); padding: 0 12px; line-height: 1.5; }
}

/* Building blocks */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; min-width: 0; }
.panel h2 { font-size: 13px; color: var(--soft); margin-bottom: 8px; }
.row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 46px; height: 28px; padding: 0 6px; border-radius: 8px; background: var(--raised); font-size: 11px; font-weight: 600; letter-spacing: .04em; flex: none; }
.tag { display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: .03em; padding: 2px 5px; border-radius: 4px; vertical-align: middle; }
.tag.bot { color: var(--bot); background: var(--bot-bg); }
.tag.you { color: var(--gold); background: rgba(245,196,81,.14); }
.tag.house { color: var(--muted); background: var(--raised); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--soft); font-size: 13px; font-weight: 500; cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); background: rgba(245,196,81,.14); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--soft); font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"].buy { background: var(--up-strong); color: var(--bg); }
.seg button[aria-pressed="true"].sell { background: var(--down-strong); color: var(--bg); }
.seg button[aria-pressed="true"].plain { background: var(--raised); color: var(--text); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #141A24; color: var(--text); padding: 0 12px; font-size: 15px; }
textarea.input { padding: 10px 12px; min-height: 80px; resize: vertical; }
.input:focus-visible, .btn:focus-visible, .chip:focus-visible, .tab:focus-visible, a:focus-visible, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 6px 2px; border-bottom: 1px solid var(--line-soft); text-decoration: none; color: var(--text); }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.item .name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 11px; color: var(--muted); }
.item .end { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-variant-numeric: tabular-nums; flex: none; }
.item .end .p { font-size: 14px; font-weight: 600; }
.item .end .c { font-size: 11px; font-weight: 600; }
.feed .n { padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; line-height: 1.45; }
.feed .n:last-child { border-bottom: 0; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }
.error-text { color: var(--danger); font-size: 13px; }
.lvl { position: relative; display: flex; justify-content: space-between; font-size: 13px; font-variant-numeric: tabular-nums; padding: 3px 8px; }
.lvl .bar { position: absolute; right: 0; top: 1px; bottom: 1px; border-radius: 4px; }
.lvl span { position: relative; }
.spread { display: flex; justify-content: space-between; padding: 5px 8px; font-size: 12px; color: var(--muted); border-top: 1px solid #232A37; border-bottom: 1px solid #232A37; margin: 3px 0; }
input[type=range] { width: 100%; accent-color: var(--gold); }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; width: max-content; bottom: calc(var(--tabbar) + var(--safe-b) + 14px); transform: translateX(-50%) translateY(20px); max-width: min(92vw, 440px); background: #F2F1EC; color: #141413; padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: #FCE8E6; color: #8C1D18; }
@media (min-width: 900px) { #toast { bottom: 24px; } }

/* Onboarding */
.welcome { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.welcome .card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.logo { width: 56px; height: 56px; border-radius: 16px; }

/* Map */
.map-wrap { position: relative; height: calc(100dvh - var(--tabbar) - var(--safe-b)); overflow: hidden; background: #071B30; }
@media (min-width: 900px) { .map-wrap { height: 100dvh; } }
.map-stage { position: absolute; inset: 0; display: flex; justify-content: center; overflow: hidden; perspective: 700px; perspective-origin: 50% 20%; }
.map-canvas { position: relative; width: 390px; height: 600px; flex: none; transform-origin: 50% 0; }
.map-tilt { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: 50% 62%; transition: transform .6s ease; }
.map-zoom { position: absolute; left: 0; top: 0; width: 390px; height: 600px; transform-style: preserve-3d; transform-origin: 0 0; transition: transform .45s ease; }
.city { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; background: none; border: 0; padding: 0; cursor: pointer; min-width: 44px; min-height: 44px; transform-origin: 50% 100%; color: #fff; }
.mk { position: absolute; display: flex; align-items: center; gap: 4px; padding: 3px 7px; border-radius: 999px; font: 600 10px Inter, sans-serif; white-space: nowrap; text-decoration: none; }
.map-top { position: absolute; left: 12px; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 10px; z-index: 5; max-width: 720px; margin: 0 auto; }
.searchbar { display: flex; align-items: center; gap: 10px; height: 48px; background: rgba(32,33,36,.9); border-radius: 999px; border: 1px solid rgba(255,255,255,.14); padding: 0 6px 0 16px; }
.searchbar .title { flex: 1; font-family: 'Space Grotesk', sans-serif; font-weight: 600; }
.pill { display: inline-flex; align-items: center; height: 36px; padding: 0 12px; border-radius: 999px; background: var(--gold); color: var(--gold-ink); font-size: 13px; font-weight: 600; text-decoration: none; font-variant-numeric: tabular-nums; }
.map-top .chip { background: rgba(32,33,36,.9); border-color: rgba(255,255,255,.18); color: #E8EAED; }
.map-top .chip[aria-pressed="true"] { background: rgba(168,199,250,.22); border-color: #A8C7FA; color: #D3E3FD; }
.fabs { position: absolute; right: 12px; top: 124px; display: flex; flex-direction: column; gap: 10px; z-index: 5; }
.fab { width: 44px; height: 44px; border-radius: 999px; background: rgba(32,33,36,.9); border: 1px solid rgba(255,255,255,.14); color: #E8EAED; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; font-weight: 600; font-size: 13px; }
.fab[aria-pressed="true"] { background: #A8C7FA; color: #062E6F; border-color: #A8C7FA; }
.legend { position: absolute; left: 12px; bottom: 300px; display: flex; flex-direction: column; gap: 6px; font-size: 10px; color: #E8EAED; z-index: 4; }
.legend > div { display: flex; align-items: center; gap: 8px; background: rgba(32,33,36,.88); border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 5px 8px; }
.city-sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 46%; overflow-y: auto; background: #202124; border-radius: 20px 20px 0 0; border-top: 1px solid rgba(255,255,255,.08); padding: 8px 16px 16px; z-index: 6; display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 900px) { .map-stage { right: 410px; } .city-sheet { left: auto; right: 16px; bottom: 16px; width: 380px; max-height: 60%; border-radius: 18px; border: 1px solid rgba(255,255,255,.1); } .legend { bottom: 16px; } }
.handle { align-self: center; width: 36px; height: 4px; border-radius: 999px; background: #5F6368; }
.want { font-size: 11px; font-weight: 500; color: #FDE293; background: rgba(253,226,147,.14); border-radius: 999px; padding: 4px 10px; }
@media (prefers-reduced-motion: no-preference) {
  .cloud { animation: drift 40s linear infinite alternate; }
  .pulse { animation: pulse 1.8s ease-out infinite; }
}
@media (prefers-reduced-motion: reduce) { .map-tilt, .map-zoom { transition: none; } }
@keyframes drift { from { transform: translateX(-20px); } to { transform: translateX(30px); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(129,199,132,.75); } 100% { box-shadow: 0 0 0 14px rgba(129,199,132,0); } }
