/* Modal windows, the backdrop, key hints and escape buttons.
 *
 * One of the stylesheets split out of the old style.css. index.html links them
 * in the order they had in that file, so the cascade is unchanged - keep
 * that order when adding a rule, or a later sheet may win where it used to lose. */

/* ---------- Human Factors & Ergonomics Additions ---------- */

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  font-family: inherit;
  /* Bold 11px Consolas renders "S" and "5" as the same blob on this chip's
     dark background - confirmed by cropping an actual combat screenshot,
     where Special (key S) and Guard (key 5) were unreadable apart. Bigger
     and lighter weight is a global fix: every kbd badge in the game reads
     better, not just this one collision, and no key binding changes. */
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  color: #f1dfba;
  background: #0f1214;
  border: 1px solid var(--gold-dark);
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.7);
  margin-right: 4px;
  text-shadow: none;
  vertical-align: middle;
  pointer-events: none;
}

#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 8, 0.75);
  backdrop-filter: blur(2px);
  z-index: 80;
  pointer-events: auto;
}

.game-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* Centred on the safe area rather than the screen: moved by half the
     difference between opposite insets. Separate from transform, so each
     window's own transform still applies; sizes use --safe-vw and --safe-dvh. */
  translate: calc((var(--edge-left) - var(--edge-right)) / 2) calc((var(--edge-top) - var(--edge-bottom)) / 2);
  z-index: 95;
  width: min(440px, calc(var(--safe-vw) * .92));
  max-height: calc(var(--safe-dvh) * .85);
  overflow-y: auto;
  background: rgba(17, 20, 24, 0.98);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 3px #08090a, 0 14px 45px rgba(0, 0, 0, 0.85);
  padding: 22px;
  pointer-events: auto;
}

.game-modal h2 {
  margin-top: 0;
  margin-bottom: 14px;
  color: var(--gold);
  border-bottom: 1px solid rgba(200, 153, 72, 0.3);
  padding-bottom: 8px;
}

/* The host stands beside the service window, outside its border. Both stay
 * within one modal for dismissal and pointer handling. */
.game-modal.npc-service-modal {
  display: grid;
  grid-template-columns: clamp(180px, 20vw, 240px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  width: min(1180px, calc(var(--safe-vw) * .96));
  max-height: calc(var(--safe-dvh) * .90);
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  overflow: visible;
}
.service-window {
  min-width: 0;
  max-height: calc(var(--safe-dvh) * .90);
  overflow-y: auto;
  padding: 16px 20px;
  background: rgba(17, 20, 24, 0.98);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 3px #08090a, 0 14px 45px rgba(0, 0, 0, 0.85);
}
.service-npc {
  position: relative;
  min-width: 0;
  max-height: calc(var(--safe-dvh) * .90);
  overflow: visible;
}
.service-npc-stage { position: relative; min-width: 0; padding-top: 112px; }
.service-npc-stage::before {
  content: "";
  position: absolute;
  bottom: 1%;
  left: 50%;
  width: 48%;
  height: 12px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.3) 45%, transparent 72%);
  pointer-events: none;
}
.service-npc-copy {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 220px;
  max-height: 104px;
  overflow-y: auto;
  min-width: 0;
  margin: 0;
  padding: 7px 9px;
  background: rgba(16, 20, 24, 0.96);
  border: 1px solid #665337;
}
.service-npc-copy::before {
  content: none;
}
.service-npc-figure {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  max-height: min(calc(var(--safe-dvh) * .9 - 112px), 420px);
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}
.service-npc-role {
  display: none;
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 1px;
}
.service-npc-copy h3 { margin: 0 0 4px; color: var(--gold); font-size: 14px; }
.service-npc-greeting { margin: 0; color: #e0d3bb; font-size: 11px; line-height: 1.45; }
.service-npc-story { margin-top: 4px; font-size: 10px; line-height: 1.5; color: var(--muted); }
.service-npc-story summary { width: fit-content; cursor: pointer; color: #cbb58c; padding: 4px 0; }
.service-npc-story summary:hover { color: var(--gold); }
.service-npc-story summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.service-npc-story p { margin: 6px 0 0; }
@media (max-width: 1000px) {
  .game-modal.npc-service-modal { gap: 14px; }
  .service-window { padding: 12px; }
}
@media (max-height: 500px) and (min-width: 601px) {
  .game-modal.npc-service-modal { gap: 12px; }
  .service-npc-greeting { font-size: 11px; }
}
@media (max-width: 600px) {
  .game-modal.npc-service-modal { display: block; overflow-y: auto; }
  .service-npc { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 12px; height: 160px; margin-bottom: 12px; overflow: visible; }
  .service-npc-stage { padding-top: 0; align-self: center; }
  .service-npc-figure { max-height: 160px; }
  .service-npc-copy { position: relative; max-width: none; max-height: 160px; margin: 0; align-self: center; }
  .service-npc-greeting { font-size: 11px; }
  .service-window { max-height: none; overflow: visible; }
}

/* Every window closes from its top-right corner. Three used to end on a
 * full-width Close bar instead, below everything else. */
.game-modal .modal-close {
  width: auto;
  min-width: 0 !important;
  min-height: 32px !important;
  margin: 0;
  padding: 4px 12px !important;
  font-size: 11px !important;
  white-space: nowrap;
}
.service-window { position: relative; }
.service-window > .modal-close {
  position: absolute;
  top: 14px;
  right: 18px;
  z-index: 2;
}

.btn-escape {
  outline-color: #8f4040 !important;
  color: #f2aaaa !important;
  background: linear-gradient(180deg, rgba(140, 50, 50, 0.2), transparent 42%), #281818 !important;
}

.btn-escape:hover:not(:disabled) {
  outline-color: #b54545 !important;
  color: #ffcccc !important;
}

.btn-secondary {
  opacity: 0.88;
}

/* --- Forge --------------------------------------------------------------- */
.forge-wallet { display:flex; justify-content:space-between; gap:10px; color:var(--muted); font-size:10px; margin-bottom:10px; }
.forge-modal {
  width: min(1200px, calc(var(--safe-vw) * .96));
  padding: 16px 20px;
}
.forge-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid rgba(200, 153, 72, 0.3);
  padding-bottom: 10px;
  margin-bottom: 10px;
}
.forge-title-block .eyebrow {
  margin: 0 0 2px 0;
  font-size: 9px;
  letter-spacing: 1px;
}
.forge-title-block h2 {
  margin: 0;
  border-bottom: none;
  padding-bottom: 0;
  font-size: 20px;
}
.forge-close-btn {
  padding: 6px 14px !important;
  font-size: 11px !important;
  white-space: nowrap !important;
  margin-top: 0 !important;
  width: auto !important;
  align-self: center;
}
.forge-list { column-width: 300px; column-gap: 7px; }
.forge-list > .forge-card { break-inside: avoid; margin-bottom: 7px; }
.forge-row-actions { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; }
.forge-row-actions label { color: var(--muted); font-size: 9px; }
.forge-wallet { flex-wrap: wrap; line-height: 1.5; margin-bottom: 8px; }
.forge-list .forge-card {
  display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 10px;
}
.forge-list .forge-weapon-card {
  min-width: 0; padding: 10px;
}
.forge-item-heading { display: grid; grid-template-columns: 48px 1fr; gap: 9px; align-items: center; }
.forge-item-heading > div { min-width: 0; }
.forge-item-heading img { width: 48px; height: 48px; object-fit: contain; image-rendering: pixelated; background: rgba(0, 0, 0, 0.25); }
.forge-item-heading strong, .forge-item-heading small { display: block; }
.forge-upgrade-path { margin: 0; color: #bbae92 !important; line-height: 1.5 !important; overflow-wrap: anywhere; }
.forge-weapon-card > button { width: 100%; min-height: 36px; }
.forge-list .forge-card > strong { font-size: 12px; }
.forge-list .forge-card > small { min-height: 30px; }
.forge-list .forge-card .forge-row-actions { width: 100%; margin-top: auto; }

/* --- Boss-room warning ------------------------------------------------------ */
.boss-warning-modal { width: min(460px, calc(var(--safe-vw) * .94)); text-align: center; border-color: #7a2f2a; }
.boss-warning-modal #boss-warning-text { line-height: 1.6; }
.boss-warning-modal #boss-warning-text strong { color: #f1c66f; }
.boss-warning-modal .boss-warning-counsel { margin: 8px 0 0; color: #d9c79c; font-size: 13px; }
.boss-warning-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }

@media (max-width: 620px) {
  .forge-list { grid-template-columns: 1fr; }
}

/* --- Bestiary: the creature is the picture, the text sits beside it ------- */
/* The bestiary: a list beside a page. It was styled inline, in a web
 * framework's slate blues and lime greens rather than this game's colours,
 * with a frame around the list, the page, the picture and each fact. */
.codex-intro { margin: 0 0 12px; }
.codex-list-container { min-height: 0; overflow-y: auto; padding-right: 6px; border-right: 1px solid var(--rule); }
.codex-monster-list { display: flex; flex-direction: column; gap: 2px; }
.codex-monster-entry {
  display: flex !important; align-items: center; justify-content: space-between;
  width: 100%; min-height: 40px !important; padding: 6px 8px !important;
  color: var(--parchment); text-align: left; text-transform: none !important;
  background: transparent !important; border: 1px solid transparent !important;
  outline: none !important; box-shadow: none !important; cursor: pointer;
}
.codex-monster-entry:hover { background: var(--row-hover) !important; }
.codex-monster-entry.is-selected { background: var(--row-hover) !important; border-color: var(--edge-strong) !important; }
.codex-entry-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.codex-entry-sprite { width: 24px; height: 24px; object-fit: contain; flex: none; }
.codex-monster-entry.is-unseen .codex-entry-sprite { filter: brightness(0) invert(0.2); }
.codex-entry-name { font-size: 12px; color: #f4e8c9; }
.codex-monster-entry.is-unseen .codex-entry-name { color: #6f675a; }
.codex-entry-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 10px; color: var(--muted); }
.codex-sprite-box { display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 60%, rgba(200, 153, 72, 0.07), transparent 70%); }
.codex-monster-img { width: 100%; height: 100%; object-fit: contain; display: none; }
.codex-silhouette { font-size: 6rem; color: #4a453c; }
.codex-details-header { display: flex; align-items: center; gap: 14px; }
.codex-monster-name { margin: 0 0 6px; color: #f6e6c4; font-size: 19px; }
.codex-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.codex-tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; font-size: 11px; color: #cdb07a; background: var(--row-hover); }
.codex-tag-armored { color: #e3b860; }
.codex-tag-ethereal { color: #c4a3e6; }
.codex-habitat { font-size: 12px; color: var(--muted); }
.codex-lore { margin: 0; font-size: 13px; line-height: 1.5; color: #e2d6bc; font-style: italic; }
.codex-tips { padding-top: 10px; border-top: 1px solid var(--rule); }
.codex-tips-title { margin-bottom: 4px; font-size: 12px; color: #cdb07a; }
.codex-tips-text { font-size: 13px; color: #f0e3c3; }
.codex-stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 10px; border-top: 1px solid var(--rule); font-size: 12px; }
.codex-stat-label { display: block; margin-bottom: 2px; font-size: 11px; color: var(--muted); }
.codex-stat strong { color: #f6e6c4; }
.codex-stat .codex-trophy { color: #b9cf8e; }
.codex-details { display: grid; grid-template-columns: minmax(160px, 40%) minmax(0, 1fr); gap: 18px; align-items: stretch; }
.codex-layout { display: grid; grid-template-columns: minmax(150px, 24%) minmax(0, 1fr); gap: 16px; height: 420px; }
.codex-details { min-height: 0; overflow: hidden; }
#codex-sprite-box { min-height: 0; min-width: 0; padding: 8px; overflow: hidden; }
.codex-details-body { min-height: 0; overflow-y: auto; }
.codex-details-body { min-width: 0; display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.codex-stars { display: flex; align-items: center; gap: 3px; color: #5d6470; letter-spacing: 0; }
.codex-stars .codex-star-icon { width: 13px; height: 13px; color: #5d6470; opacity: 0.6; }
.codex-stars .earned { color: #f1c66f; opacity: 1; filter: drop-shadow(0 0 4px rgba(241, 198, 111, 0.35)); }
.codex-next-star { margin: -4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.35; }
.codex-monster-entry .codex-entry-stars { display: inline-flex; align-items: center; gap: 3px; color: #f1c66f; font-size: 10px; letter-spacing: 0; }
.codex-monster-entry .codex-entry-stars .px-icon { width: 10px; height: 10px; }
@media (max-width: 1000px) {
  .codex-details { grid-template-columns: 1fr; }
  .codex-layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .codex-list-container { max-height: 150px; }
  #codex-sprite-box { height: 200px; }
}

.camp-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.camp-header h2 { margin: 0; padding: 0; border: 0; }
.camp-header .eyebrow { margin: 0 0 4px; }
.camp-close-btn { white-space: nowrap; padding: 6px 14px; font-size: 11px; }
.camp-squad { display: grid; gap: 8px; margin: 18px 0; }
.camp-hero { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 10px 12px; background: var(--row); font-size: 12px; }
.camp-hero strong { color: #f4e8c9; }
.camp-hero span { color: #a89f8a; }
.camp-rest-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; border-top: 1px solid var(--rule); padding-top: 12px; }
.camp-rest-row .hint { margin: 0; }
.camp-rest-row button { min-height: 40px; }
.party-rest-note { margin: 0 0 12px; }
.party-rest-note[hidden], #camp-wake-row[hidden] { display: none; }
#camp-wake-row { margin-top: 12px; }
