/* City Stack: bright, chunky, rounded — Pocket City-ish. Mobile first; the canvas fills the screen and the HUD floats. */
:root {
    --ink: #24324a; --muted: #6b7a90; --card: #ffffff; --line: #e3eaf2; --bg: #e9f7ff;
    --blue: #3aa0ff; --green: #34c46a; --red: #ff5a5f; --gold: #ffb820; --pink: #ff6fae; --violet: #8d6bff;
    --R: #5fd068; --C: #4aa8ff; --I: #ffc23d;
    --shadow: 0 4px 0 rgba(36, 50, 74, .12), 0 8px 22px rgba(36, 50, 74, .14);
    --radius: 18px;
    --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 700 15px/1.3 Nunito, system-ui, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }

/* ───── buttons and bits ───── */
.btn { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 10px 16px; border-radius: 14px; background: #fff; box-shadow: var(--shadow); font-weight: 800; transition: transform .08s; }
.btn:active { transform: translateY(2px) scale(.98); }
.btn small { font-weight: 700; font-size: 12px; color: var(--muted); }
.btn.primary { background: linear-gradient(#5ccaff, #2e9cf5); color: #fff; }
.btn.primary small { color: #e6f6ff; }
.btn.green { background: linear-gradient(#5fe08b, #2fb862); color: #fff; }
.btn.red { background: linear-gradient(#ff8a8d, #f05056); color: #fff; }
.btn.gold { background: linear-gradient(#ffd45a, #ffaa1e); color: #4a3300; }
.btn.ghost { background: rgba(255,255,255,.7); box-shadow: none; }
.btn.big { width: 100%; padding: 14px 18px; font-size: 18px; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 11px; }
.btn:disabled { opacity: .45; pointer-events: none; }
.link { color: var(--blue); text-decoration: underline; font-weight: 800; padding: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border-radius: 99px; background: #fff; box-shadow: var(--shadow); font-size: 13px; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 13px; text-align: center; min-height: 1.2em; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .field select { padding: 11px 13px; border-radius: 12px; border: 2px solid var(--line); background: #fff; color: var(--ink); font-weight: 800; font-size: 16px; user-select: text; -webkit-user-select: text; }
.field input:focus { outline: none; border-color: var(--blue); }

/* ───── title ───── */
.screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); }
#title { background: linear-gradient(180deg, rgba(120, 210, 255, .35), rgba(233, 247, 255, .2) 60%, rgba(140, 220, 140, .35)); }
.title-card { width: min(420px, 100%); background: rgba(255,255,255,.92); border-radius: 28px; padding: 24px 22px 14px; box-shadow: var(--shadow); display: grid; gap: 14px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.logo { margin: 0; text-align: center; font: 800 54px/0.9 'Baloo 2', system-ui; letter-spacing: -1px; }
.logo span:first-child { color: var(--blue); display: block; }
.logo span:last-child { color: var(--pink); display: block; transform: rotate(-3deg); text-shadow: 3px 3px 0 #ffd84a; }
.tag { margin: -4px 0 0; text-align: center; color: var(--muted); }
.title-actions { display: grid; gap: 10px; }

/* ───── world map ───── */
#world { background: #cfefff; display: flex; flex-direction: column; padding: 0; }
.bar { width: 100%; display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l)); }
.bar h2 { margin: 0; font: 800 22px 'Baloo 2', system-ui; }
.world-wrap { flex: 1; width: 100%; position: relative; }
#world-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.world-legend { position: absolute; left: 12px; bottom: calc(10px + var(--safe-b)); margin: 0; max-width: 360px; font-size: 12px; color: var(--muted); background: rgba(255,255,255,.8); padding: 8px 10px; border-radius: 12px; }
.world-sheet { right: calc(12px + var(--safe-r)); top: calc(64px + var(--safe-t)); width: min(340px, calc(100vw - 24px)); }

/* ───── HUD ───── */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud > * { pointer-events: auto; }
.top { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-t)) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l)); flex-wrap: wrap; pointer-events: none; }
.top > * { pointer-events: auto; }
.pill { display: inline-flex; align-items: center; gap: 5px; height: 38px; padding: 0 12px; border-radius: 99px; background: #fff; box-shadow: var(--shadow); white-space: nowrap; }
.pill b { font-weight: 800; }
.pill small { color: var(--muted); font-size: 11px; }
.pill.name { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; line-height: 1.05; max-width: 150px; overflow: hidden; }
.pill.name b { font-family: 'Baloo 2', system-ui; font-size: 16px; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.pill.icon { width: 38px; padding: 0; justify-content: center; font-size: 17px; }
.money small.up { color: var(--green); } .money small.down { color: var(--red); }
.rci { display: flex; gap: 3px; height: 38px; align-items: flex-end; background: #fff; border-radius: 12px; padding: 5px 7px; box-shadow: var(--shadow); }
.rci i { position: relative; width: 9px; height: 28px; border-radius: 4px; background: #eef2f6; overflow: hidden; }
.rci b { position: absolute; left: 0; right: 0; bottom: 50%; background: var(--c); border-radius: 3px; }
.rci b.neg { top: 50%; bottom: auto; opacity: .45; }
.speeds { display: flex; background: #fff; border-radius: 99px; box-shadow: var(--shadow); padding: 3px; height: 38px; }
.speeds button { width: 34px; border-radius: 99px; font-size: 14px; }
.speeds button.on { background: var(--blue); color: #fff; }

.side { position: absolute; left: calc(8px + var(--safe-l)); top: calc(58px + var(--safe-t)); display: flex; flex-direction: column; gap: 7px; }
.side button { position: relative; width: 54px; height: 50px; border-radius: 16px; background: #fff; box-shadow: var(--shadow); font-size: 19px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.side button small { font-size: 10px; color: var(--muted); margin-top: 2px; }
.side button.on { background: #e5f3ff; outline: 3px solid var(--blue); }
.badge { position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--red); color: #fff; font: 800 11px/18px Nunito; font-style: normal; }

.toolbar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 6px; padding: 8px calc(8px + var(--safe-r)) calc(8px + var(--safe-b)) calc(8px + var(--safe-l)); overflow-x: auto; scrollbar-width: none; justify-content: safe center; }
.toolbar::-webkit-scrollbar { display: none; }
.toolbar button { flex: 0 0 auto; width: 58px; height: 58px; border-radius: 18px; background: #fff; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 22px; line-height: 1; }
.toolbar button small { font-size: 10px; color: var(--muted); margin-top: 3px; }
.toolbar button.on { background: linear-gradient(#5ccaff, #2e9cf5); color: #fff; }
.toolbar button.on small { color: #e6f6ff; }
.toolbar .sep { flex: 0 0 4px; }
.tray { position: absolute; left: 0; right: 0; bottom: calc(76px + var(--safe-b)); display: flex; gap: 8px; padding: 6px calc(10px + var(--safe-r)) 6px calc(10px + var(--safe-l)); overflow-x: auto; scrollbar-width: none; justify-content: safe center; }
.tray::-webkit-scrollbar { display: none; }
.item { position: relative; flex: 0 0 auto; width: 96px; border-radius: 16px; background: #fff; box-shadow: var(--shadow); padding: 8px 6px 7px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.item .ic { font-size: 26px; line-height: 1.1; }
.item .nm { font-size: 12px; line-height: 1.1; min-height: 2.2em; display: flex; align-items: center; }
.item .co { font-size: 12px; color: var(--green); }
.item.on { outline: 3px solid var(--blue); background: #eef8ff; }
.item.locked { opacity: .55; }
.item.locked .co { color: var(--muted); }
.item.poor .co { color: var(--red); }
.item .tag { position: absolute; top: -6px; right: -4px; background: var(--gold); color: #4a3300; border-radius: 8px; font-size: 10px; padding: 1px 5px; }

.ticker { position: absolute; left: 50%; transform: translateX(-50%); top: calc(54px + var(--safe-t)); display: grid; gap: 4px; justify-items: center; pointer-events: none; width: min(460px, 70vw); }
.ticker div { background: rgba(255,255,255,.95); padding: 6px 12px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; animation: tick 5s forwards; }
.ticker div.good { border-left: 5px solid var(--green); } .ticker div.bad { border-left: 5px solid var(--red); }
@keyframes tick { 0% { opacity: 0; transform: translateY(-6px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.tool-hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(176px + var(--safe-b)); background: rgba(36,50,74,.88); color: #fff; padding: 7px 14px; border-radius: 12px; font-size: 13px; pointer-events: none; text-align: center; max-width: 90vw; }
.tool-hint.bad { background: rgba(240,80,86,.92); }
.overlay-legend { position: absolute; right: calc(10px + var(--safe-r)); bottom: calc(90px + var(--safe-b)); background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 8px 12px; font-size: 12px; }
.overlay-legend .ramp { width: 140px; height: 10px; border-radius: 5px; margin: 4px 0; }
.visit-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); display: flex; gap: 10px; align-items: center; background: #fff; padding: 8px 10px 8px 16px; border-radius: 16px; box-shadow: var(--shadow); }

/* ───── sheets ───── */
.sheet { position: fixed; z-index: 30; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; max-height: calc(100vh - 24px - var(--safe-t) - var(--safe-b)); }
.panel { right: calc(10px + var(--safe-r)); top: calc(56px + var(--safe-t)); bottom: calc(84px + var(--safe-b)); width: min(420px, calc(100vw - 20px)); }
.inspector { right: calc(10px + var(--safe-r)); bottom: calc(84px + var(--safe-b)); width: min(340px, calc(100vw - 20px)); max-height: 60vh; }
.sheet header { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; border-bottom: 2px solid var(--line); }
.sheet header h3 { margin: 0; font: 800 21px 'Baloo 2', system-ui; flex: 1; }
.sheet header .x { width: 34px; height: 34px; border-radius: 50%; background: #f0f4f8; font-size: 16px; }
.sheet .body { overflow-y: auto; padding: 12px 16px 16px; display: grid; gap: 12px; align-content: start; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; flex-wrap: wrap; }
.tabs button { padding: 6px 11px; border-radius: 10px; background: #f0f4f8; font-size: 13px; }
.tabs button.on { background: var(--blue); color: #fff; }
.box { background: #f6f9fc; border-radius: 14px; padding: 10px 12px; display: grid; gap: 6px; }
.box h4 { margin: 0; font: 800 15px 'Baloo 2', system-ui; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; align-items: center; }
.row span:first-child { color: var(--muted); }
.row.total { border-top: 2px solid var(--line); padding-top: 6px; font-weight: 800; }
.pos { color: var(--green); } .neg { color: var(--red); }
.bar-meter { height: 9px; border-radius: 5px; background: #e6ecf2; overflow: hidden; }
.bar-meter i { display: block; height: 100%; border-radius: 5px; background: var(--green); }
.seg { display: inline-flex; background: #e9eef4; border-radius: 10px; padding: 2px; }
.seg button { padding: 4px 8px; border-radius: 8px; font-size: 12px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
input[type=range] { width: 100%; accent-color: var(--blue); }
.good-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 4px 8px; align-items: center; padding: 8px 10px; background: #f6f9fc; border-radius: 14px; }
.good-row .ic { font-size: 22px; grid-row: span 2; }
.good-row .nums { font-size: 12px; color: var(--muted); grid-column: 2 / 4; display: flex; gap: 10px; flex-wrap: wrap; }
.good-row .nums b { color: var(--ink); }
.toggle { display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: #f6f9fc; border-radius: 14px; }
.toggle .ic { font-size: 24px; }
.toggle .tx { flex: 1; display: grid; gap: 2px; }
.toggle .tx small { color: var(--muted); font-size: 12px; font-weight: 700; }
.switch { width: 48px; height: 28px; border-radius: 14px; background: #d5dde6; position: relative; flex: 0 0 auto; transition: background .15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .15s; }
.switch.on { background: var(--green); } .switch.on::after { left: 23px; }
.city-row { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: #f6f9fc; border-radius: 14px; }
.city-row .tx { flex: 1; display: grid; }
.city-row .tx small { color: var(--muted); font-size: 12px; }
.feed { font-size: 13px; display: grid; gap: 5px; }
.feed div { padding: 5px 8px; background: #f6f9fc; border-radius: 10px; }
.feed small { color: var(--muted); }
.spark { width: 100%; height: 46px; }
.stack-list { display: flex; flex-wrap: wrap; gap: 6px; }
.stack-list span { background: #fff3cd; padding: 3px 8px; border-radius: 9px; font-size: 12px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }

/* ───── modal ───── */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(20, 32, 54, .45); padding: 16px; }
.modal .card { width: min(400px, 100%); background: #fff; border-radius: 26px; padding: 22px 20px 18px; box-shadow: var(--shadow); display: grid; gap: 12px; text-align: center; max-height: 90vh; overflow-y: auto; animation: pop .25s cubic-bezier(.2, 1.4, .5, 1); }
.modal .card .big-ic { font-size: 52px; line-height: 1; }
.modal .card h3 { margin: 0; font: 800 25px 'Baloo 2', system-ui; }
.modal .card p { margin: 0; color: var(--muted); }
.modal .card .choices { display: grid; gap: 8px; margin-top: 4px; }
.modal .card .from { font-size: 12px; color: var(--violet); }
.modal .card .howto { text-align: left; display: grid; gap: 8px; font-size: 14px; color: var(--ink); }
.modal .card .howto b { color: var(--blue); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%); background: rgba(36,50,74,.94); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; max-width: 90vw; text-align: center; }

/* ───── small screens ───── */
@media (max-width: 720px) {
    .pill { height: 34px; padding: 0 9px; font-size: 13px; }
    .pill.icon { width: 34px; }
    .speeds { height: 34px; } .speeds button { width: 30px; }
    .rci { height: 34px; }
    #hud-air, #btn-sound { display: none; }
    .side { top: calc(96px + var(--safe-t)); }
    .side button { width: 46px; height: 44px; font-size: 17px; }
    .side button small { display: none; }
    .toolbar button { width: 50px; height: 52px; font-size: 20px; }
    .toolbar button small { font-size: 9px; }
    .tray { bottom: calc(68px + var(--safe-b)); }
    .item { width: 84px; }
    .panel { top: auto; height: min(78vh, 640px); width: auto; left: calc(6px + var(--safe-l)); right: calc(6px + var(--safe-r)); bottom: calc(6px + var(--safe-b)); }
    .inspector { left: calc(6px + var(--safe-l)); right: calc(6px + var(--safe-r)); width: auto; bottom: calc(72px + var(--safe-b)); }
    .ticker { top: calc(92px + var(--safe-t)); }
}
@media (max-height: 500px) and (orientation: landscape) {
    .side { top: calc(52px + var(--safe-t)); gap: 4px; }
    .side button { width: 44px; height: 38px; }
    .side button small { display: none; }
    .tray { bottom: calc(62px + var(--safe-b)); }
    .toolbar button { height: 46px; }
    .panel { top: calc(6px + var(--safe-t)); bottom: calc(6px + var(--safe-b)); left: auto; height: auto; width: min(420px, 60vw); }
}

/* ───── accounts, worlds, idle ───── */
.title-sect { display: grid; gap: 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint.small { font-size: 12px; margin: 0; }
.who { display: flex; align-items: center; gap: 6px; font-size: 16px; }
.my-cities { display: grid; gap: 8px; max-height: 36vh; overflow-y: auto; touch-action: pan-y; }
.city-card { display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border-radius: 14px; background: #f3f8fd; border: 2px solid var(--line); }
.city-card .tx { flex: 1; display: grid; }
.city-card small { color: var(--muted); font-size: 12px; }
.city-card .go { font-size: 20px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); font-weight: 800; user-select: text; -webkit-user-select: text; }
.join-row input:focus { outline: none; border-color: var(--blue); }
.chip.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: 1px; cursor: pointer; }
.idle { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; background: rgba(20, 32, 54, .35); }
.idle > div { background: #fff; border-radius: 24px; padding: 22px; box-shadow: var(--shadow); display: grid; gap: 8px; text-align: center; width: min(320px, 90vw); }
.idle .big-ic { font-size: 46px; }
.idle p { margin: 0; color: var(--muted); font-size: 14px; }
