/* Orange means a capability belonging to the player. Yellow remains electricity. */
.research-moment {
  position: fixed;
  z-index: 35;
  left: 0;
  top: 110px;
  bottom: 30px;
  width: calc(100% - 390px);
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    var(--canvas) 35%,
    color-mix(in srgb, var(--canvas) 98%, transparent) 60%,
    transparent 90%
  );
}
.discovery-content {
  position: relative;
  width: min(620px, 90%);
  text-align: center;
  color: var(--fg);
  pointer-events: none;
}
.discovery-kicker {
  font-size: var(--text-meta);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.discovery-content h2 {
  font-size: clamp(var(--text-value), 3vw, var(--text-display));
  line-height: 1.15;
  margin: 0 0 12px;
  font-weight: 600;
  letter-spacing: -0.035em;
}
.discovery-content p {
  font-size: var(--text-body);
  line-height: 1.5;
  margin: 0 auto;
  max-width: 440px;
  color: var(--fg-muted);
}
.discovery-dismiss {
  position: absolute;
  top: 0;
  right: 20px;
  background: none;
  border: 0;
  color: var(--fg-muted);
  font-size: var(--text-heading);
  cursor: pointer;
  pointer-events: auto;
  padding: 8px;
}
.discovery-dismiss:hover {
  color: var(--fg);
}
.discovery-scene {
  display: block;
  width: 100%;
  height: auto;
  margin: 4px 0 12px;
  color: var(--accent);
  --structure-color: var(--accent);
  filter: drop-shadow(0 0 9px color-mix(in srgb, var(--accent) 20%, transparent));
}
.discovery-build,
.discovery-chip {
  transform-box: fill-box;
  transform-origin: center;
  animation: discovery-build 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: var(--delay, 0ms);
}
.discovery-wire {
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: discovery-wire 1.8s 0.25s ease-out forwards;
}
.discovery-signal {
  fill: var(--ok-fg);
  stroke: none;
  animation: discovery-blink 1.1s 1.2s ease-in-out infinite;
}
.discovery-data {
  animation: discovery-data 2.2s ease-in-out infinite;
  animation-delay: var(--delay, 0ms);
}
.discovery-orbit {
  animation: discovery-spin 9s linear infinite;
}
.discovery-fast {
  animation-duration: 3.4s;
}
.discovery-molecule {
  transform-box: fill-box;
  transform-origin: center;
  animation: discovery-spin 14s linear infinite;
}
.discovery-arm {
  transform-origin: -13px -36px;
  animation: discovery-wave 1.6s 1.7s ease-in-out 2;
}
.discovery-walk {
  animation: discovery-walk 2.2s ease-out both;
}
.discovery-leg {
  transform-origin: -9px -1px;
  animation: discovery-step 0.7s ease-in-out 3 alternate;
}
.discovery-other-leg {
  transform-origin: 9px -1px;
  animation: discovery-step 0.7s ease-in-out 3 alternate-reverse;
}
.discovery-eyes {
  stroke: var(--ok-fg);
  stroke-width: 3;
  animation: discovery-blink 1.2s infinite;
}
.discovery-footprint {
  animation: discovery-footprint 2.6s both;
  animation-delay: var(--delay, 0ms);
  stroke: var(--fg-subtle);
}
.discovery-ground,
.discovery-road {
  stroke: var(--border-strong);
}
.discovery-road {
  stroke-dasharray: 16 12;
}
.discovery-drive {
  animation: discovery-drive 3s ease-in-out infinite;
}
.discovery-scan {
  stroke: var(--ok-fg);
  animation: discovery-scan 2.2s ease-in-out infinite alternate;
}
.discovery-energy {
  color: var(--electricity);
  animation: discovery-blink 1.8s ease-in-out infinite;
}
.discovery-check {
  stroke: var(--ok-fg);
  stroke-width: 3;
  stroke-dasharray: 80;
  stroke-dashoffset: 80;
  animation: discovery-wire 0.7s 1.3s forwards;
}
.discovery-lift {
  animation: discovery-lift 2.2s ease-in-out infinite;
}
.discovery-conveyor {
  animation: discovery-conveyor 2.2s linear infinite;
  animation-delay: var(--delay, 0ms);
}
.discovery-horizon {
  opacity: 0.45;
  animation: discovery-build 2.4s ease-out both;
  transform-origin: 280px 125px;
}
@keyframes discovery-arrive {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes discovery-build {
  from {
    opacity: 0;
    transform: translateY(22px) scale(0.85);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes discovery-wire {
  to {
    stroke-dashoffset: 0;
  }
}
@keyframes discovery-blink {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}
@keyframes discovery-data {
  0%,
  100% {
    opacity: 0.35;
    transform: translateX(0);
  }
  50% {
    opacity: 1;
    transform: translateX(18px);
  }
}
@keyframes discovery-spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes discovery-wave {
  0%,
  100% {
    transform: rotate(0);
  }
  50% {
    transform: rotate(28deg);
  }
}
@keyframes discovery-walk {
  from {
    transform: translateX(-95px);
  }
  to {
    transform: translateX(0);
  }
}
@keyframes discovery-step {
  from {
    transform: rotate(-13deg);
  }
  to {
    transform: rotate(13deg);
  }
}
@keyframes discovery-footprint {
  0% {
    opacity: 0;
  }
  35% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
  }
}
@keyframes discovery-drive {
  0%,
  100% {
    transform: translateX(-40px);
  }
  50% {
    transform: translateX(80px);
  }
}
@keyframes discovery-scan {
  to {
    transform: translateX(120px);
  }
}
@keyframes discovery-lift {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-40px);
  }
}
@keyframes discovery-conveyor {
  from {
    transform: translateX(-25px);
  }
  to {
    transform: translateX(65px);
  }
}
@media (max-width: 900px) {
  .research-moment {
    width: calc(100% - 300px);
  }
}
@media (max-width: 650px) {
  .research-moment {
    width: 100%;
    top: 140px;
    bottom: 25%;
    background: radial-gradient(ellipse, var(--canvas) 35%, transparent 75%);
  }
  .discovery-content h2 {
    font-size: var(--text-heading);
  }
}
@media (prefers-reduced-motion: reduce) {
  .research-moment,
  .research-moment * {
    animation: none !important;
    stroke-dashoffset: 0;
  }
  .discovery-footprint {
    opacity: 0;
  }
}

.showing-discovery .earth {
  opacity: 0.1 !important;
}
.research-moment .discovery-content {
  animation: discovery-arrive 0.3s ease-out;
}

/* Discoveries take over the screen: the film is the backdrop, with a readable
   caption over its lower edge instead of a separate video card. */
.research-moment.film-discovery {
  inset: 0; width: 100%; z-index: 80; pointer-events: auto;
  background: #060e17; overflow: hidden; padding: 0; isolation: isolate;
}
.research-moment.film-discovery .discovery-content {
  position: absolute; inset: auto 0 0; width: 100%; box-sizing: border-box;
  padding: 100px clamp(24px,5vw,72px) max(32px,env(safe-area-inset-bottom));
  text-align: left; pointer-events: auto; animation: none; z-index: 2;
  background: linear-gradient(transparent,#030810b8 30%,#030810ed);
}
.moment-film-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; margin: 12px auto 20px; background: #08111b; border-radius: 8px; overflow: hidden; }
.moment-film { display: block; width: 100%; height: 100%; object-fit: contain; }
.moment-film-play { position: absolute; right: 12px; bottom: 12px; padding: 8px 14px; border: 1px solid #ffffff55; background: #08111bdd; color: #fff; border-radius: 6px; cursor: pointer; font-size:var(--text-meta); }
.moment-film-play[hidden] { display: none; }
.moment-film-message { position: absolute; bottom: 18px; left: 12px; right: 125px; color: #fff; text-align: left; font-size:var(--text-meta); text-shadow: 0 1px 4px #000; pointer-events: none; }
.film-discovery .discovery-content .discovery-kicker {display:block;margin:0 0 10px;color:#ffffffb8;font-size:var(--text-meta);}
.film-discovery .discovery-content h2 {font-size:clamp(30px,4vw,48px);margin:0 0 10px;color:#fff;}
.film-discovery .discovery-content p {max-width:620px;margin:0;font-size:16px;line-height:1.45;color:#ffffffd9;text-wrap:pretty;}
.research-moment.film-discovery .moment-film-frame {position:absolute;inset:0;width:100%;height:100%;max-width:none;aspect-ratio:auto;margin:0;border-radius:0;overflow:hidden;}
.research-moment.film-discovery .moment-film-frame > :is(video,img) {position:absolute;inset:0;width:100%;height:100%;object-fit:cover;object-position:var(--film-focus,center);border-radius:0;}
.film-discovery .moment-film-frame::after {content:"";position:absolute;inset:0 0 auto;height:150px;background:linear-gradient(#03081070,transparent);pointer-events:none;}
.film-discovery .moment-film-frame .moment-film-play {top:max(20px,env(safe-area-inset-top));bottom:auto;left:24px;right:auto;z-index:3;min-height:44px;background:#030810aa;border-color:#ffffff50;backdrop-filter:blur(8px);}
.film-discovery .moment-film-frame .moment-film-message {top:max(74px,calc(env(safe-area-inset-top) + 54px));bottom:auto;left:24px;right:24px;z-index:3;color:#fff;text-shadow:0 1px 5px #000;}
.film-discovery .discovery-audio {position:absolute;top:max(20px,env(safe-area-inset-top));right:24px;z-index:3;padding:0 6px;background:#03081070;border-radius:10px;backdrop-filter:blur(8px);}
.research-moment.film-discovery .discovery-continue {min-height:48px;padding:12px 24px;margin:22px 0 0;font-size:16px;}
.film-continue { margin-top: 15px; border: 1px solid #ffffff35; background: transparent; color: var(--fg); padding: 8px 24px; border-radius: 5px; cursor: pointer; }
.ending-banner .moment-film-frame { max-width: 820px; }
@media (max-width:700px) {
  .research-moment.film-discovery .discovery-content {padding:80px 24px max(28px,env(safe-area-inset-bottom));}
}
@media (max-height:500px) {
  .research-moment.film-discovery .discovery-content {padding-top:40px;padding-bottom:max(18px,env(safe-area-inset-bottom));}
  .film-discovery .discovery-content h2 {font-size:28px;margin-bottom:6px;}
  .film-discovery .discovery-content p {font-size:var(--text-meta);max-width:70%;}
  .research-moment.film-discovery .discovery-continue {margin-top:14px;}
}
/* Keep the immersive desktop composition in portrait, but reserve the bottom
   third for black. A shorter film backdrop reveals more of the wide shot. */
@media (max-width:700px) and (orientation:portrait) {
  .research-moment.film-discovery {background:#000;}
  .research-moment.film-discovery .moment-film-frame {
    inset:0 0 auto;
    width:100%;height:64%;aspect-ratio:auto;background:#000;overflow:hidden;
  }
  .research-moment.film-discovery .moment-film-frame > :is(video,img) {
    object-fit:cover;object-position:var(--film-focus,center);
  }
  /* Fade the displayed scene to black once. Masking each media layer lets the
     opening poster show through the playing video and its held final frame. */
  .film-discovery .moment-film-frame::after {
    inset:0;height:100%;z-index:1;
    background:linear-gradient(#0006,transparent 120px),linear-gradient(transparent 58%,#000 98%);
  }
  .research-moment.film-discovery .discovery-content {
    inset:auto 0 0;padding:64px 24px max(24px,env(safe-area-inset-bottom));
    background:linear-gradient(transparent,#0009 35%,#000 75%);
  }
  .film-discovery .discovery-content h2 {font-size:32px;}
  .film-discovery .discovery-content p {font-size:16px;}
  .research-moment.film-discovery .discovery-continue {margin-top:22px;width:100%;}
  .film-discovery .moment-film-frame .moment-film-play {
    top:max(20px,env(safe-area-inset-top));bottom:auto;left:24px;right:auto;
  }
  .film-discovery .moment-film-frame .moment-film-message {
    top:max(74px,calc(env(safe-area-inset-top) + 54px));bottom:auto;font-size:var(--text-meta);
  }
}
@media (prefers-reduced-motion: reduce) { .film-discovery .discovery-content { animation: none; } }

/* Appearance comes from the shared game-action control. */
.discovery-continue { margin-top: 1rem; cursor: pointer; }

/* Campaign choices use the same restrained controls as other inspectors. */
.research-allocation { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 16px 32px; flex: none; padding: 10px 4px 14px; border-bottom: 1px solid #ffffff24; }
.research-allocation-controls { min-width: 0; }
.research-allocation .research-allocation-help { margin: 0; max-width: 36em; color: var(--fg-muted); line-height: 1.5; }
@media (max-width: 850px) {
  .research-allocation { grid-template-columns: minmax(0, 1fr); gap: 8px; }
}
.research-allocation p { margin: 5px 0; font-size:var(--text-meta); }
.research-allocation [role=group] { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.research-allocation button[aria-pressed=true], .agreement-choice[aria-pressed=true] { border-color: var(--accent, #dc8959); background: #7c492f88; }
.regional-agreements { margin: 12px 0 18px; }
.regional-agreements details { border-bottom: 1px solid #ffffff24; padding: 12px 0; }
.regional-agreements summary { cursor: pointer; font-weight: 600; }
.agreement-choice { display: block; width: 100%; text-align: left; padding: 12px; margin: 10px 0; white-space: normal; }
.agreement-choice span, .agreement-choice small { display: block; margin-top: 6px; line-height: 1.4; }
.regional-agreements .muted { font-size:var(--text-meta); line-height: 1.45; }

.research-allocation [role=group] button { padding: 7px 12px; font-size:var(--text-meta); }
.research-allocation [role=group] small { display: block; opacity: .7; font-size:var(--text-meta); }
/* The board is fitted inside this slot; its unscaled size must not make it scroll. */
.research-workspace .research-view { overflow: hidden; }
.research-view[data-tree-owner='you'] .tree-scroll { flex: 1 1 0; height: auto; min-height: 0; overflow: clip; padding: 0; }
.research-view[data-tree-owner='you'] .tree-board { position: absolute; top: 0; left: 0; }
