:root {
  --orange: #ff6a00;
  --orange-soft: rgba(255, 106, 0, .34);
  --orange-dim: rgba(255, 106, 0, .16);
  --green: #67ff75;
  --bg: #050301;
  --hud-bg: rgba(12, 6, 2, .72);
  --hud-border: rgba(255, 106, 0, .78);
  --terminal-ratio: 1.5;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: #ffd8ad;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

button { font: inherit; }

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  isolation: isolate;
}

.grid-layer {
  position: fixed;
  inset: -2px;
  z-index: -3;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 106, 0, .18), transparent 38%),
    linear-gradient(rgba(255, 106, 0, .22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 106, 0, .22) 1px, transparent 1px),
    #030201;
  background-size: auto, 46px 46px, 46px 46px, auto;
  background-position: center;
}

.glow-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse at center, rgba(255, 124, 0, .28), transparent 34%),
    radial-gradient(ellipse at center, transparent 52%, rgba(0,0,0,.88) 100%);
  pointer-events: none;
}

.terminal-stage {
  position: relative;
  width: min(96vw, calc(96svh * var(--terminal-ratio)));
  aspect-ratio: 1536 / 1024;
  max-height: 96svh;
  filter: drop-shadow(0 36px 48px rgba(0,0,0,.72));
}

.terminal-skin {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 2;
  user-select: none;
  pointer-events: none;
}

.crt-screen {
  position: absolute;
  left: 25.4%;
  top: 20.9%;
  width: 49.4%;
  height: 49.5%;
  z-index: 3;
  border-radius: 8% / 10%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(25, 25, 22, .78), rgba(0,0,0,.96) 72%);
  box-shadow: inset 0 0 40px rgba(0,0,0,.95), inset 0 0 12px rgba(255,124,0,.11);
}

.card-image {
  position: relative;
  z-index: 3;
  height: 86%;
  max-width: 62%;
  object-fit: contain;
  border-radius: 3.2%;
  box-shadow: 0 0 18px rgba(255, 106, 0, .22), 0 20px 24px rgba(0,0,0,.48);
  opacity: 0;
  transform: scale(.98);
  transition: opacity .25s ease, transform .25s ease;
}

.card-image.loaded { opacity: 1; transform: scale(1); }

.boot-text {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: .4em;
  text-align: center;
  color: rgba(255, 106, 0, .76);
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: clamp(.5rem, 1.15vw, 1rem);
}

.boot-text.hide { display: none; }

.crt-glass,
.scanlines,
.screen-hud-line {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crt-glass {
  z-index: 4;
  background:
    radial-gradient(ellipse at 45% 25%, rgba(255,255,255,.16), transparent 28%),
    radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,.5) 100%);
  mix-blend-mode: screen;
}

.scanlines {
  z-index: 5;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.055) 0 1px, transparent 1px 4px);
  opacity: .55;
}

.screen-hud-line {
  z-index: 6;
  border: 1px solid transparent;
}
.screen-hud-line.top-left {
  inset: 7% 8% 12% 8%;
  border-top-color: rgba(255,106,0,.5);
  border-left-color: rgba(255,106,0,.5);
  border-radius: 18px 0 0 0;
}
.screen-hud-line.bottom-right {
  inset: 12% 8% 7% 8%;
  border-right-color: rgba(255,106,0,.35);
  border-bottom-color: rgba(255,106,0,.35);
  border-radius: 0 0 18px 0;
}

.hud-panel {
  position: absolute;
  z-index: 5;
  width: clamp(175px, 15.5vw, 255px);
  padding: clamp(10px, 1vw, 16px);
  color: #ff8a22;
  background: linear-gradient(180deg, rgba(19, 10, 3, .78), rgba(8, 4, 1, .58));
  border: 1px solid var(--hud-border);
  box-shadow: 0 0 28px rgba(255,106,0,.12), inset 0 0 20px rgba(255,106,0,.05);
  backdrop-filter: blur(4px);
  text-transform: uppercase;
}

.hud-panel::before,
.hud-panel::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--orange);
  border-style: solid;
  pointer-events: none;
}
.hud-panel::before { top: -2px; left: -2px; border-width: 2px 0 0 2px; }
.hud-panel::after { bottom: -2px; right: -2px; border-width: 0 2px 2px 0; }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #ff7a18;
  font-weight: 800;
  font-size: clamp(.72rem, .95vw, 1rem);
  margin-bottom: 12px;
}

.panel-head button {
  border: 0;
  background: transparent;
  color: #ff7a18;
  padding: 0;
}

.hud-panel dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  margin: 0;
  font-size: clamp(.58rem, .75vw, .82rem);
  line-height: 1.15;
}

.hud-panel dt { color: #ff6a00; }
.hud-panel dd { margin: 0; color: #ffe2bd; text-align: right; }
.hud-panel .online { color: var(--green); }

.panel-left-top { left: -1.2%; top: 13%; }
.panel-left-bottom { left: -1.2%; bottom: 15%; }
.panel-right-top { right: -1.2%; top: 13%; }
.panel-right-bottom { right: -1.2%; bottom: 15%; }

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.control-grid button,
.mobile-dock button {
  color: #ff8a22;
  background: rgba(0,0,0,.32);
  border: 1px solid var(--hud-border);
  min-height: 34px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: inset 0 0 16px rgba(255,106,0,.04);
}

.control-grid button:hover,
.mobile-dock button:hover {
  background: rgba(255,106,0,.12);
}

.mobile-dock { display: none; }

@media (max-width: 920px), (max-height: 620px) {
  .terminal-stage {
    width: min(99vw, calc(92svh * var(--terminal-ratio)));
  }
  .hud-panel { width: clamp(150px, 24vw, 210px); }
  .market, .system { display: none; }
  .panel-left-top { left: 2%; top: 10%; }
  .panel-right-bottom { right: 2%; bottom: 12%; }
}

@media (max-width: 640px) {
  .grid-layer { background-size: auto, 34px 34px, 34px 34px, auto; }
  .terminal-stage {
    width: 118vw;
    max-width: none;
    transform: translateY(-4svh);
  }
  .card-info {
    left: 6%;
    top: 8%;
    width: 38vw;
    padding: 9px;
  }
  .card-info dl { grid-template-columns: 1fr; gap: 3px; }
  .card-info dd { text-align: left; margin-bottom: 4px; }
  .controls { display: none; }
  .mobile-dock {
    position: absolute;
    z-index: 7;
    left: 50%;
    bottom: 6.5%;
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: min(76vw, 360px);
  }
  .mobile-dock button {
    min-height: 40px;
    background: rgba(8, 3, 0, .76);
    backdrop-filter: blur(4px);
  }
  .boot-text { font-size: .55rem; }
}

@media (max-width: 440px) {
  .terminal-stage { width: 140vw; transform: translateY(-2svh); }
  .card-info { display: none; }
  .mobile-dock { bottom: 8%; width: 72vw; }
}


/* v10 monitor cleanup: remove orange screen HUD lines and fit card fully inside CRT */
.screen-hud-line { display: none !important; }

.crt-screen {
  isolation: isolate;
}

.card-image {
  height: 72% !important;
  max-width: 50% !important;
  object-fit: contain !important;
  border-radius: 3.2%;
  filter: saturate(.9) contrast(.93) brightness(.86) sepia(.08);
  box-shadow:
    0 0 10px rgba(255, 106, 0, .14),
    0 12px 22px rgba(0,0,0,.62);
}

/* Extra glass layer so the card feels embedded behind the CRT surface */
.crt-glass {
  z-index: 6;
  background:
    linear-gradient(115deg, rgba(255,255,255,.14) 0%, rgba(255,255,255,.045) 18%, transparent 36%),
    radial-gradient(ellipse at 50% 45%, rgba(255, 124, 0, .08), transparent 48%),
    radial-gradient(ellipse at center, transparent 42%, rgba(0,0,0,.58) 100%);
  mix-blend-mode: screen;
}

.scanlines {
  z-index: 7;
  background:
    repeating-linear-gradient(to bottom, rgba(255,255,255,.045) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(to right, rgba(255,106,0,.012) 0 1px, transparent 1px 5px);
  opacity: .68;
}

.crt-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  border-radius: inherit;
  box-shadow:
    inset 0 0 28px rgba(0,0,0,.92),
    inset 0 0 72px rgba(0,0,0,.72),
    inset 0 0 10px rgba(255,124,0,.10);
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0,0,0,.38) 100%);
}

@media (max-width: 640px) {
  .card-image {
    height: 66% !important;
    max-width: 48% !important;
  }
}

/* v11 mobile optimization: no side cut-off, no page scroll, compact HUD. */
.mobile-hud { display: none; }

@media (max-width: 640px) {
  html,
  body {
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
  }

  .app {
    place-items: start center;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .grid-layer {
    background-size: auto, 34px 34px, 34px 34px, auto;
    background-position: center top;
  }

  .glow-layer {
    background:
      radial-gradient(ellipse at 50% 32%, rgba(255, 124, 0, .24), transparent 32%),
      radial-gradient(ellipse at center, transparent 48%, rgba(0,0,0,.9) 100%);
  }

  .terminal-stage {
    width: 100vw;
    max-width: 100vw;
    max-height: none;
    transform: translateY(6svh);
    filter: drop-shadow(0 18px 28px rgba(0,0,0,.72));
  }

  .terminal-skin {
    object-fit: contain;
  }

  .crt-screen {
    left: 25.4%;
    top: 20.9%;
    width: 49.4%;
    height: 49.5%;
  }

  .card-image {
    height: 62% !important;
    max-width: 45% !important;
    margin-top: -4px;
  }

  .hud-panel {
    display: none !important;
  }

  .mobile-hud {
    position: fixed;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(88px + env(safe-area-inset-bottom));
    z-index: 30;
    display: grid;
    gap: 7px;
    padding: 11px 12px;
    color: #ff8a22;
    background: linear-gradient(180deg, rgba(19, 10, 3, .82), rgba(8, 4, 1, .66));
    border: 1px solid rgba(255, 106, 0, .82);
    box-shadow: 0 0 24px rgba(255,106,0,.16), inset 0 0 20px rgba(255,106,0,.05);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .04em;
  }

  .mobile-hud::before,
  .mobile-hud::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border-color: var(--orange);
    border-style: solid;
    pointer-events: none;
  }

  .mobile-hud::before { top: -2px; left: -2px; border-width: 2px 0 0 2px; }
  .mobile-hud::after { bottom: -2px; right: -2px; border-width: 0 2px 2px 0; }

  .mobile-hud-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    min-width: 0;
  }

  .mobile-hud-row span {
    color: #ff6a00;
    white-space: nowrap;
  }

  .mobile-hud-row strong {
    color: #ffe2bd;
    font-weight: 700;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-hud-row.compact {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    color: #ffe2bd;
  }

  .mobile-hud-row.compact span {
    color: #ffe2bd;
    text-align: center;
    border-top: 1px solid rgba(255,106,0,.22);
    padding-top: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-dock {
    position: fixed;
    z-index: 31;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: auto;
  }

  .mobile-dock button {
    min-height: 48px;
    color: #ff8a22;
    background: rgba(8, 3, 0, .78);
    border: 1px solid rgba(255, 106, 0, .82);
    box-shadow: 0 0 18px rgba(255,106,0,.12), inset 0 0 14px rgba(255,106,0,.05);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: 13px;
    letter-spacing: .08em;
  }

  .boot-text { font-size: .5rem; }
}

@media (max-width: 440px) {
  .terminal-stage {
    width: 100vw;
    max-width: 100vw;
    transform: translateY(7svh);
  }

  .card-image {
    height: 60% !important;
    max-width: 44% !important;
  }

  .mobile-hud {
    bottom: calc(86px + env(safe-area-inset-bottom));
    font-size: 10px;
  }
}

@media (max-height: 720px) and (max-width: 640px) {
  .terminal-stage {
    width: 92vw;
    transform: translateY(2svh);
  }

  .mobile-hud {
    bottom: calc(76px + env(safe-area-inset-bottom));
    padding: 8px 10px;
    gap: 5px;
  }

  .mobile-dock {
    bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .mobile-dock button {
    min-height: 42px;
  }
}

/* v12 mobile HUD placement: move info panel below the physical monitor so it does not cover the card/screen. */
@media (max-width: 640px) {
  .terminal-stage {
    transform: translateY(2svh);
  }

  .mobile-hud {
    top: clamp(360px, 60svh, 500px);
    bottom: auto;
  }

  .mobile-dock {
    top: clamp(460px, calc(60svh + 104px), 610px);
    bottom: auto;
  }
}

@media (max-width: 440px) {
  .terminal-stage {
    transform: translateY(1svh);
  }

  .mobile-hud {
    top: clamp(350px, 58svh, 480px);
    bottom: auto;
  }

  .mobile-dock {
    top: clamp(452px, calc(58svh + 104px), 590px);
    bottom: auto;
  }
}

@media (max-height: 720px) and (max-width: 640px) {
  .terminal-stage {
    width: 92vw;
    transform: translateY(0);
  }

  .mobile-hud {
    top: 58svh;
    bottom: auto;
    padding: 8px 10px;
    gap: 5px;
  }

  .mobile-dock {
    top: calc(58svh + 96px);
    bottom: auto;
  }
}


/* v13 boot screen + card load sound support */
.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255, 106, 0, .16), transparent 34%),
    #030201;
  color: #ff8a22;
  transition: opacity .65s ease, visibility .65s ease;
}

.boot-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-grid {
  position: absolute;
  inset: -2px;
  opacity: .6;
  background:
    linear-gradient(rgba(255, 106, 0, .22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 106, 0, .22) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse at center, black 0 52%, transparent 78%);
}

.boot-window {
  position: relative;
  width: min(560px, calc(100vw - 32px));
  padding: 22px;
  background: linear-gradient(180deg, rgba(18, 8, 2, .88), rgba(5, 2, 0, .78));
  border: 1px solid rgba(255, 106, 0, .82);
  box-shadow:
    0 0 36px rgba(255, 106, 0, .18),
    inset 0 0 28px rgba(255, 106, 0, .06);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-transform: uppercase;
}

.boot-window::before,
.boot-window::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: var(--orange);
  border-style: solid;
  pointer-events: none;
}

.boot-window::before {
  top: -2px;
  left: -2px;
  border-width: 2px 0 0 2px;
}

.boot-window::after {
  right: -2px;
  bottom: -2px;
  border-width: 0 2px 2px 0;
}

.boot-window-top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 106, 0, .34);
  font-weight: 800;
  letter-spacing: .08em;
}

.boot-sequence {
  min-height: 124px;
  display: grid;
  align-content: start;
  gap: 8px;
  color: rgba(255, 216, 173, .92);
  font-size: clamp(.72rem, 2.6vw, .96rem);
  line-height: 1.25;
}

.boot-sequence p {
  margin: 0;
  opacity: .88;
}

.boot-start {
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
  color: #ff8a22;
  background: rgba(0,0,0,.38);
  border: 1px solid rgba(255, 106, 0, .88);
  box-shadow: inset 0 0 18px rgba(255,106,0,.08), 0 0 20px rgba(255,106,0,.1);
  text-transform: uppercase;
  cursor: pointer;
  letter-spacing: .12em;
}

.boot-start:hover {
  background: rgba(255,106,0,.12);
}

.boot-start:disabled {
  cursor: default;
  opacity: .72;
}

.boot-note {
  margin: 10px 0 0;
  color: rgba(255, 138, 34, .7);
  font-size: .72rem;
  letter-spacing: .08em;
  text-align: center;
}

.card-image.is-loading {
  opacity: .16;
  filter: saturate(.75) contrast(.88) brightness(.62) sepia(.14);
}

.crt-screen.is-loading::before {
  content: "LOADING CARD DATA";
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 10%;
  transform: translateX(-50%);
  color: rgba(255, 106, 0, .76);
  font-size: clamp(.42rem, .72vw, .72rem);
  letter-spacing: .12em;
  text-transform: uppercase;
  text-shadow: 0 0 8px rgba(255,106,0,.4);
  pointer-events: none;
}

@media (max-width: 640px) {
  .boot-window {
    width: calc(100vw - 28px);
    padding: 18px;
  }

  .boot-window-top {
    font-size: .72rem;
  }

  .boot-sequence {
    min-height: 112px;
  }
}

/* v14 mobile spacing + larger mobile card */
@media (max-width: 640px) {
  .terminal-stage {
    /* Bring the machine lower so it sits closer to the mobile HUD. */
    transform: translateY(9svh) !important;
  }

  .card-image {
    /* Make cards easier to see on phones while still staying inside the CRT. */
    height: 74% !important;
    max-width: 56% !important;
    margin-top: -2px !important;
  }

  .glow-layer {
    background:
      radial-gradient(ellipse at 50% 40%, rgba(255, 124, 0, .26), transparent 34%),
      radial-gradient(ellipse at center, transparent 48%, rgba(0,0,0,.9) 100%);
  }
}

@media (max-width: 440px) {
  .terminal-stage {
    transform: translateY(8svh) !important;
  }

  .card-image {
    height: 76% !important;
    max-width: 58% !important;
  }
}

@media (max-height: 720px) and (max-width: 640px) {
  .terminal-stage {
    width: 92vw;
    transform: translateY(5svh) !important;
  }

  .card-image {
    height: 74% !important;
    max-width: 56% !important;
  }
}

/* v15 mobile refinement: lower terminal closer to HUD + true card centering */
.card-image {
  position: absolute !important;
  left: 50% !important;
  top: 50% !important;
  margin: 0 !important;
  transform: translate(-50%, -50%) scale(.98) !important;
}

.card-image.loaded {
  transform: translate(-50%, -50%) scale(1) !important;
}

@media (max-width: 640px) {
  .terminal-stage {
    /* Move the terminal down more on phones so the monitor sits closer to the HUD stack. */
    transform: translateY(15svh) !important;
  }

  .card-image {
    height: 76% !important;
    max-width: 58% !important;
  }

  .mobile-hud {
    /* Pull HUD up slightly so it visually locks to the bottom of the monitor/terminal. */
    top: clamp(390px, 57svh, 510px) !important;
    bottom: auto !important;
  }

  .mobile-dock {
    top: clamp(490px, calc(57svh + 106px), 620px) !important;
    bottom: auto !important;
  }
}

@media (max-width: 440px) {
  .terminal-stage {
    transform: translateY(14svh) !important;
  }

  .card-image {
    height: 78% !important;
    max-width: 60% !important;
  }

  .mobile-hud {
    top: clamp(382px, 56svh, 500px) !important;
  }

  .mobile-dock {
    top: clamp(482px, calc(56svh + 106px), 608px) !important;
  }
}

@media (max-height: 720px) and (max-width: 640px) {
  .terminal-stage {
    width: 94vw !important;
    transform: translateY(8svh) !important;
  }

  .card-image {
    height: 76% !important;
    max-width: 58% !important;
  }

  .mobile-hud {
    top: 56svh !important;
    padding: 8px 10px;
    gap: 5px;
  }

  .mobile-dock {
    top: calc(56svh + 94px) !important;
  }
}

/* v16 mobile gap filler: rarity/star HUD between terminal and main mobile HUD */
.mobile-rarity-hud { display: none; }

@media (max-width: 640px) {
  .terminal-stage {
    transform: translateY(12svh) !important;
  }

  .mobile-rarity-hud {
    position: fixed;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    top: clamp(312px, 42svh, 410px);
    z-index: 30;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: #ff8a22;
    background: linear-gradient(180deg, rgba(19, 10, 3, .74), rgba(8, 4, 1, .52));
    border: 1px solid rgba(255, 106, 0, .72);
    box-shadow: 0 0 22px rgba(255,106,0,.14), inset 0 0 18px rgba(255,106,0,.045);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .05em;
  }

  .mobile-rarity-hud::before,
  .mobile-rarity-hud::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border-color: var(--orange);
    border-style: solid;
    pointer-events: none;
  }

  .mobile-rarity-hud::before { top: -2px; left: -2px; border-width: 2px 0 0 2px; }
  .mobile-rarity-hud::after { bottom: -2px; right: -2px; border-width: 0 2px 2px 0; }

  .mobile-rarity-row {
    display: grid;
    gap: 4px;
    min-width: 0;
  }

  .mobile-rarity-row:last-child { text-align: right; }

  .mobile-rarity-row span {
    color: #ff6a00;
    opacity: .92;
  }

  .mobile-rarity-row strong {
    color: #ffe2bd;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-rarity-row.subtle strong { color: #ffbd80; }

  .mobile-star-meter {
    color: #ff9a2a;
    font-size: 15px;
    letter-spacing: .08em;
    text-shadow: 0 0 12px rgba(255,106,0,.42);
    white-space: nowrap;
  }

  .mobile-hud {
    top: clamp(382px, 51svh, 500px) !important;
  }

  .mobile-dock {
    top: clamp(482px, calc(51svh + 106px), 610px) !important;
  }
}

@media (max-width: 440px) {
  .terminal-stage {
    transform: translateY(11svh) !important;
  }

  .mobile-rarity-hud {
    top: clamp(318px, 43svh, 390px);
    grid-template-columns: 1fr auto;
  }

  .mobile-rarity-row.subtle { display: none; }

  .mobile-hud {
    top: clamp(390px, 52svh, 485px) !important;
  }

  .mobile-dock {
    top: clamp(490px, calc(52svh + 106px), 595px) !important;
  }
}

@media (max-height: 720px) and (max-width: 640px) {
  .terminal-stage {
    width: 94vw !important;
    transform: translateY(6svh) !important;
  }

  .mobile-rarity-hud {
    top: 43svh;
    padding: 8px 10px;
  }

  .mobile-hud {
    top: 51svh !important;
  }

  .mobile-dock {
    top: calc(51svh + 94px) !important;
  }
}


/* v17 mobile enlarge viewer */
.card-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 106, 0, .16), transparent 40%),
    rgba(0,0,0,.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.card-modal.active { display: grid; }

.modal-frame {
  position: relative;
  width: min(88vw, 440px);
  padding: 14px;
  color: #ff8a22;
  background: linear-gradient(180deg, rgba(18, 8, 2, .94), rgba(5, 2, 0, .9));
  border: 1px solid rgba(255, 106, 0, .86);
  box-shadow: 0 0 42px rgba(255,106,0,.22), inset 0 0 24px rgba(255,106,0,.06);
  text-transform: uppercase;
}

.modal-frame::before,
.modal-frame::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--orange);
  border-style: solid;
  pointer-events: none;
}
.modal-frame::before { top: -2px; left: -2px; border-width: 2px 0 0 2px; }
.modal-frame::after { bottom: -2px; right: -2px; border-width: 0 2px 2px 0; }

.modal-head,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  letter-spacing: .08em;
}

.modal-head { margin-bottom: 12px; }
.modal-footer { margin-top: 12px; color: #ffe2bd; font-size: 11px; }
.modal-footer span:last-child { text-align: right; color: #ffbd80; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal-close {
  border: 1px solid rgba(255, 106, 0, .72);
  background: rgba(0,0,0,.36);
  color: #ff8a22;
  min-width: 34px;
  min-height: 30px;
  cursor: pointer;
}

.modal-crt {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  padding: 12px;
  background: radial-gradient(ellipse at center, rgba(25, 24, 20, .8), rgba(0,0,0,.96) 72%);
  box-shadow: inset 0 0 34px rgba(0,0,0,.95), inset 0 0 12px rgba(255,124,0,.12);
}

.modal-crt img {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  max-height: 70svh;
  object-fit: contain;
  border-radius: 10px;
  filter: saturate(.92) contrast(.94) brightness(.88) sepia(.08);
  box-shadow: 0 0 22px rgba(255,106,0,.16), 0 18px 28px rgba(0,0,0,.66);
}

.modal-glass,
.modal-scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.modal-glass {
  z-index: 3;
  background:
    linear-gradient(115deg, rgba(255,255,255,.16) 0%, rgba(255,255,255,.045) 20%, transparent 38%),
    radial-gradient(ellipse at center, transparent 48%, rgba(0,0,0,.48) 100%);
  mix-blend-mode: screen;
}

.modal-scanlines {
  z-index: 4;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.045) 0 1px, transparent 1px 4px);
  opacity: .72;
}

@media (min-width: 641px) {
  .card-modal { display: none !important; }
}

/* v19 market/archive upgrades */
.mobile-market-hud {
  display: none;
}

.modal-market {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 106, 0, .22);
  color: #ff8a22;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.modal-market strong {
  color: #ffe2bd;
  font-weight: 800;
}

.crt-screen.is-scanning::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -18%;
  height: 18%;
  z-index: 9;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(255, 106, 0, .34), transparent);
  animation: scan-pass .82s ease-out;
}

@keyframes scan-pass {
  from { transform: translateY(0); opacity: .25; }
  40% { opacity: .9; }
  to { transform: translateY(680%); opacity: 0; }
}

.card-image.is-loading {
  filter: saturate(.75) contrast(.9) brightness(.62) sepia(.12);
}

@media (max-width: 640px) {
  .mobile-market-hud {
    position: fixed;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    top: clamp(488px, calc(51svh + 108px), 616px);
    z-index: 30;
    display: grid;
    gap: 7px;
    padding: 10px 12px;
    color: #ff8a22;
    background: linear-gradient(180deg, rgba(19, 10, 3, .84), rgba(8, 4, 1, .68));
    border: 1px solid rgba(255, 106, 0, .82);
    box-shadow: 0 0 24px rgba(255,106,0,.16), inset 0 0 20px rgba(255,106,0,.05);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .05em;
  }

  .mobile-market-hud::before,
  .mobile-market-hud::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border-color: var(--orange);
    border-style: solid;
    pointer-events: none;
  }

  .mobile-market-hud::before { top: -2px; left: -2px; border-width: 2px 0 0 2px; }
  .mobile-market-hud::after { bottom: -2px; right: -2px; border-width: 0 2px 2px 0; }

  .mobile-market-main,
  .mobile-market-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
  }

  .mobile-market-main span,
  .mobile-market-row span:first-child {
    color: #ff6a00;
  }

  .mobile-market-main strong {
    color: #ffe2bd;
    font-size: 18px;
    text-shadow: 0 0 12px rgba(255,106,0,.28);
  }

  .mobile-market-row {
    border-top: 1px solid rgba(255,106,0,.22);
    padding-top: 7px;
    color: #ffbd80;
  }

  .mobile-dock {
    top: clamp(565px, calc(51svh + 186px), 704px) !important;
  }
}

@media (max-width: 440px) {
  .mobile-market-hud {
    top: clamp(496px, calc(52svh + 108px), 595px);
  }

  .mobile-dock {
    top: clamp(572px, calc(52svh + 186px), 680px) !important;
  }
}

@media (max-height: 720px) and (max-width: 640px) {
  .mobile-market-hud {
    top: calc(51svh + 82px);
    padding: 8px 10px;
  }

  .mobile-dock {
    top: calc(51svh + 156px) !important;
  }

  .mobile-market-main strong { font-size: 16px; }
}


/* v20 mobile stack spacing: group the three mobile HUDs tightly, then separate controls. */
.mobile-info-stack { display: contents; }

@media (max-width: 640px) {
  .mobile-info-stack {
    position: fixed;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    top: clamp(430px, 51.5svh, 560px);
    z-index: 40;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    pointer-events: none;
  }

  .mobile-info-stack .mobile-rarity-hud,
  .mobile-info-stack .mobile-hud,
  .mobile-info-stack .mobile-market-hud,
  .mobile-info-stack .mobile-dock {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
  }

  .mobile-info-stack .mobile-rarity-hud,
  .mobile-info-stack .mobile-hud,
  .mobile-info-stack .mobile-market-hud {
    display: grid !important;
    pointer-events: auto;
  }

  .mobile-info-stack .mobile-dock {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px !important;
    pointer-events: auto;
  }

  .mobile-info-stack .mobile-market-hud {
    gap: 7px;
  }

  .mobile-info-stack .mobile-dock button {
    min-height: 48px;
  }
}

@media (max-width: 440px) {
  .mobile-info-stack {
    top: clamp(418px, 50svh, 540px);
    gap: 8px;
  }

  .mobile-info-stack .mobile-dock {
    margin-top: 18px !important;
  }
}

@media (max-height: 720px) and (max-width: 640px) {
  .mobile-info-stack {
    top: 50svh;
    gap: 6px;
  }

  .mobile-info-stack .mobile-rarity-hud,
  .mobile-info-stack .mobile-hud,
  .mobile-info-stack .mobile-market-hud {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .mobile-info-stack .mobile-dock {
    margin-top: 14px !important;
  }

  .mobile-info-stack .mobile-dock button {
    min-height: 42px;
  }
}

/* v21 SH-OS v4.20: rarity index, dossier mode, and market analysis */
.scan-status {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 10;
  transform: translate(-50%, -50%);
  padding: 8px 12px;
  color: rgba(255, 138, 34, .92);
  background: rgba(0,0,0,.54);
  border: 1px solid rgba(255,106,0,.38);
  font-size: clamp(.55rem, 1vw, .8rem);
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 0 18px rgba(255,106,0,.12);
}
.scan-status.active {
  animation: scanStatusPulse 1.15s ease both;
}
@keyframes scanStatusPulse {
  0%, 100% { opacity: 0; transform: translate(-50%, -44%) scale(.98); }
  18%, 78% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.rarity-meter {
  position: relative;
  height: 9px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,106,0,.16) 1px, transparent 1px),
    rgba(0,0,0,.42);
  background-size: 12px 100%;
  border: 1px solid rgba(255,106,0,.48);
  box-shadow: inset 0 0 12px rgba(0,0,0,.65), 0 0 14px rgba(255,106,0,.10);
}
.rarity-meter-fill {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, rgba(255,106,0,.72), rgba(255,198,92,.96));
  box-shadow: 0 0 16px rgba(255,106,0,.44);
  transition: width .72s cubic-bezier(.19, 1, .22, 1);
}
.mobile-rarity-hud .rarity-meter { margin: 5px 0 2px; }
.mobile-rarity-row strong#mobileRarityScore { color: #ffe2bd; }
.market-analyze-btn {
  color: #ff8a22;
  background: rgba(255,106,0,.08);
  border: 1px solid rgba(255,106,0,.55);
  padding: 3px 8px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
}
.market-analyze-btn:hover { background: rgba(255,106,0,.18); }

.card-modal.dossier-modal {
  background:
    radial-gradient(ellipse at center, rgba(255,106,0,.10), transparent 42%),
    rgba(0,0,0,.92);
}
.dossier-frame {
  width: min(94vw, 980px);
  max-height: min(94svh, 780px);
  overflow: hidden;
  display: grid;
  gap: 12px;
}
.dossier-head span::after {
  content: " // SH-OS v4.20";
  color: rgba(255,189,128,.8);
  font-weight: 500;
}
.dossier-layout {
  display: grid;
  grid-template-columns: minmax(180px, .75fr) minmax(260px, 1.05fr) minmax(180px, .75fr);
  gap: 12px;
  align-items: stretch;
}
.dossier-card-zone { min-width: 0; }
.dossier-crt {
  aspect-ratio: 3 / 4.18;
  height: min(58svh, 520px);
  margin-inline: auto;
  display: grid;
  place-items: center;
}
.dossier-crt img {
  width: auto;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
}
.dossier-panel,
.dossier-rarity-panel,
.analysis-panel {
  position: relative;
  color: #ff8a22;
  background: linear-gradient(180deg, rgba(19, 10, 3, .84), rgba(8, 4, 1, .68));
  border: 1px solid rgba(255,106,0,.72);
  box-shadow: 0 0 24px rgba(255,106,0,.13), inset 0 0 18px rgba(255,106,0,.05);
  padding: 12px;
  text-transform: uppercase;
}
.dossier-panel::before,
.dossier-panel::after,
.dossier-rarity-panel::before,
.dossier-rarity-panel::after,
.analysis-panel::before,
.analysis-panel::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: var(--orange);
  border-style: solid;
  pointer-events: none;
}
.dossier-panel::before,
.dossier-rarity-panel::before,
.analysis-panel::before { top: -2px; left: -2px; border-width: 2px 0 0 2px; }
.dossier-panel::after,
.dossier-rarity-panel::after,
.analysis-panel::after { bottom: -2px; right: -2px; border-width: 0 2px 2px 0; }
.dossier-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .08em;
  margin-bottom: 12px;
  color: #ff7a18;
}
.dossier-panel dl {
  display: grid;
  gap: 9px;
  margin: 0;
  font-size: 11px;
}
.dossier-panel dt { color: #ff6a00; }
.dossier-panel dd {
  margin: -6px 0 4px;
  color: #ffe2bd;
  font-weight: 800;
  text-align: right;
}
.dossier-titlebar {
  gap: 12px;
}
.dossier-rarity-panel {
  display: grid;
  gap: 8px;
}
.dossier-rarity-head,
.dossier-rarity-foot {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  font-size: 11px;
  letter-spacing: .08em;
}
.dossier-rarity-head strong { color: #ffe2bd; }
.dossier-rarity-foot span:first-child { color: #ffe2bd; font-weight: 800; }
.dossier-rarity-foot span:last-child { color: #ffbd80; text-align: right; }
.dossier-rarity-meter { height: 11px; }
.analysis-panel {
  position: absolute;
  inset: 52px 16px 16px auto;
  width: min(360px, calc(100% - 32px));
  z-index: 20;
  opacity: 0;
  transform: translateX(18px);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.analysis-panel.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
.analysis-head,
.analysis-grid {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.analysis-head {
  color: #ff7a18;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .08em;
  margin-bottom: 14px;
}
.analysis-head button {
  color: #ff8a22;
  background: transparent;
  border: 1px solid rgba(255,106,0,.52);
  padding: 3px 8px;
  text-transform: uppercase;
}
.analysis-grid > div {
  flex: 1;
  display: grid;
  gap: 5px;
  padding: 8px;
  background: rgba(0,0,0,.26);
  border: 1px solid rgba(255,106,0,.22);
  text-align: center;
}
.analysis-grid span { color: #ff6a00; font-size: 10px; }
.analysis-grid strong { color: var(--green); font-size: 14px; }
.analysis-chart {
  height: 96px;
  margin-top: 14px;
  display: flex;
  align-items: end;
  gap: 6px;
  padding: 10px;
  background:
    linear-gradient(rgba(255,106,0,.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,106,0,.12) 1px, transparent 1px),
    rgba(0,0,0,.22);
  background-size: 18px 18px;
  border: 1px solid rgba(255,106,0,.22);
}
.analysis-chart span {
  flex: 1;
  min-width: 5px;
  background: linear-gradient(to top, rgba(255,106,0,.55), rgba(255,213,128,.95));
  box-shadow: 0 0 10px rgba(255,106,0,.26);
}

@media (max-width: 720px) {
  .dossier-frame {
    width: min(94vw, 430px);
    max-height: 92svh;
    gap: 8px;
    padding: 12px;
  }
  .dossier-layout {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .dossier-card-zone {
    grid-column: 1 / -1;
  }
  .dossier-crt {
    height: min(43svh, 430px);
  }
  .dossier-panel,
  .dossier-rarity-panel {
    padding: 9px;
  }
  .dossier-panel-title { font-size: 10px; margin-bottom: 8px; }
  .dossier-panel dl { font-size: 9px; gap: 5px; }
  .dossier-panel dd { margin-top: -3px; }
  .dossier-rarity-head,
  .dossier-rarity-foot,
  .modal-footer { font-size: 9px; }
  .analysis-panel {
    inset: 46px 10px 10px 10px;
    width: auto;
  }
  .analysis-chart { height: 76px; }
}

/* Ensure the v20 mobile stack actually controls the mobile HUD group. */
@media (max-width: 640px) {
  .mobile-info-stack {
    position: fixed !important;
    left: max(14px, env(safe-area-inset-left)) !important;
    right: max(14px, env(safe-area-inset-right)) !important;
    top: clamp(430px, 51.5svh, 560px) !important;
    z-index: 40 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    pointer-events: none !important;
  }
  .mobile-info-stack .mobile-rarity-hud,
  .mobile-info-stack .mobile-hud,
  .mobile-info-stack .mobile-market-hud,
  .mobile-info-stack .mobile-dock {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
  }
  .mobile-info-stack .mobile-rarity-hud,
  .mobile-info-stack .mobile-hud,
  .mobile-info-stack .mobile-market-hud {
    display: grid !important;
    pointer-events: auto !important;
  }
  .mobile-info-stack .mobile-dock {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
    margin-top: 18px !important;
    pointer-events: auto !important;
  }
}

@media (max-width: 440px) {
  .mobile-info-stack {
    top: clamp(418px, 50svh, 540px) !important;
  }
}

@media (max-height: 720px) and (max-width: 640px) {
  .mobile-info-stack {
    top: 50svh !important;
    gap: 6px !important;
  }
  .mobile-info-stack .mobile-rarity-hud,
  .mobile-info-stack .mobile-hud,
  .mobile-info-stack .mobile-market-hud {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }
  .mobile-info-stack .mobile-dock {
    margin-top: 14px !important;
  }
}

/* v22 cleanup: stronger animated rarity meter, scan button label, aligned dossier data rows */
.rarity-meter {
  height: 14px !important;
  display: block;
  padding: 2px;
  border-radius: 2px;
  background:
    repeating-linear-gradient(90deg, rgba(255,106,0,.18) 0 8px, transparent 8px 12px),
    rgba(0,0,0,.55) !important;
  border: 1px solid rgba(255,106,0,.68) !important;
  box-shadow:
    inset 0 0 12px rgba(0,0,0,.78),
    0 0 16px rgba(255,106,0,.14) !important;
}

.rarity-meter-fill {
  display: block !important;
  min-width: 0;
  height: 100% !important;
  border-radius: 1px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.20) 0 2px, transparent 2px 10px),
    linear-gradient(90deg, rgba(255,92,0,.92), rgba(255,194,75,1)) !important;
  box-shadow:
    0 0 14px rgba(255,106,0,.55),
    0 0 26px rgba(255,194,75,.25) !important;
  transform-origin: left center;
  transition: width .9s cubic-bezier(.16, 1, .3, 1) !important;
}

.mobile-rarity-hud .rarity-meter {
  height: 16px !important;
  margin: 7px 0 5px !important;
}

.dossier-rarity-meter {
  height: 16px !important;
}

/* Clean, even two-column readouts for Archive Stats + Market Intel */
.dossier-panel dl,
.modal-market dl,
.hud-panel dl {
  grid-template-columns: minmax(92px, 1fr) minmax(86px, auto) !important;
  align-items: baseline;
  column-gap: 14px !important;
  row-gap: 7px !important;
}

.dossier-panel dt,
.modal-market dt,
.hud-panel dt {
  text-align: left;
  white-space: nowrap;
}

.dossier-panel dd,
.modal-market dd,
.hud-panel dd {
  min-width: 0;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dossier-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

@media (max-width: 640px) {
  .mobile-hud-row,
  .mobile-market-main,
  .mobile-market-row,
  .mobile-rarity-row {
    display: grid !important;
    grid-template-columns: minmax(74px, auto) minmax(0, 1fr) !important;
    align-items: center;
    column-gap: 12px;
  }

  .mobile-hud-row span,
  .mobile-market-main span,
  .mobile-market-row span:first-child,
  .mobile-rarity-row span {
    text-align: left;
  }

  .mobile-hud-row strong,
  .mobile-market-main strong,
  .mobile-market-row button,
  .mobile-rarity-row strong {
    justify-self: end;
    text-align: right;
  }

  .mobile-hud-row.compact {
    grid-template-columns: 1fr 1fr 1fr !important;
  }
}

/* v23 repair patch: rarity animation + dossier alignment/containment */
.rarity-meter {
  position: relative !important;
  height: 16px !important;
  padding: 2px !important;
  overflow: hidden !important;
  border-radius: 2px;
}

.rarity-meter-fill {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  transform: scaleX(0);
  transform-origin: left center;
  transition: none !important;
  will-change: transform;
}

.rarity-meter-fill.is-animating {
  animation: rarityIndexFillV23 .92s cubic-bezier(.16, 1, .3, 1) forwards;
}

@keyframes rarityIndexFillV23 {
  from { transform: scaleX(0); }
  to { transform: scaleX(var(--rarity-scale, .72)); }
}

/* Restore dossier to a contained, balanced modal. */
.dossier-frame {
  box-sizing: border-box;
  width: min(94vw, 940px) !important;
  max-width: 940px !important;
  max-height: min(92svh, 760px) !important;
  overflow: hidden !important;
}

.dossier-layout {
  box-sizing: border-box;
  grid-template-columns: minmax(170px, .78fr) minmax(250px, 1fr) minmax(170px, .78fr) !important;
  gap: 12px !important;
  width: 100%;
  min-width: 0;
}

.dossier-card-zone,
.dossier-panel,
.dossier-rarity-panel {
  min-width: 0;
}

.dossier-panel-title {
  min-height: 30px;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  margin-bottom: 10px !important;
  line-height: 1.1;
}

.dossier-left dl,
.dossier-right dl {
  display: grid !important;
  grid-template-columns: minmax(98px, 1fr) minmax(76px, auto) !important;
  align-items: baseline !important;
  column-gap: 14px !important;
  row-gap: 9px !important;
  margin: 0 !important;
}

/* The Analyze button makes the right header visually taller; lower Archive Stats data to match. */
.dossier-left dl {
  padding-top: 4px;
}

.dossier-left dt,
.dossier-right dt {
  text-align: left !important;
  white-space: nowrap;
}

.dossier-left dd,
.dossier-right dd {
  margin: 0 !important;
  text-align: right !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Keep the Analyze button exactly as a compact action inside the Market Intel title. */
.dossier-right .market-analyze-btn {
  flex: 0 0 auto;
}

@media (max-width: 720px) {
  .dossier-frame {
    width: min(92vw, 430px) !important;
    max-width: 430px !important;
    max-height: 92svh !important;
    padding: 10px !important;
    gap: 8px !important;
  }

  .dossier-layout {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .dossier-card-zone {
    grid-column: 1 / -1;
  }

  .dossier-crt {
    height: min(38svh, 360px) !important;
  }

  .dossier-panel,
  .dossier-rarity-panel {
    padding: 8px !important;
  }

  .dossier-panel-title {
    min-height: 28px;
    font-size: 9px !important;
    margin-bottom: 7px !important;
  }

  .dossier-left dl,
  .dossier-right dl {
    grid-template-columns: 1fr !important;
    row-gap: 3px !important;
    font-size: 9px !important;
  }

  .dossier-left dl {
    padding-top: 3px;
  }

  .dossier-left dd,
  .dossier-right dd {
    text-align: left !important;
    margin-bottom: 3px !important;
  }

  .dossier-right .market-analyze-btn {
    padding: 2px 6px;
    font-size: 8px;
  }
}

/* v24 targeted fixes: reliable rarity fill, restore Analyze button, final dossier alignment. */
.rarity-meter {
  height: 16px !important;
  padding: 2px !important;
  overflow: hidden !important;
  background:
    repeating-linear-gradient(90deg, rgba(255,106,0,.18) 0 8px, transparent 8px 12px),
    rgba(0,0,0,.56) !important;
}

.rarity-meter-fill {
  display: block !important;
  width: 0%;
  min-width: 0 !important;
  height: 100% !important;
  transform: none !important;
  transform-origin: left center;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.22) 0 2px, transparent 2px 10px),
    linear-gradient(90deg, rgba(255,92,0,.94), rgba(255,194,75,1)) !important;
  box-shadow:
    0 0 14px rgba(255,106,0,.58),
    0 0 28px rgba(255,194,75,.28) !important;
  transition: width .95s cubic-bezier(.16, 1, .3, 1) !important;
}

.rarity-meter-fill.is-animating {
  animation: none !important;
}

/* Keep Archive Stats and Market Intel title rows visually level. */
.dossier-panel-title {
  min-height: 32px !important;
  height: 32px !important;
  display: flex !important;
  align-items: center !important;
  margin-bottom: 10px !important;
  line-height: 1 !important;
}

.dossier-right .dossier-panel-title {
  justify-content: space-between !important;
}

/* Restore the Analyze button to the pre-cleanup size/feel. */
.dossier-right .market-analyze-btn,
.market-analyze-btn {
  padding: 3px 8px !important;
  font-size: 10px !important;
  letter-spacing: .08em !important;
  line-height: 1.2 !important;
  min-height: 0 !important;
  width: auto !important;
  flex: 0 0 auto !important;
}

/* Move the Archive Stats readout down just enough to match the Market Intel data baseline. */
.dossier-left dl {
  padding-top: 7px !important;
}

.dossier-right dl {
  padding-top: 0 !important;
}

.dossier-left dl,
.dossier-right dl {
  grid-template-columns: minmax(104px, 1fr) minmax(82px, auto) !important;
  row-gap: 9px !important;
}

@media (max-width: 720px) {
  .dossier-panel-title {
    min-height: 30px !important;
    height: 30px !important;
    margin-bottom: 8px !important;
  }
  .dossier-right .market-analyze-btn,
  .market-analyze-btn {
    padding: 3px 8px !important;
    font-size: 10px !important;
  }
  .dossier-left dl {
    padding-top: 6px !important;
  }
  .dossier-left dl,
  .dossier-right dl {
    grid-template-columns: minmax(84px, 1fr) minmax(62px, auto) !important;
    row-gap: 7px !important;
  }
}


/* v25 targeted polish: reliable rarity fill, archive ID mobile stat, and dossier alignment. */
.rarity-meter {
  overflow: hidden !important;
}

.rarity-meter-fill {
  width: 0% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  transform: none !important;
  animation: none !important;
  transition: width .95s cubic-bezier(.16, 1, .3, 1) !important;
}

/* Move Archive Stats data up slightly so it lines up with Market Intel. */
.dossier-left dl {
  padding-top: 0 !important;
  transform: translateY(-6px);
}

.dossier-right dl {
  transform: none !important;
}

/* Preserve the original Analyze button sizing. */
.dossier-right .market-analyze-btn,
#analysisToggle.market-analyze-btn {
  padding: 3px 8px !important;
  font-size: 10px !important;
  min-height: auto !important;
  line-height: 1.2 !important;
}

@media (max-width: 720px) {
  .dossier-left dl {
    transform: translateY(-4px);
  }
}


/* v26 targeted fixes: real rarity animation, cleaner analysis detail, softer graph, and final dossier baseline. */
.rarity-meter-fill {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  transform: scaleX(0) !important;
  transform-origin: left center !important;
  transition: none !important;
  animation: none !important;
  will-change: transform !important;
}

.rarity-meter-fill.is-animating {
  animation: rarityIndexFillV26 .95s cubic-bezier(.16, 1, .3, 1) forwards !important;
}

@keyframes rarityIndexFillV26 {
  0% { transform: scaleX(0); }
  100% { transform: scaleX(var(--rarity-scale, .72)); }
}

/* Archive Stats header is level; this only lowers the readout rows to match Market Intel's data baseline. */
.dossier-left dl {
  transform: translateY(4px) !important;
  padding-top: 0 !important;
}

.dossier-right dl {
  transform: none !important;
  padding-top: 0 !important;
}

/* Keep Analyze button at the prior size. */
.dossier-right .market-analyze-btn,
#analysisToggle.market-analyze-btn {
  padding: 3px 8px !important;
  font-size: 10px !important;
  line-height: 1.2 !important;
  min-height: auto !important;
}

.analysis-grid {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}

.analysis-chart span {
  background: linear-gradient(to top, rgba(255,106,0,.15), rgba(255,213,128,.15)) !important;
  border: 1px solid rgba(255,106,0,.20);
  box-shadow: 0 0 10px rgba(255,106,0,.10) !important;
}

@media (max-width: 720px) {
  .dossier-left dl {
    transform: translateY(3px) !important;
  }
  .analysis-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}


/* v27 targeted fixes: true visible rarity width fill + tiny Archive Stats baseline nudge. */
.rarity-meter {
  overflow: hidden !important;
}

.rarity-meter-fill {
  display: block !important;
  height: 100% !important;
  width: var(--rarity-width, 0%) !important;
  max-width: 100% !important;
  min-width: 0 !important;
  transform: none !important;
  animation: none !important;
  transition: width .95s cubic-bezier(.16, 1, .3, 1) !important;
  transform-origin: left center !important;
}

.rarity-meter-fill.is-animating {
  width: var(--rarity-width, 0%) !important;
  transform: none !important;
  animation: none !important;
}

/* v26 lowered this too much. Move the 4 Archive Stats lines up just a touch. */
.dossier-left dl {
  transform: translateY(2px) !important;
}

@media (max-width: 720px) {
  .dossier-left dl {
    transform: translateY(1px) !important;
  }
}


/* v28 targeted polish: score-only mobile rarity, clearer dossier labels, and tiny Archive Stats alignment. */
@media (max-width: 640px) {
  .mobile-rarity-hud .rarity-meter,
  .mobile-rarity-hud .mobile-rarity-row.subtle {
    display: none !important;
  }

  .mobile-rarity-hud {
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }

  .mobile-rarity-hud .mobile-rarity-row {
    justify-content: center !important;
    text-align: center !important;
    gap: 10px !important;
  }

  .mobile-rarity-hud .mobile-rarity-row span {
    color: #ff6a00 !important;
  }

  .mobile-rarity-hud .mobile-rarity-row strong {
    color: #ffe2bd !important;
    text-align: center !important;
    white-space: nowrap !important;
  }
}

/* v27 was still a hair low. Move only the Archive Stats readout up slightly. */
.dossier-left dl {
  transform: translateY(0px) !important;
}

@media (max-width: 720px) {
  .dossier-left dl {
    transform: translateY(0px) !important;
  }
}

/* v29 targeted rollback: restore rarity meter + classification text, and nudge Archive Stats readout up a hair. */
@media (max-width: 640px) {
  .mobile-rarity-hud .rarity-meter {
    display: block !important;
    margin: 5px 0 2px !important;
  }

  .mobile-rarity-hud .mobile-rarity-row.subtle {
    display: flex !important;
  }

  .mobile-rarity-hud {
    padding-top: 9px !important;
    padding-bottom: 9px !important;
  }

  .mobile-rarity-hud .mobile-rarity-row {
    justify-content: space-between !important;
    text-align: left !important;
  }

  .mobile-rarity-hud .mobile-rarity-row:last-child {
    text-align: right !important;
  }

  .mobile-rarity-hud .mobile-rarity-row strong {
    text-align: right !important;
  }
}

.dossier-left dl {
  transform: translateY(-2px) !important;
}

@media (max-width: 720px) {
  .dossier-left dl {
    transform: translateY(-2px) !important;
  }
}


/* v30 polish: stars-only main mobile rarity row + SH-OS v4.20 */
@media (max-width: 640px) {
  .mobile-rarity-hud {
    grid-template-columns: 1fr !important;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }

  .mobile-rarity-hud .rarity-meter {
    display: none !important;
  }

  .mobile-rarity-hud .mobile-rarity-row.rarity-stars-row {
    display: grid !important;
    grid-template-columns: 1fr auto auto !important;
    align-items: center !important;
    gap: 12px !important;
    width: 100% !important;
    text-align: left !important;
  }

  .mobile-rarity-hud .mobile-rarity-row.rarity-stars-row span {
    color: #ff6a00 !important;
    white-space: nowrap !important;
  }

  .mobile-rarity-hud .mobile-rarity-row.rarity-stars-row #mobileRarityScore {
    color: #ff9a2a !important;
    letter-spacing: .10em !important;
    text-shadow: 0 0 12px rgba(255,106,0,.42) !important;
    white-space: nowrap !important;
    font-size: 14px !important;
    text-align: right !important;
  }

  .mobile-rarity-hud .mobile-rarity-row.rarity-stars-row #mobileRarityDetail {
    color: #ffe2bd !important;
    text-align: right !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 42vw !important;
  }
}

@media (max-width: 440px) {
  .mobile-rarity-hud .mobile-rarity-row.rarity-stars-row {
    grid-template-columns: 1fr auto auto !important;
    gap: 8px !important;
  }

  .mobile-rarity-hud .mobile-rarity-row.rarity-stars-row #mobileRarityScore {
    font-size: 12px !important;
    letter-spacing: .06em !important;
  }

  .mobile-rarity-hud .mobile-rarity-row.rarity-stars-row #mobileRarityDetail {
    max-width: 34vw !important;
  }
}
