/* Shared modal layout. Width percentages use the backdrop's padded content box. */
.game-popup-backdrop {
  position: fixed;
  inset: 0;
  place-items: center;
  padding: clamp(1.6vh, 4vw, 4vh);
  background: var(--backdrop-bg);
  backdrop-filter: blur(var(--backdrop-blur));
  -webkit-backdrop-filter: blur(var(--backdrop-blur));
  pointer-events: auto;
}

.game-popup-backdrop[hidden] {
  display: none;
}

.object-detail-backdrop {
  display: grid;
  z-index: 23;
}

:root .game-popup-panel {
  width: min(var(--popup-width, 60vh), 100%);
  height: var(--popup-height, 72vh);
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.game-popup-panel--compact {
  --popup-width: 50vh;
  --popup-height: 36vh;
}

.game-popup-panel--selection {
  --popup-width: 50vh;
}

.svg-icon-asset {
  --svg-icon-source: url('./rss/svg/ui_asset.svg?release=1ab06ec4ffb09b19942a9b7c');
}

.knowledge-currency {
  display: flex;
  justify-content: start;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin: 0 16px;
  padding: 12px 0 8px;
  color: #222;
}

.knowledge-currency strong {
  font-size: clamp(12px, 1.6vh, 16px);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  min-width: 0;
}

.knowledge-chron-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.knowledge-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  margin: 0 16px 8px;
  padding: 0 0 6px;
  border-bottom: 1px solid #ddd;
}

.knowledge-toolbar [role='tablist'] {
  display: flex;
  gap: 8px;
}

.knowledge-toolbar button {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  color: #777;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 6px;
  cursor: pointer;
}

.knowledge-toolbar button:hover {
  color: #111;
}

.knowledge-toolbar [aria-selected='true'] {
  color: #111;
  border-bottom-color: #111;
}

#knowledgeRefresh {
  font-size: 11px;
  font-weight: 400;
}

#knowledgeRefresh:disabled {
  opacity: .45;
  cursor: wait;
}

.knowledge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 72px);
  justify-content: center;
  gap: 8px;
  align-content: start;
  padding: 12px 16px 16px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.knowledge-card {
  position: relative;
  box-sizing: border-box;
  width: 72px;
  height: 72px;
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 0;
  background: #fff;
  color: #222;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
}

.knowledge-card:hover {
  background: #f5f5f5;
  border-color: #777;
}

.knowledge-card[aria-expanded='true'] {
  border-color: #111;
  box-shadow: inset 0 0 0 1px #111;
}

.knowledge-card:focus-visible,
.knowledge-toolbar button:focus-visible,
.knowledge-detail-close:focus-visible {
  outline: 2px solid #526bd1;
  outline-offset: 2px;
}

.knowledge-asset-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
}

.knowledge-card-name {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10px;
  line-height: 14px;
  font-weight: 500;
}

.knowledge-card-count {
  position: absolute;
  top: 3px;
  right: 4px;
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10px;
  line-height: 12px;
  font-variant-numeric: tabular-nums;
}

.knowledge-empty {
  grid-column: 1/-1;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.knowledge-detail-overlay {
  position: absolute;
  inset: 8px;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(0 0 0 / 30%);
}

.knowledge-detail-overlay[hidden] {
  display: none;
}

.knowledge-detail {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  max-height: 100%;
  min-height: 0;
  padding: 24px !important;
  background: white;
  color: #222;
  border: 1px solid #111;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 24px #0003;
}

.knowledge-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.knowledge-detail-tag {
  font-size: 11px;
  color: #666;
}

.knowledge-detail-close {
  border: 0;
  background: transparent;
  color: #222;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px;
}

.knowledge-detail-content {
  overflow: auto;
  min-height: 0;
}

.knowledge-detail-summary {
  display: flex;
  align-items: center;
  gap: 12px;
}

.knowledge-detail-summary>img {
  width: 48px;
  height: 48px;
  box-sizing: border-box;
}

.knowledge-detail-summary h3 {
  font-size: 14px;
  margin: 0;
  overflow-wrap: anywhere;
}

.knowledge-detail-summary>div {
  min-width: 0;
}

.knowledge-detail-summary p {
  font-size: 12px;
  line-height: 1.6;
  margin: 4px 0 0;
  color: #666;
}

.knowledge-detail dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  font-size: 12px;
  padding-top: 12px;
  border-top: 1px solid #ddd;
}

.knowledge-detail dt {
  overflow-wrap: anywhere;
  color: #666;
}

.knowledge-detail dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.player-satisfaction-zone button {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  padding: 7px 12px;
  cursor: pointer;
}

.player-satisfaction-zone {
  display: grid;
  gap: 8px;
  padding: 12px 0;
}

.player-satisfaction-zone>div:first-child {
  display: flex;
  justify-content: space-between;
}

#playerSatisfactionStatus {
  margin: 0;
  font-size: 12px;
}


.game-popup-panel>header {
  flex-shrink: 0;
}

.game-popup-panel> :is(.player-popup-body, .ship-fitting-body, .object-detail-popup-body) {
  flex: 1;
  min-height: 0;
  overflow: auto;
  align-content: start;
}

.object-detail-backdrop>.object-detail-popup.standalone {
  position: relative;
  inset: auto;
  transform: none;
  max-height: 100%;
}

/* Resource frames: main = 128px / 32px slices; button = 24px / 8px slices.
   Main shadow preserves every source shape, black at 25% opacity, offset 4px.
   Separate decoration layers keep shadows independent of text and scrolling. */
:root {
  --game-ui-text: #222222;
  --game-ui-button-color: #000000;
  --game-ui-button-bg: rgba(0, 0, 0, 0.04);
  --game-ui-button-filter: none;
  --ui-svg-filter: invert(0);
  --hud-resource-filter: invert(0);
}

:root[data-environment-mode="dark"] {
  --game-ui-text: #ffffff;
  --game-ui-button-color: #ffffff;
  --game-ui-button-bg: rgba(255, 255, 255, 0.16);
  --game-ui-button-filter: invert(1);
  --ui-svg-filter: invert(1);
  --hud-resource-filter: invert(1);
}

:root[data-environment-mode] :is(.object-list-panel, .player-popup-panel, .minimap-panel,
  .ship-info-panel, .ship-fitting-panel, .fitting-compatible-panel,
  .fitting-item-info-panel, .object-detail-popup, .target-panel, .knowledge-detail, .schedule-panel) {
  isolation: isolate;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  padding: 8px;
  /* White resource surface and the game's light palette in both environments. */
  color-scheme: light;
  --panel: rgba(246, 251, 255, 0.74);
  --panel-strong: #ffffff;
  --line: rgba(43, 98, 140, 0.22);
  --text: #133047;
  --muted: #537083;
  --primary: #8288ff;
  --primary-text: #111560;
  --accent: #0083ff;
  --svg-default-color: #6975a0;
  --ui_color: #6975a0;
  --ui_target_color: #7373ff;
  --bg: #ffffff;
  --selection-bg: rgba(246, 251, 255, 0.82);
  --selection-border: rgba(43, 98, 140, 0.26);
  --selection-hover-border: rgba(43, 98, 140, 0.44);
  --selection-hover-bg: rgba(246, 251, 255, 0.94);
  --selection-active-bg: rgba(200, 238, 255, 0.92);
  --bubble-bg: #ffffff;
  --bubble-border: rgba(43, 98, 140, 0.16);
  --bubble-button-bg: #ffffff;
  --row-hover-bg: rgba(255, 255, 255, 0.45);
  --row-active-bg: rgba(229, 246, 255, 0.78);
  --row-active-shadow: rgba(99, 210, 255, 0.78);
  --navigate-border: rgba(99, 210, 255, 0.62);
  --navigate-bg: rgba(99, 210, 255, 0.18);
  --btn-active-bg: rgba(206, 238, 255, 0.85);
  --list-inner: rgba(0, 0, 255, 0.45);
  --game-ui-text: #222222;
  --game-ui-button-color: #000000;
  --game-ui-button-bg: rgba(0, 0, 0, 0.04);
  --game-ui-button-filter: none;
  --ui-svg-filter: invert(0);
  color: var(--text);
}

/* Root theme selectors provide explicit panel fallbacks. */
:root[data-environment-mode] .target-panel input {
  background: rgba(255, 255, 255, 0.58);
}

:root[data-environment-mode] .object-list-sort-button {
  background: rgba(255, 255, 255, 0.42);
}

:root[data-environment-mode] .object-list-sort-menu {
  background: rgba(246, 251, 255, 0.98);
  box-shadow: 0 1vh 2.6vh rgba(66, 139, 190, 0.2);
}

:is(.ship-info-panel, .ship-fitting-panel, .fitting-compatible-panel,
  .fitting-item-info-panel) {
  position: relative;
}

:is(.object-list-panel, .player-popup-panel, .minimap-panel,
  .ship-info-panel, .ship-fitting-panel, .fitting-compatible-panel,
  .fitting-item-info-panel, .object-detail-popup, .target-panel, .knowledge-detail, .schedule-panel)::before,
:is(.object-list-panel, .player-popup-panel, .minimap-panel,
  .ship-info-panel, .ship-fitting-panel, .fitting-compatible-panel,
  .fitting-item-info-panel, .object-detail-popup, .target-panel, .knowledge-detail, .schedule-panel)::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: 32px solid transparent;
  border-image: url("./rss/svg/9slice-box_main1.svg?release=1ab06ec4ffb09b19942a9b7c") 32 fill / 32px / 0 stretch;
  z-index: -1;
}

:is(.object-list-panel, .player-popup-panel, .minimap-panel,
  .ship-info-panel, .ship-fitting-panel, .fitting-compatible-panel,
  .fitting-item-info-panel, .object-detail-popup, .target-panel, .knowledge-detail, .schedule-panel)::before {
  border-image-source: url("./rss/svg/9slice-box_main1_shadow.svg?release=1ab06ec4ffb09b19942a9b7c");
  transform: translate(4px, 4px);
  opacity: 0.25;
  z-index: -2;
}

:root[data-environment-mode] .object-detail-popup {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.object-detail-popup-header {
  flex-shrink: 0;
}

.object-detail-popup-body {
  display: grid;
  gap: 1.1vh;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

:is(.player-popup-body, .ship-info-body, .ship-fitting-body,
  .fitting-compatible-body, .fitting-item-info-body) {
  min-height: 0;
  overscroll-behavior: contain;
}

:is(.object-list-title, .player-popup-title, .minimap-title, .ship-info-title,
  .ship-fitting-title, .fitting-compatible-title, .fitting-item-info-title) {
  color: var(--text);
  font-weight: 800;
}

/* Scanner and map use a neutral popup palette in both environments. */
:root[data-environment-mode] :is(.object-list-panel, .minimap-panel) {
  --text: #222222;
  --muted: rgba(0, 0, 0, 0.6);
  --line: rgba(0, 0, 0, 0.25);
  --svg-default-color: var(--text);
  --ui_target_color: var(--text);
  --ui_color: var(--text);
  --accent: var(--text);
  --primary: var(--text);
  --primary-text: var(--text);
  --panel: rgba(255, 255, 255, 0.85);
  --bg: #ffffff;
  --navigate-border: rgba(0, 0, 0, 0.5);
  --navigate-bg: rgba(0, 0, 0, 0.08);
  --row-hover-bg: rgba(0, 0, 0, 0.04);
  --row-active-bg: rgba(0, 0, 0, 0.08);
  --row-active-shadow: rgba(0, 0, 0, 0.12);
  --bubble-border: rgba(0, 0, 0, 0.2);
}

:root[data-environment-mode] .object-list-panel :is(.object-list-sort-button, .object-list-sort-menu) {
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1vh 2.6vh rgba(0, 0, 0, 0.12);
}

.minimap-panel .minimap-object-toast {
  box-shadow: 0 1.1vh 3.2vh rgba(0, 0, 0, 0.2);
}

/* The 8px resource corners overlay a 4% light / 16% dark surface.
   White popups keep their fixed light palette, including their buttons. */
:root[data-environment-mode] :is(.readout, .selection-summary, .docking-undock-button,
  .object-bubble-button, .object-navigate-button) {
  isolation: isolate;
  border: 0;
  border-radius: 0;
  background: var(--game-ui-button-bg);
  box-shadow: none;
  backdrop-filter: none;
  color: var(--game-ui-button-color);
}

:is(.object-bubble-button, .object-navigate-button) {
  position: relative;
}

:root :is(.object-bubble-button, .object-navigate-button) {
  padding-inline: 16px;
}

:is(.readout, .selection-summary, .docking-undock-button,
  .object-bubble-button, .object-navigate-button)::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 8px solid transparent;
  border-image: url("./rss/svg/9slice-box_button1.svg?release=1ab06ec4ffb09b19942a9b7c") 8 fill / 8px / 0 stretch;
  pointer-events: none;
  z-index: -1;
  filter: var(--game-ui-button-filter);
}

:root :is(.readout, .selection-summary, .docking-undock-button,
  .object-bubble-button, .object-navigate-button):is(:disabled, [aria-disabled="true"]) {
  opacity: 0.5;
}

:root :is(.readout, .selection-summary, .docking-undock-button,
  .object-bubble-button, .object-navigate-button):focus-visible {
  outline: 2px solid var(--game-ui-button-color) !important;
  outline-offset: 6px;
}

:is(.readout, .selection-summary) :is(.readout-row, .readout-axis, .readout-value,
  .readout-location, .selection-clear, .selection-focus) {
  color: inherit;
}


/* These HUD groups invert as a whole; descendants keep their original paints.
   Reset the older per-resource filters to avoid applying inversion twice. */
:root[data-environment-mode] :is(#bottomNavMenu, .readout, .selection-summary) {
  --game-ui-button-color: #000000;
  --game-ui-button-filter: none;
  --ui-svg-filter: invert(0);
  filter: var(--hud-resource-filter);
}

/* Menu resources are local to the burger menu, not global icon replacements. */
#bottomNavMenu .svg-icon-setting { --svg-icon-source: url('./rss/svg/icn_setting.svg?release=1ab06ec4ffb09b19942a9b7c'); }
#bottomNavMenu .svg-icon-scan { --svg-icon-source: url('./rss/svg/icn_scanner.svg?release=1ab06ec4ffb09b19942a9b7c'); }
#bottomNavMenu .svg-icon-ship { --svg-icon-source: url('./rss/svg/icn_player-ship.svg?release=1ab06ec4ffb09b19942a9b7c'); }
#bottomNavMenu .svg-icon-player { --svg-icon-source: url('./rss/svg/icn_player.svg?release=1ab06ec4ffb09b19942a9b7c'); }
#bottomNavMenu .svg-icon-asset { --svg-icon-source: url('./rss/svg/icn_account-asset.svg?release=1ab06ec4ffb09b19942a9b7c'); }
#bottomNavMenu .svg-icon-message { --svg-icon-source: url('./rss/svg/icn_event-message.svg?release=1ab06ec4ffb09b19942a9b7c'); }

/* Reusable original/inverted SVG display. Use theme-svg on an <img> or inline
   SVG; icon spans below display their original source without masking colors.
   The inherited filter is reset by the fixed-light popup palette above. */
.theme-svg,
:is(.svg-icon-menu, .svg-icon-main-toggle, .svg-icon-main, .svg-icon-to-do,
  .svg-icon-message, .svg-icon-scan, .svg-icon-player, .svg-icon-ship, .svg-icon-asset,
  .svg-icon-target, .svg-icon-drop-arrow, .svg-icon-arrow-right, .svg-icon-chron) {
  filter: var(--ui-svg-filter);
}

:is(.svg-icon-menu, .svg-icon-main-toggle, .svg-icon-main, .svg-icon-to-do,
  .svg-icon-message, .svg-icon-scan, .svg-icon-player, .svg-icon-ship, .svg-icon-asset,
  .svg-icon-target, .svg-icon-drop-arrow, .svg-icon-arrow-right, .svg-icon-chron) {
  background: var(--svg-icon-source) center / contain no-repeat;
  -webkit-mask: none;
  mask: none;
}

/* All existing static and dynamically created close icons share this mask. */
:root .svg-icon-close {
  --svg-icon-source: url("./rss/svg/btn_pop_close.svg?release=1ab06ec4ffb09b19942a9b7c");
  color: var(--game-ui-button-color);
}

:root :is(.object-list-close, .object-detail-popup-close) {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--game-ui-button-color);
  transition: transform 80ms ease;
}

:root :is(.object-list-close, .object-detail-popup-close):active:not(:disabled):not([aria-disabled="true"]) {
  background: transparent;
  transform: translateY(2px);
}

:root :is(.object-list-close, .object-detail-popup-close) .svg-icon-close {
  width: 48px;
  height: 48px;
}

/* Notifications share a top stack: no panel, hit area, shadow or button states. */
.toast-stack {
  position: fixed;
  z-index: 1000;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, calc(100% - 32px));
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
}

:root :is(.toast, .error-toast) {
  position: static;
  inset: auto;
  width: fit-content;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  box-shadow: none;
  color: var(--game-ui-text);
  font-size: clamp(14px, 1.7vh, 20px);
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  overflow-wrap: anywhere;
  transform: translateY(-4px);
  pointer-events: none;
}

:root :is(.toast, .error-toast).visible {
  transform: none;
}

.toast:not(.visible),
.error-toast[hidden] {
  display: none;
}

/* Updated black artwork is displayed directly without tinting or masks. */
:root .svg-icon-close {
  width: 48px;
  height: 48px;
  background: var(--svg-icon-source) center / contain no-repeat;
  mask: none;
  -webkit-mask: none;
  filter: none;
}

:root :is(.object-list-close, .object-detail-popup-close) {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
}

:root .svg-icon-chron {
  filter: none;
}

/* HUD selection dismissal is independent of popup close buttons. */
.selection-summary .selection-clear {
  display: grid;
  place-items: center;
  width: 3vh;
  height: 3vh;
  padding: 0;
  flex-shrink: 0;
  color: inherit;
  border: 0;
  background: transparent;
  transition: none;
}

.selection-clear-icon {
  display: block;
  width: 3vh;
  height: 3vh;
  background-color: currentColor;
  mask: url("./rss/svg/btn_pop_close.svg?release=1ab06ec4ffb09b19942a9b7c") center / contain no-repeat;
  -webkit-mask: url("./rss/svg/btn_pop_close.svg?release=1ab06ec4ffb09b19942a9b7c") center / contain no-repeat;
}

/* Hide scrollbar chrome globally while retaining native scrolling. */
* {
  scrollbar-width: none !important;
}

*::-webkit-scrollbar {
  display: none !important;
}

:root[data-environment-mode] .object-list-panel .object-list-sort-button.active {
  box-shadow: none;
}

.navigation-recovery-overlay { position: fixed; inset: 0; z-index: 10000; pointer-events: auto; overflow: hidden; touch-action: none; }
.navigation-recovery-signal, .navigation-recovery-color { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.navigation-recovery-signal { display: block; }
.navigation-recovery-color { opacity: 0; }

/* Production information inside the existing object detail frame. */
.facility-detail-host { grid-column: 1 / -1; min-width: 0; }
.facility-production-detail { display: grid; gap: 10px; margin: 16px 0; color: var(--text); }
.facility-production-detail h4 { margin: 8px 0 0; font-size: 1em; }
.facility-production-detail p { margin: 0; }
.facility-recipe-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.facility-recipe-list li { padding: 10px; background: var(--row-active-bg); border: 1px solid var(--line); overflow-wrap: anywhere; }
.facility-recipe-duration { float: right; margin-left: 12px; font-variant-numeric: tabular-nums; }
.facility-recipe-inputs { clear: both; padding-top: 5px; color: var(--muted); font-size: .9em; }
.facility-line-list { display: grid; gap: 8px; }
.facility-line-detail { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 6px 12px; padding: 10px; border: 1px solid var(--line); }
.facility-line-status, .facility-line-detail progress, .facility-line-detail small { grid-column: 1 / -1; }
.facility-line-detail progress { width: 100%; height: 6px; accent-color: var(--text); }
.facility-line-status { color: var(--muted); font-variant-numeric: tabular-nums; }
.facility-detail-status { margin: 12px 0; color: var(--muted); }
