/* Phone controls (touch-ui.js). The middle of the screen stays clear: one status line on top, the joystick
   under the left thumb, an arc of icon buttons under the right thumb. Everything here is scoped to the
   #touchUI layer or to body.touch, so desktop is untouched. */

/* ---------- legacy panels the touch layout replaces ---------- */
body.touch #touch, body.touch #objective, body.touch #awareness, body.touch #routeHint, body.touch #scoutLine,
body.touch .exp-toolbar, body.touch #gadgetBar, body.touch #prompt, body.touch .hud.top .inv,
body.touch .hud.top .bars { display: none !important; }
/* the old touch block and #view no longer scroll or zoom the page */
body.touch #game { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* modals sit above the controls layer (which sits above the 3D canvases) */
body.touch #game > .modal { z-index: 12; }
body.touch #game > .down { z-index: 11; }
body.touch .clock { font-size: 13px; opacity: .8; }

/* ---------- one short status line at the top ---------- */
body.touch #statusLine { display: block !important; position: absolute; left: calc(max(8px, env(safe-area-inset-left)) + 84px);
  top: max(8px, env(safe-area-inset-top)); max-width: min(calc(100vw - 440px), 480px); padding: 4px 12px; border-radius: 999px;
  background: #050b10a8; color: #e5e7eb; font: 600 12px/1.35 Inter, sans-serif; letter-spacing: .3px; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; z-index: 6; }
body.touch #statusLine:empty { display: none !important; }
body.touch #statusLine.alert, body.touch #statusLine .alert { color: #fecaca; }
@media (orientation: portrait) {
  body.touch #statusLine { left: 50%; transform: translateX(-50%); top: calc(max(8px, env(safe-area-inset-top)) + 58px); max-width: calc(100vw - 32px); font-size: 11px; }
}

/* ---------- minimap: a small corner circle that taps open the full map ---------- */
body.touch #mapToggle.map-widget { position: absolute; left: max(8px, env(safe-area-inset-left)) !important;
  top: calc(max(8px, env(safe-area-inset-top)) + 30px) !important; bottom: auto !important; width: 76px !important; height: 76px;
  padding: 0 !important; border-radius: 50% !important; overflow: hidden; opacity: .8; border: 2px solid #ffffff30;
  background: #0b171dcc; box-shadow: 0 4px 14px #0008; z-index: 6; }
body.touch #mapToggle .map-title, body.touch #mapToggle .map-caption { display: none !important; }
body.touch #mapToggle canvas { display: block; width: 100%; height: 100%; margin: 0; object-fit: cover; }
@media (orientation: portrait) {
  body.touch #mapToggle.map-widget { top: calc(max(8px, env(safe-area-inset-top)) + 88px) !important; width: 68px !important; height: 68px; }
}

/* ---------- the layer ---------- */
#touchUI { position: absolute; inset: 0; z-index: 5; pointer-events: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  font-family: Inter, system-ui, sans-serif; color: #fff; }
#touchUI[hidden] { display: none; }
.tu-safe { position: absolute; top: env(safe-area-inset-top); left: env(safe-area-inset-left);
  right: env(safe-area-inset-right); bottom: env(safe-area-inset-bottom); }
.tu-c { position: absolute; transform: translate(-50%, -50%); --sz: max(48px, calc(var(--b) * var(--s, 1) * 1px));
  width: var(--sz); height: var(--sz); border-radius: 50%; pointer-events: auto; touch-action: none; }
.tu-btn { display: grid; place-items: center; padding: 0; margin: 0; border: 2px solid #ffffff2e; background: #0b1519a6;
  color: #fff; font: calc(var(--sz) * .42) / 1 system-ui, sans-serif; cursor: pointer; transition: transform .08s, background .15s, border-color .15s; }
.tu-btn .tu-ico { pointer-events: none; line-height: 1; }
.tu-badge { position: absolute; right: -2px; bottom: -2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: #111c; border: 1px solid #ffffff40; font: 700 11px/16px Inter, sans-serif; font-style: normal; text-align: center; pointer-events: none; }
.tu-badge:empty { display: none; }
.tu-top { background: #050b10a0; border-color: #ffffff22; }
.tu-btn.tu-held { transform: translate(-50%, -50%) scale(.92); background: #ffffff30; }
.tu-btn.tu-on { background: #dc262666; border-color: #f87171; }
[data-c="light"].tu-on { background: #fde04755; border-color: #fde047; }
[data-c="stealth"].tu-on { background: #16a34a66; border-color: #86efac; }
[data-c="crouch"].tu-on { background: #60a5fa55; border-color: #93c5fd; }
.tu-btn.tu-ready { border-color: #86efac; background: #12301fcc; box-shadow: 0 0 0 3px #86efac55, 0 0 16px #86efac88; animation: tu-ready 1s ease-in-out infinite; }
@keyframes tu-ready { 50% { box-shadow: 0 0 0 6px #86efac33, 0 0 24px #86efacaa; } }
.tu-btn.tu-dis { opacity: .35 !important; filter: grayscale(1); }
.tu-btn.tu-low { border-color: #f87171; }
.tu-off { display: none !important; }
.tu-slot.tu-empty { border-style: dashed; color: #ffffff80; background: #0b151966; }
.tu-down .tu-btn:not(.tu-top):not([data-c="radio"]):not([data-c="bag"]) { opacity: .25 !important; }

/* radial fills: search progress, stealth charge, battery, stamina */
.tu-ring::before, .tu-lock::before { content: ''; position: absolute; inset: -5px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(var(--rc, #86efac) calc(var(--p, 0) * 1turn), #ffffff14 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px)); }
[data-c="use"] { --rc: #fde047; }
[data-c="light"] { --rc: #fef08a; }
[data-c="light"].tu-low { --rc: #f87171; }
[data-c="stealth"] { --rc: #4ade80; }

/* ---------- floating joystick ---------- */
.tu-joy { pointer-events: none; border: 2px solid #ffffff26; background: radial-gradient(circle, #ffffff10, #ffffff06 70%); }
.tu-knob { position: absolute; left: 50%; top: 50%; width: 42%; height: 42%; margin: -21% 0 0 -21%; border-radius: 50%;
  background: #ffffff3a; border: 2px solid #ffffff55; pointer-events: none; }
.tu-joy.tu-active { opacity: .95 !important; border-color: #ffffff44; }
.tu-joy.tu-active .tu-knob { background: #ffffff66; }
.tu-lock { position: absolute; left: 50%; top: -58px; width: 48px; height: 48px; margin-left: -24px; border-radius: 50%;
  border: 2px solid #ffffff33; background: #0b1519b0; color: #fff; font-size: 20px; padding: 0; display: none; pointer-events: none; --rc: #a3e635; }
.tu-joy.tu-active .tu-lock, .tu-joy.tu-locked .tu-lock { display: grid; place-items: center; }
.tu-joy.tu-armed .tu-lock { border-color: #a3e635; background: #3f6212cc; transform: scale(1.12); }
.tu-joy.tu-locked .tu-lock { border-color: #a3e635; background: #3f6212e6; pointer-events: auto; }
.tu-joy.tu-tired { --rc: #f87171; }
.tu-joy.tu-tired .tu-lock { --rc: #f87171; }

/* ---------- backpack wheel (not a modal: the game keeps running) ---------- */
.tu-wheel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(340px, 86vw);
  max-height: min(70vh, 420px); display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 18px;
  background: #050b10d8; border: 1px solid #ffffff22; box-shadow: 0 10px 40px #000a; pointer-events: auto; z-index: 3; }
.tu-wheel[hidden] { display: none; }
.tu-tabs { display: flex; gap: 6px; }
.tu-tabs button { flex: 1; min-height: 48px; border-radius: 12px; border: 1px solid #ffffff22; background: #ffffff0d; color: #fff; font-size: 22px; padding: 0; }
.tu-tabs button.tu-on { background: #ffffff26; border-color: #ffffff66; }
.tu-tabs [data-tab="close"] { flex: 0 0 48px; }
.tu-wheel-body { overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; display: grid; gap: 10px; }
.tu-grid, .tu-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
.tu-slots { grid-template-columns: repeat(3, 1fr); padding-bottom: 8px; border-bottom: 1px solid #ffffff1a; }
.tu-cell { position: relative; min-height: 58px; display: grid; place-items: center; border-radius: 14px; border: 1px solid #ffffff26;
  background: #ffffff0f; color: #fff; font-size: 26px; padding: 0; }
.tu-cell i { position: absolute; right: 4px; bottom: 2px; font: 700 10px/1.4 Inter, sans-serif; font-style: normal; color: #d1d5db; }
.tu-cell.tu-passive { border-style: dashed; opacity: .7; }
.tu-cell.tu-pinned { border-color: #fde047; box-shadow: inset 0 0 0 1px #fde04766; }
.tu-cell.tu-dis { opacity: .35; }
.tu-cell.tu-low i { color: #f87171; }
.tu-pin { min-height: 48px; font-size: 22px; color: #ffffff80; border-style: dashed; }
.tu-digits { display: flex; justify-content: center; gap: 8px; }
.tu-digits b { width: 44px; height: 54px; display: grid; place-items: center; border-radius: 6px; background: #1f1f2e; border: 1px dashed #555;
  color: #666; font: 400 26px 'Special Elite', monospace; }
.tu-digits b.got { background: #e8e0c8; color: #1a1208; border: 0; transform: rotate(-3deg); }
.tu-row { display: flex; justify-content: center; gap: 16px; font-size: 16px; }
.tu-rule { margin: 0; font-size: 12px; line-height: 1.4; color: #d1d5db; text-align: center;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.tu-none { margin: 0; text-align: center; color: #888; }
.tu-cap { min-height: 16px; font-size: 11px; color: #cbd5e1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- tutorial ---------- */
.tu-tip { position: absolute; left: 50%; top: calc(max(8px, env(safe-area-inset-top)) + 40px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 14px; border-radius: 999px; background: #0b1519e6;
  border: 1px solid #86efac88; font-size: 14px; font-weight: 600; white-space: nowrap; pointer-events: auto; z-index: 4; }
.tu-tip[hidden] { display: none; }
.tu-tip small { color: #9ca3af; font-size: 11px; }
.tu-tip button { width: 48px; height: 48px; border-radius: 50%; border: 0; background: #ffffff14; color: #fff; font-size: 16px; padding: 0; }
@media (orientation: portrait) { .tu-tip { top: calc(max(8px, env(safe-area-inset-top)) + 170px); font-size: 13px; } }
.tu-focus { box-shadow: 0 0 0 4px #86efac, 0 0 24px #86efac; animation: tu-focus 1.2s ease-in-out infinite; }
@keyframes tu-focus { 50% { box-shadow: 0 0 0 8px #86efac55, 0 0 32px #86efac; } }
.tu-zone { position: absolute; top: 0; bottom: 0; pointer-events: none; border: 2px dashed #86efac55; background: #86efac0d; border-radius: 16px; }
.tu-zone[hidden] { display: none; }
.tu-zone-left { left: 0; width: 40%; }
.tu-zone-right { left: 40%; right: 0; }
.tu-zone i { position: absolute; left: 50%; top: 60%; width: 44px; height: 44px; margin: -22px; border-radius: 50%; background: #86efac44;
  border: 2px solid #86efac; animation: tu-swipe 1.6s ease-in-out infinite; }
.tu-zone-left i { animation-name: tu-swipe-up; }
@keyframes tu-swipe { 0%, 100% { transform: translateX(-60px); } 50% { transform: translateX(60px); } }
@keyframes tu-swipe-up { 0%, 100% { transform: translateY(30px); } 50% { transform: translateY(-50px); } }

/* ---------- layout editor ---------- */
.tu-editing .tu-c { pointer-events: auto; outline: 2px dashed #ffffff55; outline-offset: 3px; transition: none; animation: none; }
.tu-editing .tu-off { display: grid !important; opacity: .45 !important; }
.tu-editing .tu-c.tu-sel { outline: 3px solid #fde047; }
.tu-editing .tu-lock { display: grid; place-items: center; pointer-events: none; }
.tu-edbar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-wrap: wrap; justify-content: center;
  align-items: center; gap: 6px; max-width: min(520px, 76vw); padding: 8px; border-radius: 16px; background: #050b10e6; border: 1px solid #ffffff2a;
  pointer-events: auto; z-index: 4; }
.tu-edbar[hidden] { display: none; }
.tu-edbar button { min-width: 48px; min-height: 48px; padding: 0 10px; border-radius: 12px; border: 1px solid #ffffff2a; background: #ffffff10;
  color: #fff; font: 600 13px Inter, sans-serif; }
.tu-edbar [data-ed="save"] { background: #16a34a; border-color: #16a34a; font-size: 20px; }
.tu-edbar label { display: flex; align-items: center; gap: 4px; min-height: 48px; font-size: 18px; }
.tu-edbar input[type=range] { width: 96px; min-height: 40px; touch-action: pan-x; }

/* ---------- guide picture (controlsHTML) ---------- */
.tu-guide { position: relative; width: 100%; max-width: 560px; margin: 8px auto; aspect-ratio: 844 / 390; border-radius: 14px;
  background: linear-gradient(#0b1519, #050b10); border: 1px solid #ffffff22; overflow: hidden; font: 11px/1.2 Inter, sans-serif; color: #e5e7eb; }
.tu-guide-portrait { aspect-ratio: 390 / 844; max-width: 260px; }
.tu-guide-zone { position: absolute; top: 0; bottom: 0; display: grid; place-items: center; }
.tu-guide-zone small { color: #6b7280; }
.tu-guide-left { left: 0; width: 40%; border-right: 1px dashed #ffffff1a; }
.tu-guide-right { left: 40%; right: 0; }
.tu-g { position: absolute; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 1px; width: 70px; text-align: center; }
.tu-g b { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: #ffffff14; border: 1px solid #ffffff33; font-size: 14px; font-weight: 400; }
.tu-g.big b { width: 38px; height: 38px; font-size: 18px; }
.tu-g small { font-size: 8px; color: #cbd5e1; line-height: 1.15; }

/* ---------- comfort and reduced motion ---------- */
.tu-comfort *, .tu-comfort *::before { animation: none !important; transition: none !important; }
body.comfort #touchUI * { animation: none !important; }
@media (prefers-reduced-motion: reduce) { #touchUI *, #touchUI *::before { animation: none !important; transition: none !important; } }

/* ---------- four buttons on the right; the rest open from All tools ---------- */
.tu-c.tu-tucked { display: none !important; }
.tu-tools { position: absolute; inset: 0; z-index: 14; display: grid; place-items: center; pointer-events: auto;
  background: #02060899; backdrop-filter: blur(0px); -webkit-backdrop-filter: blur(0px); opacity: 0;
  transition: opacity .18s ease, backdrop-filter .18s ease, -webkit-backdrop-filter .18s ease; }
.tu-tools[hidden] { display: none; }
.tu-tools.tu-open { opacity: 1; backdrop-filter: blur(9px) saturate(.7); -webkit-backdrop-filter: blur(9px) saturate(.7); }
.tu-tools-grid { display: grid; grid-template-columns: repeat(var(--cols, 4), 72px); gap: 14px 12px; padding: 16px;
  max-height: calc(100% - 24px); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
.tu-tool { position: relative; display: grid; justify-items: center; gap: 4px; width: 72px; padding: 0; margin: 0; border: 0; background: none;
  color: #e5e7eb; font: 600 10.5px/1.15 Inter, system-ui, sans-serif; text-align: center; -webkit-tap-highlight-color: transparent;
}
.tu-tool-ico { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%; font-size: 26px; line-height: 1;
  background: #0b1519e6; border: 2px solid #ffffff38; box-shadow: 0 4px 14px #0008; }
.tu-tool small { max-width: 72px; text-shadow: 0 1px 3px #000; }
.tu-tool .tu-badge { right: 4px; bottom: auto; top: 38px; }
.tu-tool.tu-on .tu-tool-ico { background: #12301fe6; border-color: #86efac; }
.tu-tool.tu-dis { filter: grayscale(1); }
.tu-tool.tu-dis .tu-tool-ico { opacity: .4; }
.tu-tool.tu-held .tu-tool-ico { transform: scale(.9); background: #ffffff30; }
.tu-btn[data-c="tools"].tu-on { background: #1e3a33cc; border-color: #86efac; }
@media (prefers-reduced-motion: reduce) { .tu-tools { transition: none; } }
@media (orientation: portrait) { .tu-tools-grid { grid-template-columns: repeat(min(var(--cols, 4), 4), 70px); } }
@media (max-height: 420px) { .tu-tools-grid { gap: 8px 10px; } .tu-tool-ico { width: 52px; height: 52px; font-size: 23px; } .tu-tool .tu-badge { top: 33px; } }
