:root {
  --bg: #fff3dc; --card: #fffaf0; --ink: #5a3d2b; --accent: #ff9a62; --accent2: #ffc86b;
  --ok: #7cc47a; --bad: #e8736b; --line: #f0dcb8; --shadow: 0 3px 0 rgba(120, 80, 40, .18);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #7ec77b; color: var(--ink);
  font-family: ui-rounded, "Nunito", "Segoe UI", system-ui, sans-serif; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }

/* ---------- верхняя панель ---------- */
#top { position: fixed; left: 0; right: 0; top: 0; display: flex; gap: 8px; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 10px 0; pointer-events: none; }
#top > * { pointer-events: auto; }
.chip, .lvl { background: var(--card); border-radius: 999px; padding: 6px 12px; font-weight: 800;
  font-size: 15px; box-shadow: var(--shadow); white-space: nowrap; }
.lvl { flex: 1; min-width: 90px; max-width: 200px; display: flex; flex-direction: column; gap: 3px; padding: 4px 12px 6px; }
.lvl .star { font-size: 13px; }
.bar { height: 8px; border-radius: 99px; background: #f0e2c6; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffb347, #ff8a5c); transition: width .3s; }
.round { width: 38px; height: 38px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 16px; font-weight: 800; padding: 0; }
.round:active, #bottom button:active { transform: translateY(2px); }

#advice { position: fixed; left: 50%; transform: translateX(-50%); top: calc(54px + env(safe-area-inset-top));
  background: rgba(255, 250, 240, .92); border-radius: 14px; padding: 6px 14px; font-size: 13px; font-weight: 700;
  box-shadow: var(--shadow); max-width: calc(100% - 20px); text-align: center; pointer-events: none; }

/* ---------- нижняя панель ---------- */
#bottom { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; justify-content: center;
  padding: 0 10px calc(10px + env(safe-area-inset-bottom)); pointer-events: none; }
#bottom button { pointer-events: auto; flex: 1; max-width: 120px; background: var(--card); border-radius: 18px;
  padding: 8px 4px 7px; font-weight: 800; font-size: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 2px; }
#bottom button span { font-size: 24px; line-height: 1; }

/* ---------- магазин (режим стройки) ---------- */
#shop { position: fixed; left: 0; right: 0; bottom: calc(76px + env(safe-area-inset-bottom)); padding: 10px;
  background: rgba(255, 243, 220, .96); border-radius: 22px 22px 0 0; box-shadow: 0 -3px 12px rgba(0,0,0,.15); }
#shop .hint { font-size: 13px; font-weight: 700; margin: 0 0 8px 2px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#shop .row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.item { flex: 0 0 auto; width: 78px; background: var(--card); border-radius: 16px; padding: 6px 4px; text-align: center;
  font-size: 11px; font-weight: 800; border: 3px solid transparent; box-shadow: var(--shadow); }
.item .em { font-size: 26px; height: 32px; line-height: 32px; }
.item .sw { display: inline-block; width: 26px; height: 26px; border-radius: 8px; vertical-align: middle; }
.item.sel { border-color: var(--accent); background: #fff0d4; }
.item.lock { opacity: .55; }
.item.poor .pr { color: var(--bad); }
.btn { background: var(--accent); color: #fff; border-radius: 14px; padding: 8px 14px; font-weight: 800; box-shadow: var(--shadow); }
.btn.green { background: var(--ok); }
.btn.gray { background: #cdbfa6; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 11px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- попап над объектом / участком ---------- */
#popup { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom));
  background: var(--card); border-radius: 18px; padding: 10px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
  display: flex; flex-direction: column; gap: 8px; align-items: center; min-width: 220px; text-align: center; font-weight: 800; }
#popup .acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------- окна ---------- */
#modal { position: fixed; inset: 0; background: rgba(60, 35, 15, .45); display: flex; align-items: flex-end; justify-content: center; }
#modal .card { background: var(--bg); width: min(560px, 100%); max-height: 86%; border-radius: 24px 24px 0 0; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom); animation: up .18s ease-out; }
@media (min-width: 700px) { #modal { align-items: center; } #modal .card { border-radius: 24px; max-height: 80%; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
#modal .head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
#modal h2 { margin: 0; font-size: 20px; }
#modal .x { width: 34px; height: 34px; border-radius: 50%; background: var(--bad); color: #fff; font-weight: 900; box-shadow: var(--shadow); }
#modal .body { overflow-y: auto; padding: 8px 14px 16px; }
.note { font-size: 13px; opacity: .8; margin: 0 0 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.rcard { background: var(--card); border-radius: 18px; padding: 10px; text-align: center; box-shadow: var(--shadow); position: relative; }
.rcard .em { font-size: 40px; line-height: 1.1; }
.rcard .nm { font-weight: 800; font-size: 14px; margin: 2px 0; }
.rcard .st { color: #f2a900; letter-spacing: 2px; font-size: 15px; }
.rcard .st .off { color: #e3d6bd; }
.rcard .meta { font-size: 12px; opacity: .85; margin-top: 3px; }
.rcard.lock { filter: grayscale(.85); opacity: .65; }
.rcard .lk { position: absolute; top: 6px; right: 8px; font-size: 12px; font-weight: 800; background: #fff; border-radius: 99px; padding: 1px 7px; }
.ings { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin-top: 5px; }
.ing { background: #f6ead0; border-radius: 9px; padding: 1px 6px; font-size: 12px; font-weight: 700; }
.ing.u { background: #ffe39a; box-shadow: inset 0 0 0 2px #f2b600; }
.ing.u.miss { background: #ffd9d4; box-shadow: inset 0 0 0 2px var(--bad); }

.list { display: flex; flex-direction: column; gap: 10px; }
.row2 { background: var(--card); border-radius: 18px; padding: 10px 12px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center; }
.row2 .big { font-size: 34px; }
.row2 .mid { flex: 1; min-width: 0; font-size: 13px; }
.row2 .mid b { font-size: 15px; display: block; }
.row2.lock { opacity: .6; }
.prog { height: 10px; background: #f0e2c6; border-radius: 99px; overflow: hidden; margin-top: 5px; }
.prog i { display: block; height: 100%; background: linear-gradient(90deg, #7cc47a, #4fae7b); }
.invrow { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.invrow .ing { font-size: 13px; padding: 3px 9px; }
h3 { margin: 14px 0 8px; font-size: 15px; }

/* ---------- тосты ---------- */
#toasts { position: fixed; left: 0; right: 0; top: calc(96px + env(safe-area-inset-top)); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 5; }
.toast { background: rgba(70, 45, 25, .92); color: #fff; padding: 8px 14px; border-radius: 14px; font-weight: 700; font-size: 14px; max-width: 90%; text-align: center; animation: pop .25s ease-out; }
.toast.good { background: rgba(60, 150, 90, .95); }
.toast.big { font-size: 17px; padding: 12px 18px; background: linear-gradient(135deg, #ff9a62, #ffb347); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }

.welcome { text-align: center; }
.welcome .em { font-size: 54px; }
.welcome ul { text-align: left; padding-left: 20px; line-height: 1.7; font-weight: 700; }

#bottom button em { font-style: normal; }
#popup .sub { font-size: 12px; font-weight: 700; opacity: .85; line-height: 1.4; }
.row2.pick { cursor: pointer; border: 3px solid transparent; }
.row2.pick.cur { border-color: var(--accent); background: #fff0d4; }
.rcard .ract { margin-top: 6px; min-height: 28px; display: flex; justify-content: center; align-items: center; }
.rcard .ok { color: #3c9a5a; font-weight: 800; font-size: 13px; }
.toast.bad { background: rgba(200, 70, 60, .95); }
.welcome p { font-weight: 700; }

/* ---------- крестик «закрыть» в каждом меню ---------- */
#popup, #shop { position: fixed; }
#popup .x, #shop .x { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%; padding: 0;
  background: rgba(90, 61, 43, .14); color: #5a3d2b; font-size: 13px; font-weight: 900; line-height: 26px; text-align: center; box-shadow: none; }
#popup .x:active, #shop .x:active { background: rgba(90, 61, 43, .3); }
#popup { padding-top: 14px; min-width: 200px; }
#popup .ttl { padding: 0 22px; }
#shop { padding-top: 10px; }
#shop .hint { padding-right: 30px; }
#shop .tabs { display: flex; gap: 6px; padding-right: 34px; margin-bottom: 8px; overflow-x: auto; }
#shop .tab { flex: 0 0 auto; background: var(--card); border-radius: 12px; padding: 5px 10px; font-size: 13px; font-weight: 800; box-shadow: var(--shadow); opacity: .75; }
#shop .tab span { margin-right: 4px; }
#shop .tab.on { opacity: 1; background: var(--accent); color: #fff; }
#shop .soon { width: 100%; text-align: center; padding: 16px 0; font-weight: 800; opacity: .7; }
#bottom button em { font-size: 11px; }
