/* GD-7 — one UI system: touch controls, minimap, the Codex panel, dialogs, title.
   Phone-first (S24 Ultra, Brave), landscape + portrait, safe-area aware.
   Rule: nothing dims or blocks the world; panels dock between control clusters. */
:root {
  --lf-ink: #0c1224; --lf-ink2: #14243c; --lf-gold: #e4c47a; --lf-gold2: #fff1c4; --lf-text: #f7f1e4; --lf-dim: #c9b896;
  --lf-edge: rgba(228, 196, 122, 0.62); --lf-r: 14px;
  --lf-blue: #7eadd8; --lf-olive: #7aaa48; --lf-parchment: #f3e6c8;
  --ring-r: calc(var(--safe-r) + 0px); --ring-b: calc(var(--safe-b) + 0px);
}

/* ---------- title (fixes clipped portrait title) ---------- */
#title { display: none; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#title .title-inner {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 10px; padding: calc(var(--safe-t) + 18px) 18px calc(var(--safe-b) + 18px);
  max-width: 720px; margin: 0 auto;
}
#title h2 { margin: 0; font-size: 13px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--lf-gold2); font-weight: normal; }
#title h1 { margin: 0; font-size: clamp(28px, 7.2vmin, 54px); line-height: 1.05; color: #fff6dc; letter-spacing: 0.02em; }
#title p { margin: 0; font-size: clamp(13px, 3.4vmin, 16px); line-height: 1.5; max-width: 520px; color: #efe4c8; }
#title #title-enter { margin-top: 6px; min-height: 52px; padding: 12px 30px; font-size: 16px; border-radius: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  background: linear-gradient(180deg, #4a3a18, #241a0a); border: 1px solid var(--lf-gold2); box-shadow: 0 0 22px #d4b56a55, 0 6px 18px #000a; color: #fff3cf; }
#title #title-art { margin-top: 8px; justify-content: center; flex-wrap: nowrap; max-width: 100%; }
#title #title-art img { height: clamp(44px, 10vmin, 72px); border-radius: 4px; }
@media (orientation: landscape) and (max-height: 480px) {
  #title .title-inner { gap: 6px; padding-top: calc(var(--safe-t) + 10px); }
  #title p { max-width: 640px; }
  #title #title-art { display: none; }
}
#ui.on-title #hud, #ui.on-title #joy, #ui.on-title #btns, #ui.on-title #chips, #ui.on-title #util, #ui.on-title #minimap,
#ui.on-title #codex, #ui.on-title #lf-jobs, #ui.on-title #lf-pals, #ui.on-title #lf-homes, #ui.on-title #lf-store, #ui.on-title #lf-trade, #ui.on-title #lf-tribes, #ui.on-title #hero-sheet, #ui.on-title #btn-hero, #ui.on-title #lf-menu { display: none !important; }

/* ---------- HUD block ---------- */
#hud { border-radius: 8px; max-width: min(300px, 34vw); }
@media (orientation: portrait) { #hud { max-width: calc(100vw - 132px); } }
#ui.codex-open #hud { display: none; }

/* ---------- top-right: minimap + util ---------- */
#minimap {
  position: absolute; right: calc(var(--safe-r) + 6px); top: calc(var(--safe-t) + 6px);
  width: 92px; height: 92px; border-radius: 50%; pointer-events: auto; z-index: 12; cursor: pointer;
  box-shadow: 0 4px 14px #000b; background: #1a1610;
}
#minimap canvas { width: 100%; height: 100%; display: block; border-radius: 50%; }
#minimap .mm-n { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: #7a1c12; color: #fff3cf; font: bold 10px/16px Palatino, serif; text-align: center; pointer-events: none; }
#minimap .mm-d { position: absolute; left: 50%; bottom: -16px; transform: translateX(-50%); font-size: 11px; color: var(--lf-gold2);
  text-shadow: 0 1px 3px #000, 0 0 6px #000; white-space: nowrap; pointer-events: none; }
#minimap .mm-danger { position: absolute; left: 50%; bottom: calc(100% + 2px); transform: translateX(-50%);
  font-size: 10px; letter-spacing: 0.04em; color: #ffb089; white-space: nowrap; pointer-events: none;
  text-shadow: 0 1px 2px #000; }
#minimap .mm-danger[hidden] { display: none !important; }
#util { right: calc(var(--safe-r) + 106px) !important; top: calc(var(--safe-t) + 6px) !important; gap: 6px; }
#util button { height: 44px !important; min-width: 56px; border-radius: 8px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; padding: 0 12px; }
@media (orientation: portrait) {
  #util { flex-direction: column; right: calc(var(--safe-r) + 6px) !important; top: calc(var(--safe-t) + 118px) !important; }
  #util button { min-width: 92px; }
}
#ui.codex-open #util { display: none; }
@media (orientation: portrait) { #ui.codex-open #minimap { display: none; } }

/* ---------- action cluster (right thumb only; the open middle stays clear for looking) ---------- */
#btns { position: absolute; right: var(--safe-r); bottom: var(--safe-b); width: 196px; height: 176px; z-index: 11; pointer-events: none; }
#btns .act {
  position: absolute; pointer-events: auto; border-radius: 50%; width: 48px; height: 48px; padding: 0;
  font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; display: flex; align-items: center; justify-content: center;
  touch-action: none; overflow: hidden;
}
#btns .act:active, #btns .act.held { transform: scale(0.94); filter: brightness(1.25); box-shadow: 0 0 16px #d4b56a88, inset 0 0 10px #d4b56a55; }
#btn-sword  { width: 70px !important; height: 70px !important; right: 2px; bottom: 2px; font-size: 12px !important; border-width: 2px !important;
  background: radial-gradient(circle at 32% 24%, #5a4824, #1c140a) !important; }
#btn-jump   { width: 54px !important; height: 54px !important; right: 78px; bottom: 6px; }
#btn-gather { width: 50px !important; height: 50px !important; right: 138px; bottom: 10px; font-size: 9px !important; }
#btn-dodge  { right: 64px; bottom: 66px; }
#btn-parry  { right: 8px; bottom: 80px; }
#btn-name { width: 54px !important; height: 54px !important; right: 108px; bottom: 112px; display: flex !important; flex-direction: column;
  border: 2px solid #f0e0a8 !important; color: #fff3cf !important; background: radial-gradient(circle at 35% 25%, #6a5420, #22180a) !important; gap: 0; }
#btn-name .nm { position: relative; z-index: 1; line-height: 1; }
#btn-name .cdnum { position: relative; z-index: 1; font-style: normal; font-size: 9px; letter-spacing: 0; line-height: 1; opacity: 0.9; }
#btn-name .cdnum:empty { display: none; }
#btn-name:not(.ready)::before {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: conic-gradient(from -90deg, rgba(255, 220, 120, 0.85) calc((1 - var(--cd, 1)) * 360deg), transparent 0);
  pointer-events: none;
  z-index: 0;
}
#btn-name.ready::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 12px 2px rgba(255, 230, 140, 0.55);
  pointer-events: none;
}
#btns .pw::after { content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from -90deg, rgba(6,5,10,0.78) calc(var(--cd, 0) * 360deg), transparent 0); pointer-events: none; }
#btns .pw.ready { box-shadow: 0 0 14px #f0e0a8aa, 0 4px 12px #000a; }
#btns .pw.hide { display: none !important; }
#btns .act.cool { opacity: 0.55; }
#ui.build-open #btn-dodge, #ui.build-open #btn-parry, #ui.build-open #btns .pw { display: none !important; }
#ui.build-open.under-attack #btn-dodge,
#ui.build-open.under-attack #btn-parry,
#ui.build-open.under-attack #btns .pw { display: flex !important; }

/* ---------- chips: core row + context buttons, pinned to the right thumb column ---------- */
#chips { position: absolute; z-index: 11; display: flex; gap: 0; pointer-events: none;
  right: calc(var(--safe-r) + 4px); bottom: calc(var(--safe-b) + 184px);
  flex-direction: row-reverse; flex-wrap: wrap; justify-content: flex-end; align-content: flex-end;
  max-width: 210px; }
#chips .chip { pointer-events: auto; min-width: 52px; height: 44px; margin: 2px 3px; padding: 0 10px; border-radius: 20px; font-size: 11px;
  letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; touch-action: none;
  display: inline-flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
#chips .chip.ctx {
  border-color: var(--lf-gold2);
  transition: opacity .28s ease, transform .32s ease, max-width .32s ease, max-height .32s ease, margin .32s ease, padding .32s ease;
}
#chips .chip.ctx:not(.show) {
  max-width: 0; max-height: 0; width: 0; height: 0; min-width: 0 !important; min-height: 0;
  margin: 0; padding: 0 !important; border-width: 0; opacity: 0;
  transform: translateY(8px) scale(0.92); pointer-events: none;
}
#chips .chip.ctx.show {
  max-width: 148px; max-height: 44px; opacity: 1; transform: none; pointer-events: auto;
}
#chips .chip.ctx.hide, #chips .chip.ctx[hidden] { display: none !important; }
#chips .chip .pip {
  margin-left: 4px; min-width: 16px; height: 16px; padding: 0 3px; border-radius: 8px;
  background: #e4c47a; color: #1a140c; font-size: 10px; line-height: 16px; font-style: normal; font-weight: bold;
}
#chips .chip .pip[hidden] { display: none; }
#chips .chip.on { background: linear-gradient(180deg, #5a4620, #2a1e0a); box-shadow: 0 0 12px #d4b56a77; }
#chips .chip:active, #chips .chip.held { filter: brightness(1.25); transform: scale(0.96); }
#chips .chip.pw::after { content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: conic-gradient(from -90deg, rgba(6,5,10,0.72) calc(var(--cd, 0) * 360deg), transparent 0); pointer-events: none; }
#chips .chip.pw.ready { box-shadow: 0 0 10px #f0e0a877; }
#btn-weapon .lbl::after { content: ' \21C4'; opacity: 0.7; }
@media (orientation: portrait) {
  /* Left of the right-hand cluster, above the stick — never on either thumb. */
  #chips { right: auto; left: calc(var(--safe-l) + 6px); bottom: calc(var(--safe-b) + 124px);
    flex-direction: row; flex-wrap: wrap; justify-content: flex-start; align-content: flex-end;
    max-width: calc(100vw - 214px); max-height: 92px; }
}
#ui.build-open #chips .chip:not(#btn-build) { display: none !important; }
button.ob-hint, #joy.ob-hint { box-shadow: 0 0 0 3px #fff3c0, 0 0 16px #d4b56a !important; animation: lf-glow 0.9s ease-in-out infinite; }
@keyframes lf-glow { 50% { filter: brightness(1.5); } }
#lf-beat { display: grid; grid-template-columns: 42px 1fr; column-gap: 6px; align-items: center; }
#lf-beat .ico { grid-row: 1 / span 4; width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; background: radial-gradient(circle at 35% 30%, #fff6d0, #d4b56a 55%, #6a5420); border: 1px solid #fff3c0; }
#lf-beat .who, #lf-beat h2, #lf-beat .line, #lf-beat .do, #lf-beat .row { grid-column: 2; }
#lf-beat .row { display: flex; gap: 6px; align-items: center; }
#lf-beat #lf-beat-voice { min-width: 44px; font-size: 18px; }
#lf-hand { position: fixed; z-index: 16; width: 46px; height: 46px; margin-left: -8px; pointer-events: none;
  border-radius: 46% 46% 46% 16%; background: radial-gradient(circle at 40% 30%, #fff8e4, #e6c56a 62%, #8a6420);
  box-shadow: 0 8px 16px #0008, inset 0 0 0 2px #fff3c0; }
#lf-hand[hidden] { display: none !important; }
#lf-hand.g-tap { animation: lf-tap 0.85s ease-in-out infinite; }
#lf-hand.g-hold { animation: lf-hold 1.1s ease-in-out infinite; }
#lf-hand.g-swipe { animation: lf-swipe 1.05s ease-in-out infinite; }
#lf-hand.g-push { animation: lf-push 0.95s ease-in-out infinite; }
@keyframes lf-tap { 0%, 100% { transform: translateY(0) scale(1); } 45% { transform: translateY(14px) scale(0.9); } }
@keyframes lf-hold { 0%, 100% { transform: scale(1); } 50% { transform: scale(0.82); } }
@keyframes lf-swipe { 0% { transform: translateX(-16px); } 100% { transform: translateX(28px); } }
@keyframes lf-push { 0%, 100% { transform: translateY(10px); } 50% { transform: translateY(-18px); } }
#ui.on-title #lf-hand, #ui.codex-open #lf-hand { display: none !important; }
.cx-pics { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.cx-pics::-webkit-scrollbar { display: none; }
.cx-pic { flex: 0 0 76px; display: flex; flex-direction: column; align-items: center; gap: 3px; opacity: 0.45; }
.cx-pic b { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: normal;
  background: #2a2418; border: 1px solid rgba(212,181,106,0.35); }
.cx-pic span { font-size: 10px; text-align: center; line-height: 1.2; color: var(--lf-dim); max-width: 76px; }
.cx-pic.cur { opacity: 1; }
.cx-pic.cur b { border-color: #fff3c0; box-shadow: 0 0 12px #d4b56a; background: radial-gradient(circle at 35% 30%, #fff6d0, #d4b56a); }
.cx-pic.done { opacity: 0.8; }
.cx-pic.done b { background: #3a4a28; }
#bossbar {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 6px); transform: translateX(-50%);
  width: min(260px, 42vw); z-index: 12; pointer-events: none; text-align: center;
}
#bossbar[hidden] { display: none !important; }
#bossbar b { display: block; font-weight: normal; letter-spacing: 0.16em; text-transform: uppercase; font-size: 11px; color: #f0e0a8; text-shadow: 0 1px 3px #000; }
#bossbar span { display: block; height: 6px; margin-top: 3px; background: #1a100c; border: 1px solid #c9a24a; }
#bossbar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #8a2a18, #e6c56a); }

/* Directed beats + first-time tips. Left column, under the HUD, clear of both thumbs. */
#lf-beat, #lf-ftip {
  position: absolute; z-index: 14; pointer-events: none;
  left: calc(var(--safe-l) + 8px); top: calc(var(--safe-t) + 72px);
  width: min(210px, 42vw);
  background: linear-gradient(180deg, rgba(24,20,30,0.94), rgba(12,10,16,0.94));
  border: 1px solid rgba(212,181,106,0.55); border-radius: 10px; color: #f3ead7;
  box-shadow: 0 8px 24px #000a; padding: 6px 8px;
}
#lf-beat[hidden], #lf-ftip[hidden] { display: none !important; }
#lf-beat .who { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: #f0e0a8; }
#lf-beat h2 { margin: 1px 0 4px; font-size: 15px; font-weight: normal; color: #fff6dc; }
#lf-beat .line, #lf-ftip p { margin: 0; font-size: 13px; line-height: 1.35; }
#lf-beat .do { margin: 4px 0 0; font-size: 12px; color: #d4b56a; }
#lf-beat .row { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
#lf-beat .n { font-size: 11px; color: #a99f86; }
#lf-beat button, #lf-ftip button { min-height: 32px; min-width: 56px; border-radius: 8px; pointer-events: auto;
  font-family: inherit; color: var(--lf-text); background: radial-gradient(circle at 30% 20%, #3a342c, #16141c);
  border: 1px solid rgba(212,181,106,0.55); cursor: pointer; }
#lf-ftip { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
#lf-ftip b { font-weight: normal; color: #fff6dc; font-size: 14px; }
#lf-beat.with-tip { top: calc(var(--safe-t) + 148px); }
#ui.on-title #lf-beat, #ui.on-title #lf-ftip,
#ui.codex-open #lf-beat, #ui.codex-open #lf-ftip { display: none !important; }
@media (orientation: portrait) {
  #lf-beat, #lf-ftip { width: min(188px, 52vw); top: calc(var(--safe-t) + 78px); left: calc(var(--safe-l) + 6px); }
  #lf-beat.with-tip { top: calc(var(--safe-t) + 156px); }
}

/* ---------- the Codex panel ---------- */
.lf-panel {
  position: absolute; z-index: 13; display: none; flex-direction: column; pointer-events: auto;
  background: linear-gradient(180deg, rgba(24,20,30,0.95), rgba(11,10,16,0.95));
  border: 1px solid var(--lf-edge); border-radius: var(--lf-r); box-shadow: 0 10px 40px #000c, inset 0 0 0 3px rgba(212,181,106,0.08);
  color: var(--lf-text); font-size: 14px; overflow: hidden;
}
.lf-panel.open { display: flex; }
#codex { left: calc(var(--safe-l) + 124px); right: calc(var(--safe-r) + 232px); top: calc(var(--safe-t) + 6px); bottom: calc(var(--safe-b) + 60px); }
@media (orientation: portrait) {
  #codex { left: calc(var(--safe-l) + 6px); right: calc(var(--safe-r) + 6px); top: calc(var(--safe-t) + 6px); bottom: calc(var(--safe-b) + 232px); }
}
.cx-head { display: flex; align-items: stretch; border-bottom: 1px solid rgba(212,181,106,0.3); background: rgba(0,0,0,0.25); flex: 0 0 auto; min-width: 0; max-width: 100%; overflow: hidden; }
.cx-tabs { display: flex; flex: 1 1 auto; min-width: 0; max-width: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; touch-action: pan-x; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.cx-tabs::-webkit-scrollbar { display: none; }
.cx-tabs button, .cx-close { font-family: inherit; color: var(--lf-dim); background: none; border: 0; min-height: 46px; padding: 0 12px;
  font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap; border-bottom: 2px solid transparent; cursor: pointer; }
.cx-tabs button.on { color: var(--lf-gold2); border-bottom-color: var(--lf-gold); background: linear-gradient(180deg, transparent, rgba(212,181,106,0.12)); }
.cx-close { min-width: 50px; font-size: 26px; line-height: 1; color: var(--lf-gold2); border-left: 1px solid rgba(212,181,106,0.25); }
.cx-body { flex: 1; overflow-y: auto; padding: 12px 14px 16px; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.cx-body.tab-map { padding: 0; overflow: hidden; touch-action: none; }
.cx-body button { font-family: inherit; color: var(--lf-text); background: radial-gradient(circle at 30% 20%, #3a342c, #16141c);
  border: 1px solid var(--lf-gold); border-radius: 8px; min-height: 44px; padding: 0 14px; font-size: 13px; letter-spacing: 0.04em; cursor: pointer; }
.cx-body button.on { background: linear-gradient(180deg, #5a4620, #2a1e0a); border-color: var(--lf-gold2); color: #fff3cf; box-shadow: 0 0 10px #d4b56a55; }
.cx-body button:disabled { opacity: 0.42; }
.cx-body button:active { filter: brightness(1.25); }
.cx-h { margin: 14px 0 8px; font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--lf-gold2); font-weight: normal;
  display: flex; justify-content: space-between; border-bottom: 1px solid rgba(212,181,106,0.18); padding-bottom: 4px; }
.cx-h span { color: var(--lf-dim); letter-spacing: 0.08em; margin-left: 0.4em; white-space: nowrap; }
.cx-h .cx-sort { margin-left: 10px; min-height: 44px; padding: 0 16px; font-size: 11px; letter-spacing: 0.12em; vertical-align: middle; }
.cx-h:first-child { margin-top: 2px; }
.cx-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cx-chips, .cx-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.cx-seg button { flex: 1 1 0; min-width: 72px; }
.cx-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.cx-toggle .cx-seg { flex: 0 0 160px; }
.cx-card { border: 1px solid rgba(212,181,106,0.35); border-radius: 8px; padding: 10px 12px; background: rgba(212,181,106,0.06); }
.cx-card.warn { border-color: rgba(220,140,80,0.5); background: rgba(220,140,80,0.08); color: #f0d8b8; font-size: 13px; }
.cx-card.ok { border-color: rgba(140,200,120,0.5); background: rgba(140,200,120,0.08); font-size: 13px; }
.cx-kicker { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--lf-gold); }
.cx-lead { margin: 4px 0 0; font-size: 15px; line-height: 1.45; }
.cx-note { color: var(--lf-dim); font-size: 12px; line-height: 1.5; margin: 10px 0 0; }
.cx-empty { color: var(--lf-dim); font-style: italic; }
.cx-steps { list-style: none; margin: 0; padding: 0; }
.cx-steps li { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,0.04); color: var(--lf-dim); line-height: 1.35; }
.cx-steps li i { flex: 0 0 16px; height: 16px; margin-top: 2px; border-radius: 50%; border: 1.5px solid #6a5e48; }
.cx-steps li.done { color: #cfc4a6; } .cx-steps li.done span { text-decoration: line-through; text-decoration-color: rgba(212,181,106,0.5); }
.cx-steps li.done i { background: var(--lf-gold); border-color: var(--lf-gold); box-shadow: inset 0 0 0 3px #1a140a; }
.cx-steps li.cur { color: var(--lf-text); } .cx-steps li.cur i { border-color: var(--lf-gold2); box-shadow: 0 0 8px #f0e0a8aa; }
.cx-list { list-style: none; margin: 0; padding: 0; } .cx-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.cx-list li span { color: var(--lf-dim); text-align: right; }
.cx-stats { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 6px; }
.cx-stats span { background: rgba(255,255,255,0.04); border: 1px solid rgba(212,181,106,0.2); border-radius: 14px; padding: 4px 10px; font-size: 12px; color: var(--lf-dim); }
.cx-stats b { color: var(--lf-gold2); font-weight: normal; }
.cx-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 14px; }
@media (max-width: 640px) { .cx-split { grid-template-columns: 1fr; } }
.cx-slots, .cx-grid { display: grid; gap: 6px; }
.cx-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.cx-item { text-align: left; display: flex !important; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px;
  padding: 7px 10px !important; min-height: 56px; border-left: 4px solid var(--rc, #6a5e48) !important; border-radius: 6px !important; }
.cx-item.empty { border: 1px dashed rgba(212,181,106,0.25); border-left: 4px solid rgba(212,181,106,0.15); border-radius: 6px; padding: 7px 10px; opacity: 0.7; }
.cx-item b { font-weight: normal; color: var(--rc, var(--lf-text)); font-size: 13px; line-height: 1.2; filter: brightness(1.2); }
.cx-item .it-slot { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--lf-dim); }
.cx-item .it-aff { font-size: 11px; color: var(--lf-dim); }
.cx-item.sel { box-shadow: 0 0 0 2px var(--lf-gold2), 0 0 14px #d4b56a66 !important; }
.cx-detail { margin-top: 12px; border: 1px solid var(--rc); border-radius: 8px; padding: 10px 12px; background: rgba(0,0,0,0.3); }
.cx-detail > b { color: var(--rc); filter: brightness(1.25); font-weight: normal; font-size: 15px; display: block; }
.cx-detail .cx-rar { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--lf-dim); }
.cx-detail ul { margin: 6px 0 0; padding-left: 18px; color: #e8dcc0; font-size: 13px; }
.cx-cmp { margin-top: 6px; font-size: 13px; color: var(--lf-dim); } .cx-cmp .up { color: #9ad07a; } .cx-cmp .down { color: #e08a6a; }
.cx-pals { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.cx-pal { display: flex; gap: 12px; border: 1px solid rgba(212,181,106,0.3); border-radius: 10px; padding: 10px; background: rgba(255,255,255,0.03); }
.cx-pal.wild { opacity: 0.85; border-style: dashed; }
.pal-ico { flex: 0 0 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; color: #1a140a;
  background: radial-gradient(circle at 35% 30%, #fff8e0, var(--pc) 70%); border: 2px solid var(--lf-gold); }
.pal-txt { flex: 1; min-width: 0; } .pal-txt b { color: var(--lf-gold2); font-weight: normal; font-size: 15px; }
.pal-txt > span { display: block; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--lf-dim); margin-top: 2px; }
.pal-txt p { margin: 6px 0 0; font-size: 13px; line-height: 1.4; color: #e2d6ba; }
.pal-txt .cx-row button { min-height: 40px; padding: 0 12px; }
.cx-tree { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-top: 10px; }
.cx-node { border: 1px solid rgba(212,181,106,0.35); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; background: rgba(255,255,255,0.03); }
.cx-node b { color: var(--lf-gold2); font-weight: normal; } .cx-node span { font-size: 12px; color: var(--lf-dim); }
.cx-node .cost.short { color: #e09a7a; }
.cx-node.chosen { border-color: var(--lf-gold2); box-shadow: 0 0 12px #d4b56a44; } .cx-node.locked { opacity: 0.45; }
.cx-tag { font-size: 11px !important; letter-spacing: 0.12em; text-transform: uppercase; color: var(--lf-gold2) !important; }
.cx-tag.dim { color: var(--lf-dim) !important; }

/* ---------- map tab ---------- */
.map-wrap { position: relative; width: 100%; height: 100%; overflow: hidden; background: #c9b689; }
.map-cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.map-tools { position: absolute; left: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; }
.map-tools button { width: 44px; height: 44px; min-height: 44px; padding: 0 !important; font-size: 20px !important; border-radius: 50% !important;
  background: rgba(244,230,192,0.92) !important; color: #3a2610 !important; border: 1px solid #7a5a1e !important; box-shadow: 0 2px 6px #0006; }
.map-status { position: absolute; left: 60px; right: 70px; top: 10px; font-size: 12px; color: #3a2610; background: rgba(244,230,192,0.82);
  border: 1px solid rgba(122,90,30,0.6); border-radius: 12px; padding: 3px 10px; width: fit-content; max-width: calc(100% - 130px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.map-card { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); width: min(360px, calc(100% - 20px));
  background: rgba(24,18,12,0.94); border: 1px solid var(--lf-gold); border-radius: 10px; padding: 10px 12px; box-shadow: 0 6px 20px #000a; }
.map-card[hidden] { display: none; }
.mc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mc-title { color: var(--lf-gold2); font-weight: normal; font-size: 15px; }
.map-card .mc-x { min-height: 36px !important; width: 36px; padding: 0 !important; font-size: 20px !important; border-radius: 50% !important;
  display: flex; align-items: center; justify-content: center; flex: none;
  font-family: inherit; color: var(--lf-gold2); background: rgba(255,255,255,0.06); border: 1px solid rgba(212,181,106,0.45); cursor: pointer; }
.mc-sub { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--lf-dim); }
.mc-body { margin: 6px 0 0; font-size: 13px; line-height: 1.4; color: #e8dcc0; }
.mc-acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; } .mc-acts:empty { display: none; }
.mc-acts button { font-family: inherit; color: var(--lf-text); background: radial-gradient(circle at 30% 20%, #3a342c, #16141c);
  border: 1px solid rgba(212,181,106,0.55); border-radius: 8px; min-height: 44px; padding: 0 14px; font-size: 13px; cursor: pointer; }
.mc-acts button:active { filter: brightness(1.25); }

/* ---------- dialogs (help / shop / Miriam): same frame, no full-screen dim ---------- */
#help, #shop, #dlg { background: transparent !important; pointer-events: none !important; }
#help .card, #shop .card, #dlg .card {
  pointer-events: auto; transform: none !important; border-radius: var(--lf-r); border: 1px solid var(--lf-edge) !important;
  background: linear-gradient(180deg, rgba(24,20,30,0.96), rgba(11,10,16,0.96)) !important; box-shadow: 0 10px 40px #000c;
  left: calc(var(--safe-l) + 124px) !important; right: calc(var(--safe-r) + 232px) !important; width: auto !important;
  top: calc(var(--safe-t) + 6px) !important; max-height: calc(100% - var(--safe-t) - var(--safe-b) - 70px) !important;
}
@media (orientation: portrait) {
  #help .card, #shop .card, #dlg .card { left: calc(var(--safe-l) + 6px) !important; right: calc(var(--safe-r) + 6px) !important;
    max-height: calc(100% - var(--safe-t) - var(--safe-b) - 244px) !important; }
}
#help .close-x, #shop .close-x, #dlg .close-x { min-height: 46px; }
#ui.menu-open #joy, #ui.menu-open #btns, #ui.menu-open #chips { visibility: hidden; pointer-events: none; }
#ui.menu-open #hud, #ui.menu-open #util { visibility: hidden; }

/* ---------- toast/verse: keep clear of panels ---------- */
#toast { top: calc(var(--safe-t) + 54px) !important; max-width: min(560px, 60vw) !important; background: rgba(8,8,14,0.5); border-radius: 14px; padding: 4px 12px; }
#toast:empty { display: none; }
#ui.codex-open #toast { top: auto !important; bottom: calc(var(--safe-b) + 64px); }
@media (orientation: portrait) { #toast { max-width: 86vw !important; top: calc(var(--safe-t) + 112px) !important; } #ui.codex-open #toast { bottom: calc(var(--safe-b) + 236px); } }
#guide .guide-card { z-index: 14; }
#fps { bottom: auto !important; top: calc(var(--safe-t) + 104px); left: auto !important; right: calc(var(--safe-r) + 8px); }
@media (orientation: portrait) {
  .cx-tabs button { padding: 0 7px; letter-spacing: 0.05em; font-size: 11px; flex: 1 0 auto; }
  #toast { top: calc(var(--safe-t) + 230px) !important; }
}
.cx-detail { margin: 6px 0 10px; }

/* ---------- GD-7 build bar (replaces the old build tray) ---------- */
body.gd7-build #build-tray { display: none !important; }
#build-bar { left: calc(var(--safe-l) + 6px); right: calc(var(--safe-r) + 108px); top: calc(var(--safe-t) + 6px); padding: 6px; gap: 5px; overflow: visible; }
#ui.build-open #build-bar { right: calc(var(--safe-r) + 8px); }
#ui.build-open #minimap { opacity: 0.85; }
@media (orientation: portrait) {
  #build-bar { right: calc(var(--safe-r) + 6px); }
  #ui.build-open #minimap { display: none; }
}
#build-bar button { font-family: inherit; color: var(--lf-text); background: radial-gradient(circle at 30% 20%, #3a342c, #16141c);
  border: 1px solid rgba(212,181,106,0.55); border-radius: 8px; min-height: 40px; padding: 0 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
#build-bar button.on { background: linear-gradient(180deg, #5a4620, #2a1e0a); border-color: var(--lf-gold2); color: #fff3cf; box-shadow: 0 0 10px #d4b56a55; }
#build-bar button.dim { opacity: 0.45; }
#build-bar button:active { filter: brightness(1.3); }
.bb-top { display: flex; gap: 6px; align-items: center; }
.bb-cats { display: flex; gap: 4px; flex: 1; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.bb-cats button { flex: 0 0 auto; }
.bb-cats::-webkit-scrollbar, .bb-pieces::-webkit-scrollbar { display: none; }
.bb-modes { display: flex; gap: 0; border-radius: 9px; overflow: hidden; border: 1px solid rgba(212,181,106,0.55); }
.bb-modes button { border: 0 !important; border-radius: 0 !important; min-width: 58px; }
.bb-modes button[data-mode="remove"].on { background: linear-gradient(180deg, #6a2018, #2a0a06); }
.bb-modes button[data-mode="move"].on { background: linear-gradient(180deg, #1c4a6a, #0a1a2a); }
.bb-done { background: linear-gradient(180deg, #4a6a2a, #1c2a0a) !important; color: #f4ffd8 !important; min-width: 62px; font-weight: bold; }
.bb-mid { display: flex; gap: 6px; align-items: stretch; }
.bb-tier { display: flex; flex-direction: column; justify-content: center; min-width: 64px; line-height: 1.1; }
.bb-tier span { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--lf-dim); }
.bb-pieces { display: flex; gap: 5px; overflow-x: auto; flex: 1; scrollbar-width: none; touch-action: pan-x; }
.bb-pieces button { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; min-height: 46px; line-height: 1.15; padding: 2px 10px; }
.bb-pieces button b { font-weight: normal; font-size: 13px; }
.bb-pieces button span { font-size: 10px; color: var(--lf-gold2); }
.bb-pieces button.short span { color: #ff8a7a; }
.bb-pieces button.short b { opacity: 0.7; }
.bb-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; padding: 0 3px; color: var(--lf-dim); }
.bb-hint { color: #bfffc8; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bb-hint.bad { color: #ff9a8a; }
@media (orientation: portrait) {
  .bb-top { flex-wrap: wrap; }
  .bb-cats { flex: 1 1 100%; order: 1; }
  .bb-modes { flex: 1; order: 2; }
  .bb-modes button { flex: 1; }
  .bb-done { order: 3; }
  .bb-foot { flex-direction: column; gap: 2px; }
  .bb-hint { text-align: left; }
}
#btn-sword.bok { box-shadow: 0 0 0 3px #7dff8a, 0 0 18px #7dff8a88 !important; }
#btn-sword.bbad { box-shadow: 0 0 0 3px #ff6a5a, 0 0 14px #ff6a5a66 !important; opacity: 0.85; }
#ui.build-open #btn-sword { font-size: 13px; }
#ui.build-open #btn-gather { font-size: 10px; letter-spacing: 0; }
#ui.build-open #toast { top: calc(var(--safe-t) + 150px) !important; }
@media (orientation: portrait) { #ui.build-open #toast { top: calc(var(--safe-t) + 200px) !important; } }
.cx-slider { align-items: center; }
.cx-sens { flex: 1 1 160px; max-width: 260px; height: 44px; accent-color: #d4b56a; touch-action: none; }
.sens-v { color: var(--lf-gold2); font-weight: normal; margin-left: 6px; }
#ui button { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: none; }
#btn-pray.held { background: linear-gradient(180deg, #6a5420, #2a1e0a); box-shadow: 0 0 0 2px #ffe08a, 0 0 16px #ffe08a88; color: #fff3cf; }
/* ---------- GD-7 tooltips ---------- */
#lf-tip { position: fixed; z-index: 80; pointer-events: none; opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
  background: linear-gradient(180deg, rgba(30,24,36,0.97), rgba(12,10,16,0.97)); border: 1px solid #d4b56a; border-radius: 10px;
  padding: 8px 11px; color: #f1e6cc; font: 13px/1.35 Palatino, Georgia, serif; box-shadow: 0 6px 24px #000c; display: flex; flex-direction: column; gap: 3px; }
#lf-tip.on { opacity: 1; transform: none; }
#lf-tip b { color: #ffe7a8; font-weight: normal; letter-spacing: .06em; font-size: 14px; }
#lf-tip i { color: #c9b07a; font-style: normal; font-size: 12px; border-top: 1px solid rgba(212,181,106,.25); padding-top: 3px; }
/* Look pass: title gold carried onto the quest line. Layout is unchanged. */
#hud { background: linear-gradient(180deg, rgba(48, 36, 18, 0.82), rgba(12, 10, 8, 0.72)); border-color: rgba(240, 224, 168, 0.75); box-shadow: 0 0 0 1px rgba(212, 181, 106, 0.25), 0 8px 22px rgba(0,0,0,0.35); }
#quest { background: linear-gradient(90deg, rgba(232, 214, 170, 0.16), rgba(212, 181, 106, 0.04)); border-left: 2px solid var(--lf-gold, #d4b56a); padding-left: 6px; }

/* ---------- Heaven chrome: scroll, safe insets, non-blocking guidance ---------- */
html, body { overscroll-behavior: none; touch-action: none; }
#c, #ui { touch-action: none; }
.lf-scroll, .lf-scroll-x {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(228, 196, 122, 0.75) transparent;
}
.lf-scroll { overflow-y: auto; touch-action: pan-y; }
.lf-scroll-x { overflow-x: auto; touch-action: pan-x; overscroll-behavior-x: contain; }
#ui .lf-scroll button, #ui .lf-scroll .cx-item,
#ui #help .card button, #ui #shop .card button, #ui #dlg .card button, #ui .map-card button { touch-action: pan-y; }
#ui .lf-scroll input.cx-sens, #ui .lf-scroll input.cx-vol { touch-action: none; }
#ui .lf-scroll-x button,
#ui #build-bar .bb-cats button, #ui #build-bar .bb-pieces button,
#ui #build-bar .bb-tools button, #ui #build-bar .bb-menu button { touch-action: pan-x pan-y; }
#joy, #btns .act, #chips .chip, #minimap { touch-action: none; }

.lf-panel {
  display: flex;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(126, 173, 216, 0.22), transparent 44%),
    radial-gradient(80% 70% at 100% 110%, rgba(122, 170, 72, 0.12), transparent 48%),
    linear-gradient(180deg, rgba(16, 32, 56, 0.96), rgba(7, 12, 24, 0.97));
  border: 1px solid rgba(228, 196, 122, 0.66);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 241, 196, 0.22);
}
.lf-panel.open {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}
/* Edge sheet: about half the old centre panel, stuck to the rim so the middle stays open. */
#codex, #lf-jobs, #lf-pals, #lf-homes, #lf-store, #lf-trade, #lf-tribes, #hero-sheet {
  left: calc(var(--safe-l) + 4px);
  right: auto;
  top: calc(var(--safe-t) + 4px);
  bottom: calc(var(--safe-b) + 8px);
  width: min(560px, calc(100vw - 240px));
  height: calc(100vh - var(--safe-t) - var(--safe-b) - 16px);
  max-height: calc(100vh - var(--safe-t) - var(--safe-b) - 16px);
}
#lf-jobs .cx-head, #lf-pals .cx-head, #lf-homes .cx-head, #lf-store .cx-head, #lf-trade .cx-head, #lf-tribes .cx-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; }
#lf-jobs .cx-head b, #lf-pals .cx-head b, #lf-homes .cx-head b, #lf-store .cx-head b, #lf-trade .cx-head b, #lf-tribes .cx-head b { font-weight: normal; letter-spacing: 0.14em; text-transform: uppercase; font-size: 12px; color: #f0e0a8; }
#lf-jobs .job-row, #lf-pals .job-row, #lf-homes .job-row, #lf-store .job-row, #lf-trade .job-row, #lf-tribes .job-row { display: flex; gap: 8px; align-items: center; margin: 6px 0 2px; }
#lf-jobs .job-row b, #lf-pals .job-row b, #lf-homes .job-row b, #lf-store .job-row b, #lf-trade .job-row b, #lf-tribes .job-row b { font-size: 20px; font-weight: normal; }
#lf-jobs .job-row span, #lf-pals .job-row span, #lf-homes .job-row span, #lf-store .job-row span, #lf-trade .job-row span, #lf-tribes .job-row span { display: flex; flex-direction: column; font-size: 13px; flex: 1; }
#lf-jobs .job-row i, #lf-pals .job-row i, #lf-homes .job-row i, #lf-store .job-row i, #lf-trade .job-row i, #lf-tribes .job-row i { font-style: normal; font-size: 11px; color: #c9b07a; }
#lf-store .job-row button, #lf-trade .job-row button, #lf-tribes .job-row button { min-height: 32px; padding: 0 8px; }
#lf-talk {
  left: calc(var(--safe-l) + 128px);
  right: calc(var(--safe-r) + 188px);
  top: auto;
  bottom: calc(var(--safe-b) + 10px);
  width: auto;
  height: auto;
  max-height: none;
  overflow: visible;
  z-index: 36;
}
#lf-talk .cx-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px; }
#lf-talk .cx-head b { font-weight: normal; letter-spacing: 0.06em; font-size: 15px; color: #fff6dc; }
#lf-talk .lf-talk-line { margin: 0 0 8px; font-size: 15px; line-height: 1.4; color: #fff6dc; }
#lf-talk .cx-body { padding: 10px 12px 12px; overflow: visible; flex: 0 0 auto; }
#lf-talk .lf-talk-acts { display: flex; flex-wrap: wrap; gap: 6px; }
#lf-talk .lf-talk-acts button {
  width: auto;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff8e4;
  background: #2c261c;
  border: 1px solid #e4c47a;
  border-radius: 8px;
  height: 36px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0.02em;
}
@media (orientation: portrait) {
  #lf-talk { left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px); }
}
#lf-jobs .job-picks { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
#lf-jobs .job-picks button { min-width: 32px; min-height: 32px; padding: 0; font-size: 16px; }
#lf-jobs .job-picks button.on { box-shadow: 0 0 0 2px #fff3c0; }
@media (orientation: portrait) {
  #codex, #lf-jobs, #lf-pals, #lf-homes, #lf-store, #lf-trade, #lf-tribes, #hero-sheet {
    left: calc(var(--safe-l) + 6px);
    right: calc(var(--safe-r) + 6px);
    top: calc(var(--safe-t) + 6px);
    bottom: auto;
    width: auto;
    height: auto;
    max-height: calc(100vh - var(--safe-t) - var(--safe-b) - 16px);
  }
}
.cx-head { background: linear-gradient(180deg, rgba(126, 173, 216, 0.12), rgba(0, 0, 0, 0.18)); border-bottom: 1px solid rgba(228, 196, 122, 0.35); }
.cx-tabs { gap: 2px; }
.cx-tabs button {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 68px;
  min-height: 54px;
  padding: 4px 10px 6px;
  flex: 0 0 auto;
  color: #c9b896;
}
.cx-tabs button svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.cx-tabs button span { font-size: 10px; letter-spacing: 0.12em; }
.cx-tabs button.on { color: #fff1c4; border-bottom-color: #e4c47a; background: linear-gradient(180deg, transparent, rgba(228, 196, 122, 0.16)); }
.cx-close { min-width: 52px; min-height: 54px; color: #fff1c4; }
.cx-body { padding: 16px 16px 22px; }
.cx-body.cx-swap { animation: cxIn .22s ease; }
@keyframes cxIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.cx-body button {
  min-height: 48px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(40, 64, 96, 0.95), rgba(12, 22, 40, 0.96));
  border-color: rgba(228, 196, 122, 0.55);
}
.cx-body button.on {
  background: linear-gradient(180deg, #6a5424, #243418);
  border-color: #fff1c4;
  box-shadow: 0 0 0 1px rgba(122, 170, 72, 0.55), 0 0 14px rgba(228, 196, 122, 0.28);
}
.cx-card.now {
  background: linear-gradient(180deg, rgba(243, 230, 200, 0.16), rgba(228, 196, 154, 0.06));
  border-color: rgba(243, 214, 164, 0.6);
}
.cx-h { margin: 18px 0 10px; }
.cx-row { gap: 10px; }
.cx-steps li { padding: 10px 0; }
@media (orientation: portrait) {
  .cx-tabs button { min-width: 64px; padding: 4px 8px; letter-spacing: 0.06em; font-size: 10px; flex: 0 0 auto; }
}

#help .card, #shop .card, #dlg .card {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(126, 173, 216, 0.2), transparent 42%),
    linear-gradient(180deg, rgba(16, 32, 56, 0.97), rgba(7, 12, 24, 0.97)) !important;
  border-color: rgba(228, 196, 122, 0.66) !important;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 241, 196, 0.2);
}
#help .card button, #shop .card button, #dlg .card button, #shop .opts button { touch-action: pan-y; }
#help .card, #shop .card {
  left: calc(var(--safe-l) + 4px) !important;
  right: auto !important;
  top: calc(var(--safe-t) + 4px) !important;
  width: min(272px, 46vw) !important;
  height: min(220px, calc(100vh - var(--safe-t) - var(--safe-b) - 128px)) !important;
  max-height: min(220px, calc(100vh - var(--safe-t) - var(--safe-b) - 128px)) !important;
}
#dlg .card {
  left: calc(var(--safe-l) + 8px) !important;
  right: auto !important;
  transform: none !important;
  width: min(300px, calc(100vw - 240px)) !important;
  top: calc(var(--safe-t) + 96px) !important;
  max-height: min(168px, calc(100vh - var(--safe-t) - var(--safe-b) - 240px)) !important;
}
@media (orientation: portrait) {
  #help .card, #shop .card {
    left: calc(var(--safe-l) + 6px) !important;
    right: calc(var(--safe-r) + 6px) !important;
    width: auto !important;
    height: min(300px, 38vh) !important;
    max-height: min(300px, 38vh) !important;
  }
  #dlg .card {
    left: calc(var(--safe-l) + 8px) !important;
    right: calc(var(--safe-r) + 112px) !important;
    width: auto !important;
    top: calc(var(--safe-t) + 86px) !important;
    max-height: min(150px, 30vh) !important;
  }
}
#ui.menu-open #joy, #ui.menu-open #btns, #ui.menu-open #chips,
#ui.menu-open #hud, #ui.menu-open #util { visibility: visible; pointer-events: auto; }
#ui.menu-open #chips { pointer-events: none; }
#ui.menu-open #chips .chip { pointer-events: auto; }

#build-bar.open {
  left: calc(var(--safe-l) + 4px);
  right: calc(var(--safe-r) + 110px);
  top: calc(var(--safe-t) + 4px);
  max-height: 108px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
#build-bar .bb-top { position: sticky; top: 0; z-index: 1; background: rgba(10, 18, 32, 0.96); }
#build-bar .bb-cats, #build-bar .bb-pieces, #build-bar .bb-tools, #build-bar .bb-menu {
  touch-action: pan-x;
  overscroll-behavior-x: contain;
}
#build-bar .bb-cats button, #build-bar .bb-pieces button, #build-bar .bb-tools button, #build-bar .bb-menu button { touch-action: pan-x; }
#build-bar button { min-height: 44px; }
@media (orientation: portrait) {
  #build-bar.open { max-height: 120px; right: calc(var(--safe-r) + 4px); }
  .bb-top { flex-wrap: nowrap; }
  .bb-cats { flex: 1 1 auto; order: 0; }
}

.map-card {
  max-height: 46%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: linear-gradient(180deg, rgba(16, 28, 48, 0.94), rgba(8, 14, 24, 0.94));
}
.map-card button { touch-action: pan-y; }

#ui.sheet-open #lf-beat,
#ui.sheet-open #lf-ftip,
#ui.sheet-open #lf-hand,
#ui.sheet-open #lf-pin,
#ui.sheet-open #dlg,
#ui.talk-open #lf-beat,
#ui.talk-open #lf-ftip,
#ui.talk-open #lf-hand,
#ui.talk-open #lf-pin { display: none !important; }
#lf-beat, #lf-ftip {
  pointer-events: none !important;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: start;
  gap: 6px 8px;
  left: calc(var(--safe-l) + 28vw + 18px);
  right: auto;
  top: calc(var(--safe-t) + 8px);
  width: min(420px, calc(72vw - 210px));
  min-width: 220px;
  transform: none;
  max-height: 200px;
  padding: 8px 10px;
  overflow: auto;
  background:
    radial-gradient(90% 120% at 0% 0%, rgba(126, 173, 216, 0.16), transparent 46%),
    linear-gradient(180deg, rgba(12, 24, 44, 0.97), rgba(7, 12, 22, 0.98));
  border: 1px solid rgba(228, 196, 122, 0.7);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 241, 196, 0.2);
  transition: opacity .2s ease, transform .2s ease;
}
#hud { max-width: min(248px, 30vw); }
#lf-beat button, #lf-ftip button { pointer-events: auto; }
#lf-beat .ico, #lf-ftip .ico {
  grid-column: 1;
  grid-row: 1 / span 2;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  margin: 0;
  padding: 0;
  border-radius: 14px;
  font-size: 26px;
  line-height: 1;
  color: #1a1408;
  background: radial-gradient(circle at 35% 30%, #fff6d0, #e4c47a 55%, #6a5420);
  border: 1px solid #fff1c4;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}
#lf-beat .coach-copy { grid-column: 2; grid-row: 1; min-width: 0; width: 100%; }
#lf-beat .who, #lf-beat h2, #lf-beat .line, #lf-beat .do { grid-column: auto; }
#lf-beat h2 { margin: 0 0 2px; font-size: 16px; white-space: normal; line-height: 1.25; }
#lf-beat .line, #lf-beat .do { white-space: normal; line-height: 1.35; overflow: visible; text-overflow: unset; }
#lf-beat .row { grid-column: 2; grid-row: 2; width: auto; margin-top: 4px; }
#lf-goal { display: block; margin-top: 4px; padding: 4px 6px; background: rgba(12, 16, 28, 0.82); border: 1px solid #e4c47a; border-radius: 8px; }
#lf-goal b { display: block; color: #fff6dc; font-size: 13px; font-weight: normal; }
#lf-goal .bar { display: block; height: 6px; margin: 3px 0; background: #1a140c; border-radius: 4px; overflow: hidden; }
#lf-goal .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8a6a28, #ffe6a0); }
#lf-goal em { display: block; color: #e6d7b0; font-style: normal; font-size: 12px; }
#lf-pray { display: block; margin-top: 3px; color: #fff6dc; font-size: 13px; background: rgba(40, 28, 12, 0.8); border-radius: 6px; padding: 2px 6px; }
#lf-pray[hidden] { display: none !important; }
#lf-beat .do { margin: 0; }
#lf-beat .row { margin: 4px 0 0; flex: none; gap: 6px; justify-content: flex-start; }
#lf-beat .row button, #lf-ftip #lf-ftip-x { min-height: 44px; min-width: 44px; }
#lf-ftip { align-items: center; }
#lf-ftip b { flex: 0 0 auto; color: #fff1c4; font-size: 14px; font-weight: normal; }
#lf-ftip p { margin: 0; flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lf-beat.is-min, #lf-ftip.is-min {
  width: 44px;
  min-width: 0;
  height: 44px;
  max-height: 44px;
  right: auto;
  padding: 0;
  border-radius: 50%;
  left: calc(var(--safe-l) + 4px);
  top: calc(var(--safe-t) + 72px);
  transform: none;
  overflow: visible;
}
#lf-beat.is-min .coach-copy, #lf-beat.is-min .row,
#lf-ftip.is-min b, #lf-ftip.is-min p, #lf-ftip.is-min #lf-ftip-x { display: none !important; }
#lf-beat.is-min .ico, #lf-ftip.is-min .ico { width: 44px; height: 44px; min-width: 0; border-radius: 50%; flex-basis: 44px; }
#lf-beat.with-tip:not(.is-min) { top: calc(var(--safe-t) + 8px); left: calc(var(--safe-l) + 28vw + 18px); }
#lf-beat[hidden], #lf-ftip[hidden] { display: none !important; }
#ui.codex-open #lf-beat, #ui.codex-open #lf-ftip { display: none !important; }
@media (orientation: portrait) {
  #hud { max-width: calc(100vw - 132px); }
  #lf-beat:not(.is-min), #lf-ftip:not(.is-min) {
    left: calc(var(--safe-l) + 8px);
    right: auto;
    top: calc(var(--safe-t) + 176px);
    width: min(360px, calc(100vw - 24px));
    min-width: 0;
    max-height: 150px;
  }
  #lf-beat.is-min, #lf-ftip.is-min {
    left: calc(var(--safe-l) + 6px);
    right: auto;
    top: calc(var(--safe-t) + 108px);
  }
  #toast { top: calc(var(--safe-t) + 210px) !important; }
}
#toast { top: calc(var(--safe-t) + 88px) !important; max-width: min(420px, 52vw) !important; }
#ui.codex-open #toast { top: auto !important; bottom: calc(var(--safe-b) + 76px) !important; }
@media (orientation: portrait) {
  #ui.codex-open #toast { bottom: calc(var(--safe-b) + 252px) !important; }
}
#lf-hand { width: 32px; height: 32px; pointer-events: none; z-index: 15; }
#ui.on-title #lf-hand { display: none !important; }
#ui.codex-open #lf-hand { display: none !important; }
#ui.codex-open #lf-hand.on-menu { display: block !important; }
@keyframes lf-tap { 0%, 100% { transform: translateY(0) scale(1); } 45% { transform: translateY(8px) scale(0.92); } }
@keyframes lf-swipe { 0% { transform: translateX(-8px); } 100% { transform: translateX(14px); } }
@keyframes lf-push { 0%, 100% { transform: translateY(6px); } 50% { transform: translateY(-8px); } }
#lf-pin {
  position: fixed; z-index: 12; width: 22px; height: 22px; pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff6d0, #e4c47a 62%, #6a5420);
  box-shadow: 0 0 10px rgba(228, 196, 122, 0.85);
}
#lf-pin::before {
  content: '';
  position: absolute; left: 50%; top: -9px; transform: translateX(-50%);
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 9px solid #fff1c4;
}
#lf-pin[hidden] { display: none !important; }
#guide, #guide .guide-card { pointer-events: none !important; }
#guide .guide-card { width: min(420px, calc(100vw - 280px)); max-height: 120px; overflow: auto; }
#guide .guide-card button { pointer-events: auto; }
#hud {
  background: linear-gradient(180deg, rgba(20, 36, 58, 0.86), rgba(8, 14, 28, 0.8));
  border-color: rgba(255, 241, 196, 0.7);
}
#quest {
  background: linear-gradient(90deg, rgba(243, 230, 200, 0.22), rgba(228, 196, 122, 0.05));
  border-left: 2px solid #e4c47a;
}
#lf-tip {
  background: linear-gradient(180deg, rgba(16, 32, 56, 0.97), rgba(8, 14, 26, 0.97));
  border-color: #e4c47a;
  pointer-events: none;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  z-index: 80;
}
#lf-tip .tip-ico {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: radial-gradient(circle at 35% 30%, #fff6d0, #e4c47a 60%, #6a5420);
}
#lf-tip .tip-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#lf-tip .tip-copy span { font-size: 13px; line-height: 1.3; }

/* One sheet. Combat controls stay above every sheet. Quest cards stay under them. */
#ui #hud, #ui #joy, #ui #btns, #ui #chips, #ui #util { z-index: 40; }
#codex.lf-panel, #build-bar.lf-panel, #lf-jobs.lf-panel, #hero-sheet.lf-panel, #help, #shop, #dlg, #more-sheet, #creature, #build-tray { z-index: 22; }
#lf-talk.lf-panel { z-index: 36; overflow: visible; }
#ui.codex-open #hero-sheet, #ui.build-open #hero-sheet, #ui.jobs-open #hero-sheet,
#ui[data-sheet="help"] #hero-sheet, #ui[data-sheet="shop"] #hero-sheet, #ui[data-sheet="dlg"] #hero-sheet,
#ui[data-sheet="codex"] #hero-sheet, #ui[data-sheet="build"] #hero-sheet, #ui[data-sheet="jobs"] #hero-sheet { display: none !important; }
#ui[data-sheet="hero"] #codex, #ui[data-sheet="hero"] #build-bar, #ui[data-sheet="hero"] #lf-jobs,
#ui[data-sheet="hero"] #help, #ui[data-sheet="hero"] #shop, #ui[data-sheet="hero"] #dlg { display: none !important; }
#ui.codex-open #lf-jobs, #ui.build-open #lf-jobs, #ui[data-sheet="help"] #lf-jobs, #ui[data-sheet="shop"] #lf-jobs, #ui[data-sheet="dlg"] #lf-jobs { display: none !important; }
#lf-beat, #lf-ftip, #guide, #lf-pin, #lf-hand { z-index: 8 !important; }
#ui.sheet-open #lf-beat,
#ui.sheet-open #lf-ftip,
#ui.sheet-open #guide,
#ui.talk-open #lf-beat,
#ui.talk-open #lf-ftip,
#ui.talk-open #guide,
#ui[data-sheet="codex"] #lf-beat,
#ui[data-sheet="codex"] #lf-ftip,
#ui[data-sheet="codex"] #guide,
#ui[data-sheet="build"] #lf-beat,
#ui[data-sheet="build"] #lf-ftip,
#ui[data-sheet="build"] #guide,
#ui[data-sheet="help"] #lf-beat,
#ui[data-sheet="help"] #lf-ftip,
#ui[data-sheet="help"] #guide,
#ui[data-sheet="shop"] #lf-beat,
#ui[data-sheet="shop"] #lf-ftip,
#ui[data-sheet="shop"] #guide,
#ui[data-sheet="dlg"] #lf-beat,
#ui[data-sheet="dlg"] #lf-ftip,
#ui[data-sheet="dlg"] #guide {
  display: none !important;
}
#ui[data-sheet="codex"] #build-bar,
#ui[data-sheet="codex"] #help,
#ui[data-sheet="codex"] #shop,
#ui[data-sheet="codex"] #dlg,
#ui[data-sheet="build"] #codex,
#ui[data-sheet="build"] #help,
#ui[data-sheet="build"] #shop,
#ui[data-sheet="build"] #dlg,
#ui[data-sheet="help"] #codex,
#ui[data-sheet="help"] #build-bar,
#ui[data-sheet="help"] #shop,
#ui[data-sheet="help"] #dlg,
#ui[data-sheet="shop"] #codex,
#ui[data-sheet="shop"] #build-bar,
#ui[data-sheet="shop"] #help,
#ui[data-sheet="shop"] #dlg,
#ui[data-sheet="dlg"] #codex,
#ui[data-sheet="dlg"] #build-bar,
#ui[data-sheet="dlg"] #help,
#ui[data-sheet="dlg"] #shop {
  display: none !important;
}
#lf-compass {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-t) + 6px);
  width: 92px;
  margin-left: -46px;
  z-index: 36;
  display: none;
  pointer-events: none;
  text-align: center;
}
#lf-compass.on { display: block; }
#lf-compass i {
  display: block;
  width: 0;
  height: 0;
  margin: 0 auto 2px;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 16px solid #fff1c4;
  filter: drop-shadow(0 0 6px #e4c47a);
  transform-origin: 50% 12px;
}
#lf-compass b {
  display: block;
  font-size: 11px;
  font-weight: normal;
  color: #fff1c4;
  text-shadow: 0 1px 3px #000;
}

/* Hero sheet — same edge dock as the Codex. The portrait stays above every sheet. */
#ui.hero-open #hud { display: flex !important; }
#ui.hero-open #hud .hud-col { display: none; }
#hud.with-hero { display: flex; align-items: center; gap: 6px; max-width: min(340px, 46vw); }
#hud.with-hero .hud-col { flex: 1; min-width: 0; }
#btn-hero {
  position: relative; z-index: 50; flex: 0 0 46px; width: 46px; height: 46px; padding: 0; border-radius: 50%;
  border: 2px solid #f0e0a8; background: #1a140c; overflow: hidden; box-shadow: 0 0 10px rgba(228, 196, 122, 0.45);
}
#ui.sheet-open #btn-hero, #ui.hero-open #btn-hero, #ui.codex-open #btn-hero, #ui.build-open #btn-hero, #ui.jobs-open #btn-hero {
  display: block !important;
  visibility: visible !important;
  z-index: 50;
}
#btn-hero i {
  display: block; width: 100%; height: 100%;
  background: url("../art/concept/09-hero-shepherd-warrior.jpg") center 18% / cover no-repeat;
}
#btn-hero .pip {
  position: absolute; right: -2px; top: -2px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 8px; background: #e4c47a; color: #1a140c; font-size: 10px; line-height: 16px; font-weight: bold;
}
#btn-hero .pip[hidden] { display: none; }
#hero-sheet .cx-tabs button { min-width: 52px; min-height: 42px; padding: 2px 6px; }
#hero-sheet .cx-close { min-height: 44px; }
#hero-sheet .cx-body { padding: 6px 8px 10px; }
#hero-sheet .hx-lead { margin: 0 0 4px; font-size: 12px; line-height: 1.3; color: #f3ead7; }
#hero-sheet .hx-hint { margin: 4px 0 6px; font-size: 11px; color: var(--lf-dim); }
#hero-sheet .hx-res { margin: 0 0 6px; font-size: 11px; color: #f0e0a8; }
#hero-sheet .hx-level { margin: 0 0 6px; font-size: 12px; }
#hero-sheet .hx-level b { color: #fff6dc; font-weight: normal; margin-right: 6px; }
#hero-sheet .hx-level span, #hero-sheet .hx-level i { display: block; color: var(--lf-dim); font-style: normal; font-size: 11px; }
#hero-sheet .hx-bar { display: block; height: 6px; margin: 3px 0; background: #1a1814; border: 1px solid #6a5a30; border-radius: 4px; overflow: hidden; }
#hero-sheet .hx-bar b { display: block; height: 100%; background: linear-gradient(90deg, #3a4a8a, #e4c47a); }
#hero-sheet .hx-chips, #hero-sheet .hx-branches { display: flex; gap: 4px; margin: 0 0 6px; }
#hero-sheet .hx-chip, #hero-sheet .hx-branches button {
  flex: 0 0 auto; min-height: 32px; padding: 0 8px; border-radius: 8px; font-size: 12px;
}
#hero-sheet .hx-row { display: flex; gap: 6px; align-items: center; padding: 3px 0; border-bottom: 1px solid rgba(228, 196, 122, 0.14); }
#hero-sheet .hx-row .ic { flex: 0 0 22px; text-align: center; font-size: 16px; }
#hero-sheet .hx-mid { flex: 1; min-width: 0; }
#hero-sheet .hx-mid b { display: block; font-weight: normal; color: #fff6dc; font-size: 13px; }
#hero-sheet .hx-mid span { display: block; color: var(--lf-dim); font-size: 11px; line-height: 1.3; }
#hero-sheet .hx-mid em { font-style: normal; color: #f0e0a8; }
#hero-sheet .hx-plus {
  flex: 0 0 44px; width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 10px;
  font-size: 22px; line-height: 1;
}
#hero-sheet .hx-plus.off, #hero-sheet .hx-buy.off { opacity: 0.45; }
#hero-sheet .hx-buy { min-height: 44px; max-width: 96px; padding: 4px 6px; font-size: 10px; line-height: 1.15; white-space: normal; }
#hero-sheet .hx-pips { display: flex; gap: 3px; margin: 2px 0; }
#hero-sheet .hx-pips i { width: 8px; height: 8px; border-radius: 50%; border: 1px solid #e4c47a; display: inline-block; }
#hero-sheet .hx-pips i.on { background: #e4c47a; }
#hero-sheet .hx-node {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  text-align: left; min-height: 52px; margin: 0 0 6px; padding: 6px 8px;
}
#hero-sheet .hx-node b { font-weight: normal; color: #fff6dc; }
#hero-sheet .hx-node span, #hero-sheet .hx-node em { font-size: 11px; color: var(--lf-dim); font-style: normal; }
#hero-sheet .hx-node.owned { border-color: #f0e0a8; }
#hero-sheet .hx-node.locked { opacity: 0.55; }
#hero-sheet .hx-inc { display: grid; grid-template-columns: 1.3fr 0.9fr 0.8fr; gap: 4px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 11px; }
#hero-sheet .hx-inc.head { color: #f0e0a8; letter-spacing: 0.06em; text-transform: uppercase; font-size: 10px; }
#hero-sheet .hx-inc b { display: block; font-weight: normal; color: #c9b07a; font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; }
@media (orientation: landscape) and (max-height: 460px) {
  #hero-sheet .cx-tabs button { min-height: 36px; padding: 2px 6px; }
  #hero-sheet .cx-close { min-height: 36px; min-width: 44px; }
  #hero-sheet .cx-body { padding: 4px 8px 6px; }
  #hero-sheet .hx-lead { margin: 0 0 2px; font-size: 11px; line-height: 1.2; }
  #hero-sheet .hx-level { margin: 0 0 4px; font-size: 11px; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; }
  #hero-sheet .hx-level span { display: inline; font-size: 11px; }
  #hero-sheet .hx-level .hx-bar { flex: 1 0 100%; margin: 2px 0 0; height: 5px; }
  #hero-sheet .hx-chips { margin: 0 0 4px; gap: 3px; }
  #hero-sheet .hx-chip { min-height: 26px; padding: 0 6px; font-size: 11px; }
  #hero-sheet .hx-row { padding: 2px 0; gap: 6px; }
  #hero-sheet .hx-mid b { font-size: 12px; line-height: 1.15; }
  #hero-sheet .hx-mid span { font-size: 10px; line-height: 1.15; }
  #hero-sheet .hx-plus { flex: 0 0 38px; width: 38px; height: 36px; min-height: 36px; font-size: 20px; }
}
#hero-explain {
  position: fixed; z-index: 80; width: 240px; display: flex; gap: 8px; align-items: flex-start;
  padding: 8px 10px; pointer-events: none;
  background: linear-gradient(180deg, rgba(16, 32, 56, 0.97), rgba(8, 14, 26, 0.97));
  border: 1px solid #e4c47a; border-radius: 10px; color: #f3ead7;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
#hero-explain[hidden] { display: none !important; }
#hero-explain .ic { font-size: 26px; line-height: 1; }
#hero-explain strong { display: block; color: #fff6dc; font-weight: normal; font-size: 14px; }
#hero-explain p { margin: 2px 0 0; font-size: 13px; line-height: 1.35; }
#hero-explain i { display: block; margin-top: 4px; color: #e4c47a; font-style: normal; font-size: 12px; }

/* One sheet: the rest of the HUD slides off, then back. */
#hud, #joy, #btns, #chips, #util, #minimap { transition: transform .32s ease, opacity .32s ease; }
#ui.sheet-open #hud, #ui.talk-open #hud { transform: translateX(-130%); opacity: 0; pointer-events: none; }
#ui.sheet-open #joy, #ui.talk-open #joy { transform: translate(-30%, 140%); opacity: 0; pointer-events: none; }
#ui.sheet-open #btns, #ui.talk-open #btns,
#ui.sheet-open #chips, #ui.talk-open #chips { transform: translateX(140%); opacity: 0; pointer-events: none; }
#ui.sheet-open #util, #ui.talk-open #util { transform: translateY(-170%); opacity: 0; pointer-events: none; }
#ui.sheet-open #minimap, #ui.talk-open #minimap { transform: translate(90%, -90%); opacity: 0; pointer-events: none; }
#ui.under-attack.build-open #btns { transform: none; opacity: 1; pointer-events: none; }
#ui.under-attack.build-open #btns .act { pointer-events: auto; }
body.lf-sheet #lf-hand { display: none !important; }
#ui:not(.hero-open) #hero-explain { display: none !important; }
#lf-jobs button, #lf-pals button, #lf-homes button, #lf-store button, #lf-trade button, #lf-tribes button {
  background-image: none !important;
}

#lf-map-full { position: fixed; inset: 0; z-index: 70; background: #1a140c; }
#lf-map-full .map-wrap { position: absolute; inset: 0; width: 100%; height: 100%; }
#lf-map-full .map-tools, #lf-map-full .map-status { display: none !important; }
#lf-map-full .map-x {
  position: absolute; z-index: 4; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right));
  width: 52px; height: 52px; min-height: 52px; padding: 0; border-radius: 50%;
  font-size: 30px; line-height: 1; color: #3a2610; background: rgba(244, 230, 192, 0.96);
  border: 1px solid #7a5a1e; box-shadow: 0 2px 8px #0008;
}
.bb-purpose { margin: 2px 6px 0; font-size: 12px; line-height: 1.35; color: #fff1c4; }
.bb-act { display: flex; gap: 8px; padding: 4px 6px 0; }
.bb-act button { flex: 1; min-height: 48px !important; font-size: 15px !important; }
#build-bar .bb-go { background: linear-gradient(180deg, #6a5420, #2a1e0a) !important; border-color: #fff1c4 !important; color: #fff6dc !important; }
#build-bar .bb-pieces button { white-space: normal; text-align: left; height: auto; min-height: 54px; align-items: flex-start; }
#build-bar .bb-pieces button i { display: block; font-style: normal; font-size: 11px; line-height: 1.25; color: #c9b896; max-width: 28ch; }

/* Gold medallions from art/ui. Round actions are the picture. Chips and the
   top buttons keep their word beside it. Build mode still needs Place / Rotate. */
button.lf-glyph { background-repeat: no-repeat; }
#btns button.lf-glyph {
  background-image: var(--lf-glyph) !important;
  background-size: cover !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
  color: transparent; text-shadow: none;
}
#btn-name.lf-glyph { color: #fff6dc !important; }
#btn-name.lf-glyph .nm { font-size: 0; line-height: 0; }
#btn-name.lf-glyph .cdnum { color: #fff6dc; text-shadow: 0 1px 2px #000; }
#chips button.lf-glyph, #util button.lf-glyph, #btn-rot.lf-glyph {
  background-image: var(--lf-glyph), radial-gradient(circle at 30% 20%, #3a342c, #16141c) !important;
  background-repeat: no-repeat !important;
  background-size: 26px 26px, auto !important;
  background-position: 8px center, center !important;
  padding-left: 36px;
  color: #f3ead7;
}
#lf-beat .ico.lf-glyph {
  background-image: var(--lf-glyph) !important;
  background-size: cover !important;
  background-position: center !important;
  color: transparent !important;
}
#ui.build-open #btn-sword.lf-glyph,
#ui.build-open #btn-gather.lf-glyph {
  background-image: none !important;
  color: #fff6dc !important;
  font-size: 12px !important;
}

/* Shoulder stays in the Menu grid. The top row is Menu and the compass. */
#btn-cam { display: none !important; }

#lf-menu {
  left: calc(var(--safe-l) + 8px);
  top: calc(var(--safe-t) + 8px);
  width: min(620px, calc(100vw - var(--safe-l) - var(--safe-r) - 16px));
  height: min(348px, calc(100vh - var(--safe-t) - var(--safe-b) - 16px));
  z-index: 28;
}
#lf-menu .cx-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 0 12px; }
#lf-menu .cx-head b { font-weight: normal; letter-spacing: 0.16em; text-transform: uppercase; color: #f0e0a8; font-size: 13px; }
#lf-menu .menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
#lf-menu .menu-grid button {
  position: relative;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: normal;
  color: var(--lf-text);
  background: radial-gradient(circle at 30% 20%, #3a342c, #16141c);
  border: 1px solid rgba(212, 181, 106, 0.5);
  border-radius: 8px;
  cursor: pointer;
}
#lf-menu .menu-grid button:active { filter: brightness(1.25); }
#lf-menu .menu-grid button b { font-size: 18px; font-weight: normal; line-height: 1; }
#lf-menu .menu-grid button.quiet { opacity: 0.45; }
#lf-menu .menu-grid .pip {
  position: absolute; top: 4px; right: 6px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 8px; background: #e4c47a; color: #1a140c; font-size: 10px; line-height: 16px; font-style: normal;
}
#lf-menu .menu-grid .pip[hidden] { display: none; }
#ui #lf-menu .menu-grid button { touch-action: pan-y; }

@media (orientation: landscape) and (min-height: 521px) {
  #ui.build-open #build-bar.open {
    max-height: min(360px, calc(100vh - var(--safe-t) - var(--safe-b) - 180px));
  }
}
/* Phone landscape: build dock on the left, above the stick, clear of the grid. */
@media (orientation: landscape) and (max-height: 520px) {
  #ui.build-open #build-bar.open {
    left: calc(var(--safe-l) + 4px);
    right: auto;
    top: calc(var(--safe-t) + 4px);
    bottom: calc(var(--safe-b) + 118px);
    width: min(328px, 40vw);
    max-height: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px;
    z-index: 24;
  }
  #ui.build-open #build-bar.open .bb-top,
  #ui.build-open #build-bar.open .bb-act,
  #ui.build-open #build-bar.open .bb-tools,
  #ui.build-open #build-bar.open .bb-foot { flex: 0 0 auto; }
  #ui.build-open #build-bar.open .bb-cats { min-width: 0; }
  #ui.build-open #build-bar.open .bb-cats button { min-width: 72px; min-height: 40px; }
  #ui.build-open #build-bar.open .bb-mid {
    flex: 1 1 auto; min-height: 0; display: flex; overflow: hidden;
  }
  #ui.build-open #build-bar.open .bb-pieces {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: pan-y;
  }
  #ui.build-open #build-bar.open .bb-pieces button {
    flex: 0 0 auto;
    width: 100%;
    min-height: 64px;
    height: auto;
    white-space: normal;
    align-items: flex-start;
    padding: 6px 10px;
  }
  #ui.build-open #build-bar.open .bb-pieces button i {
    max-width: none;
    font-size: 12px;
    line-height: 1.35;
    color: #fff1c4;
    white-space: normal;
  }
  #ui.build-open #build-bar.open .bb-purpose { display: none; }
  #ui.build-open #build-bar.open .bb-act {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 0;
  }
  #ui.build-open #build-bar.open .bb-act button {
    min-height: 48px !important;
    min-width: 0;
    font-size: 13px !important;
    padding: 0 2px;
  }
  #ui.build-open #build-bar.open .bb-tools { max-height: 48px; }
  #ui.build-open #build-bar.open .bb-pieces button { touch-action: pan-y; }
}

/* ---------- toast: bottom centre in landscape ----------
   Between the stick and the action buttons, so the guide card, the quest card
   and the build dock never cover a message. */
@media (orientation: landscape) {
  #toast, #ui.build-open #toast, #ui.codex-open #toast {
    top: auto !important;
    bottom: calc(var(--safe-b) + 76px) !important;
    max-width: min(460px, calc(100vw - 400px)) !important;
    z-index: 16;
  }
}
/* Place name and time of day stay on one line, above the quest card. */
#hud #place { white-space: nowrap; overflow: visible; }
/* Title only: a quiet nudge to hold the phone sideways; dismissed once, remembered. */
#rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 700px) {
  #title #rotate-hint:not(.gone) { display: flex; align-items: center; gap: 10px; max-width: 520px; padding: 8px 10px 8px 14px;
    border: 1px solid rgba(233, 201, 122, 0.45); border-radius: 10px; background: rgba(12, 18, 32, 0.72); color: #f3e7c8; font-size: 14px; line-height: 1.4; text-align: left; }
  #rotate-hint button { min-width: 44px; min-height: 44px; flex: none; border-radius: 8px; font: inherit; letter-spacing: 0.08em;
    background: linear-gradient(180deg, #4a3a18, #241a0a); border: 1px solid var(--lf-gold2); color: #fff3cf; }
}
/* The goal card is appended to #hud; give it its own row so the stats column keeps its width. */
#hud.with-hero { flex-wrap: wrap; }
#hud.with-hero #lf-goal { flex: 1 0 100%; margin-top: 2px; }
#ui.hero-open #hud #lf-goal { display: none; }
/* Landscape: the coach card starts where the portrait HUD ends (min(340px, 46vw)) and stops short of Menu and the chips. */
@media (orientation: landscape) {
  #lf-beat:not(.is-min), #lf-ftip:not(.is-min) {
    left: calc(var(--safe-l) + min(340px, 46vw) + 12px);
    width: clamp(220px, calc(100vw - var(--safe-l) - var(--safe-r) - min(340px, 46vw) - 234px), 420px);
  }
}
/* Text size (Settings). Zoom scales a box's offsets and width too, so the boxes that share
   the top and bottom bands divide theirs by the zoom: the text grows, the layout stays put. */
#ui.text-2 { --tz: 1.15; }
#ui.text-3 { --tz: 1.3; }
#ui.text-2 #toast, #ui.text-2 #hud, #ui.text-2 #guide .guide-card, #ui.text-2 #lf-beat, #ui.text-2 #lf-ftip, #ui.text-2 #codex .cx-body,
#ui.text-3 #toast, #ui.text-3 #hud, #ui.text-3 #guide .guide-card, #ui.text-3 #lf-beat, #ui.text-3 #lf-ftip, #ui.text-3 #codex .cx-body { zoom: var(--tz); }
#ui.text-2 #hud, #ui.text-3 #hud { left: calc(var(--safe-l) / var(--tz)); top: calc(var(--safe-t) / var(--tz)); }
#ui.text-2 #hud.with-hero, #ui.text-3 #hud.with-hero { max-width: calc(min(340px, 46vw) / var(--tz)); }
@media (orientation: landscape) {
  #ui.text-2 #lf-beat:not(.is-min), #ui.text-2 #lf-ftip:not(.is-min),
  #ui.text-3 #lf-beat:not(.is-min), #ui.text-3 #lf-ftip:not(.is-min) {
    left: calc((var(--safe-l) + min(340px, 46vw) + 12px) / var(--tz));
    top: calc((var(--safe-t) + 8px) / var(--tz));
    width: calc(clamp(220px, calc(100vw - var(--safe-l) - var(--safe-r) - min(340px, 46vw) - 234px), 420px) / var(--tz));
    min-width: 0;
    max-height: none;
    grid-template-columns: 30px minmax(0, 1fr);
  }
  #ui.text-2 #lf-beat .ico, #ui.text-3 #lf-beat .ico, #ui.text-2 #lf-ftip .ico, #ui.text-3 #lf-ftip .ico { width: 30px; min-width: 0; height: 30px; min-height: 0; flex-basis: 30px; padding: 0; border-radius: 9px; font-size: 16px; grid-row: 1; }
  #ui.text-2 #lf-beat .row, #ui.text-3 #lf-beat .row { grid-column: 1 / span 2; }
  #ui.text-2 #toast, #ui.text-3 #toast, #ui.text-2.build-open #toast, #ui.text-3.build-open #toast, #ui.text-2.codex-open #toast, #ui.text-3.codex-open #toast {
    bottom: calc((var(--safe-b) + 76px) / var(--tz)) !important;
    max-width: calc(min(460px, calc(100vw - 400px)) / var(--tz)) !important;
  }
}

/* ---------- close X on every card ----------
   One 44px target, top-right. A closed card is kept in Notes on the map. */
.lf-x { position: absolute; top: 0; right: 0; width: 44px; height: 44px; min-width: 44px; min-height: 44px; padding: 0 !important; margin: 0;
  display: flex; align-items: center; justify-content: center; background: none !important; border: 0 !important; border-radius: 10px;
  color: #f0e0a8 !important; pointer-events: auto !important; cursor: pointer; z-index: 2; touch-action: manipulation; }
.lf-x::before { content: '\00d7'; font: 26px/1 Palatino, 'Book Antiqua', Georgia, serif; text-shadow: 0 1px 3px #000; }
.lf-x:active { background: rgba(212,181,106,0.18) !important; }
#lf-beat:not(.is-min) { padding-right: 44px; }
#lf-ftip:not(.is-min) { padding-right: 44px; }
#lf-ftip .ico { grid-column: 1; grid-row: 1 / span 2; }
#lf-ftip b, #lf-ftip p { grid-column: 2; }
#lf-ftip:not(.is-min) p { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
/* The X is the one way to set a tip aside; it waits in Notes. */
#lf-ftip #lf-ftip-x { display: none !important; }
#lf-beat.is-min .lf-x, #lf-ftip.is-min .lf-x { display: none !important; }
#hud #lf-goal { position: relative; padding-right: 44px; min-height: 44px; box-sizing: border-box; }
#hud #lf-goal .lf-x { top: -1px; right: -1px; }
.map-card .mc-x { min-height: 44px !important; width: 44px; }
/* A first-time tip takes the coach slot for its moment; Miriam's card waits in Notes and returns after. */
#lf-beat.lf-yield { display: none !important; }

/* Messages: a pill with its own X. Only a shown message takes taps. */
#toast { display: flex; align-items: center; justify-content: center; gap: 2px; min-height: 44px; box-sizing: border-box; padding: 0 0 0 12px !important; }
#toast:not(.show) { visibility: hidden; transition: opacity 0.35s ease, visibility 0s linear 0.35s; }
#toast .t-msg { flex: 0 1 auto; min-width: 0; padding: 4px 0; }
#toast .t-x { flex: none; width: 44px; height: 44px; padding: 0; border: 0; background: none; color: #f0e0a8; pointer-events: none; cursor: pointer; touch-action: manipulation; }
#toast .t-x::before { content: '\00d7'; font: 22px/1 Palatino, 'Book Antiqua', Georgia, serif; }
#toast.show .t-x { pointer-events: auto; }

/* NPC talk (pals, people, errands) is one sheet at a time, bottom centre between the thumbs. */
body #life-talk { top: auto; bottom: calc(var(--safe-b) + 10px); left: calc(var(--safe-l) + 128px); right: calc(var(--safe-r) + 188px); width: auto;
  max-width: 560px; margin: 0 auto; padding: 10px 48px 12px 12px; z-index: 36; }
body #life-talk .lf-x { top: 2px; right: 2px; margin: 0; }
body #life-talk button:not(.lf-x) { min-height: 44px; }
@media (orientation: portrait) {
  body #life-talk { left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px); }
}
#ui.npc-open #lf-beat, #ui.npc-open #lf-ftip, #ui.npc-open #lf-pin { display: none !important; }

@media (orientation: landscape) {
  /* The lamp sits in the coach slot, where the card it stands for appears. */
  #lf-beat.is-min, #lf-ftip.is-min { left: calc(var(--safe-l) + min(340px, 46vw) + 12px); top: calc(var(--safe-t) + 8px); }
  #ui.text-2 #lf-beat.is-min, #ui.text-3 #lf-beat.is-min, #ui.text-2 #lf-ftip.is-min, #ui.text-3 #lf-ftip.is-min {
    left: calc((var(--safe-l) + min(340px, 46vw) + 12px) / var(--tz)); top: calc((var(--safe-t) + 8px) / var(--tz)); }
  /* The pal compass sits under Menu, clear of the coach slot and the minimap. */
  #lf-compass { left: auto; right: calc(var(--safe-r) + 106px); top: calc(var(--safe-t) + 56px); margin-left: 0; }
  /* The boss bar takes the coach slot; Miriam's card waits until the fight is done. */
  #bossbar { left: calc(var(--safe-l) + min(340px, 46vw) + 12px); transform: none; top: calc(var(--safe-t) + 10px);
    width: clamp(200px, calc(100vw - var(--safe-l) - var(--safe-r) - min(340px, 46vw) - 234px), 420px); }
  #ui:has(#bossbar:not([hidden])) #lf-beat, #ui:has(#bossbar:not([hidden])) #lf-ftip { display: none !important; }
  /* Scripture rises from the bottom band, above the message pill. */
  #verse { top: auto; bottom: calc(var(--safe-b) + 136px); max-width: min(56vw, calc(100vw - 400px)); }
  /* While someone is speaking at the bottom, messages use the free coach slot at the top. */
  #ui.npc-open #toast, #ui.text-2.npc-open #toast, #ui.text-3.npc-open #toast { bottom: auto !important; top: calc(var(--safe-t) + 10px) !important; }
  #ui.npc-open #toast, #ui.text-2.npc-open #toast, #ui.text-3.npc-open #toast { max-width: calc(min(640px, calc(100vw - 200px)) / var(--tz, 1)) !important; }
  #ui.npc-open #verse { bottom: auto; top: calc(var(--safe-t) + 20px + 44px * var(--tz, 1)); }
  /* Larger text on a short screen: the coach card ends above the message pill and its words scroll. */
  #ui.text-2 #lf-beat:not(.is-min), #ui.text-3 #lf-beat:not(.is-min) {
    max-height: calc((100vh - var(--safe-t) - var(--safe-b) - 92px - 60px * var(--tz)) / var(--tz));
    grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; }
  #ui.text-2 #lf-beat .coach-copy, #ui.text-3 #lf-beat .coach-copy { min-height: 0; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; pointer-events: auto; touch-action: pan-y; }
}

/* ---------- Notes on the map ---------- */
.map-notes-btn { position: absolute; top: 8px; right: 8px; z-index: 3; min-height: 44px; padding: 0 14px !important; border-radius: 22px !important;
  display: flex; align-items: center; gap: 6px; font: 14px Palatino, 'Book Antiqua', Georgia, serif !important; letter-spacing: 0.04em;
  background: rgba(244,230,192,0.94) !important; color: #3a2610 !important; border: 1px solid #7a5a1e !important; box-shadow: 0 2px 6px #0006; }
.map-notes-btn .nt-n { font-style: normal; min-width: 20px; padding: 1px 5px; border-radius: 10px; background: #7a5a1e; color: #fff6dc; font-size: 12px; text-align: center; }
.map-notes-btn .nt-n:empty { display: none; }
.map-wrap.is-full .map-notes-btn { top: max(12px, calc(env(safe-area-inset-top) + 4px)); right: calc(max(8px, env(safe-area-inset-right)) + 62px); }
.map-wrap:not(.is-full) .map-status { right: 130px; max-width: calc(100% - 190px); }
.map-notes { position: absolute; z-index: 4; top: 60px; right: 8px; bottom: 8px; width: min(360px, calc(100% - 76px)); display: flex; flex-direction: column;
  background: rgba(18,14,10,0.95); border: 1px solid var(--lf-gold, #d4b56a); border-radius: 10px; box-shadow: 0 8px 24px #000a; overflow: hidden; }
.map-notes[hidden] { display: none; }
.map-wrap.is-full .map-notes { top: max(70px, calc(env(safe-area-inset-top) + 66px)); right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); }
.mn-head { position: relative; padding: 8px 48px 8px 12px; border-bottom: 1px solid rgba(212,181,106,0.3); }
.mn-head b { display: block; font-weight: normal; color: #f0e0a8; font-size: 15px; letter-spacing: 0.08em; }
.mn-head span { display: block; font-size: 12px; color: #c9b896; }
.mn-list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 6px 8px; touch-action: pan-y; }
.nt-list { list-style: none; margin: 0; padding: 0; }
.nt-item { border-bottom: 1px solid rgba(212,181,106,0.15); }
.nt-row { display: grid; grid-template-columns: 22px auto minmax(0, 1fr); align-items: center; gap: 6px; width: 100%; min-height: 44px; padding: 4px 6px !important;
  background: none !important; border: 0 !important; color: #f3ead7 !important; text-align: left; font: 14px/1.3 Palatino, 'Book Antiqua', Georgia, serif !important; touch-action: pan-y; }
.nt-row i { font-style: normal; color: #e6c56a; text-align: center; }
.nt-row .nt-k { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: #c9b07a; white-space: nowrap; }
.nt-row b { font-weight: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nt-item.on .nt-row b { white-space: normal; }
.nt-item.on { background: rgba(212,181,106,0.08); }
.nt-body { padding: 0 8px 8px 34px; }
.nt-body p { margin: 0 0 6px; font-size: 13px; line-height: 1.45; color: #e8dcc0; }
.nt-open { min-height: 44px; padding: 0 14px !important; border-radius: 8px !important; font: 14px Palatino, 'Book Antiqua', Georgia, serif !important;
  background: linear-gradient(180deg, #4a3a18, #241a0a) !important; border: 1px solid #e4c47a !important; color: #fff3cf !important; touch-action: pan-y; }
.nt-empty { margin: 12px; font-size: 13px; line-height: 1.45; color: #c9b896; }
#help .card, #shop .card, #dlg .card { position: relative; }
#help .card > h2, #shop .card > h2, #dlg .card > h2 { padding-right: 40px; }
#build-tray .head { position: relative; padding-right: 48px; }
#build-tray #btn-build-x.lf-x { top: 50%; transform: translateY(-50%); right: 0; }
#build-bar .bb-top { display: flex; align-items: center; gap: 4px; }
#build-bar .bb-top .bb-cats { flex: 1; min-width: 0; }
#build-bar .bb-x { position: static; flex: none; }
#ui.text-2 #lf-beat.is-min .ico, #ui.text-3 #lf-beat.is-min .ico, #ui.text-2 #lf-ftip.is-min .ico, #ui.text-3 #lf-ftip.is-min .ico {
  width: 44px; height: 44px; flex-basis: 44px; border-radius: 50%; font-size: 18px; }
/* A line shown again from Notes: Skip would skip the live guide step, so it waits. */
#lf-beat.is-replay #lf-beat-skip, #lf-beat.is-replay .n { display: none; }

/* ---------- Clues ----------
   Pop-up lines wait behind the Clues button. Off and Important keep the screen to the goal
   strip, the boss bar, damage numbers, prompts and brief urgent banners. */
#ui:not(.clues-all) #lf-beat, #ui:not(.clues-all) #lf-ftip, #ui:not(.clues-all) #verse,
#ui:not(.clues-all) #hud #quest, #ui:not(.clues-all) #hud #lf-goal { display: none !important; }
#ui.clues-off #toast { display: none !important; }
#ui.clues-all #lf-strip { display: none !important; }

#btn-clues { position: absolute; z-index: 40; right: calc(var(--safe-r) + 106px); top: calc(var(--safe-t) + 56px);
  min-width: 88px; height: 44px; padding: 0 12px; display: flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 8px; border: 1px solid rgba(228,196,122,0.7); background: rgba(14,20,34,0.82); color: #f0e0a8;
  font: 12px Palatino, 'Book Antiqua', Georgia, serif; letter-spacing: 0.08em; text-transform: uppercase;
  pointer-events: auto; touch-action: manipulation; cursor: pointer; box-shadow: 0 2px 8px #0006; }
#btn-clues b { font-weight: normal; }
#btn-clues .cl-ic { color: #e6c56a; font-size: 13px; }
#btn-clues .cl-n { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; box-sizing: border-box;
  border-radius: 10px; background: #c9a24a; color: #1a1208; font: bold 11px/20px system-ui, sans-serif; letter-spacing: 0; text-align: center; font-style: normal; }
#btn-clues .cl-n[hidden] { display: none; }
#btn-clues.pulse { animation: lf-clue-pulse 1.3s ease-out 1; }
@keyframes lf-clue-pulse { 0% { box-shadow: 0 0 0 0 rgba(230,197,106,0.7); } 100% { box-shadow: 0 0 0 14px rgba(230,197,106,0); } }
#ui.on-title #btn-clues, #ui.on-title #lf-strip, #ui.on-title #lf-alert { display: none !important; }
#btn-clues, #lf-strip { transition: transform .32s ease, opacity .32s ease; }
#ui.sheet-open #btn-clues, #ui.talk-open #btn-clues { transform: translateY(-10px); opacity: 0; pointer-events: none; }
#ui.sheet-open #lf-strip, #ui.talk-open #lf-strip { transform: translateY(-160%); opacity: 0; pointer-events: none; }
#ui.menu-open #btn-clues { visibility: hidden; }

/* The goal strip: one line in the coach slot; tap it for Clues, fold it to its mark. */
#lf-strip { position: absolute; z-index: 30; left: calc(var(--safe-l) + min(340px, 46vw) + 12px); top: calc(var(--safe-t) + 8px);
  width: clamp(200px, calc(100vw - var(--safe-l) - var(--safe-r) - min(340px, 46vw) - 234px), 420px);
  height: 40px; display: flex; align-items: stretch; box-sizing: border-box; pointer-events: auto;
  border-radius: 20px; border: 1px solid rgba(228,196,122,0.55); background: rgba(10,14,24,0.72); box-shadow: 0 2px 8px #0005; }
#lf-strip[hidden] { display: none; }
#lf-strip button { background: none; border: 0; margin: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; touch-action: manipulation; }
#lf-strip .sp-go { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 4px 0 12px; text-align: left; }
#lf-strip .sp-go i { font-style: normal; color: #e6c56a; font-size: 14px; flex: none; }
#lf-strip .sp-go span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: #fff3d6; font: calc(13px * var(--tz, 1)) / 1.2 Palatino, 'Book Antiqua', Georgia, serif; text-shadow: 0 1px 2px #000; }
#lf-strip .sp-fold { flex: none; width: 44px; color: #f0e0a8; border-left: 1px solid rgba(228,196,122,0.25) !important; }
#lf-strip .sp-fold::before { content: '\2039'; font: 22px/1 Palatino, 'Book Antiqua', Georgia, serif; }
#lf-strip.folded { width: 44px; height: 44px; border-radius: 22px; }
#lf-strip.folded .sp-go { padding: 0; justify-content: center; }
#lf-strip.folded .sp-go span, #lf-strip.folded .sp-fold { display: none; }
#lf-strip.folded .sp-go i { font-size: 16px; }
#lf-strip.flash { animation: lf-strip-flash 1.6s ease-out 1; }
@keyframes lf-strip-flash { 0% { border-color: #ffe9a8; box-shadow: 0 0 14px #e6c56a; } 100% { border-color: rgba(228,196,122,0.55); box-shadow: 0 2px 8px #0005; } }

/* Urgent: a small banner for two seconds that takes no taps. */
#lf-alert { position: absolute; z-index: 45; left: 50%; bottom: calc(var(--safe-b) + 76px); transform: translate(-50%, 8px);
  max-width: min(420px, calc(100vw - 400px)); padding: 6px 14px; box-sizing: border-box; border-radius: 16px;
  background: rgba(70,16,12,0.88); border: 1px solid #e08a5a; color: #fff0dc; text-align: center;
  font: calc(13px * var(--tz, 1)) / 1.3 Palatino, 'Book Antiqua', Georgia, serif; letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; opacity: 0; visibility: hidden;
  transition: opacity .25s ease, transform .25s ease, visibility 0s linear .25s; }
#lf-alert.on { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition: opacity .2s ease, transform .2s ease; }

/* The pal compass sits under the goal strip; with cards on, it waits while a full card is up. */
@media (orientation: landscape) {
  #lf-compass { left: calc(var(--safe-l) + min(340px, 46vw) + 12px); right: auto; top: calc(var(--safe-t) + 54px); margin-left: 0; width: 92px; }
  #ui:not(.clues-all) #bossbar { top: calc(var(--safe-t) + 54px); }
  #ui:has(#bossbar:not([hidden])) #lf-compass { display: none !important; }
  #ui.clues-all:has(#lf-beat:not([hidden]):not(.is-min)) #lf-compass,
  #ui.clues-all:has(#lf-ftip:not([hidden]):not(.is-min)) #lf-compass { display: none !important; }
}
@media (orientation: portrait) {
  #btn-clues { right: calc(var(--safe-r) + 6px); top: calc(var(--safe-t) + 172px); min-width: 92px; }
  #lf-compass { top: calc(var(--safe-t) + 78px); }
  #lf-strip { left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 112px); top: auto; bottom: calc(var(--safe-b) + 250px); width: auto; }
  #lf-strip.folded { right: auto; }
  #lf-alert { max-width: calc(100vw - 32px); bottom: calc(var(--safe-b) + 300px); }
}

/* The Clues sheet: the rest of the HUD slides away while it is open. */
#lf-clues { left: calc(var(--safe-l) + 8px); top: calc(var(--safe-t) + 6px); bottom: calc(var(--safe-b) + 8px);
  width: min(560px, calc(100vw - var(--safe-l) - var(--safe-r) - 240px)); z-index: 24; }
@media (orientation: portrait) {
  #lf-clues { left: calc(var(--safe-l) + 6px); right: calc(var(--safe-r) + 6px); width: auto; bottom: auto; height: min(520px, 62vh); }
}
#lf-clues .cx-head { display: flex; align-items: center; justify-content: space-between; padding: 0 0 0 12px; }
#lf-clues .cx-head b { font-weight: normal; letter-spacing: 0.16em; text-transform: uppercase; font-size: 13px; color: #f0e0a8; }
#lf-clues .cx-close { min-width: 52px; min-height: 48px; }
#lf-clues .cl-tabs { display: flex; gap: 0; border-bottom: 1px solid rgba(212,181,106,0.22); flex: none; overflow-x: auto; scrollbar-width: none; }
#lf-clues .cl-tabs button { flex: 1 0 auto; min-height: 44px; padding: 0 12px; background: none; border: 0; border-bottom: 2px solid transparent;
  color: #c9b896; font: 12px Palatino, 'Book Antiqua', Georgia, serif; letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer; }
#lf-clues .cl-tabs button.on { color: #fff1c4; border-bottom-color: #e4c47a; background: linear-gradient(180deg, transparent, rgba(212,181,106,0.12)); }
#lf-clues .cl-tabs i { font-style: normal; display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 4px; border-radius: 8px; background: #c9a24a; color: #1a1208; font-size: 10px; letter-spacing: 0; }
#lf-clues .cx-body { padding: 4px 12px 12px; }
#ui.text-2 #lf-clues .cx-body, #ui.text-3 #lf-clues .cx-body { zoom: var(--tz); }
#lf-clues .cl-h { margin: 12px 0 4px; font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: #e6c56a; font-weight: normal;
  border-bottom: 1px solid rgba(212,181,106,0.18); padding-bottom: 3px; }
#lf-clues .cl-goal { border: 1px solid rgba(228,196,122,0.45); border-radius: 10px; padding: 2px 10px 8px; margin-top: 8px; background: rgba(212,181,106,0.07); }
#lf-clues .cl-goal .cl-h { margin-top: 6px; border: 0; }
#lf-clues .cl-g-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
#lf-clues .cl-g-top b { font-weight: normal; color: #fff3d6; font-size: 15px; }
#lf-clues .cl-step { font-size: 11px; color: #c9b07a; letter-spacing: 0.06em; }
#lf-clues .cl-g-now { margin: 4px 0 0; font-size: 14px; line-height: 1.4; color: #fff6dc; }
#lf-clues .cl-g-say { margin: 4px 0 0; font-size: 13px; line-height: 1.45; color: #d8cba8; font-style: italic; }
#lf-clues .cl-bar { display: block; height: 4px; margin: 6px 0 2px; background: #1a100c; border-radius: 2px; overflow: hidden; }
#lf-clues .cl-bar i { display: block; height: 100%; background: linear-gradient(90deg, #8a6a28, #e6c56a); }
#lf-clues .cl-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#lf-clues .cl-acts button, #lf-clues .cl-more { min-height: 44px; padding: 0 14px; font-size: 13px; }
#lf-clues .cl-more { margin-top: 6px; background: none; border-style: dashed; }
#lf-clues .cl-list { list-style: none; margin: 0; padding: 0; }
#lf-clues .cl-item { border-bottom: 1px solid rgba(212,181,106,0.14); }
#lf-clues .cl-row { display: grid; grid-template-columns: 22px auto minmax(0, 1fr); align-items: center; gap: 8px; width: 100%; min-height: 44px;
  padding: 4px 6px; background: none; border: 0; border-radius: 6px; color: #f3ead7; text-align: left; font-size: 14px; line-height: 1.3; letter-spacing: 0; touch-action: pan-y; }
#lf-clues .cl-row i { font-style: normal; color: #e6c56a; text-align: center; }
#lf-clues .cl-row .cl-k { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: #c9b07a; white-space: nowrap; }
#lf-clues .cl-row b { font-weight: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lf-clues .cl-item.new .cl-row b::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #e6c56a; vertical-align: 1px; }
#lf-clues .cl-item.on { background: rgba(212,181,106,0.08); }
#lf-clues .cl-item.on .cl-row b { white-space: normal; }
#lf-clues .cl-body { padding: 0 8px 8px 36px; }
#lf-clues .cl-body p { margin: 0; font-size: 13px; line-height: 1.45; color: #e8dcc0; }
#lf-clues .cl-body .cl-acts:empty { display: none; }
#lf-clues .cl-empty { margin: 6px 2px; font-size: 13px; color: #c9b896; font-style: italic; }
.cx-toggle .cx-sub { display: block; font-style: normal; font-size: 11px; color: var(--lf-dim, #c9b896); margin-top: 2px; }
#ui.sheet-open #lf-compass, #ui.talk-open #lf-compass { display: none !important; }
#lf-strip:not(.folded) .sp-go i { display: none; }
/* While someone is speaking at the bottom, an urgent line uses the free top band. */
#ui.npc-open #lf-alert { bottom: auto; top: calc(var(--safe-t) + 10px); }
