/* Miners World — GBA-style UI. Pixel aesthetics, DOM overlays for menus. */

:root {
  --ink: #2a1d10;
  --panel: #fffbe8;
  --panel-edge: #6b5a2e;
  --panel-edge2: #c9b872;
  --accent: #f4d03f;
  --accent2: #e8963c;
  --bg: #1a1230;
  --good: #58c258;
  --bad: #e05038;
  --water: #4aa8e0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  background: #0d0a1a;
  color: #fffbe8;
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  /* manipulation: no double-tap zoom, but does NOT blanket-ban panning — a
     body-wide `none` also froze scrolling inside menu panels on phones
     (rotating to landscape pushed buttons below the fold with no way to
     reach them). The game surfaces below re-declare `none` themselves. */
  touch-action: manipulation;
}

/* The ONE place text may be selected: the wallet panel (deposit addresses
   and mint ids are long hex strings players must be able to copy by hand).
   Everywhere else stays unselectable so drag-to-pan misclicks don't smear
   the UI. */
.selectable, .selectable * {
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}
.selectable button, .selectable a { cursor: pointer; }
button { font-family: inherit; font-weight: 700; cursor: pointer; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }

/* Game surfaces keep absorbing every gesture (no pan/pinch) exactly as
   before — only menu panels became touch-scrollable (see .panel-body). */
#viewport, #screen, #touch { touch-action: none; }

/* --- viewport ---------------------------------------------------------- */
#viewport {
  position: relative;
  background: #000;
  box-shadow: 0 0 0 4px #2a2140, 0 0 40px #000a;
  overflow: hidden;
}
#screen {
  display: block;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#crt {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, #0002 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
  opacity: .35;
}

/* --- crisp text overlay (240x160 game coords -> DOM labels) ------------ */
#overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 30;
  overflow: hidden;
  --mw-fs: 24px;
}
.mw-ov {
  position: absolute;
  font-size: var(--mw-fs);
  line-height: 1.05;
  white-space: nowrap;
  transform-origin: left top;
}
.mw-txt {
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  color: #2a1d10;
  letter-spacing: .02em;
}
.mw-txt.light { color: #ffe98a; text-shadow: 0 1px 0 #000000cc; }
.mw-bubble {
  background: #1a1230f2;
  border: 2px solid #f4d03f;
  border-radius: 4px;
  color: #f4d03f;
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  padding: 0 .28em;
}
.mw-star {
  color: #f4d03f;
  font-weight: 700;
  text-shadow: 0 0 2px #000000e0, 0 1px 0 #000000b0;
}

/* --- HUD ---------------------------------------------------------------- */
#hud { position: absolute; inset: 0; pointer-events: none; font-size: 12px; }
#hud-top {
  position: absolute; top: 4px; left: 4px; right: 4px;
  display: flex; gap: 6px; align-items: center;
}
#hud-top span {
  background: #1a1230d9; padding: 2px 7px; border: 2px solid #c9b872;
  white-space: nowrap; letter-spacing: .5px;
}
#hud-map { color: var(--accent); }
#hud-mwc { color: #7fe08a; }
#hud-menu { pointer-events: auto; margin-left: auto; }
#hud-bag, #hud-quests { pointer-events: auto; }
.hbtn {
  background: var(--accent); color: var(--ink); border: 2px solid #6b5a2e;
  border-radius: 4px; padding: 2px 8px; font-size: 13px;
}
#hud-party {
  position: absolute; top: 30px; left: 4px; display: flex; flex-direction: column; gap: 2px;
}
.hp-pip {
  width: 74px; background: #1a1230d9; border: 2px solid #c9b872; padding: 1px 3px;
  display: flex; align-items: center; gap: 4px;
}
.hp-pip img, .hp-pip canvas { width: 16px; height: 16px; image-rendering: pixelated; }
.hp-pip .bar { flex: 1; height: 4px; background: #3a2a1a; }
.hp-pip .bar i { display: block; height: 100%; background: var(--good); }
.hp-pip .bar i.mid { background: var(--accent); }
.hp-pip .bar i.low { background: var(--bad); }
.hp-pip.faint { opacity: .45; }

/* --- dialogue ------------------------------------------------------------ */
#dialogue {
  position: absolute; left: 2%; right: 2%; bottom: 3%; z-index: 60;
  background: var(--panel); color: var(--ink);
  border: 3px solid var(--panel-edge); border-radius: 6px;
  box-shadow: 0 3px 0 #0006, inset 0 0 0 2px var(--panel-edge2);
  padding: 8px 12px 14px;
  font-size: 13px; line-height: 1.45; min-height: 74px;
  pointer-events: none;
}
/* confirm prompts (e.g. starter choice) must stay clickable even while a
   z-40 panel overlay is open — lift the buttons above it */
#dialogue button { pointer-events: auto; }
#dl-name {
  position: absolute; top: -12px; left: 10px;
  background: var(--accent2); color: #fff; border: 2px solid #6b5a2e;
  padding: 0 8px; font-size: 11px; border-radius: 4px;
}
#dl-text { white-space: pre-wrap; }
#dl-more {
  position: absolute; right: 10px; bottom: 4px; color: var(--accent2);
  animation: bob 0.8s infinite;
}
@keyframes bob { 50% { transform: translateY(2px); } }

/* --- battle UI ------------------------------------------------------------ */
#battle-ui {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  justify-content: flex-end; pointer-events: none; font-size: 12px;
}
#b-msg {
  min-height: 34px; margin: 0 2% 4px;
  background: #1a1230e6; border: 2px solid #c9b872; border-radius: 4px;
  padding: 5px 9px; line-height: 1.4;
}
#b-actions, #b-moves, #b-party, #b-bag {
  pointer-events: auto;
  margin: 0 2% 3%;
  background: var(--panel); color: var(--ink);
  border: 3px solid var(--panel-edge); border-radius: 6px;
  box-shadow: inset 0 0 0 2px var(--panel-edge2);
  padding: 6px;
}
.b-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.b-grid.moves { grid-template-columns: 1fr 1fr; }
.b-btn {
  background: #fff; border: 2px solid #a89858; border-radius: 4px;
  padding: 5px 8px; text-align: left; color: var(--ink); font-size: 12px;
  display: flex; justify-content: space-between; gap: 6px; align-items: center;
}
.b-btn:active, .b-btn:focus-visible { background: var(--accent); outline: none; }
.b-btn small { color: #7a6a3a; font-size: 10px; }
.b-btn .pp { color: #3a6a9a; }
.b-btn.back { background: var(--accent2); color: #fff; }
.type-chip {
  display: inline-block; padding: 0 5px; border-radius: 3px; color: #fff;
  font-size: 10px; text-shadow: 1px 1px 0 #0006; border: 1px solid #0004;
}
.row-line { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 3px 6px; border-bottom: 1px dashed #c9b87288; }
.row-line:last-child { border-bottom: 0; }

/* --- touch controls (screen-level, above panels so B always works) -------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 45; }
#dpad { position: absolute; left: 10px; bottom: 12px; width: 108px; height: 108px; }
.dbtn {
  position: absolute; width: 36px; height: 36px;
  background: #1a1230cc; color: #fffbe8; border: 2px solid #c9b87288; border-radius: 8px;
  pointer-events: auto; font-size: 14px;
}
.du { top: 0; left: 36px; } .dd { bottom: 0; left: 36px; }
.dl { top: 36px; left: 0; } .dr { top: 36px; right: 0; }
#abtns { position: absolute; right: 12px; bottom: 20px; display: flex; gap: 10px; }
.abtn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 50%;
  background: #e8963ccc; border: 3px solid #fffbe8aa; color: #fff; font-size: 16px;
}
#btn-b { background: #7d5fb2cc; }

/* --- location banner -------------------------------------------------------- */
#banner {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  background: #1a1230e6; border: 2px solid var(--accent); color: var(--accent);
  padding: 6px 18px; font-size: 14px; letter-spacing: 1px;
  animation: bannerIn 2.6s forwards; pointer-events: none; white-space: nowrap;
}
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -8px); }
  12%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; }
}

/* --- boot screen ------------------------------------------------------------- */
#boot {
  position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 30%, #2a2140 0%, #0d0a1a 70%);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.boot-inner { text-align: center; padding: 16px; max-width: 420px; width: 100%; }
#boot-canvas { width: 240px; image-rendering: pixelated; margin-bottom: 4px; }
.boot-logo { display: flex; justify-content: center; }
#boot h1 {
  margin: 8px 0 0; font-size: 30px; letter-spacing: 2px;
  color: var(--accent); text-shadow: 2px 2px 0 #6b4a10, 4px 4px 0 #0008;
}
#boot h2 { margin: 2px 0 18px; font-size: 13px; color: #c9b872; letter-spacing: 3px; }
#boot-status { font-size: 12px; color: #9a8ab2; margin-bottom: 12px; min-height: 16px; }
#boot-controls { display: flex; flex-direction: column; gap: 10px; align-items: center; }
#boot-controls button {
  width: 260px; padding: 10px; font-size: 14px;
  border-radius: 6px; border: 3px solid #6b5a2e;
}
.primary { background: #5865f2; color: #fff; border-color: #3c45a8 !important; }
#btn-dev { background: var(--accent); color: var(--ink); }
.boot-note { font-size: 10px; color: #7a6a9a; margin-top: 8px; }

/* --- panels (full menus) -------------------------------------------------------- */
#panels:not(:empty) {
  position: absolute; inset: 0; z-index: 40;
  background: #0d0a1ae0;
  display: flex; align-items: center; justify-content: center;
  padding: 10px;
}
.panel {
  background: var(--panel); color: var(--ink);
  border: 4px solid var(--panel-edge); border-radius: 8px;
  box-shadow: 0 6px 0 #0008, inset 0 0 0 3px var(--panel-edge2);
  width: min(560px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.panel.dark { background: #221a3a; color: #fffbe8; border-color: #6b5a2e; }
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--accent2); color: #fff;
  border-bottom: 3px solid var(--panel-edge); letter-spacing: 1px;
}
.panel.dark .panel-header { background: #3a2a6a; }
.panel-header button {
  background: #fffbe8; color: var(--ink); border: 2px solid #6b5a2e; border-radius: 4px;
  padding: 1px 8px; font-size: 12px;
}
.panel-body { padding: 10px 12px; overflow-y: auto; font-size: 13px; touch-action: pan-y; overscroll-behavior: contain; }
.panel-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb { background: #c9b872; border-radius: 4px; }

.tabs { display: flex; gap: 4px; padding: 6px 10px 0; flex-wrap: wrap; }
.tab {
  background: #d8caa0; color: var(--ink); border: 2px solid #a89858; border-bottom: 0;
  border-radius: 6px 6px 0 0; padding: 3px 10px; font-size: 11px;
}
.tab.on { background: var(--accent); }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.menu-item {
  background: #fff; border: 2px solid #a89858; border-radius: 6px;
  padding: 8px; text-align: left; color: var(--ink); font-size: 13px;
  display: flex; flex-direction: column; gap: 3px;
}
.menu-item:active { background: var(--accent); }
.menu-item .sub { font-size: 10px; color: #7a6a3a; }
.menu-item[disabled] { opacity: .5; }

.card {
  background: #fff; border: 2px solid #a89858; border-radius: 6px;
  padding: 8px; margin-bottom: 8px; color: var(--ink);
}
.card h4 { margin: 0 0 4px; font-size: 13px; }
.card .dim { color: #7a6a3a; font-size: 11px; }
.card.done { border-color: var(--good); }
.progress { height: 8px; background: #d8caa0; border: 1px solid #a89858; border-radius: 4px; overflow: hidden; margin: 4px 0; }
.progress i { display: block; height: 100%; background: var(--good); }
.progress i.pct { background: var(--accent); }

.starter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.starter {
  background: #fff; border: 3px solid #a89858; border-radius: 8px; padding: 6px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink);
}
.starter.on { border-color: var(--accent2); background: #fff4c8; box-shadow: 0 0 0 2px var(--accent2); }
.starter canvas { width: 64px; height: 64px; image-rendering: pixelated; }
.starter .nm { font-size: 12px; }
.starter .el { font-size: 10px; color: #7a6a3a; }
.starter .ds { font-size: 10px; line-height: 1.35; color: #5a4a2a; margin-top: 2px; }

input[type="text"], input[type="number"] {
  font-family: inherit; font-weight: 700; font-size: 14px;
  border: 2px solid #a89858; border-radius: 4px; padding: 6px 8px;
  background: #fff; color: var(--ink); width: 100%;
}
.pkt { display: grid; grid-template-columns: 56px 1fr; gap: 8px; align-items: center; }
.pkt canvas { width: 48px; height: 48px; image-rendering: pixelated; background: #d8caa0; border-radius: 6px; }
.pkt .big { font-size: 13px; }
.pkt .tiny { font-size: 10px; color: #7a6a3a; }

.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 4px; }
.dex-cell {
  background: #fff; border: 2px solid #a89858; border-radius: 6px; text-align: center;
  padding: 3px 1px; color: var(--ink); font-size: 10px;
}
.dex-cell canvas { width: 32px; height: 32px; image-rendering: pixelated; }
.dex-cell.unknown { opacity: .45; filter: grayscale(1); }
.dex-cell .no { color: #7a6a3a; font-size: 9px; }

/* ---- battle bag tabs (mirrors the menu bag pockets) ---- */
#b-bag .tabs { padding: 0 0 4px; }
#b-bag .tab { font-size: 10px; padding: 3px 7px; }
#b-bag .b-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; max-height: 96px; overflow-y: auto; }
#b-bag .b-btn.disabled { opacity: .55; }
#b-bag .b-empty { grid-column: 1 / -1; color: #7a6a3a; font-size: 11px; padding: 4px; }

/* ---- admin: players table ---- */
.admin-tbl-wrap { overflow-x: auto; max-height: 300px; overflow-y: auto; border: 1px solid #4a3f6e; border-radius: 6px; }
.admin-tbl { border-collapse: collapse; width: 100%; font-size: 11px; min-width: 720px; }
.admin-tbl th {
  position: sticky; top: 0; background: #1d1736; color: #c9b872; text-align: left;
  padding: 5px 6px; border-bottom: 2px solid #4a3f6e; white-space: nowrap;
}
.admin-tbl td { padding: 4px 6px; border-bottom: 1px solid #38305a; vertical-align: middle; white-space: nowrap; }
.admin-tbl td small { font-size: 10px; }
.admin-av { width: 24px; height: 24px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.admin-av-fb { background: #4a3f6e; color: #fffbe8; font-size: 12px; font-weight: 700; text-align: center; line-height: 24px; }
.admin-wal { font-family: ui-monospace, monospace; cursor: pointer; }
.admin-wal:hover { color: #8fd3d9; text-decoration: underline; }

.lb-row { display: flex; justify-content: space-between; padding: 4px 6px; border-bottom: 1px dashed #c9b87288; }
.lb-row.me { background: #fff4c8; }
.lb-row .rank { width: 28px; color: #7a6a3a; }

/* NOTE: this was `.toasts` (a class) while the markup is <div id="toasts"> —
   the container matched nothing, so toasts rendered as unstyled static flex
   items that physically shoved the game viewport aside on every toast. */
#toasts {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 90; align-items: center;
  pointer-events: none;
}
.toast {
  background: #1a1230ee; color: #fffbe8; border: 2px solid var(--accent);
  border-radius: 6px; padding: 6px 14px; font-size: 12px;
  animation: toastIn 3.5s forwards; max-width: 88vw; text-align: center;
}
.toast.bad { border-color: var(--bad); }
.toast.good { border-color: var(--good); }
@keyframes toastIn {
  0% { opacity: 0; transform: translateY(8px); }
  8%, 84% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; }
}

.badge { display: inline-block; padding: 0 6px; border-radius: 8px; font-size: 10px; border: 1px solid #0004; color: #fff; text-shadow: 1px 1px 0 #0006; }
.badge.sim { background: #b58900; }
.badge.live { background: var(--good); }
.mini-note { font-size: 10px; color: #7a6a3a; margin-top: 6px; }

@media (max-width: 720px) {
  #dialogue { font-size: 12px; }
  #b-msg { font-size: 11px; }
}

/* --- touch layout adjustments ---------------------------------------------- */
/* Keep panel content scrollable past the fixed touch controls */
body.touch .panel-body { padding-bottom: 132px; }
/* In landscape the controls sit in the bottom corners — keep the dialogue
   text and battle menus in the clear middle column */
@media (orientation: landscape) {
  body.touch #dialogue { left: 24%; right: 24%; }
  body.touch #b-actions, body.touch #b-moves, body.touch #b-party, body.touch #b-bag { margin: 0 22% 3%; }
}

/* --- world map marker ------------------------------------------------------- */
@keyframes mw-bounce { from { transform: translate(-50%, 0); } to { transform: translate(-50%, -4px); } }

/* --- portrait rotation blocker (phones) -------------------------------------- */
/* Phones held upright get a friendly "rotate me" screen; it clears by itself
   the moment the device is horizontal. `pointer: coarse` keeps every desktop
   window (however narrow) and landscape phone/tablet untouched — Android
   Chrome and iOS Safari both evaluate these media queries live. */
#rotate-block {
  position: fixed; inset: 0; z-index: 200;
  background: #0d0a1a;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; text-align: center; padding: 24px;
  color: #fffbe8;
}
#rotate-block .rb-phone {
  width: 34px; height: 60px; border: 3px solid var(--accent); border-radius: 7px;
  position: relative;
  animation: rb-turn 1.8s ease-in-out infinite;
}
#rotate-block .rb-phone::after {
  content: ""; position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
#rotate-block h2 { margin: 0; font-size: 18px; letter-spacing: 1px; color: var(--accent); }
#rotate-block p { margin: 0; font-size: 12px; color: #9a8ab2; }
@keyframes rb-turn {
  0%, 15% { transform: rotate(0deg); }
  55%, 85% { transform: rotate(-90deg); }
  100% { transform: rotate(-90deg); }
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-block { display: flex; }
}
