/* ui.css — everything that is not drawn on a canvas.
   It lives in its own file (as does every script) so the server can send a content
   security policy with no 'unsafe-inline' in it. */
:root {
  --night: #10130e; --panel: rgba(10, 14, 10, .88); --line: #3c4434; --line-hi: #586349;
  --fg: #e8e8dd; --muted: #a8b19c; --dim: #7b8471; --gold: #ffe9a8; --accent: #78dc8c;
  --red: #e2574a; --blue: #5aa2d8; --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
html, body { margin: 0; height: 100%; background: var(--night); overflow: hidden; }
/* Three stacked layers: the world in 2D, the same frame after the GPU pass, and the
   labels on top (which must never be blurred). The CSS size is set by resize() from
   innerWidth/innerHeight: 100vh on mobile is the LARGE viewport (URL bar hidden) and
   this page never scrolls, so with 100vh taps landed 2-3 tiles short. */
canvas.layer { position: fixed; left: 0; top: 0; display: block; }
#cv, #gl { image-rendering: pixelated; }
#gl { display: none; }
body.post #gl { display: block; }
body.post #cv { visibility: hidden; }
#ui { touch-action: none; }
button { font: inherit; }
[hidden] { display: none !important; }

/* One kind of panel for the whole HUD: a 1 px border with a light fillet on top and
   a hard shadow, no round corners — a pixel-art interface, not a dashboard. */
.card {
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--line); border-radius: 3px;
  box-shadow: 0 0 0 1px #000, inset 0 1px 0 rgba(255, 255, 255, .05), 0 3px 0 rgba(0, 0, 0, .35);
  font: 12px/1.45 var(--mono);
}

#chat {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  width: min(420px, 80vw); padding: 9px 12px; display: none; outline: none;
  font: 14px var(--mono);
}
#chat.open { display: block; }
#chat:focus { border-color: var(--accent); }
#hint {
  position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%);
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; width: max-content; max-width: 62vw;
  font: 11px var(--mono); color: var(--dim); user-select: none; pointer-events: none;
  transition: opacity .8s;
}
#hint span { background: rgba(10, 14, 10, .7); border: 1px solid #2a3024; border-radius: 3px; padding: 2px 7px; }
#hint b { color: var(--muted); font-weight: 600; }
#hint.quiet { opacity: .3; }

#side {
  position: fixed; top: 10px; right: 10px; display: flex;
  flex-direction: column; align-items: flex-end; gap: 7px;
}
#side .btns { display: flex; gap: 7px; }
#side button { padding: 6px 10px; cursor: pointer; color: var(--fg); }
#side button:hover, #chatBtn:hover, #bag button:hover:not(:disabled), #guide button:hover, #pokeBtn:hover { border-color: var(--accent); }
#side button.icon { min-width: 31px; padding: 6px 0; color: var(--dim); }
#side button.icon.on { color: var(--accent); border-color: #2f5a3a; }
#opsBtn::before { content: "◉ "; color: var(--dim); }
#opsBtn.on { border-color: var(--accent); color: var(--accent); }
#opsBtn.on::before { color: var(--accent); animation: pulse 1.2s steps(2) infinite; }
@keyframes pulse { 50% { opacity: .25; } }
#who { padding: 5px 10px; color: var(--muted); }
#who i { display: inline-block; width: 7px; height: 7px; background: var(--accent); margin-right: 6px; }
#qr { padding: 9px 9px 7px; width: 104px; text-align: center; color: var(--muted); }
#qr img { width: 104px; height: 104px; border-radius: 2px; background: #fff; display: block; }
#qr p { margin: 6px 0 0; font-size: 11px; }

/* ---- the player: who you are, health, experience and what you carry ---- */
#hud { position: fixed; left: 10px; bottom: 10px; width: 232px; padding: 9px 11px 10px; user-select: none; }
.hud-id { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.hud-id .lvl {
  min-width: 22px; height: 22px; line-height: 22px; text-align: center; font-weight: 700;
  background: #2a3320; border: 1px solid var(--line-hi); color: var(--gold);
}
.hud-id b { color: var(--gold); font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zone { font-size: 10px; letter-spacing: .06em; padding: 1px 6px; border: 1px solid; }
.zone.safe { color: var(--accent); border-color: #2f5a3a; background: rgba(120, 220, 140, .08); }
.zone.wild { color: var(--red); border-color: #6a2f2a; background: rgba(226, 87, 74, .08); }
.meter { position: relative; height: 13px; background: #0b0d0a; border: 1px solid #000; margin-top: 4px; overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .18s linear;
           box-shadow: inset 0 2px 0 rgba(255, 255, 255, .18), inset 0 -2px 0 rgba(0, 0, 0, .25); }
.meter.hp i { background: #b23a30; } .meter.xp i { background: #3d78a8; }
.meter em { position: absolute; inset: 0; text-align: center; font: 600 10px/13px var(--mono); font-style: normal;
            color: #fff; text-shadow: 0 1px 0 #000, 1px 0 0 #000, -1px 0 0 #000; }
#bag { display: flex; align-items: center; gap: 6px; margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--line); }
#bag svg { width: 16px; height: 16px; shape-rendering: crispEdges; flex: none; }
#bag b { color: var(--gold); font-weight: 600; min-width: 14px; }
#bag .gap { flex: 1; }
#bag button { padding: 2px 7px; cursor: pointer; color: var(--fg); font-size: 11px; }
#bag button:disabled { color: var(--dim); cursor: default; opacity: .6; }
#bag button kbd { color: var(--gold); font: inherit; }
#skills { margin-top: 5px; color: var(--dim); font-size: 10.5px; display: flex; justify-content: space-between; }
#skills b { color: var(--muted); font-weight: 600; }

/* ---- first steps ---- */
#guide {
  position: fixed; top: 10px; left: calc(min(128px, 30vw) + 26px); right: 424px;
  padding: 8px 12px 9px; width: max-content; max-width: calc(100vw - min(128px, 30vw) - 450px); user-select: none;
}
#guide h3 { margin: 0 0 5px; font: 700 11px var(--mono); letter-spacing: .1em; color: var(--gold); display: flex; justify-content: space-between; gap: 18px; }
#guide button { background: none; border: 1px solid transparent; color: var(--dim); cursor: pointer; padding: 0 4px; font-size: 11px; letter-spacing: 0; }
#guide ol { margin: 0; padding: 0; list-style: none; display: flex; gap: 6px 16px; flex-wrap: wrap; }
#guide li { color: var(--muted); }
#guide li::before { content: "□ "; color: var(--dim); }
#guide li.done { color: var(--dim); text-decoration: line-through; }
#guide li.done::before { content: "■ "; color: var(--accent); }
#guide li.now { color: var(--fg); }
#guide li.now::before { color: var(--gold); animation: pulse 1s steps(2) infinite; }
#guide kbd { border: 1px solid var(--line-hi); padding: 0 4px; color: var(--gold); font: inherit; }

/* ---- ops view ---- */
#ops {
  position: fixed; left: 10px; top: calc(min(128px, 30vw) + 46px);
  width: min(286px, calc(100vw - 20px)); max-height: calc(100vh - min(128px, 30vw) - 236px);
  overflow: auto; padding: 9px 11px 10px; font-size: 11px; scrollbar-width: none;
}
#ops h3 { margin: 0 0 6px; font: 700 11px var(--mono); letter-spacing: .1em; color: var(--accent);
          display: flex; justify-content: space-between; align-items: baseline; }
#ops h3 span { font-weight: 400; letter-spacing: 0; color: var(--dim); }
#ops h3 + .row { border-top: 0; }
#ops .row { display: grid; grid-template-columns: 46px 1fr auto; gap: 6px; align-items: center;
            padding: 3px 0; border-top: 1px solid #1c211a; }
#ops .row label { color: var(--dim); }
#ops .row span { color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ops b { color: var(--gold); font-weight: 600; }
#ops canvas { width: 64px; height: 16px; image-rendering: pixelated; }
#pokeBtn { padding: 1px 6px; cursor: pointer; color: var(--fg); font-size: 10.5px; }
.budget { height: 6px; background: #0b0d0a; border: 1px solid #000; margin: 2px 0 3px; position: relative; }
.budget i { position: absolute; inset: 0 auto 0 0; background: var(--accent); min-width: 2px; }
.budget-t { color: var(--dim); margin-bottom: 4px; }
#ops h3.sec { margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); }
#oChain.ok { color: var(--accent); } #oChain.bad { color: var(--red); }
#oLedger { list-style: none; margin: 0; padding: 0; }
#oLedger li { display: grid; grid-template-columns: 22px 54px 1fr 50px; gap: 5px; padding: 2px 0; white-space: nowrap; }
#oLedger li > * { overflow: hidden; text-overflow: ellipsis; }
#oLedger .seq { color: var(--dim); } #oLedger .ts { color: var(--muted); }
#oLedger .ev b { font-weight: 400; } #oLedger .h { color: #6fae8a; text-align: right; }
#oLedger li.new { animation: flashrow 1.2s ease-out; }
@keyframes flashrow { from { background: rgba(120, 220, 140, .28); } to { background: transparent; } }
.legend { margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--line); color: var(--dim); line-height: 1.7; }
.legend i { display: inline-block; width: 9px; height: 9px; margin-right: 5px; vertical-align: -1px; border: 1px solid; }
.legend .k1 { border-color: var(--red); background: rgba(226, 87, 74, .25); }
.legend .k2 { border-color: #e6c558; border-radius: 50%; border-style: dashed; }
.legend .k3 { border-color: var(--accent); border-style: dashed; }
.legend .k4 { border-color: var(--blue); transform: rotate(45deg) scale(.8); }

/* ---- "how does this work?" ---- */
#info {
  position: fixed; inset: 0; z-index: 10; display: flex;
  align-items: center; justify-content: center; background: rgba(4, 6, 4, .66);
}
#infoCard {
  width: min(620px, calc(100vw - 32px)); max-height: 84vh; overflow: auto;
  padding: 18px 22px; font-size: 13px; outline: none;
}
#infoCard h2 { margin: 0 0 8px; font-size: 15px; color: var(--gold); }
#infoCard ul { margin: 8px 0; padding-left: 18px; }
#infoCard li { margin-bottom: 7px; }
#infoCard b { color: var(--accent); font-weight: normal; }
#infoCard kbd { border: 1px solid var(--line-hi); padding: 0 5px; color: var(--gold); font: inherit; }
#infoCard .dim { color: var(--dim); margin: 10px 0 0; }

#chatBtn {
  position: fixed; right: 10px; bottom: 120px; display: none;
  padding: 10px 12px; font-size: 18px; cursor: pointer; color: var(--fg);
}
#log {
  position: fixed; right: 12px; bottom: 12px; width: min(340px, 48vw);
  font: 12px var(--mono); text-align: right;
  user-select: none; pointer-events: none; text-shadow: 0 1px 0 #000, 0 0 4px #000;
}
#log div { margin-top: 3px; }
#log .say { color: #f4ecc8; } #log .yell { color: #ff5f4a; } #log .whisper { color: #a9b2a4; } #log .system { color: #78dc8c; }
#bye {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(10, 14, 10, .88); color: var(--fg); text-align: center; cursor: pointer;
  font: 15px/1.6 var(--mono); padding: 2rem;
}

/* ---- the title card: the name of the place, as when you enter a zone ---- */
#title {
  position: fixed; left: 0; right: 0; top: 21%; text-align: center; pointer-events: none;
  font-family: var(--mono); color: var(--gold); opacity: 0;
  text-shadow: 0 3px 0 #000, 0 0 22px rgba(0, 0, 0, .9);
}
#title b { display: block; font-size: clamp(15px, 4.4vw, 46px); letter-spacing: .22em; margin-right: -.22em; }
#title span { display: block; margin-top: 10px; font-size: clamp(11px, 1.6vw, 14px); color: var(--fg); letter-spacing: .12em; }
#title span::before, #title span::after { content: " ◆ "; color: var(--accent); }
#title.show { animation: zone 4.2s ease forwards; }
@keyframes zone {
  0% { opacity: 0; transform: translateY(10px); } 14% { opacity: 1; transform: none; }
  74% { opacity: 1; } 100% { opacity: 0; transform: translateY(-6px); }
}

/* ---- the sprite sheet (preview.html) ---- */
body.sheet { overflow: auto; color: #cfd6c4; font: 12px var(--mono); }
body.sheet canvas { display: block; image-rendering: pixelated; }
#status { padding: 8px 12px; }
#status.ok { color: #9fd07a; } #status.bad { color: #e2725b; }

@media (pointer: coarse) {
  #qr, #hint { display: none; }        /* the QR is for the OTHER device */
  #chatBtn { display: block; }
  #hud { width: 196px; }
}
@media (max-width: 700px) {
  #side button { padding: 5px 7px; font-size: 11px; }
  #side .btns { flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - min(128px, 30vw) - 34px); }
  #side button.icon { min-width: 26px; }
  #log { bottom: 304px; left: 10px; right: auto; text-align: left; width: 70vw; }
  #guide { top: auto; bottom: 170px; left: 10px; right: 10px; max-width: none; width: auto; }
  #guide ol { flex-direction: column; gap: 3px; }
  /* on a phone the ops view is a strip along the bottom, numbers only: the ledger
     and the legend would cover the world it is supposed to explain */
  #ops { top: auto; bottom: 170px; left: 6px; right: 6px; width: auto; max-height: 30vh; font-size: 10px; padding: 7px 9px; }
  #ops .legend, #ops .budget-t { display: none; }
  #oLedger li:nth-child(n+4) { display: none; }
  body.ops #guide, body.ops #log { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #title.show { animation: none; }
  #opsBtn.on::before, #guide li.now::before { animation: none; }
}
