:root {
  --ink: #2b2a3a;
  --paper: #f4ecd8;
  --paper-2: #e8ddc2;
  --gold: #e0b84c;
  --p2p: #4ea1d3;
  --o2c: #e08a4e;
  --green: #57a773;
  --red: #d9534f;
  --shadow: rgba(20, 16, 30, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #1a1626;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 120% at 50% 0%, #2b2440 0%, #15111f 70%);
}

#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#locationTag {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper);
  color: var(--ink);
  padding: 7px 22px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--shadow);
  font-size: 15px;
  transition: opacity 0.25s;
}

.hint {
  position: absolute;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 16, 30, 0.86);
  color: #fff;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.18s;
  border: 2px solid rgba(255,255,255,0.18);
  white-space: nowrap;
}
.hint.show { opacity: 1; }
.hint kbd { margin: 0 2px; }

kbd {
  display: inline-block;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-bottom-width: 3px;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85em;
  line-height: 1.4;
}

#purse {
  position: absolute;
  top: 16px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 5px 16px 5px 12px;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 4px 0 var(--shadow);
}
#purse .coin {
  color: var(--gold);
  font-size: 18px;
  text-shadow: 0 1px 0 #a8842f;
}
#purse.bump { animation: bump 0.35s; }
@keyframes bump { 0%,100% { transform: scale(1); } 40% { transform: scale(1.18); } }

.hud-btn {
  position: absolute;
  top: 16px;
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--paper);
  border: 3px solid var(--ink);
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow);
  pointer-events: auto;
}
.hud-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--shadow); }
#guideBtn { left: 16px; }
#missionBtn { left: 64px; }
.rank-chip {
  position: absolute;
  top: 64px;
  left: 16px;
  background: var(--ink);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  border: 2px solid rgba(255,255,255,0.2);
}

/* ---------- Modals (quiz / shop) ---------- */
.modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 8, 16, 0.55);
  z-index: 20;
  transition: opacity 0.18s;
}
.modal.hidden { opacity: 0; pointer-events: none; }

.modal-card {
  width: min(620px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 16px 0 var(--shadow), 0 30px 60px rgba(0,0,0,0.5);
  padding: 22px;
}
.modal.hidden .modal-card { transform: scale(0.94); transition: transform 0.18s; }
.modal-close {
  background: var(--ink); color: #fff; border: none;
  width: 32px; height: 32px; border-radius: 8px; font-size: 15px; cursor: pointer; flex: none;
}
.modal-close:hover { background: #44425c; }

/* quiz */
.quiz-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.npc-avatar { width: 48px; height: 48px; border-radius: 12px; border: 3px solid var(--ink); flex: none; box-shadow: 0 3px 0 var(--shadow); }
.quiz-name { font-size: 18px; font-weight: 800; }
.chips { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.app-chip { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: #fff; padding: 2px 9px; border-radius: 6px; }
.level-badge { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: 0.5px; color: #fff; padding: 2px 9px; border-radius: 6px; }
.quiz-head .modal-close { margin-left: auto; }
.quiz-prompt { font-size: 17px; line-height: 1.5; margin: 4px 0 12px; }
.quiz-rec { font-size: 13px; line-height: 1.5; background: #f3ecd6; border: 2px solid rgba(43,42,58,0.25); border-radius: 10px; padding: 9px 13px; margin-bottom: 16px; }
.quiz-rec .rec-ic { margin-right: 4px; }

.quiz-status { font-size: 13px; line-height: 1.5; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; border: 2px solid var(--ink); }
.quiz-status.locked { background: #fbe6e5; }
.quiz-status.ok { background: #d8f0df; }
.quiz-status kbd { font-size: 0.8em; }
.opt.hidden-opt { opacity: 0.6; color: #8a8170; font-style: italic; }
.found { background: #fff7e0; border: 2px solid var(--ink); border-radius: 10px; padding: 10px 14px; font-size: 13px; line-height: 1.5; margin-top: 14px; }

/* analysis run result */
.quiz-analysis:empty { display: none; }
.analysis { margin-top: 16px; border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; box-shadow: 0 4px 0 var(--shadow); }
.analysis-head { background: var(--ink); color: #fff; font-weight: 800; font-size: 14px; padding: 9px 14px; }
.analysis > .bars, .analysis > table, .analysis > .flow, .analysis > .kpi-row, .analysis > .charts-2, .analysis > .block-title { margin: 14px; }
.analysis-insight { background: #fff7e0; border-top: 2px dashed rgba(43,42,58,0.25); padding: 12px 14px; font-size: 14px; line-height: 1.5; }

.quiz-toolswrap, .quiz-itemswrap { margin-top: 16px; padding-top: 14px; border-top: 2px dashed rgba(43,42,58,0.25); }
.quiz-tools-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.tool-btn { font-family: inherit; font-weight: 800; font-size: 14px; border-radius: 11px; padding: 11px 16px; cursor: pointer; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--shadow); }
.tool-btn.run { background: var(--gold); color: var(--ink); }
.tool-btn.run.alt { background: #cdbef0; }
.tool-btn.run:hover { filter: brightness(1.05); }
.tool-btn.run:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--shadow); }
.tool-btn.locked { background: #e6dcc6; color: #8a8170; cursor: default; box-shadow: 0 2px 0 var(--shadow); }
.kindtag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #fff; background: #9a93b0; padding: 1px 6px; border-radius: 5px; vertical-align: middle; }
.shop-item.done { opacity: 0.85; background: #eef6ef; }

.quiz-options { display: grid; gap: 10px; }
.opt {
  text-align: left; width: 100%;
  background: #fff; border: 3px solid var(--ink); border-radius: 12px;
  padding: 13px 16px; font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
  box-shadow: 0 4px 0 var(--shadow); transition: transform 0.08s, background 0.15s;
  display: flex; align-items: center; gap: 12px;
}
.opt .opt-key { width: 24px; height: 24px; border-radius: 6px; background: var(--paper-2); border: 2px solid var(--ink); display: grid; place-items: center; font-size: 12px; font-weight: 800; flex: none; }
.opt:hover:not(:disabled) { transform: translateY(-1px); background: #fffdf6; }
.opt:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--shadow); }
.opt:disabled { cursor: default; box-shadow: 0 2px 0 var(--shadow); }
.opt.correct { background: #d8f0df; border-color: #2c7a4b; }
.opt.correct .opt-key { background: #2c7a4b; color: #fff; }
.opt.wrong { background: #f7d7d6; border-color: #a3322e; opacity: 0.9; }
.opt.struck { opacity: 0.4; text-decoration: line-through; }

.quiz-feedback { margin-top: 14px; font-size: 14px; line-height: 1.5; min-height: 0; }
.quiz-feedback .fb { padding: 11px 14px; border-radius: 10px; border: 2px solid var(--ink); margin-top: 10px; }
.quiz-feedback .fb.hint { background: #fff7e0; }
.quiz-feedback .fb.good { background: #d8f0df; }
.quiz-feedback .fb.bad { background: #fbe6e5; }
.quiz-feedback .fb b { font-weight: 800; }

.quiz-tools { margin-top: 18px; padding-top: 14px; border-top: 2px dashed rgba(43,42,58,0.25); }
.tools-label { font-size: 12px; font-weight: 700; opacity: 0.6; text-transform: uppercase; letter-spacing: 0.5px; }
.quiz-items { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.item-btn {
  background: #fff; border: 2px solid var(--ink); border-radius: 10px;
  padding: 7px 11px; font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
  display: flex; align-items: center; gap: 6px; box-shadow: 0 3px 0 var(--shadow);
}
.item-btn:hover:not(:disabled) { background: #fffdf6; }
.item-btn:disabled { opacity: 0.4; cursor: default; }
.item-btn .ct { background: var(--ink); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; }
.no-items { font-size: 13px; opacity: 0.6; margin-top: 8px; }
.quiz-reward { margin-top: 14px; font-size: 13px; opacity: 0.75; }

/* shop */
.shop-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.shop-title { font-size: 22px; font-weight: 800; }
.shop-sub { font-size: 13px; opacity: 0.7; }
.shop-purse { margin-left: auto; display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 17px; background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 4px 14px; }
.shop-purse .coin { color: var(--gold); }
.shop-items { display: grid; gap: 12px; margin-bottom: 12px; }
.shop-item { display: flex; align-items: center; gap: 14px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 12px 14px; box-shadow: 0 4px 0 var(--shadow); }
.shop-item .ic { font-size: 30px; flex: none; width: 44px; text-align: center; }
.shop-item .meta { flex: 1; }
.shop-item .nm { font-size: 16px; font-weight: 800; }
.shop-item .ds { font-size: 13px; opacity: 0.7; }
.shop-item .owned { font-size: 12px; font-weight: 700; color: var(--green); }
.buy-btn { background: var(--gold); color: var(--ink); border: 3px solid var(--ink); border-radius: 10px; padding: 9px 14px; font-weight: 800; font-family: inherit; cursor: pointer; box-shadow: 0 4px 0 var(--shadow); white-space: nowrap; }
.buy-btn:hover:not(:disabled) { background: #ecc665; }
.buy-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--shadow); }
.buy-btn:disabled { opacity: 0.45; cursor: default; }

/* ---------- Analysis Console ---------- */
.console-card { width: min(760px, 95vw); }
.console-body { display: grid; grid-template-columns: 168px 1fr; gap: 16px; min-height: 340px; }
@media (max-width: 600px) { .console-body { grid-template-columns: 1fr; } }
.console-tabs { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 600px) { .console-tabs { flex-direction: row; flex-wrap: wrap; } }
.con-tab {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 3px solid var(--ink); border-radius: 10px;
  padding: 9px 11px; font-family: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow); text-align: left;
}
.con-tab .ti { font-size: 16px; }
.con-tab.active { background: var(--ink); color: #fff; }
.con-tab.locked { opacity: 0.55; }
.console-view { background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 16px; box-shadow: 0 4px 0 var(--shadow); overflow-y: auto; max-height: 56vh; }

.ana-insight { background: var(--ink); color: #fff; border-radius: 10px; padding: 11px 14px; font-size: 14px; line-height: 1.5; margin-bottom: 14px; }
.ana-sub { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.55; margin: 14px 0 8px; }
.ana-detail { margin-top: 14px; background: #f6efdd; border: 2px dashed rgba(43,42,58,0.3); border-radius: 10px; padding: 12px 14px; font-size: 13px; line-height: 1.55; min-height: 20px; }
.ana-empty, .ana-locked { text-align: center; padding: 30px 16px; }
.ana-locked .lock-ic { font-size: 40px; }
.ana-locked .lock-nm { font-size: 17px; font-weight: 800; margin: 8px 0 4px; }
.ana-locked .lock-ds { font-size: 13px; opacity: 0.75; max-width: 360px; margin: 0 auto 12px; }
.ana-locked .lock-buy { font-size: 13px; background: #fff7e0; border: 2px solid var(--ink); border-radius: 10px; padding: 10px 14px; display: inline-block; }

.seq { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.seq .pill { background: var(--paper-2); border: 2px solid var(--ink); border-radius: 8px; padding: 4px 9px; font-size: 12px; font-weight: 700; }
.seq .arrow { opacity: 0.5; font-weight: 800; }

.edge-list, .var-list, .bn-list, .tbl-list { display: flex; flex-direction: column; gap: 7px; }
.edge-row, .bn-row, .tbl-row, .var-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #fff; border: 2px solid var(--ink); border-radius: 9px; padding: 9px 12px;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer; text-align: left; width: 100%;
}
.edge-row:hover, .bn-row:hover, .tbl-row:hover, .var-row:hover { background: #fffdf6; }
.edge-row.sel, .var-row.sel { background: #eef4ff; }
.edge-row.anomaly { border-color: var(--red); background: #fbeceb; }
.edge-row .freq { font-variant-numeric: tabular-nums; opacity: 0.7; font-weight: 700; }
.arrow { opacity: 0.5; }

.var-row { gap: 10px; }
.var-row .vr-rank { font-weight: 800; width: 26px; opacity: 0.6; }
.var-row .vr-bar { flex: 1; height: 14px; background: #eee; border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; }
.var-row .vr-bar span { display: block; height: 100%; background: #9a93b0; }
.var-row.happy .vr-bar span { background: var(--green); }
.var-row.dev .vr-bar span { background: var(--gold); }
.var-row.bad .vr-bar span { background: var(--red); }
.var-row .vr-pct { width: 42px; text-align: right; font-weight: 800; }
.dt-note { margin-top: 10px; }

.bn-row .bn-l { flex: 0 0 42%; }
.bn-row .bn-bar { flex: 1; height: 14px; background: #eee; border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; }
.bn-row .bn-bar span { display: block; height: 100%; background: #4ea1d3; }
.bn-row.slow .bn-bar span { background: var(--red); }
.bn-row .bn-h { width: 48px; text-align: right; font-weight: 800; }
.rw-meta { opacity: 0.7; font-weight: 700; font-size: 12px; }

.cop-bar { display: flex; align-items: center; gap: 10px; background: #ece7fb; border: 2px solid var(--ink); border-radius: 10px; padding: 10px 14px; font-weight: 700; font-size: 14px; }
.cop-bar .cop-credits { margin-left: auto; background: var(--ink); color: #fff; border-radius: 999px; font-size: 12px; padding: 2px 10px; }
.cop-chips { display: flex; flex-direction: column; gap: 7px; }
.chip { text-align: left; background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 8px 12px; font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; box-shadow: 0 3px 0 var(--shadow); }
.chip:hover { background: #f6f1ff; }
.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.cop-q { font-weight: 800; font-size: 14px; margin-bottom: 6px; }
.cop-a { font-size: 13.5px; line-height: 1.55; }
.cop-ev { font-size: 12px; opacity: 0.72; margin-top: 8px; }

/* copilot chat transcript — a bounded scroll panel under the questions */
.cop-chat {
  margin-top: 12px; height: clamp(190px, 40vh, 300px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 9px;
  padding: 12px; border: 2px solid rgba(43, 42, 58, 0.22); border-radius: 12px;
  background: #fffdf7; box-shadow: inset 0 1px 4px rgba(0,0,0,0.06); scroll-behavior: smooth;
}
.cop-empty { font-size: 13px; opacity: 0.6; margin: auto; text-align: center; padding: 10px; }
.cop-chat .msg { font-size: 13px; line-height: 1.5; max-width: 92%; }
.cop-chat .msg.user { align-self: flex-end; background: var(--ink); color: #fff; font-weight: 600; padding: 8px 12px; border-radius: 12px 12px 3px 12px; }
.cop-chat .msg.bot { align-self: flex-start; display: flex; gap: 8px; }
.cop-chat .bot-ic { font-size: 18px; line-height: 1.4; }
.cop-chat .bot-body { background: #ece7fb; border: 2px solid var(--ink); border-radius: 12px 12px 12px 3px; padding: 9px 12px; box-shadow: 0 3px 0 var(--shadow); }
.cop-chat .tools { display: flex; flex-direction: column; gap: 5px; }
.cop-chat .tool { font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; background: #fff; border: 1px solid rgba(43,42,58,0.25); border-radius: 7px; padding: 4px 8px; }
.cop-chat .tool b { color: #6a4ca8; }
.cop-chat .tool .targs { opacity: 0.75; }
.cop-chat .tool-ok { color: var(--green); font-weight: 700; }
.cop-chat .bot-body .cop-a { margin-top: 8px; }
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: #8a7fb0; display: inline-block; animation: typedot 1s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typedot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-3px); opacity: 1; } }

/* field guide */
.guide-card { width: min(680px, 94vw); }
.guide-progress { font-size: 13px; font-weight: 700; background: var(--paper-2); border: 2px solid var(--ink); border-radius: 10px; padding: 8px 12px; margin-bottom: 14px; }
.guide-items { display: grid; gap: 10px; }
.guide-item { display: flex; gap: 14px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 12px 14px; box-shadow: 0 4px 0 var(--shadow); }
.guide-item.locked { opacity: 0.7; background: #efe9da; }
.guide-item .g-ic { font-size: 26px; width: 38px; text-align: center; flex: none; }
.guide-item .g-nm { font-size: 15px; font-weight: 800; margin-bottom: 3px; }
.guide-item .g-what { font-size: 13px; line-height: 1.5; }
.guide-item .g-what.locked { font-style: italic; opacity: 0.7; }
.guide-item .g-when { font-size: 12px; line-height: 1.5; opacity: 0.8; margin-top: 4px; }

/* toast */
.toast {
  position: absolute;
  bottom: 70px; left: 50%; transform: translate(-50%, 12px);
  background: var(--ink); color: #fff;
  padding: 11px 22px; border-radius: 12px; font-weight: 700; font-size: 15px;
  border: 2px solid rgba(255,255,255,0.2);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Data panel ---------- */
.panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  width: min(860px, 92vw);
  max-height: 86vh;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 18px 0 var(--shadow), 0 30px 60px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.18s, transform 0.18s;
}
.panel.hidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.92);
  pointer-events: none;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 22px 14px;
  background: var(--paper-2);
  border-bottom: 3px solid var(--ink);
}
.panel-app {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #fff;
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
}
.panel-head h2 { font-size: 24px; line-height: 1.1; }
.panel-sub { font-size: 13px; opacity: 0.7; margin-top: 4px; }

#panelClose {
  background: var(--ink);
  color: #fff;
  border: none;
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  flex: none;
}
#panelClose:hover { background: #44425c; }

.panel-body {
  padding: 20px 22px;
  overflow-y: auto;
}
.panel-foot {
  padding: 10px 22px;
  font-size: 12px;
  opacity: 0.6;
  border-top: 2px dashed rgba(43,42,58,0.3);
}

/* KPI cards */
.kpi-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.kpi {
  flex: 1 1 130px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 4px 0 var(--shadow);
}
.kpi .v { font-size: 26px; font-weight: 800; }
.kpi .l { font-size: 12px; opacity: 0.7; margin-top: 2px; }
.kpi .d { font-size: 12px; font-weight: 700; margin-top: 4px; }
.kpi .d.up { color: var(--green); }
.kpi .d.down { color: var(--red); }

.block-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.6;
  margin: 18px 0 10px;
}

/* Bar chart */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%;
  max-width: 46px;
  border-radius: 6px 6px 0 0;
  border: 2px solid var(--ink);
  border-bottom: none;
  position: relative;
  min-height: 4px;
  transition: height 0.5s cubic-bezier(.2,.9,.3,1);
}
.bar .bv { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 700; white-space: nowrap; }
.bar-col .bl { font-size: 11px; opacity: 0.7; text-align: center; }

/* Table */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 2px solid rgba(43,42,58,0.12); }
table.data th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.6; }
table.data tr:last-child td { border-bottom: none; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.tag.ok { background: #d8f0df; color: #2c7a4b; }
.tag.warn { background: #fbe6c8; color: #9a6213; }
.tag.bad { background: #f7d7d6; color: #a3322e; }

/* Funnel / flow */
.flow { display: flex; flex-direction: column; gap: 8px; }
.flow-step { display: flex; align-items: center; gap: 12px; }
.flow-bar {
  height: 30px; border-radius: 8px; border: 2px solid var(--ink);
  display: flex; align-items: center; padding: 0 10px;
  font-size: 12px; font-weight: 700; color: #fff;
  box-shadow: 0 3px 0 var(--shadow);
}
.flow-step .fl { width: 130px; font-size: 12px; font-weight: 700; }
.flow-step .fv { font-size: 12px; opacity: 0.7; }

/* Donut legend */
.legend { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 12px; }
.legend span { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; border: 2px solid var(--ink); display: inline-block; }

.charts-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 620px) { .charts-2 { grid-template-columns: 1fr; } }

/* ---------- Title / main menu ---------- */
/* The live game renders behind this overlay; we blur + tilt-shift it. */
#splash {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(26,18,40,0.55) 0%, rgba(24,30,22,0.28) 42%, rgba(20,14,28,0.6) 100%);
  -webkit-backdrop-filter: blur(7px) saturate(1.3) brightness(1.02);
  backdrop-filter: blur(7px) saturate(1.3) brightness(1.02);
  transition: opacity 0.6s;
}
#splash.gone { opacity: 0; pointer-events: none; }
body.titlescreen #hud, body.titlescreen #touchControls { opacity: 0; pointer-events: none; }

/* tilt-shift miniature: sharp-ish bright middle band, darkened/vignetted edges */
.title-bands {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(180deg, rgba(10,8,16,0.7) 0%, rgba(10,8,16,0) 26%, rgba(10,8,16,0) 64%, rgba(10,8,16,0.78) 100%),
    radial-gradient(120% 80% at 50% 46%, rgba(255,236,190,0.10) 0%, rgba(0,0,0,0) 55%),
    radial-gradient(140% 120% at 50% 50%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.45) 100%);
}

.title-overlay {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 34px; padding: 24px;
  text-align: center;
}

/* wooden carved sign */
.logo-plaque {
  position: relative;
  padding: 20px 46px 24px;
  border-radius: 18px;
  color: #ffe9b0;
  background:
    repeating-linear-gradient(180deg, rgba(0,0,0,0.06) 0 6px, rgba(255,255,255,0.03) 6px 12px),
    linear-gradient(180deg, #a6713e 0%, #8a5a30 55%, #74492685 100%);
  background-color: #8a5a30;
  border: 5px solid #4a2f18;
  box-shadow:
    inset 0 3px 0 rgba(255,255,255,0.28), inset 0 -7px 0 rgba(0,0,0,0.30),
    0 10px 0 rgba(0,0,0,0.32), 0 22px 34px rgba(0,0,0,0.55);
}
/* leafy vines peeking from behind the corners */
.logo-plaque::before, .logo-plaque::after {
  content: ''; position: absolute; top: -22px; width: 90px; height: 56px; z-index: -1;
  background:
    radial-gradient(circle at 30% 60%, #4fa55e 0 12px, transparent 13px),
    radial-gradient(circle at 60% 30%, #3f8f4e 0 14px, transparent 15px),
    radial-gradient(circle at 78% 66%, #57b069 0 10px, transparent 11px),
    radial-gradient(circle at 12% 38%, #3f8f4e 0 9px, transparent 10px);
}
.logo-plaque::before { left: -26px; transform: rotate(-12deg); }
.logo-plaque::after { right: -26px; transform: rotate(12deg) scaleX(-1); }

/* mpmX brand logo, sat on a cream chip so it reads against the wood */
.logo-mpmx {
  display: block; height: 52px; width: auto; margin: 0 auto 14px;
  padding: 10px 20px; border-radius: 11px;
  background: #f4ecd8; border: 2px solid #4a2f18;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55), 0 3px 0 rgba(0,0,0,0.28);
}
.logo-title {
  font-size: 60px; line-height: 1; font-weight: 900; letter-spacing: 1px;
  color: #ffe9b0;
  text-shadow: 0 2px 0 #b9823f, 0 4px 0 #6e3f1c, 0 6px 0 #4a2810, 0 8px 8px rgba(0,0,0,0.5);
}
.logo-sub { margin-top: 10px; font-size: 14px; font-weight: 700; color: #f6ddae; opacity: 0.92; letter-spacing: 0.5px; text-shadow: 0 2px 0 rgba(0,0,0,0.4); }

/* wooden menu buttons */
.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: min(320px, 80vw); }
.wood-btn {
  font-family: inherit; font-weight: 800; font-size: 19px; cursor: pointer;
  color: #fff4dd;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 20px; border-radius: 14px;
  border: 3px solid #4a2f18;
  background: linear-gradient(180deg, #c5894c 0%, #a06a39 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), inset 0 -4px 0 rgba(0,0,0,0.28), 0 6px 0 #5a3717, 0 10px 14px rgba(0,0,0,0.4);
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
  transition: transform 0.06s;
}
.wood-btn .ico { font-size: 22px; }
.wood-btn:hover { filter: brightness(1.06); }
.wood-btn:active { transform: translateY(5px); box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), inset 0 -3px 0 rgba(0,0,0,0.28), 0 1px 0 #5a3717, 0 3px 6px rgba(0,0,0,0.4); }
.wood-btn.primary { background: linear-gradient(180deg, #76c267 0%, #56a049 100%); border-color: #2c6b27; box-shadow: inset 0 2px 0 rgba(255,255,255,0.4), inset 0 -4px 0 rgba(0,0,0,0.25), 0 6px 0 #2f6b2a, 0 10px 14px rgba(0,0,0,0.4); }
.wood-btn.small { font-size: 16px; padding: 11px 18px; }

/* How-to overlay */
.howto { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8,6,14,0.5); }
.howto.hidden { display: none; }
.wood-card {
  width: min(440px, 90vw); color: #fff4dd; text-align: left;
  padding: 22px 24px; border-radius: 16px;
  border: 4px solid #4a2f18;
  background: linear-gradient(180deg, #a6713e, #835530);
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.22), 0 14px 0 rgba(0,0,0,0.3), 0 24px 40px rgba(0,0,0,0.5);
}
.wood-card h2 { font-size: 24px; margin-bottom: 14px; text-shadow: 0 2px 0 rgba(0,0,0,0.4); }
.wood-card ul { list-style: none; display: grid; gap: 9px; margin-bottom: 14px; }
.wood-card li { font-size: 15px; }
.wood-card kbd { background: #f4ecd8; color: var(--ink); }
.howto-goal { font-size: 14px; line-height: 1.6; opacity: 0.95; background: rgba(0,0,0,0.18); padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; }
.wood-card .wood-btn { width: 100%; }
.touch-only { display: none; }
body.touch .touch-only { display: inline; }

/* ---------- On-screen touch controls ---------- */
#touchControls { display: none; }
body.touch #touchControls { display: block; }
body.touch.overlay-open #touchControls { display: none; }

/* allow finger-scroll inside long overlays (body itself is touch-action:none) */
.modal-card, .panel, .panel-body, .console-view, .guide-items, .shop-items { touch-action: pan-y; -webkit-overflow-scrolling: touch; }

#joyBase {
  position: absolute;
  left: calc(20px + env(safe-area-inset-left));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 122px; height: 122px;
  border-radius: 50%;
  background: rgba(20, 16, 30, 0.30);
  border: 3px solid rgba(255, 255, 255, 0.32);
  z-index: 15;
  touch-action: none;
}
#joyKnob {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(244, 236, 216, 0.92);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--shadow);
  pointer-events: none;
}
#touchBtns {
  position: absolute;
  right: calc(22px + env(safe-area-inset-right));
  bottom: calc(30px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 14px;
  z-index: 15;
}
.touch-btn {
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 22px; font-weight: 800;
  font-family: inherit;
  box-shadow: 0 5px 0 var(--shadow);
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.touch-btn.primary { width: 80px; height: 80px; background: var(--gold); font-size: 26px; }
.touch-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--shadow); }

/* ---------- Mobile / narrow-screen layout ---------- */
@media (max-width: 680px) {
  #locationTag {
    top: calc(10px + env(safe-area-inset-top));
    font-size: 12px; padding: 5px 12px;
    max-width: 42vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .hud-btn { top: calc(10px + env(safe-area-inset-top)); width: 38px; height: 38px; font-size: 18px; }
  #guideBtn { left: 10px; }
  #missionBtn { left: 54px; }
  .rank-chip { top: calc(54px + env(safe-area-inset-top)); left: 10px; font-size: 11px; padding: 5px 11px; }
  #purse { top: calc(10px + env(safe-area-inset-top)); right: 10px; font-size: 14px; padding: 4px 13px 4px 10px; }

  .hint { bottom: calc(120px + env(safe-area-inset-bottom)); font-size: 12px; max-width: 88vw; white-space: normal; text-align: center; }

  .modal-card, .panel { width: 94vw; border-width: 3px; }
  .modal-card { padding: 16px; max-height: 84vh; }
  .panel { max-height: 84vh; }
  .panel-head { padding: 14px 16px 12px; }
  .panel-head h2 { font-size: 19px; }
  .panel-body { padding: 16px; }
  .quiz-prompt { font-size: 15px; }
  .quiz-rec, .quiz-status { font-size: 12.5px; }
  .opt { padding: 11px 13px; font-size: 14px; }
  .logo-title { font-size: 42px; }
  .logo-plaque { padding: 16px 28px 18px; }
  .logo-sub { font-size: 13px; }
  .logo-mpmx { height: 44px; margin-bottom: 12px; }
  .title-overlay { gap: 26px; }
  .wood-btn { font-size: 17px; padding: 13px 18px; }

  .console-body { grid-template-columns: 1fr; }
  .console-tabs { flex-direction: row; flex-wrap: wrap; }
  .con-tab { flex: 1 1 30%; }
  .console-view { max-height: 46vh; }

  .shop-item .ic { font-size: 24px; width: 36px; }
  .shop-item .nm { font-size: 15px; }
  .kpi { flex-basis: 110px; }
  .charts-2 { grid-template-columns: 1fr; }
}

/* short landscape (phone on its side): tighten vertical space */
@media (max-height: 480px) {
  .modal-card, .panel { max-height: 92vh; }
  .logo-title { font-size: 36px; }
  .title-overlay { gap: 18px; }
  #joyBase { width: 104px; height: 104px; }
  .touch-btn { width: 54px; height: 54px; }
  .touch-btn.primary { width: 66px; height: 66px; }
}

/* ---------- Tip button (NPC hint) ---------- */
.item-btn.tip { background: #fff3cf; }
.item-btn.tip:hover { background: #ffeec0; }

/* ---------- Mission tracker ---------- */
.mission-card { width: min(560px, 94vw); }
.mz-list { display: grid; gap: 10px; margin-bottom: 14px; }
.mz-row { display: flex; align-items: center; gap: 12px; background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 11px 13px; box-shadow: 0 4px 0 var(--shadow); }
.mz-row.done { background: #eef6ef; }
.mz-ic { width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--ink); flex: none; display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 16px; }
.mz-meta { flex: 1; min-width: 0; }
.mz-nm { font-size: 14px; font-weight: 800; margin-bottom: 5px; }
.mz-sub { font-size: 11px; font-weight: 600; opacity: 0.6; }
.mz-badge { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: #fff; background: var(--green); padding: 1px 7px; border-radius: 5px; }
.mz-bar { height: 12px; background: #eee; border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; }
.mz-bar span { display: block; height: 100%; transition: width 0.5s; }
.mz-count { font-weight: 800; font-variant-numeric: tabular-nums; opacity: 0.75; flex: none; }

/* ---------- Win celebration ---------- */
.winscreen {
  position: absolute; inset: 0; z-index: 35;
  display: grid; place-items: center;
  background: radial-gradient(120% 120% at 50% 10%, #2e2747 0%, #120e1c 80%);
  transition: opacity 0.4s;
}
.winscreen.hidden { opacity: 0; pointer-events: none; }
.win-card { text-align: center; color: var(--paper); max-width: 520px; padding: 30px; }
.win-emoji { font-size: 76px; line-height: 1; margin-bottom: 8px; animation: trophy 1.6s ease-in-out infinite; }
@keyframes trophy { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
.win-card h1 { font-size: 46px; margin: 6px 0 14px; text-shadow: 0 4px 0 rgba(0,0,0,0.4); }
.win-card p { opacity: 0.88; line-height: 1.6; margin-bottom: 18px; }
.win-stats { font-size: 14px; font-weight: 700; background: rgba(255,255,255,0.1); border: 2px solid rgba(255,255,255,0.2); border-radius: 12px; padding: 10px 16px; display: inline-block; margin-bottom: 24px; }
#winClose {
  background: var(--gold); color: var(--ink); border: 4px solid #fff;
  padding: 14px 30px; font-size: 17px; font-weight: 800; border-radius: 12px;
  cursor: pointer; box-shadow: 0 6px 0 rgba(0,0,0,0.4); font-family: inherit;
}
#winClose:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,0.4); }
