/* ==========================================================================
   RUG PATROL — game.css
   Everything layered on top of the game canvas: HUD, dialogue, the
   character creator, the mobile pad, and the end-of-round card.
   All overlays live inside .game-stage (position: relative).
   ========================================================================== */

.game-stage { --pad: clamp(8px, 1.4vw, 16px); }

/* overlays sit above the canvas but must not eat pointer events unless
   they are actually interactive */
.g-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: var(--f-pixel);
  color: var(--txt);
}
/* `place-items: center` overflows in BOTH directions once the card is taller
   than the stage, pushing its top above the scroll origin where it can never
   be reached. `safe center` centres while it fits and falls back to top
   alignment the moment it does not. */
.g-layer--modal {
  pointer-events: auto;
  background: rgba(5, 8, 12, 0.88);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center;
  padding: var(--pad);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.g-layer--modal > * { flex: 0 0 auto; }
.g-layer[hidden] { display: none !important; }

/* ============================ HUD ============================ */

.hud {
  position: absolute;
  inset: var(--pad) var(--pad) auto var(--pad);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  font-size: clamp(8px, 1.05vw, 11px);
  letter-spacing: 0.05em;
  text-shadow: 0 1px 0 #000, 0 0 6px rgba(0,0,0,0.9);
}

.hud__box {
  background: rgba(7, 11, 16, 0.74);
  border: 1px solid rgba(120, 150, 180, 0.22);
  border-radius: 3px;
  padding: 7px 10px;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.hud__row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.hud__row b { font-weight: 400; color: var(--green); }
.hud__k { color: var(--txt-faint); }

/* evidence pips */
.pips { display: flex; gap: 3px; }
.pip {
  width: 9px; height: 9px;
  border: 1px solid var(--txt-faint);
  border-radius: 1px;
  background: transparent;
}
.pip.is-on { background: var(--amber); border-color: var(--amber); box-shadow: 0 0 5px rgba(255,180,84,0.7); }

/* liquidity meter */
.meter {
  width: clamp(70px, 13vw, 120px);
  height: 7px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(120,150,180,0.3);
  border-radius: 2px;
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  width: 100%;
  background: var(--green);
  transition: width 0.3s linear, background 0.3s linear;
}
.meter__fill.is-low { background: var(--amber); }
.meter__fill.is-crit { background: var(--red); animation: pulse 0.7s infinite; }

/* right-side objective ticker */
.hud__obj {
  text-align: right;
  max-width: 46%;
}
.hud__obj .hud__k { display: block; margin-bottom: 5px; }
.hud__obj span { color: var(--txt); line-height: 1.5; display: block; }

/* The objective box and the map stack, but only the text sits on an opaque
   panel — wrapping both in one box put a large dark rectangle over the view. */
.hud__side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: 46%;
}
.hud__side .hud__obj { max-width: none; }

/* minimap — one pixel per tile, so the whole town and its edges fit */
.hud__map {
  display: block;
  width: clamp(62px, 12vw, 116px);
  height: auto;
  image-rendering: pixelated;
  border: 1px solid rgba(120, 150, 180, 0.32);
  border-radius: 2px;
  background: rgba(7, 11, 16, 0.55);
}

/* ============================ interaction prompt ============================ */

.g-prompt {
  position: absolute;
  left: 50%;
  bottom: calc(var(--pad) + 6px);
  transform: translateX(-50%);
  background: rgba(7, 11, 16, 0.85);
  border: 1px solid rgba(120,150,180,0.28);
  border-radius: 3px;
  padding: 7px 13px;
  font-size: clamp(8px, 1vw, 11px);
  letter-spacing: 0.06em;
  white-space: nowrap;
  animation: bob 1.6s var(--ease) infinite;
}
.g-prompt b { color: var(--amber); }

@keyframes bob {
  0%, 100% { transform: translate(-50%, 0); }
  50%      { transform: translate(-50%, -3px); }
}

/* ============================ dialogue ============================ */

.dlg {
  position: absolute;
  inset: auto var(--pad) var(--pad) var(--pad);
  pointer-events: auto;
  background: rgba(7, 11, 16, 0.94);
  border: 1px solid rgba(120,150,180, 0.3);
  border-radius: 4px;
  padding: clamp(12px, 1.8vw, 18px);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: clamp(10px, 1.6vw, 18px);
  max-height: 62%;
}

.dlg__face {
  width: clamp(40px, 6vw, 64px);
  height: clamp(40px, 6vw, 64px);
  image-rendering: pixelated;
  border: 1px solid rgba(120,150,180,0.25);
  border-radius: 3px;
  background: var(--bg-2);
  flex: none;
}

.dlg__body { min-width: 0; display: flex; flex-direction: column; }

.dlg__name {
  font-size: clamp(9px, 1.15vw, 12px);
  letter-spacing: 0.09em;
  color: var(--green);
  margin-bottom: 8px;
}
.dlg[data-side="law"]   .dlg__name { color: var(--ice); }
.dlg[data-side="chaos"] .dlg__name { color: var(--red); }
.dlg[data-side="sys"]   .dlg__name { color: var(--amber); }

.dlg__text {
  font-family: var(--f-mono);
  font-size: clamp(11px, 1.35vw, 14px);
  line-height: 1.6;
  color: var(--txt);
  overflow-y: auto;
  flex: 1;
  min-height: 2.4em;
}
.dlg__caret {
  display: inline-block;
  width: 0.5em;
  color: var(--amber);
  animation: pulse 0.9s steps(2) infinite;
}

.dlg__choices {
  display: grid;
  gap: 5px;
  margin-top: 11px;
}
.dlg__choice {
  text-align: left;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 8px 11px;
  font-family: var(--f-mono);
  font-size: clamp(10px, 1.2vw, 13px);
  color: var(--txt-dim);
  cursor: pointer;
  transition: all 0.14s var(--ease);
}
.dlg__choice:hover,
.dlg__choice.is-sel {
  border-color: var(--green);
  color: var(--txt);
  background: rgba(0, 224, 90, 0.08);
}
.dlg__choice::before { content: "> "; color: var(--green); }

.dlg__hint {
  margin-top: 9px;
  font-size: clamp(7px, 0.95vw, 10px);
  color: var(--txt-faint);
  letter-spacing: 0.07em;
}

/* ============================ modals (creator / start / end) ============================ */

.g-card {
  width: min(560px, 100%);
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: clamp(18px, 3vw, 30px);
  pointer-events: auto;
}

.g-card__eyebrow {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--txt-faint);
  text-transform: uppercase;
  margin-bottom: 12px;
}
.g-card h3 {
  font-family: var(--f-head);
  font-size: clamp(20px, 3vw, 30px);
  text-transform: uppercase;
  margin-bottom: 10px;
}
.g-card p {
  font-family: var(--f-mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--txt-dim);
}

/* --- character creator --- */

.cc {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 22px;
  margin: 22px 0 4px;
  align-items: start;
}
/* Narrow stage: stack, shrink the preview, and tighten every gap so the whole
   creator still fits without a long scroll inside a small canvas frame. */
@media (max-width: 620px) {
  .cc { grid-template-columns: 88px 1fr; gap: 14px; margin: 16px 0 0; }
  .cc__preview { width: 88px; height: 88px; }
  .cc__fields { gap: 11px; }
  .g-card { padding: 16px; }
  .g-card h3 { font-size: 19px; }
  .g-card p { font-size: 12px; line-height: 1.5; }
  .g-card__actions { margin-top: 16px; padding-top: 14px; }
  .sw { width: 22px; height: 22px; }
  .chip { padding: 6px 9px; font-size: 8px; }
  .g-stats div { padding: 9px 12px; font-size: 12px; }
}

.cc__preview {
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
  background: linear-gradient(180deg, #16222f, #0a1119);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.cc__fields { display: grid; gap: 15px; width: 100%; }

.cc__field > label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--txt-faint);
  margin-bottom: 7px;
}

.cc__name {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px 12px;
  font-family: var(--f-mono);
  font-size: 14px;
  color: var(--txt);
}
.cc__name:focus { outline: none; border-color: var(--green); }
.cc__name::placeholder { color: var(--txt-faint); }

.sw-row { display: flex; flex-wrap: wrap; gap: 7px; }
.sw {
  width: 26px; height: 26px;
  border: 2px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.5);
  transition: transform 0.12s var(--ease);
}
.sw:hover { transform: scale(1.12); }
.sw.is-sel { border-color: var(--txt); }
.sw:focus-visible { outline: 2px solid var(--ice); outline-offset: 2px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--txt-dim);
  cursor: pointer;
  transition: all 0.14s var(--ease);
}
.chip:hover { border-color: var(--txt-faint); color: var(--txt); }
.chip.is-sel { border-color: var(--green); color: var(--green); background: rgba(0,224,90,0.08); }

.g-card__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
}

/* --- end-of-round stat list --- */

.g-stats {
  display: grid;
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  overflow: hidden;
  margin: 20px 0 4px;
}
.g-stats div {
  background: var(--bg);
  padding: 11px 15px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-family: var(--f-mono);
  font-size: 13px;
}
.g-stats dt { color: var(--txt-dim); margin: 0; }
.g-stats dd { margin: 0; color: var(--txt); }
.g-stats dd.win { color: var(--green); }
.g-stats dd.lose { color: var(--red); }

/* ============================ mobile pad ============================ */

.pad {
  position: absolute;
  inset: auto var(--pad) var(--pad) var(--pad);
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
.game-stage.is-touch .pad { display: flex; }
/* dialogue open? the pad would sit under it, so hide the dpad half */
.game-stage.is-dlg-open .pad__dpad { opacity: 0.25; }

.pad__dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  pointer-events: auto;
  transition: opacity 0.2s var(--ease);
}
.pad__btn {
  background: rgba(7,11,16,0.6);
  border: 1px solid rgba(120,150,180,0.3);
  border-radius: 4px;
  color: var(--txt);
  font-size: 15px;
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.pad__btn:active { background: rgba(0,224,90,0.25); }
.pad__btn--up    { grid-area: 1 / 2; }
.pad__btn--left  { grid-area: 2 / 1; }
.pad__btn--right { grid-area: 2 / 3; }
.pad__btn--down  { grid-area: 3 / 2; }

.pad__acts { display: grid; gap: 8px; pointer-events: auto; }
.pad__a {
  width: 62px; height: 62px;
  border-radius: 50%;
  background: rgba(0,224,90,0.16);
  border: 1px solid var(--green-dim);
  color: var(--green);
  font-family: var(--f-pixel);
  font-size: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.pad__a--esc {
  width: 46px; height: 46px;
  justify-self: end;
  background: rgba(255,77,94,0.14);
  border-color: var(--red-dim);
  color: var(--red);
  font-size: 9px;
}
.pad__a:active { filter: brightness(1.5); }

/* ============================ paused / focus veil ============================ */

.g-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5,8,12,0.55);
  pointer-events: auto;
  cursor: pointer;
  text-align: center;
  padding: 20px;
}
.g-veil span {
  font-size: clamp(9px, 1.3vw, 12px);
  letter-spacing: 0.1em;
  border: 1px solid rgba(120,150,180,0.3);
  background: rgba(7,11,16,0.8);
  padding: 12px 20px;
  border-radius: 4px;
}
.g-veil[hidden] { display: none !important; }

/* ============================ toast inside game ============================ */

.g-toasts {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  display: grid;
  gap: 6px;
  justify-items: center;
  pointer-events: none;
  width: 90%;
}
.g-toast {
  background: rgba(7,11,16,0.9);
  border: 1px solid var(--green-dim);
  border-radius: 3px;
  padding: 8px 14px;
  font-size: clamp(8px, 1.05vw, 11px);
  letter-spacing: 0.06em;
  color: var(--green);
  text-align: center;
  animation: gtoast 2.6s var(--ease) forwards;
}
.g-toast--bad { border-color: var(--red-dim); color: var(--red); }
.g-toast--warn { border-color: var(--amber-dim); color: var(--amber); }

@keyframes gtoast {
  0%   { opacity: 0; transform: translateY(6px); }
  12%  { opacity: 1; transform: none; }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}

/* ============================ shared panel ============================ */

.g-panel { width: min(600px, 100%); }
.g-panel .btn b { color: inherit; opacity: 0.7; font-weight: 400; margin-right: 2px; }

/* ---- contract inspector ---- */

.ins h3 { font-family: var(--f-pixel); letter-spacing: 0.04em; }

.ins__status {
  margin: 10px 0 14px;
  padding: 8px 12px;
  border-radius: 3px;
  border: 1px solid rgba(0, 224, 90, 0.28);
  background: rgba(0, 224, 90, 0.06);
  color: #9FE8C0;
  font-family: var(--f-mono);
  font-size: 12px;
}
.ins__status--bad {
  border-color: rgba(255, 77, 94, 0.4);
  background: rgba(255, 77, 94, 0.08);
  color: var(--red);
}

.ins__rows {
  margin: 0 0 12px;
  display: grid;
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  overflow: hidden;
}
.ins__rows > div {
  background: var(--bg);
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 124px 1fr;
  gap: 12px;
  align-items: center;
}
.ins__rows dt {
  margin: 0;
  font-family: var(--f-pixel);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--txt-faint);
}
.ins__rows dd {
  margin: 0;
  font-size: clamp(11px, 1.35vw, 14px);
  color: var(--txt);
  word-break: break-all;
  letter-spacing: 0.02em;
}
@media (max-width: 620px) {
  .ins__rows > div { grid-template-columns: 1fr; gap: 3px; }
}

.ins__expand {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 3px;
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--txt-dim);
  cursor: pointer;
}
.ins__expand:hover { border-color: var(--ice); color: var(--txt); }
.ins__expand b { color: var(--amber); font-weight: 500; }

.ins__hint {
  margin-top: 10px !important;
  font-size: 12px !important;
  color: var(--txt-faint) !important;
}
