:root {
  --bg: #101418;
  --fg: #f2f4f6;
  --muted: #aab4bf;
  --accent: #f6c35a;
  --accent-fg: #1a1200;
  --card: rgba(16, 20, 24, 0.86);
  --btn: rgba(255, 255, 255, 0.12);
  --btn-border: rgba(255, 255, 255, 0.25);
  --ok: #7ad67a;
  --warn: #ffb347;
  --bad: #ff7a7a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; touch-action: none;
}
#cam {
  position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0;
  background: #000; display: none;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; display: block; }
#overlay { position: fixed; inset: 0; z-index: 2; pointer-events: auto; }
.hidden { display: none !important; }

#hud {
  position: absolute; left: 0; right: 0; top: 0; padding: calc(8px + var(--sat)) 12px 8px;
  background: linear-gradient(rgba(0,0,0,.65), rgba(0,0,0,0));
  font-size: 13px; line-height: 1.35; white-space: pre-line; text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
#hint {
  text-align: center; font-size: 15px; padding: 8px 12px; margin: 0 2px 4px; border-radius: 10px;
  background: rgba(0,0,0,.6); text-shadow: 0 1px 2px #000; pointer-events: none;
}

#panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 100%; overflow-y: auto;
  padding: 16px 16px calc(16px + var(--sab)); background: var(--card);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: 16px 16px 0 0; touch-action: pan-y;
}
#panel h1 { margin: 0 0 10px; font-size: 22px; }
#panel .tag { font-size: 13px; color: var(--muted); font-weight: normal; margin-left: 8px; }
#panel .lead { margin: 0 0 14px; color: var(--muted); line-height: 1.4; }
#aboutDetails .note { font-size: 14px; line-height: 1.45; }
#devDetails { margin-top: 10px; border-top: 1px solid var(--btn-border); }
#devDetails > summary { font-size: 13px; }
.caps { font-size: 14px; margin-bottom: 12px; white-space: pre-line; }
.caps .ok { color: var(--ok); } .caps .warn { color: var(--warn); } .caps .bad { color: var(--bad); }

button {
  font: inherit; color: var(--fg); background: var(--btn); border: 1px solid var(--btn-border);
  border-radius: 10px; padding: 12px 14px; min-height: 48px; cursor: pointer; touch-action: manipulation;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; font-size: 18px; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; }
.actions { display: flex; gap: 10px; margin-bottom: 12px; }
.actions button { flex: 1; }

details { margin-top: 4px; }
summary { cursor: pointer; padding: 8px 0; color: var(--muted); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin: 10px 0; }
label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
input {
  font: inherit; font-size: 16px; color: var(--fg); background: rgba(255,255,255,.08);
  border: 1px solid var(--btn-border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
.row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.row button { flex: 1; }
.msg { min-height: 1.4em; margin: 8px 0 0; color: var(--accent); font-size: 14px; }
.foot { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

#controls {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px calc(10px + var(--sab));
  display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.7));
}
.ctl-row { display: flex; gap: 8px; }
.ctl-row button { flex: 1; padding: 10px 6px; font-size: 14px; background: rgba(0,0,0,.55); }
.ctl-row[data-mode] { display: none; }
#controls[data-mode="xr"] .ctl-row[data-mode="xr"],
#controls[data-mode="compass"] .ctl-row[data-mode="compass"],
#controls[data-mode="view"] .ctl-row[data-mode="view"] { display: flex; }
#controls[data-mode="view"] #btnDisp { display: none; } /* при разглеждане мащабът е приближаването */
#controls, #hud, #overlay.viewing { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } /* влаченето не бива да маркира текста на бутоните */
#overlay.viewing { cursor: grab; }
#overlay.viewing:active { cursor: grabbing; }
.actions { flex-wrap: wrap; }
.actions #btnView { flex: 1 1 100%; }                    /* главният бутон е сам на ред */
.actions #btnLife, .actions #btnStart { font-size: 15px; } /* „Оживи“ и „Виж го на място“ са под него */
#controls:not([data-mode="view"]) #btnViewAr { display: none; }
.ctl-row button.active { border-color: var(--ok); color: var(--ok); }
.ctl-row[data-mode="view"] button { font-size: 13px; padding: 10px 2px; white-space: nowrap; flex: 1 1 auto; } /* пет бутона на един ред и на тесен телефон: ширината е по надписа */
.ctl-row[data-mode="view"] { gap: 6px; }
/* сцената на превземането: вместо бутоните на разглеждането стои нейният ред с плъзгача */
#controls:not(.siege) #siegeRow, #controls.siege .ctl-row[data-mode="view"]:not(#siegeRow) { display: none !important; }
#siegeRow { align-items: center; }
#siegeRow input[type=range] { flex: 4 1 80px; min-width: 60px; padding: 0; height: 36px; background: transparent; border: 0; accent-color: var(--accent); touch-action: pan-x; }
#siegeRow button { flex: 0 1 auto; padding: 10px 9px; }

@media (min-width: 700px) {
  #panel { left: 50%; transform: translateX(-50%); width: 560px; bottom: 16px; border-radius: 16px; }
}

#planWrap { margin: 4px 0 12px; }
#plan {
  display: block; width: 100%; aspect-ratio: 1 / 1; border-radius: 12px;
  background: #0b0e11; border: 1px solid var(--btn-border); touch-action: none;
}
.plan-row { margin: 8px 0 0; }
.plan-row button { padding: 10px 6px; font-size: 14px; min-height: 42px; }
.plan-row button.active { border-color: var(--ok); color: var(--ok); }

#preset, #tex, #quality {
  font: inherit; font-size: 15px; color: var(--fg); background: rgba(255,255,255,.08);
  border: 1px solid var(--btn-border); border-radius: 10px; padding: 10px 12px; width: 100%; margin-bottom: 8px;
}
.note { margin: 8px 2px 0; font-size: 13px; color: var(--muted); line-height: 1.4; }

#snap {
  position: absolute; inset: 0; z-index: 5; background: rgba(0,0,0,.92); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: calc(12px + var(--sat)) 12px calc(12px + var(--sab)); gap: 10px;
}
#snap img { max-width: 100%; max-height: 72vh; border-radius: 10px; box-shadow: 0 4px 24px rgba(0,0,0,.6); }
#snap .row { width: 100%; max-width: 480px; }
#controls[data-mode="compass"] [data-xr-only] { display: none; }

/* ---------------------------------------------------------------- разглеждане: карта с котви */
#viewUi { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
#viewUi button, #vCard, .vsheet { pointer-events: auto; }
#overlay.viewing #controls { display: none !important; }   /* старите бутони са само за добавената реалност */
#overlay.viewing #hud { display: none; }
#vTop { position: absolute; left: 0; right: 0; top: 0; padding: calc(8px + var(--sat)) 10px 8px; display: flex; gap: 8px; align-items: center;
  background: linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,0)); }
.vround { width: 46px; min-width: 46px; height: 46px; min-height: 46px; padding: 0; border-radius: 50%; background: rgba(16,20,24,.82); font-size: 18px;
  display: flex; align-items: center; justify-content: center; flex-direction: column; line-height: 1; }
.vchip { flex: 1; min-height: 46px; border-radius: 23px; background: rgba(16,20,24,.82); font-weight: 600; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 6px; overflow: hidden; white-space: nowrap; }
.vchip .caret { opacity: .7; font-size: 13px; }
#vNorth small { font-size: 9px; color: var(--muted); margin-top: 1px; }
#vNorthArrow { display: inline-block; color: #ff6b5a; font-size: 14px; transition: transform .15s linear; }
#vScale { position: absolute; right: 10px; top: 50%; transform: translateY(-60%); display: flex; flex-direction: column; gap: 6px; }
#vScale button { min-height: 40px; padding: 6px 10px; font-size: 13px; border-radius: 10px; background: rgba(16,20,24,.78); text-align: center; }
#vScale button.active { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
#vBottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 10px calc(10px + var(--sab)); display: flex; flex-direction: column; gap: 8px; }
#vHintSlot #hint { margin: 0; pointer-events: none; }
#vCard { background: var(--card); border: 1px solid var(--btn-border); border-radius: 14px; padding: 10px 12px; max-height: 42vh; overflow-y: auto; }
#vCardHead { display: flex; align-items: baseline; gap: 8px; }
#vCardTitle { font-weight: 600; font-size: 16px; }
#vCardCentury { color: var(--accent); font-size: 13px; flex: 1; }
#vCardToggle { min-height: 30px; padding: 2px 10px; font-size: 13px; background: transparent; }
#vCardBody { font-size: 14px; line-height: 1.4; color: var(--muted); margin-top: 4px; }
#vCard.short #vCardBody { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#vCardDist { font-size: 13px; margin-top: 6px; color: #8fc4e8; }
#vCardDist:empty { display: none; }
#vCardDist button { min-height: 32px; padding: 4px 8px; margin: 4px 4px 0 0; font-size: 13px; }
#vBar { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
#vLayers, #vTour { min-height: 46px; border-radius: 23px; background: rgba(16,20,24,.82); padding: 0 16px; white-space: nowrap; }
#vTourCtl { display: flex; align-items: center; gap: 2px; min-height: 46px; border-radius: 23px; background: var(--accent); padding: 0 4px; }
#vTourCtl.hidden { display: none; }
#vTourCtl button { min-height: 42px; min-width: 40px; padding: 0 8px; border: 0; background: transparent; color: var(--accent-fg); font-size: 16px; font-weight: 600; border-radius: 20px; }
#vTourCtl button:active { background: rgba(0,0,0,.12); }
#vTourPlay { white-space: nowrap; }
#vMe.on { background: #2f8cff; }
#vMe.follow { background: #2f8cff; box-shadow: 0 0 0 3px rgba(47,140,255,.4); }
.vsheet { position: absolute; left: 8px; right: 8px; bottom: calc(70px + var(--sab)); max-height: 62vh; overflow-y: auto; background: var(--card);
  border: 1px solid var(--btn-border); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.vsheet h3 { margin: 6px 4px 2px; font-size: 13px; color: var(--muted); font-weight: 600; }
.vsheet button { text-align: left; min-height: 42px; padding: 8px 12px; font-size: 15px; }
.vsheet button small { color: var(--muted); margin-left: 6px; }
.vsheet button.active { border-color: var(--accent); }
.vtoggle.on { border-color: var(--ok); color: var(--ok); }
.vabout { margin: 2px 6px 6px; font-size: 14px; line-height: 1.45; color: var(--fg); }
.vabout.small { font-size: 12.5px; color: var(--muted); }
.vlink { background: transparent; border: 0; color: #8fc4e8; min-height: 30px; padding: 4px 0; font-size: 13px; }
#vCardSrc { font-size: 12.5px; line-height: 1.4; color: var(--muted); border-left: 2px solid var(--btn-border); padding-left: 8px; margin-top: 2px; }
.vsheet { background: #12171c; z-index: 4; box-shadow: 0 -6px 24px rgba(0,0,0,.45); } /* плътни: картичката отдолу не прозира */
