/* Бункер 77 — інтерфейс у теплому ретро-стилі сховища */
:root {
    --bg: #120f0b;
    --glass: rgba(28, 22, 16, 0.9);
    --glass2: rgba(36, 29, 21, 0.96);
    --line: rgba(245, 184, 61, 0.28);
    --line2: rgba(214, 190, 150, 0.16);
    --txt: #f3ead8;
    --dim: #b3a58b;
    --amber: #f5b83d;
    --green: #4ade80;
    --red: #f87171;
    --blue: #38bdf8;
    --r: 14px;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { position: fixed; inset: 0; overflow: hidden; background: var(--bg); color: var(--txt); font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
input { font: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
.off { display: none !important; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.glass { background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-radius: var(--r); box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55); }
.ib { width: 44px; height: 44px; flex: none; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(8px); position: relative; color: #fde7b5; }
.ib svg { width: 22px; height: 22px; }
.ib:active { transform: scale(0.94); }
.badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #ef4444; color: #fff; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px #1c1610; }
.badge.ok { background: var(--green); color: #052e16; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 13px; border-radius: 10px; font-weight: 700; font-size: 13px; background: rgba(245, 184, 61, 0.12); border: 1px solid rgba(245, 184, 61, 0.5); color: #fde7b5; white-space: nowrap; }
.btn:active { transform: scale(0.97); }
.btn.gold { background: linear-gradient(180deg, #fcd34d, #f59e0b); color: #241503; border-color: #fbbf24; }
.btn.red { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.5); color: #fecaca; }
.btn.green { background: rgba(74, 222, 128, 0.14); border-color: rgba(74, 222, 128, 0.5); color: #bbf7d0; }
.btn.blue { background: rgba(56, 189, 248, 0.14); border-color: rgba(56, 189, 248, 0.5); color: #bae6fd; }
.btn.dim, .btn:disabled { background: rgba(214, 190, 150, 0.06); border-color: rgba(214, 190, 150, 0.2); color: #8c7f68; }
.btn:disabled { cursor: not-allowed; }
.btn.sm { padding: 6px 9px; font-size: 12px; }
.btn.xs { padding: 3px 7px; font-size: 11px; border-radius: 7px; }
.muted { color: var(--dim); }
.k { color: var(--amber); font-weight: 800; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 3px; transition: width 0.25s; }

/* ---------- верх ---------- */
#top { position: absolute; top: calc(8px + var(--safe-t)); left: 8px; right: 8px; z-index: 20; display: flex; gap: 8px; align-items: flex-start; pointer-events: none; }
#top > * { pointer-events: auto; }
#resbox { display: flex; gap: 10px; padding: 7px 12px; flex-wrap: wrap; }
.res { display: flex; align-items: center; gap: 6px; min-width: 92px; }
.res svg { width: 18px; height: 18px; flex: none; }
.res .bar { width: 56px; height: 7px; }
.res b { font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 26px; }
.res.low .bar { box-shadow: 0 0 0 1px #ef4444; animation: lowp 1s infinite; }
@keyframes lowp { 50% { box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3); } }
.spacer { flex: 1; }
#money { flex-direction: column; align-items: flex-end; padding: 5px 12px; display: flex; min-width: 108px; }
#money small { font-size: 9px; letter-spacing: 0.16em; color: var(--dim); font-weight: 700; }
#money b { font-size: 21px; font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; }
#money b::before { content: 'К '; color: var(--amber); }
#sub { position: absolute; top: calc(58px + var(--safe-t)); left: 8px; z-index: 19; display: flex; gap: 6px; flex-wrap: wrap; max-width: calc(100% - 16px); }
.chip { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 11px; background: var(--glass); border: 1px solid var(--line2); font-size: 12px; font-weight: 700; }
.chip svg { width: 15px; height: 15px; }
button.chip { border-color: var(--line); }

/* ---------- низ ---------- */
#dock { position: absolute; left: 0; right: 0; bottom: 0; z-index: 20; padding: 0 8px calc(8px + var(--safe-b)); display: flex; justify-content: center; pointer-events: none; }
#dock > * { pointer-events: auto; }
#nav { display: flex; gap: 6px; padding: 6px; }
.nb { width: 66px; height: 58px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 700; color: #e9dcc0; position: relative; border: 1px solid transparent; }
.nb svg { width: 24px; height: 24px; color: var(--amber); }
.nb:active { transform: scale(0.95); }
.nb.on { border-color: var(--amber); background: rgba(245, 184, 61, 0.12); }
#buildbar { flex-direction: column; gap: 6px; width: min(980px, 100%); }
#buildbar .head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 13px; }
#buildlist { display: flex; gap: 6px; padding: 7px; overflow-x: auto; scrollbar-width: thin; }
.bt { flex: none; width: 92px; border-radius: 12px; border: 1px solid var(--line2); background: rgba(255, 255, 255, 0.03); padding: 5px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative; }
.bt img { width: 82px; height: 54px; border-radius: 6px; object-fit: cover; image-rendering: auto; }
.bt .nm { font-size: 10.5px; font-weight: 700; text-align: center; line-height: 1.15; min-height: 24px; display: flex; align-items: center; }
.bt .c { font-size: 11px; font-weight: 800; color: var(--amber); }
.bt.on { border-color: var(--amber); background: rgba(245, 184, 61, 0.14); box-shadow: 0 0 14px rgba(245, 184, 61, 0.3); }
.bt.lock { opacity: 0.45; filter: grayscale(0.8); }
.bt.poor .c { color: var(--red); }

/* ---------- картка (кімната / мешканець) ---------- */
#card { position: absolute; z-index: 25; left: 8px; right: 8px; bottom: calc(84px + var(--safe-b)); max-width: 440px; margin: 0 auto; padding: 12px; max-height: 58vh; overflow-y: auto; scrollbar-width: thin; }
#card h3 { margin: 0; font-size: 17px; font-weight: 800; }
#card .x { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 8px; color: var(--dim); font-size: 15px; }
.sec { margin-top: 10px; }
.lbl { font-size: 10px; font-weight: 800; letter-spacing: 0.14em; color: var(--dim); text-transform: uppercase; margin-bottom: 5px; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; padding: 4px 0; border-bottom: 1px dashed rgba(214, 190, 150, 0.12); }
.kv b { font-weight: 800; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.worker { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 10px; background: rgba(255, 255, 255, 0.03); margin-bottom: 4px; }
.worker img { width: 36px; height: 36px; border-radius: 9px; background: rgba(0,0,0,0.25); }
.worker .nm { font-weight: 700; font-size: 13px; }
.worker small { display: block; color: var(--dim); font-size: 11px; }
.statv { font-weight: 900; font-size: 14px; padding: 2px 7px; border-radius: 7px; background: rgba(0, 0, 0, 0.3); }
.stats { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 8px; align-items: center; font-size: 12px; }
.stats .bar { height: 7px; }
.av { width: 56px; height: 56px; flex: none; border-radius: 12px; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line2); }
.gear { display: flex; gap: 6px; }
.gear button { flex: 1; text-align: left; padding: 7px 9px; border-radius: 10px; border: 1px solid var(--line2); background: rgba(255, 255, 255, 0.03); font-size: 12px; }
.gear small { display: block; font-size: 10px; color: var(--dim); letter-spacing: 0.08em; text-transform: uppercase; }
.picker { margin-top: 8px; max-height: 210px; overflow-y: auto; border-radius: 10px; border: 1px solid var(--line2); }
.picker button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 9px; border-bottom: 1px solid rgba(214, 190, 150, 0.08); font-size: 12.5px; text-align: left; }
.picker button:hover { background: rgba(245, 184, 61, 0.08); }
.picker img { width: 30px; height: 30px; border-radius: 8px; background: rgba(0,0,0,0.25); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); font-weight: 900; }

/* ---------- великі панелі ---------- */
#sheet { position: absolute; inset: 0; z-index: 40; background: rgba(8, 6, 4, 0.6); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: calc(10px + var(--safe-t)) 10px calc(10px + var(--safe-b)); }
.sheet-box { width: min(640px, 100%); max-height: 100%; display: flex; flex-direction: column; background: var(--glass2); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7); animation: pop 0.18s ease-out; overflow: hidden; }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.sheet-box > header { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line2); }
.sheet-box > header h2 { margin: 0; font-size: 18px; font-weight: 800; flex: 1; }
.sheet-box > header svg { width: 22px; height: 22px; color: var(--amber); }
.sheet-box > header .x { width: 34px; height: 34px; border-radius: 10px; color: var(--dim); font-size: 18px; }
#sheetBody { padding: 12px 14px 16px; overflow-y: auto; scrollbar-width: thin; min-height: 0; }
.subtabs { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.subtabs button { padding: 6px 11px; border-radius: 9px; font-size: 12px; font-weight: 700; color: var(--dim); border: 1px solid var(--line2); }
.subtabs button.on { color: #fff; border-color: var(--amber); background: rgba(245, 184, 61, 0.12); }
.card { position: relative; padding: 10px 12px; border-radius: 13px; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line2); margin-bottom: 8px; }
.card h4 { margin: 0; font-size: 14px; font-weight: 800; }
.card p { margin: 3px 0 0; font-size: 12px; color: var(--dim); line-height: 1.35; }
.card.done { border-color: rgba(74, 222, 128, 0.55); background: rgba(74, 222, 128, 0.06); }
.dw-row { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 11px; border: 1px solid var(--line2); background: rgba(255, 255, 255, 0.03); margin-bottom: 5px; width: 100%; text-align: left; }
.dw-row img { width: 40px; height: 40px; flex: none; border-radius: 10px; background: rgba(0,0,0,0.25); }
.dw-row .nm { font-weight: 700; font-size: 13px; }
.dw-row small { display: block; font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dw-row .st { font-weight: 900; min-width: 26px; text-align: center; }
.pill { font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 999px; background: rgba(245, 184, 61, 0.14); color: #fde68a; border: 1px solid rgba(245, 184, 61, 0.35); }
.pill.g { background: rgba(74, 222, 128, 0.14); color: #86efac; border-color: rgba(74, 222, 128, 0.35); }
.pill.b { background: rgba(56, 189, 248, 0.14); color: #7dd3fc; border-color: rgba(56, 189, 248, 0.35); }
.pill.r { background: rgba(239, 68, 68, 0.12); color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.it { padding: 8px 9px; border-radius: 11px; border: 1px solid var(--line2); background: rgba(255, 255, 255, 0.03); font-size: 12px; text-align: left; }
.it b { display: block; font-size: 12.5px; }
.log { font-size: 12px; line-height: 1.45; color: #d9ccb0; max-height: 160px; overflow-y: auto; padding: 6px 8px; border-radius: 9px; background: rgba(0, 0, 0, 0.25); }
.log div { padding: 2px 0; border-bottom: 1px dashed rgba(214, 190, 150, 0.08); }
.log span { color: var(--dim); font-size: 10.5px; margin-right: 6px; }
.menu-list { display: flex; flex-direction: column; gap: 6px; }
.menu-list button, .menu-list a { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; border: 1px solid var(--line2); background: rgba(255, 255, 255, 0.03); font-weight: 700; font-size: 14px; text-align: left; }
.menu-list svg { width: 20px; height: 20px; color: var(--amber); flex: none; }
.menu-list .danger { color: #fca5a5; }
.ach { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 11px; border: 1px solid var(--line2); margin-bottom: 6px; opacity: 0.45; }
.ach.got { opacity: 1; border-color: rgba(245, 184, 61, 0.5); background: rgba(245, 184, 61, 0.06); }
.ach b { font-size: 13px; } .ach small { display: block; font-size: 11.5px; color: var(--dim); }
.help p { font-size: 13px; line-height: 1.5; margin: 0 0 9px; color: #e2d6bd; }
.help b { color: var(--amber); }
.help h4 { margin: 14px 0 6px; font-size: 14px; color: var(--amber); }

/* ---------- модалки ---------- */
.modal { position: absolute; inset: 0; z-index: 60; background: rgba(8, 6, 4, 0.72); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal .box { width: min(420px, 100%); max-height: 100%; overflow-y: auto; padding: 20px; text-align: center; border-radius: 18px; background: var(--glass2); border: 1px solid rgba(245, 184, 61, 0.45); box-shadow: 0 0 60px rgba(245, 184, 61, 0.12); animation: pop 0.2s ease-out; }
.modal h2 { margin: 6px 0 4px; font-size: 21px; font-weight: 900; }
.modal .btn { width: 100%; padding: 12px; font-size: 15px; margin-top: 8px; }
.loot { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
.loot > div { padding: 12px 8px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25); font-size: 13px; font-weight: 700; animation: flip 0.45s ease-out backwards; }
.loot > div:nth-child(2) { animation-delay: 0.15s; } .loot > div:nth-child(3) { animation-delay: 0.3s; } .loot > div:nth-child(4) { animation-delay: 0.45s; }
.loot .big { font-size: 26px; display: block; margin-bottom: 4px; }
@keyframes flip { from { transform: rotateY(90deg); opacity: 0; } }
.sumrow { display: flex; justify-content: space-between; padding: 6px 2px; font-size: 14px; border-bottom: 1px dashed rgba(214, 190, 150, 0.12); }

#toasts { position: absolute; z-index: 70; left: 50%; transform: translateX(-50%); top: calc(96px + var(--safe-t)); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: min(460px, 92vw); }
.toast { padding: 9px 14px; border-radius: 12px; font-size: 13px; font-weight: 600; background: rgba(28, 22, 16, 0.96); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); animation: tin 0.2s ease-out; transition: opacity 0.3s, transform 0.3s; text-align: center; }
.toast.err { border-color: rgba(239, 68, 68, 0.6); color: #fecaca; }
.toast.good { border-color: rgba(74, 222, 128, 0.6); color: #bbf7d0; }
.toast.warn { border-color: rgba(249, 115, 22, 0.8); color: #fed7aa; }
.toast.gold { border-color: rgba(245, 184, 61, 0.7); color: #fde68a; }
.toast.hide { opacity: 0; transform: translateY(-8px); }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }
#hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-b)); z-index: 18; width: min(460px, calc(100% - 16px)); padding: 9px 34px 9px 12px; font-size: 13px; line-height: 1.35; border-color: rgba(245, 184, 61, 0.55); }
#hint b { color: var(--amber); }
#hint .x { position: absolute; top: 6px; right: 8px; width: 22px; height: 22px; color: var(--dim); }
#hint .step { font-size: 10px; font-weight: 800; letter-spacing: 0.15em; color: var(--amber); display: block; margin-bottom: 2px; }
body.carded #hint, body.building #hint { display: none; }

@media (min-width: 900px) {
    #card { left: auto; right: 12px; bottom: auto; top: calc(100px + var(--safe-t)); margin: 0; width: 380px; max-height: calc(100% - 200px); }
}
@media (max-width: 520px) {
    #resbox { gap: 6px; padding: 6px 8px; }
    .res { min-width: 0; gap: 4px; } .res .bar { display: none; }
    #money { min-width: 0; } #money b { font-size: 18px; }
    .nb { width: 56px; font-size: 9.5px; }
    #card { bottom: calc(80px + var(--safe-b)); }
    #toasts { top: calc(132px + var(--safe-t)); }
}

/* ---------- смуги прокрутки в стилі гри (замість білих системних) ---------- */
:root { color-scheme: dark; }
* { scrollbar-width: thin; scrollbar-color: rgba(245, 184, 61, 0.45) rgba(255, 255, 255, 0.04); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.04); border-radius: 8px; }
::-webkit-scrollbar-thumb { background: rgba(245, 184, 61, 0.45); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(245, 184, 61, 0.7); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
