/* ==========================================================================
   Research tree — War Thunder style tech tree window over a blurred hangar.
   ========================================================================== */

.page-research {
  --r-line: rgba(140, 165, 185, 0.22);
  --r-text: #c9d3dc;
  --r-dim: #8b9aa7;
  --r-gold: #f0b640;

  min-height: 100dvh;
  color: var(--r-text);
  font-size: 14px;
  background: #0b1014;
}
.rbg {
  position: fixed;
  inset: -20px;
  z-index: 0;
  background: #0b1014 url("../assets/img/hangar-fallback.jpg") center / cover no-repeat;
  filter: blur(8px) brightness(0.5) saturate(0.8);
}

/* ---------- top bar ---------- */
.rbar {
  position: sticky;
  top: 0;
  z-index: var(--z-hud);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  height: 40px;
  padding: 0 10px;
  background: linear-gradient(180deg, rgba(30, 41, 51, 0.97), rgba(20, 28, 36, 0.94));
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.rbar__left,
.rbar__right {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  min-width: 0;
}
.rbar__right {
  justify-self: end;
}
.rbar__icon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--r-dim);
  text-decoration: none;
  font-size: 13px;
}
.rbar__icon .icon {
  width: 20px;
  height: 20px;
}
.rbar__icon:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}
.rbar__medal .icon {
  color: var(--r-gold);
}
.rbar__player {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 8px;
  color: var(--r-text);
  text-decoration: none;
  white-space: nowrap;
}
.rbar__roundel {
  width: 18px;
  height: 18px;
}
.rbar__star {
  color: var(--r-gold);
  margin-right: 4px;
}
.rcoin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  font-variant-numeric: tabular-nums;
}
.rcoin .icon {
  width: 18px;
  height: 18px;
}
.rcoin--sl {
  color: #aeb9c2;
}
.rcoin--rp {
  color: #5aaef0;
}
.rcoin--ge {
  color: var(--r-gold);
}
.rbattle {
  display: grid;
  justify-items: center;
  padding-top: 3px;
}
.rbattle__btn {
  width: 152px;
  height: 36px;
  border: 1px solid #e27a66;
  background: linear-gradient(180deg, #c92e22 0%, #b8261d 45%, #86170f 100%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 21px;
  font-weight: 500;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.55);
}
.rbattle__btn:hover {
  filter: brightness(1.12);
}
.rbattle__btn:disabled {
  cursor: progress;
  filter: saturate(0.35) brightness(0.8);
}
.rbattle__mode {
  margin-top: 1px;
  padding: 3px 12px 4px;
  border: 1px solid var(--r-line);
  border-top: 0;
  background: rgba(24, 38, 56, 0.9);
  color: var(--r-dim);
  font-size: 12px;
  white-space: nowrap;
}

/* ---------- window ---------- */
.rtree {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(1220px, calc(100vw - 24px));
  height: calc(100dvh - 40px - 112px);
  min-height: 520px;
  margin: 46px auto 0;
  border: 1px solid var(--r-line);
  background: rgba(20, 28, 36, 0.93);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}
.rtree__tabs {
  display: flex;
  align-items: stretch;
  height: 36px;
  border-bottom: 1px solid var(--r-line);
  background: rgba(36, 48, 60, 0.9);
}
.rtab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--r-dim);
  font-size: 14px;
  white-space: nowrap;
}
.rtab:hover {
  color: #fff;
}
.rtab.is-active {
  border-bottom-color: #e3e9ee;
  color: #fff;
}
.rtab__star {
  color: var(--r-gold);
}
.rtab__sale {
  padding: 0 5px;
  background: #b8261d;
  color: #fff;
  font-size: 11px;
}
.rsearch {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 5px 6px 5px auto;
  padding: 0 8px;
  width: 220px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--r-line);
  color: var(--r-dim);
}
.rsearch .icon {
  width: 14px;
  height: 14px;
}
.rsearch input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font-size: 13px;
  outline: none;
}
.rtree__close {
  display: grid;
  place-items: center;
  width: 40px;
  color: var(--r-dim);
}
.rtree__close .icon {
  width: 18px;
  height: 18px;
}
.rtree__close:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}

.rtree__body {
  display: flex;
  flex: 1;
  min-height: 0;
}
.rtree__main {
  flex: 1;
  min-width: 0;
  overflow: auto;
}
.rtree__prem {
  flex: none;
  width: 320px;
  overflow: auto;
  border-left: 1px solid var(--r-line);
}
.rtree__sub {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 5px 0;
  border-bottom: 1px solid var(--r-line);
  background: rgba(28, 38, 48, 0.97);
  color: var(--r-text);
  font-weight: 400;
  font-size: 13px;
  text-align: center;
}

/* ---------- tree grid ---------- */
.rrank {
  display: grid;
  grid-template-columns: 96px repeat(3, minmax(0, 1fr));
  align-items: start;
  padding: 16px 0 18px;
  border-top: 1px solid rgba(140, 165, 185, 0.14);
}
.rrank:first-child {
  border-top: 0;
}
.rrank__label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 0 0 12px;
  color: var(--r-dim);
  font-size: 13px;
  white-space: nowrap;
}
.rrank__label .icon {
  width: 12px;
  height: 12px;
  transform: rotate(180deg);
}
.rcell {
  display: flex;
  justify-content: center;
}

.rcard {
  position: relative;
  display: grid;
  grid-template-columns: 48px 1fr;
  grid-template-rows: 1fr auto;
  width: 164px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(140, 165, 185, 0.32);
  background: linear-gradient(180deg, #25323d, #1a242d);
  color: #eef2f4;
  text-align: right;
  transition: border-color 0.15s ease, filter 0.15s ease;
}
.rcard:hover {
  border-color: rgba(220, 230, 238, 0.75);
  filter: brightness(1.12);
}
.rcard__art {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  color: #b8c3cc;
}
.rcard__art svg {
  width: 38px;
  height: 24px;
}
.rcard__name {
  align-self: start;
  padding: 3px 7px 0 0;
  overflow: hidden;
  font-size: 12.5px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rcard__meta {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 0 7px 4px 0;
  color: var(--r-text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.rcard__meta svg {
  width: 11px;
  height: 11px;
}
.rcard__meta .rp {
  color: #5aaef0;
}
.rcard__meta .ok {
  color: #8fd694;
}
.rcard__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: 3px;
  background: rgba(90, 174, 240, 0.18);
}
.rcard__bar span {
  display: block;
  height: 100%;
  background: #5aaef0;
}
/* connectors */
.rcard[data-down]::after {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(100% + 1px);
  width: 2px;
  height: 34px;
  margin-left: -1px;
  background: rgba(140, 165, 185, 0.4);
  pointer-events: none;
}
.rcard[data-down="hot"]::after {
  background: #a82a20;
}

.rcard.is-done {
  border-color: rgba(200, 215, 225, 0.4);
  background: linear-gradient(180deg, #3a4a57, #2a3743);
}
.rcard.is-target {
  border-color: #e7ecef;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 0 18px rgba(90, 174, 240, 0.25);
}
.rcard.is-locked {
  background: #161d24;
}
.rcard.is-locked .rcard__art,
.rcard.is-locked .rcard__name,
.rcard.is-locked .rcard__meta {
  opacity: 0.45;
}
.rcard.is-dim {
  opacity: 0.25;
}
.rcard.is-flash {
  animation: node-flash 0.9s ease-out;
}
@keyframes node-flash {
  0% {
    box-shadow: 0 0 0 2px #8fd694, 0 0 40px rgba(143, 214, 148, 0.6);
  }
}

/* premium */
.rprem {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  justify-items: center;
  gap: 16px 8px;
  padding: 16px 8px;
}
.rcard--prem {
  width: 140px;
  border-color: rgba(240, 182, 64, 0.55);
  background: linear-gradient(180deg, #3d3620, #231f14);
}
.rcard--prem .rcard__art {
  color: var(--r-gold);
}
.rcard--prem.is-done {
  border-color: rgba(240, 182, 64, 0.8);
  background: linear-gradient(180deg, #54482a, #332b18);
}
.rcard__ge {
  color: #e9564a;
}
.rcard__ge svg {
  color: var(--r-gold);
}

/* ---------- footer strip ---------- */
.rtree__foot {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  min-height: 44px;
  padding: 6px 14px;
  border-top: 1px solid var(--r-line);
  background: rgba(30, 42, 54, 0.95);
  font-size: 13px;
}
.rtree__bonus {
  color: var(--r-dim);
}
.rhelp {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-left: 4px;
  border: 1px solid var(--r-dim);
  font-size: 11px;
}
.rtree__result {
  color: var(--r-text);
  text-align: center;
}
.rtree__result b.win {
  color: var(--r-gold);
  font-weight: 600;
}
.rtree__result b.loss {
  color: #e2584a;
  font-weight: 600;
}
.rtree__result .rp {
  color: #5aaef0;
}
.rtree__stats {
  display: flex;
  gap: 14px;
  color: var(--r-dim);
  font-variant-numeric: tabular-nums;
}
.rtree__stats b {
  color: var(--r-text);
  font-weight: 500;
}

/* ---------- nations dock ---------- */
.rdock {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 1;
  display: flex;
  width: min(1220px, calc(100vw - 24px));
  height: 30px;
  border: 1px solid var(--r-line);
  background: rgba(16, 23, 29, 0.94);
  transform: translateX(-50%);
}
.rdock__research {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 140px;
  flex: none;
  background: rgba(60, 78, 96, 0.55);
  color: #e3e9ee;
  text-decoration: none;
}
.rdock__research .icon {
  width: 16px;
  height: 16px;
  transform: rotate(180deg);
}
.rdock__nations {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.rdock__nations span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 0 10px;
  color: var(--r-dim);
  font-size: 13px;
  white-space: nowrap;
}
.rdock__nations span.is-active {
  border-bottom: 2px solid #e3e9ee;
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}
.rdock__nations svg {
  width: 18px;
  height: 12px;
}
.rdock__nations span:first-child svg {
  width: 15px;
  height: 15px;
}
.rfoot {
  position: fixed;
  right: 12px;
  bottom: 3px;
  z-index: 1;
  display: flex;
  gap: 12px;
  color: #6f7d88;
  font-size: 11px;
}
.rfoot a,
.rfoot button {
  padding: 0;
  border: 0;
  background: none;
  color: #9aa7b1;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- small screens ---------- */
@media (max-width: 1000px) {
  .rtree__body {
    flex-direction: column;
    overflow: auto;
  }
  .rtree__main,
  .rtree__prem {
    overflow: visible;
  }
  .rtree__prem {
    width: auto;
    border-left: 0;
    border-top: 1px solid var(--r-line);
  }
  .rprem {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .rbar__player span:not(.rbar__star),
  .rcoin:nth-child(2) {
    display: none;
  }
  .rsearch {
    width: 150px;
  }
  .rtab[data-soon] {
    display: none;
  }
}
@media (max-width: 720px) {
  .rbar {
    grid-template-columns: auto 1fr auto;
  }
  .rbar__player,
  .rcoin,
  .rbattle__mode {
    display: none;
  }
  .rtree {
    width: 100vw;
    height: auto;
    min-height: calc(100dvh - 96px);
    margin-top: 8px;
    border-left: 0;
    border-right: 0;
  }
  .rrank {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    row-gap: 8px;
    padding: 10px 4px 16px;
  }
  .rrank__label {
    grid-column: 1 / -1;
  }
  .rcard {
    width: calc(100% - 6px);
    grid-template-columns: 30px 1fr;
  }
  .rcard__art svg {
    width: 26px;
  }
  .rcard[data-down]::after {
    display: none;
  }
  .rcard__name {
    font-size: 11.5px;
  }
  .rtree__foot {
    grid-template-columns: 1fr;
    gap: 4px;
    text-align: center;
  }
  .rtree__stats {
    justify-content: center;
  }
  .rtree__bonus {
    display: none;
  }
  .rdock {
    width: 100vw;
    bottom: 20px;
  }
  .rfoot p {
    display: none;
  }
}
