/* =========================================================================
   Arbre de Technologies — cartoon sci-fi premium, hologrammes, mobile first.
   Bleu profond + violet + or. Tout est construit mobile d'abord, puis
   elargi au desktop en fin de fichier.
   ========================================================================= */

.tech-panel {
  --tech-void: #070f2c;
  --tech-deep: #0d1a45;
  --tech-violet: #6d3fd6;
  --tech-violet-soft: rgba(140, 96, 255, 0.24);
  --tech-gold: #ffc233;
  --tech-gold-bright: #ffe08a;
  --tech-cyan: #5fd8ff;
  --tech-line: rgba(146, 178, 255, 0.28);

  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: auto auto 1fr;
  background:
    radial-gradient(120% 80% at 12% 0%, rgba(109, 63, 214, 0.42), transparent 62%),
    radial-gradient(120% 90% at 92% 12%, rgba(38, 120, 214, 0.34), transparent 60%),
    linear-gradient(180deg, var(--tech-deep), var(--tech-void) 62%);
  color: var(--text-primary);
  overflow: hidden;
}

/* Grille holographique de fond : lisible sans jamais concurrencer les noeuds. */
.tech-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(120, 170, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 170, 255, 0.07) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(120% 90% at 50% 30%, #000 42%, transparent 88%);
  pointer-events: none;
}

/* ---------------------------------------------------------------- En-tete */

.tech-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: calc(var(--safe-top) + var(--space-3)) var(--space-4) var(--space-3);
  border-bottom: 2px solid var(--tech-line);
  background: linear-gradient(180deg, rgba(15, 30, 78, 0.94), rgba(10, 21, 56, 0.72));
  backdrop-filter: blur(8px);
}

.tech-header-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}

.tech-header-glyph {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  font-size: 1.25rem;
  color: #1a1030;
  background: linear-gradient(160deg, var(--tech-gold-bright), var(--tech-gold));
  box-shadow: 0 0.25rem 0 rgba(120, 78, 12, 0.6), 0 0 1.4rem rgba(255, 194, 51, 0.4);
}

.tech-header-title strong {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  letter-spacing: var(--tracking-display);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tech-header-title p {
  margin: 0;
  font-size: var(--text-2xs);
  color: var(--text-tertiary);
}

.tech-header-research {
  display: none;
}

.tech-header-research[hidden] {
  display: none !important;
}

/* --------------------------------------------------------- Rail de branches */

.tech-branch-rail {
  position: relative;
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--tech-line);
  background: rgba(8, 18, 48, 0.55);
}

.tech-branch-rail::-webkit-scrollbar {
  display: none;
}

.tech-branch-chip {
  --chip: var(--accent-blue);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4);
  border: 2px solid color-mix(in srgb, var(--chip) 48%, transparent);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--chip) 14%, rgba(8, 20, 52, 0.9));
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--motion-fast) var(--ease-tactical), border-color var(--motion-fast), background var(--motion-fast);
}

.tech-branch-chip i {
  font-style: normal;
  font-size: var(--text-md);
  line-height: 1;
}

.tech-branch-chip b {
  font-size: var(--text-2xs);
  font-weight: 600;
  color: color-mix(in srgb, var(--chip) 70%, #ffffff);
}

.tech-branch-chip:hover {
  transform: translateY(-1px);
}

.tech-branch-chip.is-active {
  border-color: var(--chip);
  background: color-mix(in srgb, var(--chip) 30%, rgba(8, 20, 52, 0.9));
  color: var(--text-primary);
  box-shadow: 0 0 1rem color-mix(in srgb, var(--chip) 45%, transparent);
}

/* ------------------------------------------------------------ Scene / canvas */

.tech-stage {
  position: relative;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

.tech-stage.is-panning {
  cursor: grabbing;
}

.tech-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.tech-links {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

.tech-link {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  opacity: 0.24;
  transition: opacity var(--motion-normal), stroke-width var(--motion-normal);
}

/* Une liaison s'illumine des que son prerequis est acquis. */
.tech-link.is-unlocked {
  opacity: 0.95;
  stroke-width: 4;
  filter: drop-shadow(0 0 6px currentColor);
}

.tech-link.is-dimmed {
  opacity: 0.07;
}

.tech-branch-label {
  position: absolute;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-4);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

/* ------------------------------------------------------------------ Noeuds */

.tech-node {
  --node: var(--accent-blue);
  position: absolute;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 2px;
  padding: var(--space-2);
  border: 2px solid color-mix(in srgb, var(--node) 45%, transparent);
  border-radius: var(--radius-md);
  background: linear-gradient(165deg, rgba(24, 44, 100, 0.96), rgba(11, 23, 58, 0.96));
  box-shadow: 0 0.3rem 0 rgba(4, 10, 30, 0.6);
  color: var(--text-primary);
  text-align: center;
  cursor: pointer;
  transition: transform var(--motion-fast) var(--ease-tactical), box-shadow var(--motion-fast), border-color var(--motion-fast), opacity var(--motion-normal);
}

.tech-node:hover {
  transform: translateY(-2px);
}

.tech-node-icon {
  font-size: 1.35rem;
  line-height: 1.2;
}

.tech-node-name {
  font-family: var(--font-display);
  font-size: 0.6875rem;
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tech-node-level {
  font-family: var(--font-data);
  font-size: 0.625rem;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
}

/* --- Etat : verrouillee --- */
.tech-node.is-locked {
  filter: grayscale(0.85);
  opacity: 0.42;
  border-color: rgba(140, 170, 210, 0.28);
  box-shadow: none;
}

.tech-node.is-locked .tech-node-icon {
  opacity: 0.6;
}

/* --- Etat : disponible (contour bleu) --- */
.tech-node.is-available {
  border-color: var(--accent-cyan);
  box-shadow: 0 0.3rem 0 rgba(4, 10, 30, 0.6), 0 0 0.9rem rgba(95, 216, 255, 0.34);
}

/* --- Etat : en recherche (halo anime + barre) --- */
.tech-node.is-researching {
  border-color: var(--tech-violet);
  animation: tech-pulse 1.7s ease-in-out infinite;
}

@keyframes tech-pulse {
  0%,
  100% {
    box-shadow: 0 0.3rem 0 rgba(4, 10, 30, 0.6), 0 0 0.6rem rgba(140, 96, 255, 0.5);
  }
  50% {
    box-shadow: 0 0.3rem 0 rgba(4, 10, 30, 0.6), 0 0 1.8rem rgba(160, 120, 255, 0.95);
  }
}

/* --- Etat : terminee (contour dore + coche) --- */
.tech-node.is-completed {
  border-color: var(--tech-gold);
  background: linear-gradient(165deg, rgba(74, 58, 24, 0.9), rgba(24, 30, 62, 0.96));
  box-shadow: 0 0.3rem 0 rgba(60, 40, 6, 0.7), 0 0 1.1rem rgba(255, 194, 51, 0.45);
}

.tech-node.is-selected {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 0.4rem 0 rgba(4, 10, 30, 0.6), 0 0 0 3px var(--tech-gold-bright);
}

.tech-node.is-dimmed {
  opacity: 0.16;
  pointer-events: none;
}

.tech-node-check {
  position: absolute;
  top: -0.45rem;
  right: -0.45rem;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: var(--radius-pill);
  background: linear-gradient(160deg, var(--tech-gold-bright), var(--tech-gold));
  color: #1a1030;
  font-size: 0.7rem;
  font-weight: 700;
  box-shadow: 0 0 0.6rem rgba(255, 194, 51, 0.7);
}

.tech-node-bar {
  position: absolute;
  left: var(--space-2);
  right: var(--space-2);
  bottom: 3px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: rgba(4, 12, 34, 0.8);
  overflow: hidden;
}

.tech-node-bar i {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--tech-violet), var(--tech-cyan));
}

.tech-node-rarity {
  position: absolute;
  top: -0.4rem;
  left: -0.3rem;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: var(--radius-pill);
  box-shadow: 0 0 0.5rem currentColor;
}

/* --------------------------------------------------- Controles de la scene */

.tech-stage-controls {
  position: absolute;
  right: var(--space-4);
  bottom: calc(var(--safe-bottom) + var(--space-4));
  display: grid;
  gap: var(--space-2);
  z-index: 3;
}

.tech-stage-controls button {
  width: var(--touch-min);
  height: var(--touch-min);
  border: 2px solid var(--tech-line);
  border-radius: var(--radius-md);
  background: linear-gradient(165deg, rgba(28, 50, 112, 0.96), rgba(12, 24, 62, 0.96));
  color: var(--text-primary);
  font-size: var(--text-lg);
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 0.25rem 0 rgba(4, 10, 30, 0.6);
  transition: transform var(--motion-fast), border-color var(--motion-fast);
}

.tech-stage-controls button:active {
  transform: translateY(2px);
  box-shadow: 0 0.1rem 0 rgba(4, 10, 30, 0.6);
}

.tech-stage-controls button:hover {
  border-color: var(--accent-cyan);
}

/* ------------------------------------------------------- Panneau de detail */

.tech-detail {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  max-height: 74%;
  display: flex;
  flex-direction: column;
  border-top: 2px solid var(--tech-line);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: linear-gradient(180deg, rgba(20, 36, 88, 0.99), rgba(9, 18, 48, 0.99));
  box-shadow: 0 -1rem 3rem rgba(3, 8, 24, 0.7);
  animation: tech-detail-in var(--motion-slow) var(--ease-tactical);
}

@keyframes tech-detail-in {
  from {
    transform: translateY(18%);
    opacity: 0;
  }
}

.tech-detail-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-4);
  z-index: 2;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--tech-line);
  border-radius: var(--radius-pill);
  background: rgba(8, 18, 48, 0.9);
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.tech-detail-scroll {
  padding: var(--space-5) var(--space-5) calc(var(--safe-bottom) + var(--space-5));
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Illustration holographique, generee en CSS : aucune image a charger. */
.tech-detail-art {
  --art: var(--accent-blue);
  position: relative;
  display: grid;
  place-items: center;
  height: 6.5rem;
  margin-bottom: var(--space-4);
  border: 2px solid color-mix(in srgb, var(--art) 45%, transparent);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(80% 120% at 50% 120%, color-mix(in srgb, var(--art) 42%, transparent), transparent 70%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 5px),
    linear-gradient(180deg, rgba(10, 22, 56, 0.9), rgba(6, 14, 38, 0.9));
  overflow: hidden;
}

.tech-detail-art span {
  font-size: 2.75rem;
  filter: drop-shadow(0 0 1rem color-mix(in srgb, var(--art) 80%, transparent));
}

.tech-detail-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, color-mix(in srgb, var(--art) 22%, transparent));
  animation: tech-scan 3.4s linear infinite;
}

@keyframes tech-scan {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(100%);
  }
}

.tech-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.tech-detail-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  line-height: 1.15;
}

.tech-detail-branch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-1);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.tech-detail-rarity {
  flex-shrink: 0;
  padding: var(--space-1) var(--space-3);
  border: 1px solid currentColor;
  border-radius: var(--radius-pill);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.tech-detail-desc {
  margin: 0 0 var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-secondary);
}

.tech-detail-levels {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.tech-detail-levels b {
  font-family: var(--font-data);
  font-size: var(--text-lg);
  color: var(--tech-gold-bright);
}

.tech-level-track {
  flex: 1;
  height: 8px;
  border-radius: var(--radius-pill);
  background: rgba(4, 12, 34, 0.85);
  overflow: hidden;
}

.tech-level-track i {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--tech-violet), var(--tech-gold));
}

.tech-detail-section {
  margin-bottom: var(--space-4);
}

.tech-detail-section > h4 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.tech-bonus-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--tech-line);
  border-radius: var(--radius-sm);
  background: rgba(8, 20, 52, 0.6);
}

.tech-bonus-row strong {
  font-size: var(--text-sm);
}

.tech-bonus-row span {
  font-family: var(--font-data);
  font-size: var(--text-xs);
  color: var(--state-success);
  white-space: nowrap;
}

.tech-cost-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  gap: var(--space-2);
}

.tech-cost-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--tech-line);
  border-radius: var(--radius-sm);
  background: rgba(8, 20, 52, 0.6);
  font-size: var(--text-xs);
}

.tech-cost-chip i {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.tech-cost-chip b {
  font-family: var(--font-data);
  margin-left: auto;
}

.tech-cost-chip.is-missing {
  border-color: var(--state-danger);
  color: var(--state-danger);
}

.tech-prereq-list {
  display: grid;
  gap: var(--space-2);
}

.tech-prereq-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--tech-line);
  border-radius: var(--radius-sm);
  background: rgba(8, 20, 52, 0.6);
  font-size: var(--text-xs);
  cursor: pointer;
}

.tech-prereq-row em {
  margin-left: auto;
  font-style: normal;
  font-size: var(--text-2xs);
}

.tech-prereq-row.is-met em {
  color: var(--state-success);
}

.tech-prereq-row.is-missing em {
  color: var(--state-warning);
}

.tech-research-button {
  display: block;
  width: 100%;
  min-height: var(--touch-comfortable);
  margin-top: var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--tech-gold-bright), var(--tech-gold));
  color: #1c1206;
  font-family: var(--font-display);
  font-size: var(--text-md);
  letter-spacing: var(--tracking-label);
  cursor: pointer;
  box-shadow: 0 0.35rem 0 rgba(120, 78, 12, 0.75);
  transition: transform var(--motion-fast), box-shadow var(--motion-fast);
}

.tech-research-button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 0.1rem 0 rgba(120, 78, 12, 0.75);
}

.tech-research-button:disabled {
  background: linear-gradient(180deg, #4a5b7d, #364766);
  color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0.35rem 0 rgba(12, 22, 46, 0.7);
  cursor: not-allowed;
}

.tech-research-note {
  margin: var(--space-2) 0 0;
  text-align: center;
  font-size: var(--text-2xs);
  color: var(--text-tertiary);
}

/* ============================== Desktop / tablette ======================== */

@media (min-width: 48rem) {
  .tech-panel {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "header header"
      "rail rail"
      "stage detail";
    grid-template-rows: auto auto 1fr;
  }

  .tech-header {
    grid-area: header;
  }

  .tech-branch-rail {
    grid-area: rail;
  }

  .tech-stage {
    grid-area: stage;
  }

  /* Sur grand ecran le detail devient une vraie colonne laterale. */
  .tech-detail {
    position: relative;
    grid-area: detail;
    width: 23rem;
    max-height: none;
    border-top: 0;
    border-left: 2px solid var(--tech-line);
    border-radius: 0;
    box-shadow: -1rem 0 3rem rgba(3, 8, 24, 0.5);
    animation: tech-detail-slide var(--motion-slow) var(--ease-tactical);
  }

  @keyframes tech-detail-slide {
    from {
      transform: translateX(12%);
      opacity: 0;
    }
  }

  .tech-header-research {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 15rem;
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--tech-line);
    border-radius: var(--radius-pill);
    background: rgba(8, 20, 52, 0.7);
  }

  .tech-header-research small {
    display: block;
    font-size: var(--text-2xs);
    color: var(--text-secondary);
  }

  .tech-header-research b {
    font-family: var(--font-data);
    font-size: var(--text-xs);
    color: var(--tech-gold-bright);
  }

  .tech-progress-bar {
    width: 9rem;
    height: 5px;
    margin-top: 3px;
    border-radius: var(--radius-pill);
    background: rgba(4, 12, 34, 0.85);
    overflow: hidden;
  }

  .tech-progress-bar i {
    display: block;
    height: 100%;
    border-radius: var(--radius-pill);
    background: linear-gradient(90deg, var(--tech-violet), var(--tech-cyan));
  }

  .tech-header-research-icon {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: var(--radius-pill);
    background: radial-gradient(circle, var(--tech-cyan), transparent 70%);
    animation: tech-pulse 1.7s ease-in-out infinite;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tech-node,
  .tech-detail,
  .tech-detail-art::after,
  .tech-header-research-icon {
    animation: none !important;
    transition: none !important;
  }
}
