/* ============================================================
   Title-screen transparent-window phase
   Hide all game chrome so only the floating title image is seen.
   With transparent: true in Electron the desktop shows through.
   Both html AND body must be transparent — html paints first and
   would otherwise leave the blue --bg box visible underneath.
   ============================================================ */
html.title-screen-active,
body.title-screen-active {
  background: transparent !important;
}

body.title-screen-active .app-container {
  display: none !important;
}

body.title-screen-active #retro-window-chrome,
body.title-screen-active .resize-handle {
  display: none !important;
}

body.main-menu-active .app-container {
  display: none;
}

.main-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  background: linear-gradient(180deg, #071d49 0%, #050916 58%, #020309 100%);
}

.main-menu-backdrop::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--main-menu-art);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  filter: saturate(1.12) contrast(1.08);
  image-rendering: auto;
  opacity: 0.92;
}

.main-menu-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 100%
      4px,
    radial-gradient(
      circle at 50% 47%,
      rgba(0, 0, 0, 0.08) 0,
      rgba(0, 0, 0, 0.7) 100%
    ),
    linear-gradient(180deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.34));
  pointer-events: none;
}

/* ============================================================
   Title Screen Overlay
   ============================================================ */
.title-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  pointer-events: auto;
  transition: opacity 0.6s ease;
}

.title-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.title-image-frame {
  position: relative;
  width: min(90vw, 82vh);
  aspect-ratio: 1;
}

.title-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: pixelated;
  transition: opacity 0.2s ease;
}

.press-any-key {
  position: absolute;
  left: 50%;
  bottom: 27%;
  transform: translateX(-50%);
  font-family: "Chicago_12", sans-serif;
  font-size: clamp(14px, 2.1vw, 22px);
  line-height: 1;
  white-space: nowrap;
  color: #e0e0e0;
  letter-spacing: 1px;
  text-shadow:
    0 0 8px rgba(0, 200, 255, 0.8),
    2px 2px 0 #000;
  animation: pak-pulse 1.4s ease-in-out infinite;
}

@keyframes pak-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.1;
  }
}

/* ============================================================
   New Game Intro Story
   ============================================================ */
.intro-story-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  padding: 0;
  background: #050505;
  box-sizing: border-box;
}

.intro-story-window {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #050505;
  color: #eeeeee;
  font-family: "Chicago_12", sans-serif;
}

.intro-story-heading {
  margin: 0;
  padding: 18px 22px 0;
  color: #f0f0f0;
  font-size: 18px;
  font-weight: normal;
  line-height: 1;
  text-align: center;
  text-shadow: 2px 2px 0 #000000;
}

.intro-story-body {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 18px 22px 22px;
  background: #050505;
  overflow: hidden;
}

.intro-story-figure {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
  gap: 18px;
  margin: 0;
}

.intro-story-image {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  display: block;
  background: #050505;
  image-rendering: auto;
}

.intro-story-text {
  min-height: 0;
  overflow-y: auto;
  align-self: stretch;
  padding: 18px 20px;
  background: rgba(5, 5, 5, 0.74);
  color: #eeeeee;
  font-size: 16px;
  line-height: 1.62;
  text-shadow: 1px 1px 0 #000000;
}

.intro-story-text p {
  margin: 0 0 10px;
}

.intro-story-text p:last-child {
  margin-bottom: 0;
}

.intro-story-text p:first-child {
  color: #66b7ff;
}

.intro-story-footer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

.intro-story-counter {
  color: #b8b8b8;
  font-size: 13px;
  text-align: center;
}

.intro-story-actions {
  display: flex;
  gap: 8px;
}

.intro-story-prev:disabled,
.intro-story-prev:disabled:hover {
  background: var(--modal-bg-soft);
  color: var(--modal-muted);
  cursor: default;
  opacity: 0.58;
}

@media (max-width: 640px) {
  .intro-story-body {
    padding: 12px;
  }

  .intro-story-heading {
    padding: 12px 12px 0;
    font-size: 16px;
  }

  .intro-story-figure {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(170px, 0.75fr);
    gap: 12px;
  }

  .intro-story-image {
    min-height: 0;
  }

  .intro-story-text {
    padding: 12px;
    font-size: 15px;
  }

  .intro-story-footer {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .intro-story-counter {
    order: -1;
  }

  .intro-story-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

/* ============================================================
   Retro Mac OS 7 Window Chrome
   ============================================================ */
#retro-window-chrome,
.resize-handle {
  display: none;
}

body.game-window-active #retro-window-chrome,
body.game-window-active .resize-handle {
  display: block;
}

.retro-window-chrome {
  position: fixed;
  inset: 0;
  z-index: 9997;
  pointer-events: none;
}

.retro-window-chrome::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--chrome-border);
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset 4px 4px 0 var(--chrome-mid),
    inset -2px -2px 0 var(--chrome-lowlight),
    inset -4px -4px 0 var(--chrome-mid),
    2px 2px 0 var(--chrome-shadow);
}

.retro-titlebar {
  position: absolute;
  top: 6px;
  left: 10px;
  right: 10px;
  height: 42px;
  display: grid;
  grid-template-columns: auto minmax(32px, 1fr) auto minmax(32px, 1fr);
  align-items: center;
  gap: 9px;
  padding: 0 7px;
  background: var(--chrome-title-bg);
  border: 2px solid var(--chrome-border);
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight);
  pointer-events: auto;
  -webkit-app-region: no-drag;
}

.retro-traffic-lights {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
  -webkit-app-region: no-drag;
}

.retro-window-button {
  position: relative;
  width: 27px;
  height: 27px;
  padding: 0;
  border: 0;
  background: var(--chrome-bg);
  color: transparent;
  cursor: pointer;
  image-rendering: pixelated;
  box-shadow:
    0 0 0 2px var(--chrome-border),
    inset 2px 2px 0 rgba(255, 255, 255, 0.35),
    inset -2px -2px 0 rgba(0, 0, 0, 0.65);
  -webkit-app-region: no-drag;
}

.retro-window-button *,
.retro-window-button::before {
  pointer-events: none;
  -webkit-app-region: no-drag;
}

.retro-window-button::before {
  content: "";
  position: absolute;
  inset: 5px;
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.28),
    inset -2px -2px 0 rgba(0, 0, 0, 0.48);
}

.retro-window-button span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #100f0f;
  font-family: "Chicago_12", sans-serif;
  font-size: 15px;
  line-height: 1;
}

.retro-window-button-close::before {
  background: #f04f3c;
}

.retro-window-button-minimize::before {
  background: #f4b53d;
}

.retro-window-button-fullscreen::before {
  background: #4abf3c;
}

.retro-window-button:active {
  box-shadow:
    0 0 0 2px var(--chrome-border),
    inset 2px 2px 0 rgba(0, 0, 0, 0.65),
    inset -2px -2px 0 rgba(255, 255, 255, 0.25);
}

.retro-window-button:hover {
  filter: brightness(1.18) saturate(1.12);
}

.retro-window-button:focus-visible {
  outline: 2px solid var(--modal-accent);
  outline-offset: 4px;
}

.retro-window-button:hover span {
  color: #050505;
}

.retro-window-button:active::before {
  transform: translate(1px, 1px);
  box-shadow:
    inset 2px 2px 0 rgba(0, 0, 0, 0.48),
    inset -2px -2px 0 rgba(255, 255, 255, 0.2);
}

.retro-window-button:active span {
  transform: translate(1px, 1px);
}

.retro-title-stripes {
  height: 28px;
  -webkit-app-region: drag;
  background: repeating-linear-gradient(
    to bottom,
    var(--chrome-stripe-light) 0,
    var(--chrome-stripe-light) 2px,
    var(--chrome-stripe-dark) 2px,
    var(--chrome-stripe-dark) 5px
  );
  box-shadow:
    inset 0 2px 0 var(--chrome-border),
    inset 0 -2px 0 var(--chrome-border);
}

.retro-window-title {
  padding: 0 10px;
  background: var(--chrome-title-bg);
  color: var(--chrome-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 18px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  text-shadow: 1px 1px 0 var(--chrome-shadow);
  cursor: default;
  -webkit-app-region: no-drag;
}

.retro-content-frame {
  position: absolute;
  top: 56px;
  left: 10px;
  right: 10px;
  bottom: 10px;
  border: 3px solid var(--chrome-border);
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset 4px 4px 0 var(--chrome-bright),
    inset -2px -2px 0 var(--chrome-lowlight),
    0 2px 0 var(--chrome-shadow);
}

.resize-handle {
  position: fixed;
  z-index: 9998;
  background: transparent;
  -webkit-app-region: no-drag;
}

.resize-handle[data-edge="top"] {
  top: 0;
  left: 16px;
  right: 16px;
  height: 14px;
  cursor: n-resize;
}

.resize-handle[data-edge="bottom"] {
  bottom: 0;
  left: 16px;
  right: 16px;
  height: 18px;
  cursor: s-resize;
}

.resize-handle[data-edge="left"] {
  left: 0;
  top: 16px;
  bottom: 16px;
  width: 18px;
  cursor: w-resize;
}

.resize-handle[data-edge="right"] {
  right: 0;
  top: 16px;
  bottom: 16px;
  width: 18px;
  cursor: e-resize;
}

.resize-handle[data-edge="top-left"],
.resize-handle[data-edge="top-right"],
.resize-handle[data-edge="bottom-left"],
.resize-handle[data-edge="bottom-right"] {
  width: 28px;
  height: 28px;
}

.resize-handle[data-edge="top-left"] {
  top: 0;
  left: 0;
  cursor: nw-resize;
}

.resize-handle[data-edge="top-right"] {
  top: 0;
  right: 0;
  cursor: ne-resize;
}

.resize-handle[data-edge="bottom-left"] {
  bottom: 0;
  left: 0;
  cursor: sw-resize;
}

.resize-handle[data-edge="bottom-right"] {
  bottom: 0;
  right: 0;
  cursor: se-resize;
}

body.is-fullscreen #retro-window-chrome,
body.is-fullscreen .resize-handle {
  display: none;
}

body.is-fullscreen .app-container {
  padding: 0;
}

/* ============================================================
   Reusable Retro Modals
   ============================================================ */
.imb-modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: var(--modal-scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  pointer-events: auto;
}

.imb-modal-scrim.hidden {
  display: none;
}

body.imb-modal-open .app-container {
  filter: blur(3px);
}

body.main-menu-active.imb-modal-open .app-container {
  filter: none;
}

body.main-menu-active .imb-modal-scrim {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
}

body.imb-modal-open #retro-window-chrome {
  z-index: 10000;
  filter: none;
}

.imb-dialog {
  position: fixed;
  z-index: 10001;
  width: min(450px, calc(100vw - 32px));
  min-width: 320px;
  background: var(--modal-bg);
  border: 2px solid var(--modal-border);
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight),
    4px 4px 0 var(--chrome-shadow);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
}

.imb-dialog.hidden {
  display: none;
}

.imb-dialog.dragging {
  cursor: move;
}

.imb-dialog-titlebar {
  display: grid;
  grid-template-columns: auto minmax(28px, 1fr) auto minmax(28px, 1fr);
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 3px 7px;
  background: var(--chrome-title-bg);
  border-bottom: 2px solid var(--modal-border);
  cursor: move;
}

.imb-dialog-stripes {
  height: 18px;
  background: repeating-linear-gradient(
    to bottom,
    var(--chrome-stripe-light) 0,
    var(--chrome-stripe-light) 2px,
    var(--chrome-stripe-dark) 2px,
    var(--chrome-stripe-dark) 5px
  );
  box-shadow:
    inset 0 2px 0 var(--chrome-border),
    inset 0 -2px 0 var(--chrome-border);
}

.imb-dialog-title {
  padding: 0 8px;
  background: var(--chrome-title-bg);
  color: var(--chrome-text);
  font-size: 14px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  text-shadow: 1px 1px 0 var(--chrome-shadow);
}

.imb-dialog-close {
  width: 21px;
  height: 21px;
  justify-self: start;
}

.imb-dialog-close span {
  font-size: 13px;
}

.imb-dialog-body {
  max-height: min(68vh, 520px);
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 38%),
    var(--modal-bg);
}

.imb-settings-stack {
  display: grid;
  gap: 14px;
}

.imb-slider-row,
.imb-theme-row {
  display: grid;
  grid-template-columns: 116px minmax(120px, 1fr) 40px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.imb-theme-row {
  grid-template-columns: 116px 1fr;
}

.imb-slider-row label,
.imb-theme-label {
  color: var(--modal-accent);
}

.imb-slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  background: var(--modal-bg-soft);
  border: 2px solid var(--modal-border);
  outline: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  border-radius: 0;
  box-shadow:
    inset 1px 1px 0 var(--chrome-lowlight),
    inset -1px -1px 0 var(--chrome-highlight);
}

.imb-slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 18px;
  background: var(--scroll-thumb);
  border: 2px solid var(--modal-border);
  cursor: pointer;
  box-shadow:
    inset 2px 2px 0 var(--chrome-bright),
    inset -2px -2px 0 var(--chrome-lowlight),
    1px 1px 0 var(--chrome-shadow);
}

.imb-slider-val {
  width: 40px;
  text-align: right;
  color: var(--modal-text);
  font-size: 12px;
}

.imb-theme-toggle {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  border: 2px solid var(--modal-border);
  box-shadow:
    inset 1px 1px 0 var(--chrome-lowlight),
    inset -1px -1px 0 var(--chrome-highlight);
}

.imb-theme-option {
  min-height: 25px;
  border: 0;
  border-right: 2px solid var(--modal-border);
  background: var(--modal-bg-soft);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 13px;
  cursor: pointer;
}

.imb-theme-option:last-child {
  border-right: 0;
}

.imb-theme-option.selected {
  background: var(--modal-text);
  color: var(--modal-bg);
}

.imb-about-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.imb-about-icon {
  width: 112px;
  height: 112px;
  flex: 0 0 112px;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(2px 2px 0 var(--chrome-shadow));
}

.imb-about-text {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  line-height: 1.5;
}

.imb-about-title {
  font-size: 20px;
  font-family: "Chicago_12", sans-serif;
  color: var(--modal-accent);
  margin-bottom: 2px;
}

.imb-about-version,
.imb-about-small {
  color: var(--modal-muted);
  font-size: 11px;
}

.imb-about-version {
  margin-bottom: 8px;
}

.imb-about-sep {
  height: 1px;
  background: var(--modal-line);
  margin: 8px 0;
}

.imb-about-credit {
  color: var(--modal-text);
}

.imb-about-small {
  margin-top: 4px;
}

.imb-dialog-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.imb-btn {
  min-width: 72px;
  min-height: 26px;
  padding: 3px 16px;
  background: var(--modal-bg-soft);
  border: 2px solid var(--modal-border);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 13px;
  cursor: pointer;
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight),
    2px 2px 0 var(--chrome-shadow);
}

.imb-btn:hover {
  background: var(--modal-text);
  color: var(--modal-bg);
}

.imb-btn:focus-visible,
.imb-pause-option:focus-visible,
.imb-theme-option:focus-visible,
.imb-keybinding-button:focus-visible,
.imb-text-input:focus-visible,
.imb-slider-row input[type="range"]:focus-visible {
  outline: 2px solid var(--modal-accent);
  outline-offset: 3px;
}

.imb-btn:active {
  transform: translate(1px, 1px);
  box-shadow:
    inset 2px 2px 0 var(--chrome-lowlight),
    inset -2px -2px 0 var(--chrome-highlight);
}

.imb-pause-dialog {
  width: min(430px, calc(100vw - 32px));
}

.imb-pause-dialog .imb-dialog-body {
  padding: 20px 24px 24px;
}

.imb-main-menu-dialog {
  inset: 0 auto auto 0 !important;
  width: 100vw;
  height: 100vh;
  min-width: 0;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  z-index: 10001 !important;
}

.imb-main-menu-dialog .imb-dialog-titlebar {
  display: none;
}

.imb-main-menu-dialog .imb-dialog-body {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: visible;
  background: transparent;
}

.imb-main-menu-dialog .imb-pause-menu {
  min-height: min(560px, calc(100vh - 32px));
  align-content: center;
}

.imb-main-menu-dialog .imb-pause-view {
  padding: 24px;
  background: rgba(17, 18, 20, 0.84);
  border: 2px solid var(--modal-border);
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight),
    4px 4px 0 var(--chrome-shadow);
}

.imb-main-menu-dialog .imb-pause-options,
.imb-main-menu-dialog .imb-mp-options {
  width: min(320px, 100%);
  justify-self: center;
}

.imb-main-menu-dialog .imb-pause-option {
  text-align: center;
}

.imb-main-menu-dialog .imb-pause-option::before {
  width: 0;
  margin-right: 0;
}

.imb-main-menu-dialog .imb-pause-option.selected::before {
  content: "";
}

.imb-pause-menu {
  display: grid;
  gap: 16px;
  justify-items: stretch;
}

.imb-pause-view {
  display: grid;
  gap: 16px;
}

.imb-pause-view.hidden,
.imb-dev-tools-panel.hidden,
.imb-keybinding-row.hidden {
  display: none;
}

.imb-pause-logo {
  width: min(300px, 80%);
  justify-self: center;
  image-rendering: auto;
  filter: drop-shadow(2px 2px 0 var(--chrome-shadow));
}

.imb-pause-message {
  min-height: 30px;
  padding: 6px 10px;
  border: 2px solid var(--modal-border);
  background: var(--modal-bg-soft);
  color: var(--modal-accent);
  font-size: 13px;
  line-height: 1.25;
  text-align: center;
  box-shadow:
    inset 1px 1px 0 var(--chrome-lowlight),
    inset -1px -1px 0 var(--chrome-highlight);
}

.imb-pause-message.hidden {
  display: none;
}

.imb-pause-options {
  display: grid;
  gap: 8px;
}

.imb-pause-option {
  min-height: 34px;
  padding: 6px 14px;
  border: 2px solid var(--modal-border);
  background: var(--modal-bg-soft);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 15px;
  line-height: 1;
  text-align: left;
  cursor: pointer;
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight),
    2px 2px 0 var(--chrome-shadow);
}

.imb-pause-option::before {
  content: "";
  display: inline-block;
  width: 18px;
}

.imb-pause-option:hover,
.imb-pause-option.selected {
  background: var(--modal-text);
  color: var(--modal-bg);
}

.imb-pause-option:disabled,
.imb-pause-option.disabled,
.imb-pause-option:disabled:hover,
.imb-pause-option.disabled:hover,
.imb-pause-option:disabled.selected,
.imb-pause-option.disabled.selected {
  background: var(--modal-bg-soft);
  color: var(--modal-muted);
  cursor: default;
  opacity: 0.58;
}

.imb-pause-option.selected::before {
  content: ">";
}

.imb-pause-option:disabled.selected::before,
.imb-pause-option.disabled.selected::before {
  content: "";
}

.imb-pause-option:active {
  transform: translate(1px, 1px);
  box-shadow:
    inset 2px 2px 0 var(--chrome-lowlight),
    inset -2px -2px 0 var(--chrome-highlight);
}

.imb-settings-header {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
}

.imb-settings-header h3 {
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 18px;
  line-height: 1;
  text-align: center;
}

.imb-back-btn {
  min-width: 58px;
}

.imb-checkbox-row {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--modal-accent);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.imb-checkbox-input {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.imb-checkbox-box {
  position: relative;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  background: var(--modal-bg);
  border: 2px solid var(--modal-border);
  box-sizing: border-box;
  box-shadow:
    inset 2px 2px 0 var(--chrome-lowlight),
    inset -2px -2px 0 var(--chrome-highlight);
}

.imb-checkbox-input:checked + .imb-checkbox-box::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 7px;
  height: 12px;
  border-right: 3px solid var(--modal-text);
  border-bottom: 3px solid var(--modal-text);
  transform: rotate(45deg);
}

.imb-checkbox-row:hover .imb-checkbox-box,
.imb-checkbox-input:focus-visible + .imb-checkbox-box {
  outline: 2px solid var(--modal-accent);
  outline-offset: 3px;
}

.imb-dev-tools-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.imb-keybinding-list {
  display: grid;
  gap: 7px;
  max-height: min(44vh, 360px);
  overflow: auto;
  padding-right: 4px;
}

.imb-keybinding-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(112px, 140px);
  align-items: center;
  gap: 10px;
  color: var(--modal-text);
  font-size: 13px;
}

.imb-keybinding-button {
  min-height: 28px;
  padding: 4px 8px;
  border: 2px solid var(--modal-border);
  background: var(--modal-bg-soft);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight);
}

.imb-keybinding-button:hover,
.imb-keybinding-button.listening {
  background: var(--modal-text);
  color: var(--modal-bg);
}

.save-slot-dialog {
  width: min(820px, calc(100vw - 32px));
  min-width: 320px;
}

.save-slot-dialog .imb-dialog-body {
  max-height: min(76vh, 720px);
}

.save-slot-status {
  min-height: 22px;
  margin-bottom: 12px;
  color: var(--modal-accent);
  font-size: 13px;
  line-height: 1.25;
}

.save-slot-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.save-slot-shell {
  position: relative;
  min-width: 0;
}

.save-slot-tile {
  position: relative;
  width: 100%;
  min-height: 150px;
  display: grid;
  align-content: end;
  gap: 5px;
  overflow: hidden;
  padding: 12px;
  background:
    linear-gradient(180deg, rgba(5, 7, 10, 0.18), rgba(5, 7, 10, 0.9)),
    var(--save-preview, var(--modal-bg-soft));
  background-size: cover;
  background-position: center;
  border: 2px solid var(--modal-border);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  text-align: left;
  cursor: pointer;
  image-rendering: pixelated;
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight),
    2px 2px 0 var(--chrome-shadow);
}

.save-slot-shell.is-empty .save-slot-tile {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.04) 0,
      rgba(255, 255, 255, 0.04) 8px,
      rgba(0, 0, 0, 0.1) 8px,
      rgba(0, 0, 0, 0.1) 16px
    ),
    var(--modal-bg-soft);
}

.save-slot-tile:hover,
.save-slot-tile:focus,
.save-slot-shell.selected .save-slot-tile {
  outline: 2px solid var(--modal-accent);
  outline-offset: 2px;
}

.save-slot-tile:disabled {
  cursor: default;
  opacity: 0.58;
}

.save-slot-number {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 3px 7px;
  background: rgba(0, 0, 0, 0.72);
  color: #ffffff;
  font-size: 12px;
  line-height: 1;
  text-shadow: 1px 1px 0 #000000;
}

.save-slot-overlay {
  display: grid;
  gap: 4px;
  padding: 9px;
  background: rgba(0, 0, 0, 0.74);
  color: #ffffff;
  text-shadow: 1px 1px 0 #000000;
}

.save-slot-character {
  font-size: 16px;
  line-height: 1.1;
}

.save-slot-region,
.save-slot-date,
.save-slot-empty,
.save-slot-hint {
  font-size: 12px;
  line-height: 1.25;
}

.save-slot-region {
  color: #c8e6ff;
}

.save-slot-date,
.save-slot-hint {
  color: #d7d7d7;
}

.save-slot-empty {
  color: var(--modal-text);
  font-size: 17px;
}

.save-slot-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 2px solid var(--modal-border);
  background: var(--modal-bg);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight),
    1px 1px 0 var(--chrome-shadow);
}

.save-slot-delete:hover,
.save-slot-delete:focus {
  background: var(--modal-text);
  color: var(--modal-bg);
}

@media (max-width: 560px) {
  .imb-dialog {
    left: 12px !important;
    width: calc(100vw - 24px);
    min-width: 0;
  }

  .imb-about-layout {
    flex-direction: column;
  }

  .imb-slider-row,
  .imb-theme-row,
  .imb-dev-tools-panel,
  .imb-keybinding-row,
  .save-slot-grid {
    grid-template-columns: 1fr;
  }

  .imb-slider-val {
    text-align: left;
  }
}

/* Keep game content inside the custom retro frame. */
.app-container {
  padding: 64px 18px 20px;
}

:root {
  --bg: #0f1013;
  --panel: #141922;
  --ink: #e6edf3;
  --ink-dim: #a9b1bb;
  --border: rgba(255, 255, 255, 0.06);
  --primary: #18191b;
  --secondary: #d9d9d9;
  --tertiary: #707070;
  --chrome-bg: #1e1e1e;
  --chrome-title-bg: #1e1e1e;
  --chrome-text: #d9d9d9;
  --chrome-border: #050505;
  --chrome-lowlight: #0a0a0a;
  --chrome-mid: #3b3b3b;
  --chrome-highlight: #707070;
  --chrome-bright: #b0b0b0;
  --chrome-shadow: #050505;
  --chrome-stripe-light: #747474;
  --chrome-stripe-dark: #151515;
  --modal-bg: #111214;
  --modal-bg-soft: #202123;
  --modal-text: #eeeeee;
  --modal-muted: #a9aaad;
  --modal-accent: #66b7ff;
  --modal-border: #050505;
  --modal-line: #3d3e40;
  --modal-scrim: rgba(0, 0, 0, 0.34);
  --scroll-track: #111214;
  --scroll-track-mark: #4f5052;
  --scroll-thumb: #c8c8c8;
  --scroll-border: #050505;
}

:root[data-theme="light"] {
  --bg: #d4d0c8;
  --panel: #eee8dc;
  --ink: #111111;
  --ink-dim: #4f4f4f;
  --border: rgba(0, 0, 0, 0.22);
  --primary: #f0ece3;
  --secondary: #111111;
  --tertiary: #8f8a82;
  --chrome-bg: #d9d4c9;
  --chrome-title-bg: #e9e2d8;
  --chrome-text: #111111;
  --chrome-border: #111111;
  --chrome-lowlight: #7d776e;
  --chrome-mid: #a9a399;
  --chrome-highlight: #ffffff;
  --chrome-bright: #ffffff;
  --chrome-shadow: #4c4943;
  --chrome-stripe-light: #111111;
  --chrome-stripe-dark: #eee8dc;
  --modal-bg: #eee8dc;
  --modal-bg-soft: #ddd7cc;
  --modal-text: #111111;
  --modal-muted: #4d4944;
  --modal-accent: #244ad8;
  --modal-border: #111111;
  --modal-line: #8f8a82;
  --modal-scrim: rgba(225, 220, 210, 0.28);
  --scroll-track: #eee8dc;
  --scroll-track-mark: #111111;
  --scroll-thumb: #f7f2e9;
  --scroll-border: #111111;
}

::-webkit-scrollbar {
  width: 22px;
  height: 22px;
  background-color: var(--scroll-track);
}

::-webkit-scrollbar-track {
  background:
    linear-gradient(
      45deg,
      var(--scroll-track-mark) 25%,
      transparent 25%,
      transparent 75%,
      var(--scroll-track-mark) 75%,
      var(--scroll-track-mark)
    ),
    linear-gradient(
      45deg,
      var(--scroll-track-mark) 25%,
      transparent 25%,
      transparent 75%,
      var(--scroll-track-mark) 75%,
      var(--scroll-track-mark)
    );
  background-color: var(--scroll-track);
  background-size: 4px 4px;
  background-position:
    0 0,
    2px 2px;
  border-left: 3px solid var(--scroll-border);
}

::-webkit-scrollbar-thumb {
  background-color: var(--scroll-thumb);
  border: 2px solid var(--scroll-border);
  border-right: none;
  box-shadow:
    inset 1px 1px 0 var(--chrome-bright),
    inset -1px -1px 0 var(--chrome-lowlight);
}

::-webkit-scrollbar-button {
  background-color: var(--scroll-thumb);
  border: 1px solid var(--scroll-border);
}

*::-webkit-scrollbar-button {
  filter: invert(1) brightness(0.84);
}

:root[data-theme="light"] *::-webkit-scrollbar-button {
  filter: none;
}

.window-pane::-webkit-scrollbar {
  width: 22px;
  background-color: var(--scroll-track);
}

.window-pane::-webkit-scrollbar-track {
  background:
    linear-gradient(
      45deg,
      var(--scroll-track-mark) 25%,
      transparent 25%,
      transparent 75%,
      var(--scroll-track-mark) 75%,
      var(--scroll-track-mark)
    ),
    linear-gradient(
      45deg,
      var(--scroll-track-mark) 25%,
      transparent 25%,
      transparent 75%,
      var(--scroll-track-mark) 75%,
      var(--scroll-track-mark)
    );
  background-color: var(--scroll-track);
  background-size: 4px 4px;
  background-position:
    0 0,
    2px 2px;
  border-left: 3px solid var(--scroll-border);
}

.window-pane::-webkit-scrollbar-thumb {
  background-color: var(--scroll-thumb);
  border: 2px solid var(--scroll-border);
  border-right: none;
}

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

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Chicago_12", sans-serif;
  font-size: 1em;
  overflow: hidden;
  line-height: 1.4em;
  -webkit-font-smoothing: none;
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.viewport {
  flex: 1;
  /* Windowed renderer: the canvas is sized to this element and the camera
     follows the player in-engine, so there is nothing to scroll. */
  overflow: hidden;
  position: relative; /* anchor for floating inventory bar */
}

.game-over-overlay {
  position: absolute;
  inset: 0;
  z-index: 90;
  opacity: 0;
  transition: opacity 1s ease-in;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0) 40%,
    rgba(0, 0, 0, 0.7) 100%
  );
}

.game-over-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.game-over-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.game-over-text {
  font-size: 128px;
  font-weight: normal;
  color: #ff0000;
  line-height: 1em;
  text-shadow:
    0 0 10px rgba(255, 0, 0, 0.8),
    0 0 20px rgba(255, 0, 0, 0.6),
    0 0 30px rgba(255, 0, 0, 0.4),
    4px 4px 0px rgba(0, 0, 0, 0.9);
  letter-spacing: 8px;
  animation: pulse 2s ease-in-out infinite;
  font-family: "Chicago_12", sans-serif;
}

.game-over-score {
  font-size: 48px;
  font-weight: normal;
  color: #ffd54f;
  text-shadow:
    0 0 8px rgba(255, 213, 79, 0.6),
    3px 3px 0px rgba(0, 0, 0, 0.9);
  letter-spacing: 2px;
  font-family: "Chicago_12", sans-serif;
  line-height: 1em;
  margin-bottom: 18px;
}

.new-game-button {
  margin-top: 6px;
  padding: 10px 24px;
  border-radius: 999px;
  border: 2px solid #ffd54f;
  background: rgba(0, 0, 0, 0.5);
  color: #ffd54f;
  font-family: "Chicago_12", sans-serif;
  font-size: 32px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 2px;
  transition:
    transform 0.2s ease,
    background 0.2s ease;
}

.new-game-button:hover {
  background: rgba(0, 0, 0, 0.8);
  transform: translateY(-1px);
}

.new-game-button:active {
  transform: translateY(1px);
}

.new-game-button:focus {
  outline: 2px solid #ffd54f;
  outline-offset: 3px;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

#game {
  display: block;
  /* Fill the viewport. The drawing buffer is resized (debounced) on settle; in
     between, CSS stretches the existing buffer so live window resizing stays
     smooth instead of reallocating WebGL every frame. */
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.world-callout-composer {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 75;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto minmax(180px, 360px) auto;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 28px);
  padding: 8px 10px 7px;
  border: 0;
  border-radius: 10px;
  color: #3b365d;
  background: #fff0bd;
  box-shadow:
    3px 4px 0 rgba(77, 62, 115, 0.68),
    0 10px 26px rgba(43, 42, 76, 0.24);
  font-family: "Chicago_12", "Chicago", monospace;
}

.world-callout-composer[hidden] {
  display: none;
}

.world-callout-composer[data-kind="thought"] {
  background: #eee4ff;
}

.world-callout-composer__mode {
  min-width: 42px;
  color: #6a4fa3;
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
}

.world-callout-composer__input {
  min-width: 0;
  padding: 6px 8px;
  border: 0;
  border-radius: 5px;
  outline: 2px solid transparent;
  color: #3b365d;
  background: rgba(255, 255, 255, 0.78);
  font: inherit;
}

.world-callout-composer__input:focus {
  outline-color: #5de2d1;
}

.world-callout-composer__send {
  padding: 6px 10px;
  border: 0;
  border-radius: 5px;
  color: #fff7db;
  background: #6a4fa3;
  box-shadow: 0 2px 0 #3b365d;
  font: inherit;
  cursor: pointer;
}

.world-callout-composer__hint {
  grid-column: 2 / 3;
  color: #6a6488;
  font-size: 10px;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 560px) {
  .world-callout-composer {
    grid-template-columns: auto minmax(120px, 1fr) auto;
    width: calc(100% - 28px);
  }
}

.hp-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 50;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hp-bar-outer {
  width: 120px;
  height: 14px;
  border: 2px solid #ffffff;
  padding: 1px;
  background: #2a2a2a;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.15),
    inset -1px -1px 0 rgba(0, 0, 0, 0.5),
    1px 1px 0 rgba(0, 0, 0, 0.9);
  flex-shrink: 0;
}

.hp-bar-inner {
  height: 100%;
  width: 100%;
  background: linear-gradient(
    90deg,
    #dd4444 0%,
    #dd4444 20%,
    #dd7733 20%,
    #dd7733 40%,
    #dddd44 40%,
    #dddd44 60%,
    #77cc33 60%,
    #77cc33 80%,
    #4db54d 80%,
    #4db54d 100%
  );
  overflow: hidden;
  position: relative;
}

.hp-bar-inner::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  background: #2a2a2a;
  width: calc(100% - var(--hp-width, 100%));
  transition: width 0.3s ease;
}

.hp-overlay-text {
  opacity: 0;
  color: #ffffff;
  font-family: "Chicago_12", sans-serif;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
  text-shadow:
    1px 1px 0 #000,
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000,
    0 2px 6px rgba(0, 0, 0, 0.9);
  transition: opacity 0.15s ease;
}

.resting-status {
  color: #ffe07a;
  font-family: "Chicago_12", sans-serif;
  font-size: 13px;
  line-height: 1;
  letter-spacing: 1px;
  text-shadow: 1px 1px 0 #000;
}

.hp-overlay.hovered .hp-overlay-text {
  opacity: 1;
}

/* ============================================================
   Story Overlay — floating CRT terminal over game canvas
   ============================================================ */

/* ── Overlay: always same width, inset from scrollbars ────── */
.story-overlay {
  position: absolute;
  left: 8px;
  right: 8px; /* viewport no longer scrolls — symmetric 8px inset */
  bottom: 8px;
  z-index: 50;
  pointer-events: none;
}

/* ── Glass panel — same width in both modes ─────────────────
   Normal mode:  short strip at the bottom
   Expanded mode: JS sets height to fill from 8px-top to 30px-bottom
   ─────────────────────────────────────────────────────────── */
.story-panel {
  position: relative;
  height: 88px;
  overflow: hidden;
  transition:
    height 0.38s cubic-bezier(0.4, 0, 0.2, 1),
    border-radius 0.38s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.38s ease;

  /* Semi-transparent glass with backdrop blur */
  background: rgba(0, 11, 5, 0.52);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);

  /* Fully rounded — free-floating glass pane */
  border-radius: 13px;

  /* Glass edge */
  border: 1px solid rgba(57, 255, 106, 0.3);

  /* Depth: outer glow + inner bevel */
  box-shadow:
    0 4px 32px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(57, 255, 106, 0.06),
    0 -2px 16px rgba(57, 255, 106, 0.07),
    inset 0 1px 0 rgba(57, 255, 106, 0.18),
    inset 0 0 40px rgba(0, 18, 7, 0.48);

  /* Pass clicks through the glass in normal mode */
  pointer-events: none;
}

/* Top glass sheen */
.story-panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  border-radius: 13px 13px 0 0;
  background: linear-gradient(
    to bottom,
    rgba(57, 255, 106, 0.07) 0%,
    rgba(57, 255, 106, 0.02) 55%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 3;
}

/* Scanlines */
.story-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0, 0, 0, 0.07) 3px,
    rgba(0, 0, 0, 0.07) 4px
  );
  pointer-events: none;
  z-index: 2;
}

/* ── Expand button: top-right corner of the glass pane ────── */
.story-expand-tab {
  position: absolute;
  top: 7px;
  right: 9px;
  width: 20px;
  height: 20px;
  z-index: 10;
  pointer-events: auto;

  background: rgba(0, 18, 7, 0.8);
  border: 1px solid rgba(57, 255, 106, 0.42);
  border-radius: 4px;
  color: rgba(57, 255, 106, 0.78);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition:
    background 0.13s,
    color 0.13s,
    box-shadow 0.13s;
  box-shadow:
    0 0 6px rgba(57, 255, 106, 0.12),
    inset 0 1px 0 rgba(57, 255, 106, 0.15);
}

/* Remove browser focus ring for mouse interactions, but show it for keyboard */
.story-expand-tab:focus:not(:focus-visible) {
  outline: none;
}

.story-expand-tab:focus-visible {
  outline: 2px solid rgba(57, 255, 106, 0.8);
  outline-offset: 2px;
}

.story-expand-tab:hover {
  background: rgba(0, 32, 14, 0.92);
  color: rgba(57, 255, 106, 1);
  box-shadow:
    0 0 10px rgba(57, 255, 106, 0.28),
    inset 0 1px 0 rgba(57, 255, 106, 0.2);
}

.story-tab-label {
  font-family: monospace;
  font-size: 15px;
  font-weight: bold;
  line-height: 1;
  text-shadow: 0 0 6px rgba(57, 255, 106, 0.7);
  pointer-events: none;
  /* nudge the + / − to optical centre */
  margin-top: -1px;
}

/* ── Scroll container (both modes) ───────────────────────── */
.story-scroll {
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 8px;
}

/* Always hide scrollbar in base mode (re-shown in expanded mode below) */
.story-scroll::-webkit-scrollbar {
  display: none;
}

/* ── Story messages list ──────────────────────────────────── */
.story-messages {
  list-style: none;
  padding: 0;
  margin: 0;
  margin-top: auto; /* anchor text to bottom */
}

.story-messages li {
  padding: 2px 0;
  line-height: 1.45;
  font-family: "Chicago_12", monospace;
  font-size: 13px;
  color: #39ff6a;
  text-shadow:
    0 0 5px rgba(57, 255, 106, 0.75),
    0 0 12px rgba(57, 255, 106, 0.35),
    0 0 22px rgba(57, 255, 106, 0.12);
}

/* ── Expanded mode ────────────────────────────────────────── */
.story-overlay.expanded .story-panel {
  /* height is set by JS to fill from 8px-top to bottom of overlay */
  overflow: hidden;

  /* Slightly more opaque than normal, still with blur */
  background: rgba(0, 10, 4, 0.62);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);

  /* Larger rounded corners */
  border-radius: 16px;

  border: 1px solid rgba(57, 255, 106, 0.28);

  box-shadow:
    0 8px 48px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(57, 255, 106, 0.05),
    0 -4px 24px rgba(57, 255, 106, 0.07),
    inset 0 1px 0 rgba(57, 255, 106, 0.22),
    inset 0 0 70px rgba(0, 18, 7, 0.52),
    inset 2px 0 24px rgba(57, 255, 106, 0.015),
    inset -2px 0 24px rgba(57, 255, 106, 0.015);

  /* Accept scroll & click events */
  pointer-events: auto;
}

/* Expanded: wider sheen covers more of the taller panel */
.story-overlay.expanded .story-panel::before {
  border-radius: 16px 16px 0 0;
  height: 18%;
  background: linear-gradient(
    to bottom,
    rgba(57, 255, 106, 0.065) 0%,
    rgba(57, 255, 106, 0.02) 55%,
    transparent 100%
  );
}

/* Expanded: scroll area — flex column, text anchored bottom */
.story-overlay.expanded .story-scroll {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  /* 36px top clears the expand button (20px) + 7px offset + 8px margin;
     sides and bottom are 8px as requested */
  padding: 36px 8px 8px 8px;
  -webkit-mask-image: none;
  mask-image: none;
}

/* Custom CRT green scrollbar — visible only when expanded */
.story-overlay.expanded .story-scroll::-webkit-scrollbar {
  display: block;
  width: 5px;
  background: transparent;
}

.story-overlay.expanded .story-scroll::-webkit-scrollbar-track {
  background: transparent;
  border: none;
  box-shadow: none;
}

.story-overlay.expanded .story-scroll::-webkit-scrollbar-thumb {
  background: rgba(57, 255, 106, 0.52);
  border-radius: 0;
  border: none;
  box-shadow: 0 0 4px rgba(57, 255, 106, 0.28);
}

.story-overlay.expanded .story-scroll::-webkit-scrollbar-button {
  display: none;
  height: 0;
  width: 0;
}

/* ── Multiplayer menu styles ───────────────────────────────────────────────── */

.imb-mp-options {
  display: grid;
  gap: 8px;
}

.imb-mp-hint {
  font-size: 11px;
  color: var(--modal-text-muted, var(--modal-text));
  opacity: 0.6;
  margin-top: 4px;
  line-height: 1.5;
}

.imb-input-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  align-items: center;
  gap: 8px;
}

.imb-input-row label {
  font-size: 12px;
  white-space: nowrap;
}

.imb-text-input {
  padding: 4px 8px;
  background: var(--modal-bg);
  border: 2px solid var(--modal-border);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 13px;
  box-shadow: inset 2px 2px 0 var(--chrome-lowlight);
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.imb-text-input:focus {
  border-color: var(--modal-text);
}

.imb-mp-status {
  font-size: 11px;
  padding: 6px 8px;
  background: var(--modal-bg-soft);
  border: 1px solid var(--modal-border);
  color: var(--modal-text);
  line-height: 1.4;
}

.imb-mp-status.hidden {
  display: none;
}

/* Server list (Browse view) */
.imb-server-list {
  min-height: 80px;
  max-height: 200px;
  overflow-y: auto;
  border: 2px solid var(--modal-border);
  background: var(--modal-bg);
  box-shadow: inset 2px 2px 0 var(--chrome-lowlight);
}

.imb-server-searching {
  padding: 16px;
  font-size: 12px;
  color: var(--modal-text);
  opacity: 0.6;
  text-align: center;
}

.imb-server-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--modal-border);
  gap: 8px;
}

.imb-server-entry:last-child {
  border-bottom: none;
}

.imb-server-entry:hover {
  background: var(--modal-bg-soft);
}

.imb-server-info {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.imb-server-name {
  font-size: 13px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.imb-server-meta {
  font-size: 10px;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.imb-server-join-btn {
  flex-shrink: 0;
  min-width: 48px;
  font-size: 11px;
  padding: 2px 10px;
  min-height: 22px;
}

/* Lobby view */
.imb-mp-lobby-status {
  font-size: 12px;
  color: var(--modal-text);
  opacity: 0.8;
  padding: 4px 0;
}

.imb-lobby-players {
  display: grid;
  gap: 4px;
  min-height: 40px;
}

.imb-lobby-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--modal-bg-soft);
  border: 1px solid var(--modal-border);
}

.imb-lobby-player.is-host {
  border-color: var(--modal-text);
}

.imb-lobby-player-name {
  font-size: 13px;
  flex: 1;
}

.imb-lobby-host-badge {
  font-size: 9px;
  padding: 1px 5px;
  background: var(--modal-text);
  color: var(--modal-bg);
  font-weight: bold;
  letter-spacing: 0.05em;
}

.imb-lobby-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* Widen the pause dialog slightly for MP views */
.imb-pause-dialog {
  width: min(460px, calc(100vw - 32px));
}

.imb-pause-dialog.imb-main-menu-dialog {
  width: 100vw;
  height: 100vh;
}

/* ============================================================
   Inventory Bar
   ============================================================ */

/* ============================================================
   Floating HUD inventory bar — overlays the game canvas
   ============================================================ */
/* ── Retro floating inventory HUD ─────────────────────────── */

.inventory-bar {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;

  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 1px;
  padding: 4px 5px;

  /* Retro sharp look — no blur, no rounded corners */
  background: rgba(0, 0, 0, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.1),
    inset -1px -1px 0 rgba(0, 0, 0, 0.5),
    3px 3px 0 rgba(0, 0, 0, 0.8);

  pointer-events: auto;
  white-space: nowrap;
}

.inv-slot {
  position: relative;
  width: 42px;
  height: 50px;
  background: rgba(0, 0, 0, 0);
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px;
  box-sizing: border-box;
  flex-shrink: 0;
}

.inv-slot:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.28);
}

.inv-slot.selected {
  background: rgba(80, 160, 255, 0.2);
  border-color: rgba(100, 180, 255, 0.8);
  box-shadow:
    0 0 0 1px rgba(100, 180, 255, 0.45),
    inset 1px 1px 0 rgba(100, 180, 255, 0.2);
}

.inv-slot.empty .inv-slot-icon {
  opacity: 0.1;
}

/* Matter Manipulator active: items it can't place are dimmed and desaturated. */
.inv-slot.mm-unplaceable .inv-slot-icon {
  opacity: 0.28;
  filter: grayscale(1);
}

.inv-slot.mm-unplaceable .inv-slot-count {
  opacity: 0.35;
}

.inv-slot-key {
  position: absolute;
  top: 1px;
  left: 3px;
  font-family: "Chicago_12", sans-serif;
  font-size: 8px;
  color: rgba(255, 255, 255, 0.35);
  line-height: 1;
  pointer-events: none;
  z-index: 1;
}

.inv-slot.selected .inv-slot-key {
  color: rgba(140, 200, 255, 0.9);
}

.inv-slot-icon {
  display: block;
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex-shrink: 0;
}

.inv-slot-count {
  position: absolute;
  bottom: 9px;
  right: 2px;
  font-family: "Chicago_12", sans-serif;
  font-size: 11px;
  color: #ffffff;
  text-shadow:
    1px 1px 0 #000,
    -1px 0 0 #000,
    0 -1px 0 #000;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

.inv-slot-bar {
  position: absolute;
  bottom: 2px;
  left: 2px;
  right: 2px;
  height: 3px;
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.inv-slot-bar-fill {
  height: 100%;
  width: 0;
  background: var(--bar-color, #44ff88);
  transition: width 0.15s ease;
}

/* ============================================================
   Inventory / Character Modal Tooltip
   ============================================================ */

.inv-tooltip {
  position: fixed;
  z-index: 9000;
  background: var(--modal-bg);
  border: 2px solid var(--chrome-border);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 12px;
  padding: 6px 8px;
  pointer-events: none;
  box-shadow:
    inset 1px 1px 0 var(--chrome-highlight),
    inset -1px -1px 0 var(--chrome-lowlight),
    3px 3px 0 rgba(0, 0, 0, 0.6);
  line-height: 1.5;
}

.inv-tip-name {
  color: var(--modal-accent);
  font-size: 12px;
  margin-bottom: 2px;
}

.inv-tip-count {
  color: var(--modal-muted);
  font-size: 11px;
}

.inv-tip-actions {
  color: var(--modal-text);
  font-size: 10px;
  margin-top: 4px;
  border-top: 1px solid var(--modal-line);
  padding-top: 4px;
  opacity: 0.8;
}

/* ============================================================
   Character Modal
   Uses .imb-dialog chrome classes for visual consistency with
   RetroModal (same titlebar, stripes, close button).
   ============================================================ */

/* ── Character Modal scrim (full-screen backdrop) ────────── */

.char-modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 8000;
  background: var(--modal-scrim);
  pointer-events: none; /* window sits on top, scrim doesn't steal clicks */
}

/* ── Character Modal window ──────────────────────────────── */

/* Inherits .imb-dialog (position: fixed, z-index: 10001).
   We override width and add flex column layout. */
.char-modal-window {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Center via CSS — JS clears this on drag start */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 8001;
}

/* Drag cursor on titlebar */
.char-modal-titlebar-drag {
  cursor: move;
}
.char-modal-window.dragging {
  cursor: move;
  user-select: none;
}

/* ── Tabs ─────────────────────────────────────────────────── */

.char-modal-tabs {
  display: flex;
  border-bottom: 2px solid var(--chrome-border);
  background: var(--chrome-bg);
  padding: 0 6px;
  gap: 2px;
  flex-shrink: 0;
}

.char-modal-tab-btn {
  padding: 6px 18px;
  background: var(--modal-bg-soft);
  border: 2px solid var(--chrome-border);
  border-bottom: none;
  color: var(--modal-muted);
  font-family: "Chicago_12", sans-serif;
  font-size: 14px;
  cursor: pointer;
  margin-top: 4px;
  margin-bottom: -2px;
  position: relative;
  box-shadow:
    inset 1px 1px 0 var(--chrome-highlight),
    inset -1px 0 0 var(--chrome-lowlight);
}

.char-modal-tab-btn:hover {
  color: var(--modal-text);
  background: var(--chrome-mid);
}
.char-modal-tab-btn:focus-visible {
  outline: 2px solid var(--modal-accent);
  outline-offset: -2px;
}

.char-modal-tab-btn.active {
  background: var(--modal-bg);
  color: var(--modal-text);
  z-index: 1;
  box-shadow:
    inset 1px 1px 0 var(--chrome-highlight),
    inset -1px 0 0 var(--chrome-lowlight),
    0 2px 0 var(--modal-bg);
}

/* ── Panel container — fixed height so tabs don't resize modal ── */

.char-modal-panels {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

/* All panels share the same fixed height — prevents modal resizing on tab switch */
.char-modal-panel {
  height: 400px;
  overflow-y: auto;
}

/* ── Inventory grid: 12 columns ──────────────────────────── */

.char-modal-inv-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 3px;
}

.char-inv-slot {
  position: relative;
  aspect-ratio: 1;
  background: var(--modal-bg-soft);
  border: 2px solid var(--chrome-border);
  box-shadow:
    inset 1px 1px 0 var(--chrome-lowlight),
    inset -1px -1px 0 var(--chrome-highlight);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  overflow: hidden;
}

.char-inv-slot:hover {
  background: var(--chrome-mid);
}

.char-inv-slot.bar-slot {
  border-color: var(--modal-accent);
  box-shadow:
    inset 1px 1px 0 rgba(100, 183, 255, 0.25),
    inset -1px -1px 0 rgba(0, 0, 0, 0.4);
}

.char-inv-slot.selected {
  background: rgba(100, 180, 255, 0.15);
  box-shadow:
    0 0 0 1px var(--modal-accent),
    inset 1px 1px 0 rgba(100, 180, 255, 0.3);
}

.char-inv-slot.empty {
  cursor: default;
}

.char-inv-key {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 7px;
  color: var(--modal-muted);
  line-height: 1;
  pointer-events: none;
  z-index: 1;
}

.char-inv-slot.selected .char-inv-key {
  color: var(--modal-accent);
}

.char-inv-icon {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  padding: 4px;
  box-sizing: border-box;
}

.char-inv-count {
  position: absolute;
  bottom: 8px;
  right: 1px;
  font-size: 8px;
  color: #e8e8e8;
  text-shadow:
    1px 1px 0 #000,
    -1px -1px 0 #000;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

.char-inv-bar {
  position: absolute;
  bottom: 1px;
  left: 1px;
  right: 1px;
  height: 3px;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.char-inv-bar-fill {
  height: 100%;
  width: 0;
  background: var(--bar-color, #44ff88);
}

/* ── Settings panel ──────────────────────────────────────── */

.char-settings-view {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.char-settings-heading {
  font-size: 12px;
  font-family: "Chicago_12", sans-serif;
  color: var(--modal-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--modal-border);
}

/* Larger font for settings controls */
.char-settings-view .imb-slider-row label,
.char-settings-view .imb-theme-label,
.char-settings-view .imb-checkbox-row,
.char-settings-view .imb-keybinding-row {
  font-size: 14px;
}

.char-settings-view .imb-slider-row {
  grid-template-columns: 140px minmax(120px, 1fr) 46px;
}

.char-settings-view .imb-theme-row {
  grid-template-columns: 140px 1fr;
}

.char-settings-view .imb-slider-val {
  font-size: 13px;
}

.char-settings-view .imb-theme-option {
  font-size: 13px;
  padding: 4px 14px;
}

/* Keybinding list */
.char-keybinding-list {
  max-height: 260px;
  overflow-y: auto;
}

.char-settings-view .imb-keybinding-button {
  font-size: 13px;
  min-width: 100px;
}

.char-nav-btn {
  padding: 7px 14px;
  background: var(--modal-bg-soft);
  border: 2px solid var(--chrome-border);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight),
    2px 2px 0 var(--chrome-shadow);
}
.char-nav-btn:hover {
  background: var(--chrome-mid);
}
.char-nav-btn:focus-visible {
  outline: 2px solid var(--modal-accent);
  outline-offset: -2px;
}

.char-sub-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.char-sub-title {
  font-family: "Chicago_12", sans-serif;
  font-size: 15px;
  color: var(--modal-text);
  margin: 0;
}

.char-dev-tools-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.char-dev-tools-panel.hidden {
  display: none;
}

/* ── Game tab ─────────────────────────────────────────────── */

.char-game-panel-wrap {
  display: flex;
  flex-direction: column;
}

.char-game-view {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.char-game-logo {
  display: block;
  width: 180px;
  height: auto;
  image-rendering: pixelated;
  margin: 0 auto 20px;
}

.char-game-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 240px;
}

.char-modal-game-btn {
  width: 100%;
  min-height: 34px;
  padding: 6px 16px;
  background: var(--modal-bg-soft);
  border: 2px solid var(--chrome-border);
  color: var(--modal-text);
  font-family: "Chicago_12", sans-serif;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  box-shadow:
    inset 2px 2px 0 var(--chrome-highlight),
    inset -2px -2px 0 var(--chrome-lowlight),
    2px 2px 0 var(--chrome-shadow);
}

.char-modal-game-btn:hover {
  background: var(--chrome-mid);
}
.char-modal-game-btn:focus-visible {
  outline: 2px solid var(--modal-accent);
  outline-offset: -2px;
}

.char-modal-game-btn:active {
  box-shadow:
    inset 2px 2px 0 var(--chrome-lowlight),
    inset -2px -2px 0 var(--chrome-highlight);
  transform: translate(1px, 1px);
}

/* ── Multiplayer sub-views ───────────────────────────────── */

.char-mp-hint {
  font-size: 12px;
  color: var(--modal-muted);
  margin: 14px 0 0;
  max-width: 320px;
  line-height: 1.5;
}

.char-mp-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.char-mp-status {
  font-size: 13px;
  color: var(--modal-accent);
  font-family: "Chicago_12", sans-serif;
  padding: 4px 0;
}
.char-mp-status.hidden {
  display: none;
}

.char-mp-server-list {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--chrome-border);
  background: var(--modal-bg-soft);
  margin: 8px 0;
}

.char-mp-server-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid var(--chrome-border);
}
.char-mp-server-entry:last-child {
  border-bottom: none;
}

.char-mp-server-name {
  font-size: 13px;
  color: var(--modal-text);
  display: block;
}

.char-mp-server-meta {
  font-size: 11px;
  color: var(--modal-muted);
  display: block;
}

.char-mp-searching {
  padding: 12px;
  font-size: 12px;
  color: var(--modal-muted);
  text-align: center;
}

.char-mp-lobby-status {
  font-size: 13px;
  color: var(--modal-muted);
  margin-bottom: 10px;
}

.char-mp-lobby-players {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.char-mp-lobby-player {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--modal-text);
}

.char-mp-host-badge {
  font-size: 10px;
  color: var(--modal-accent);
  border: 1px solid var(--modal-accent);
  padding: 1px 4px;
}

/* Cursor ghost while dragging */
.inv-cursor-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.85;
}

.inv-cursor-ghost canvas {
  display: block;
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

/* ── Conversation dialogue panel ─────────────────────────────────────────── */
.dialogue-panel {
  position: fixed;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  width: min(720px, 92vw);
  padding: 16px;
  background: rgba(10, 16, 22, 0.94);
  border: 2px solid #3fb6c8;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  color: #e7f4f7;
  font-family: "Courier New", monospace;
  z-index: 60;
}
.dialogue-panel[hidden],
.dialogue-input-row[hidden],
.dialogue-input[hidden] {
  display: none;
}
.dialogue-portrait {
  width: 112px;
  height: 112px;
  flex: 0 0 auto;
  image-rendering: pixelated;
  background: #0c1420;
  border: 1px solid #2b6472;
  border-radius: 6px;
}
.dialogue-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}
.dialogue-name {
  font-weight: bold;
  color: #6be2df;
  letter-spacing: 0.5px;
}
.dialogue-text {
  line-height: 1.4;
  font-size: 15px;
}
.dialogue-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.dialogue-choice {
  text-align: left;
  padding: 7px 10px;
  background: rgba(63, 182, 200, 0.1);
  border: 1px solid #2b6472;
  border-radius: 5px;
  color: #e7f4f7;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.dialogue-choice:hover,
.dialogue-choice:focus-visible {
  background: rgba(63, 182, 200, 0.28);
  border-color: #6be2df;
  outline: 2px solid #e6c85c;
  outline-offset: 1px;
}
.dialogue-input-row {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.dialogue-input {
  flex: 1 1 auto;
  padding: 7px 10px;
  background: #0c1420;
  border: 1px solid #2b6472;
  border-radius: 5px;
  color: #e7f4f7;
  font-family: inherit;
}
.dialogue-input-submit {
  padding: 7px 14px;
  background: #2b6472;
  border: 1px solid #6be2df;
  border-radius: 5px;
  color: #e7f4f7;
  font-family: inherit;
  cursor: pointer;
}
.dialogue-input:focus-visible,
.dialogue-input-submit:focus-visible {
  outline: 2px solid #e6c85c;
  outline-offset: 1px;
}

@media (max-width: 560px) {
  .dialogue-panel {
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
  }

  .dialogue-portrait {
    width: 72px;
    height: 72px;
  }
}
