:root {
  --bg: #070b18;
  --ink: #dbe8f0;
  --muted: #8ea4b8;
  --teal: #5ec4c8;
  --cyan: #5ff2ff;
  --orange: #f0a13c;
  --red: #e8524a;
  --violet: #d66bff;
  --panel: rgba(16, 28, 44, 0.92);
  --line: #2c4a5e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(ellipse at 70% 20%, #1c2450 0%, #0b1024 45%, var(--bg) 100%);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

#stars {
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 70%, #bffbff 50%, transparent 51%),
    radial-gradient(2px 2px at 55% 35%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 75% 80%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 15%, #ffd27a 50%, transparent 51%),
    radial-gradient(1px 1px at 20% 90%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 65% 55%, #bffbff 50%, transparent 51%);
  background-size: 420px 420px;
  opacity: 0.7;
  animation: drift 120s linear infinite;
  pointer-events: none;
}

@keyframes drift { to { background-position: -420px 210px; } }
@keyframes pulse { 50% { transform: scale(1.12); filter: drop-shadow(0 0 14px var(--cyan)); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes float { 50% { transform: translateY(-10px); } }
@keyframes fadein { from { opacity: 0; transform: translateY(12px); } }

#view {
  position: relative;
  height: 100%;
  overflow: auto;
}

.screen {
  min-height: 100%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadein 0.35s ease-out;
}

h1, h2, h3 {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

h2 { font-size: 1.15rem; color: var(--teal); }
h3 { font-size: 0.95rem; color: var(--orange); }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.panel {
  border: 26px solid transparent;
  border-image: url(../assets/pack/frame-blue.png) 44 fill / 26px stretch;
  padding: 4px 8px;
}

.panel.neon { border-image-source: url(../assets/pack/frame-neon.png); border-image-slice: 40 fill; }
.panel.metal { border-image-source: url(../assets/pack/frame-metal.png); border-image-slice: 46 fill; border-width: 30px; }
.panel.gold { border-image-source: url(../assets/pack/frame-gold.png); border-image-slice: 46 fill; border-width: 28px; }
.panel.dark { border-image-source: url(../assets/pack/frame-dark.png); border-image-slice: 30 fill; border-width: 20px; }

.btn {
  appearance: none;
  border: 16px solid transparent;
  border-image: url(../assets/pack/button-teal.png) 30 46 fill / 16px 22px stretch;
  background: none;
  color: #eafcff;
  font: inherit;
  font-weight: bold;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0 14px;
  min-height: 52px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
  text-shadow: 0 2px 0 #0b1a26;
}

.btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.2) drop-shadow(0 0 8px rgba(95, 242, 255, 0.5)); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { filter: grayscale(1) brightness(0.6); cursor: not-allowed; }
.btn.alt { border-image-source: url(../assets/pack/button-blue.png); border-image-slice: 24 40 fill; }
.btn.hex { border-image-source: url(../assets/pack/button-hex.png); border-image-slice: 24 40 fill; }
.btn.big { min-height: 64px; font-size: 1.1rem; padding: 0 28px; }
.btn.danger { filter: hue-rotate(150deg) saturate(1.4); }

.icon { width: 22px; height: 22px; object-fit: contain; vertical-align: middle; }
.icon.lg { width: 34px; height: 34px; }

/* Titre */
.title-screen { justify-content: center; gap: 18px; text-align: center; position: relative; overflow: hidden; }
.title-screen .galaxy { position: absolute; width: min(1100px, 140vw); left: 50%; top: 50%; transform: translate(-50%, -50%); opacity: 0.35; animation: spin 240s linear infinite; pointer-events: none; }
.title-screen .deco { position: absolute; pointer-events: none; animation: float 7s ease-in-out infinite; }
.title-plate {
  position: relative;
  padding: 26px 70px;
  background: url(../assets/pack/title-plate.png) center / 100% 100% no-repeat;
  font-size: clamp(1.6rem, 4.6vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 0.18em;
  color: #eafcff;
  text-shadow: 0 0 18px rgba(95, 242, 255, 0.6), 0 3px 0 #2a1a48;
}
.subtitle { color: var(--orange); letter-spacing: 0.3em; text-transform: uppercase; font-size: 0.9rem; }
.menu { display: flex; flex-direction: column; gap: 10px; width: min(340px, 90vw); position: relative; z-index: 1; }
.corner-btn { position: fixed; top: 14px; right: 14px; z-index: 30; background: none; border: 0; cursor: pointer; width: 46px; height: 46px; padding: 0; }
.corner-btn img { width: 100%; height: 100%; transition: transform 0.3s; }
.corner-btn:hover img { transform: rotate(60deg); }
.corner-btn.off { filter: grayscale(1) brightness(0.6); }
.meta-line { display: flex; gap: 18px; justify-content: center; align-items: center; color: var(--muted); font-size: 0.9rem; position: relative; }

/* Hangar */
.hangar { gap: 18px; }
.hangar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; width: min(1200px, 100%); }
.card {
  position: relative;
  border: 18px solid transparent;
  border-image: url(../assets/pack/frame-square.png) 34 fill / 18px stretch;
  padding: 6px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.card:hover { transform: translateY(-3px); filter: brightness(1.15); }
.card.selected { border-image-source: url(../assets/pack/frame-gold.png); border-image-slice: 46 fill; filter: drop-shadow(0 0 12px rgba(240, 161, 60, 0.5)); }
.card.locked > img { filter: grayscale(1) brightness(0.45); }
.card img.ship { width: 100%; height: 110px; object-fit: contain; scale: -1 1; transition: translate 0.3s; }
.card:hover img.ship { translate: 8px 0; }
.card.selected img.ship { animation: hover 2.4s ease-in-out infinite, thrust 0.18s ease-in-out infinite alternate; }
.card.selected img.portrait { animation: float 4s ease-in-out infinite; }
.card img.portrait { width: 110px; height: 110px; object-fit: contain; }
.card .name { font-weight: bold; color: #eafcff; letter-spacing: 0.06em; }
.card .desc { font-size: 0.8rem; color: var(--muted); line-height: 1.35; }
.card .lock { position: absolute; top: 4px; right: 4px; display: flex; align-items: center; gap: 4px; background: rgba(7, 11, 24, 0.85); border-radius: 12px; padding: 2px 8px; font-weight: bold; color: #d6f5ff; }
.statline { display: flex; gap: 10px; font-size: 0.75rem; color: var(--teal); flex-wrap: wrap; justify-content: center; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; }

/* Barre de ressources */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  padding: 8px 70px 8px 16px;
  background: linear-gradient(180deg, rgba(7, 11, 24, 0.95), rgba(7, 11, 24, 0.6));
  border-bottom: 2px solid var(--line);
}
.res { display: inline-flex; align-items: center; gap: 6px; font-weight: bold; font-size: 1.05rem; }
.res img { width: 28px; height: 28px; object-fit: contain; }
.bar {
  position: relative;
  width: 170px;
  height: 22px;
  border: 6px solid transparent;
  border-image: url(../assets/pack/bar-thin.png) 12 30 fill / 6px 12px stretch;
}
.bar > i { position: absolute; left: 4px; top: 3px; bottom: 3px; border-radius: 4px; background: linear-gradient(90deg, #e8524a, #f7a23b); transition: width 0.2s; }
.bar.shield > i { background: linear-gradient(90deg, #2fa8c8, var(--cyan)); }
.bar.good > i { background: linear-gradient(90deg, #3fae7a, #7fe3a0); }
.bar > span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 0.72rem; font-weight: bold; text-shadow: 0 1px 2px #000; }
.portrait-ring { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; }

/* Carte */
.map-screen { padding: 0; }
.map-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; width: min(1400px, 100%); padding: 16px; }
.map-wrap { position: relative; min-height: 520px; }
.map-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.map { position: relative; width: 100%; height: 480px; }
.map svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.map line { stroke: #2c4a5e; stroke-width: 3; stroke-dasharray: 8 7; }
.map line.done { stroke: var(--orange); stroke-dasharray: none; opacity: 0.8; }
.map line.next { stroke: var(--cyan); animation: dash 1s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -30; } }
.node {
  position: absolute;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  border: 0;
  padding: 4px;
  background: radial-gradient(circle, rgba(30, 50, 70, 0.95) 55%, rgba(30, 50, 70, 0) 72%);
  cursor: default;
  transition: transform 0.15s;
}
.node img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.node::after { content: ""; position: absolute; inset: -6px; background: url(../assets/pack/ring-frame.png) center / contain no-repeat; opacity: 0.5; }
.node.visited { opacity: 0.45; filter: grayscale(0.7); }
.node.current { opacity: 1; filter: none; }
.node.current::before { content: ""; position: absolute; inset: -14px; background: url(../assets/pack/ring-gold.png) center / contain no-repeat; animation: spin 12s linear infinite; }
.node.reachable { cursor: pointer; animation: pulse 1.6s ease-in-out infinite; }
.node.reachable::after { opacity: 1; filter: drop-shadow(0 0 6px var(--cyan)); }
.node.reachable:hover { animation: none; transform: scale(1.2); }
.node.boss { width: 92px; height: 92px; margin: -46px 0 0 -46px; }
.node.boss img { transform: scaleX(1); }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 0.8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.side { display: flex; flex-direction: column; gap: 14px; }
.ship-view { text-align: center; }
.ship-view img.ship { width: 100%; max-height: 120px; object-fit: contain; scale: -1 1; animation: float 5s ease-in-out infinite; }
.upgrades { display: flex; flex-wrap: wrap; gap: 6px; }
.upg { width: 42px; height: 42px; padding: 4px; border-radius: 10px; background: rgba(7, 11, 24, 0.7); border: 2px solid var(--c, var(--teal)); }
.upg img { width: 100%; height: 100%; object-fit: contain; }
.statgrid { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 0.82rem; }
.statgrid b { color: #eafcff; text-align: right; }

/* Modale */
#modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(3, 6, 14, 0.72);
  backdrop-filter: blur(3px);
  padding: 16px;
}
#modal[hidden] { display: none; }
.modal-box { width: min(760px, 100%); max-height: 92vh; overflow: auto; animation: fadein 0.25s ease-out; }
.event { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: start; }
.event-art { position: relative; display: grid; place-items: center; min-height: 200px; }
.event-art .main { width: 100%; max-height: 220px; object-fit: contain; animation: float 6s ease-in-out infinite; }
.event-art .who { position: absolute; bottom: -6px; right: -6px; width: 96px; height: 96px; object-fit: contain; filter: drop-shadow(0 4px 10px #000); }
.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.choices .btn { text-transform: none; letter-spacing: 0.02em; text-align: left; font-size: 0.95rem; }
.gains { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0; }
.gains .neg { color: #ff8a7e; }
.gains .pos { color: #9ff6c0; }
.offers { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 12px 0; }
.offer {
  border: 18px solid transparent;
  border-image: url(../assets/pack/frame-square.png) 34 fill / 18px stretch;
  text-align: center;
  padding: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  transition: transform 0.15s, filter 0.15s;
}
.offer:hover:not(.disabled) { transform: translateY(-4px) scale(1.02); filter: brightness(1.2); }
.offer.disabled { filter: grayscale(0.8) brightness(0.6); cursor: not-allowed; }
.offer img { width: 64px; height: 64px; object-fit: contain; }
.offer .rar { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--c); }
.offer .name { font-weight: bold; }
.offer .desc { font-size: 0.82rem; color: var(--muted); }
.price { display: inline-flex; align-items: center; gap: 4px; font-weight: bold; color: #ffd27a; }
.shop-head { display: flex; gap: 16px; align-items: center; }
.shop-head img { width: 150px; }
.end { text-align: center; }
.end .big-art { width: 220px; margin: 0 auto; display: block; }

/* Combat */
#combat { position: fixed; inset: 0; background: #000; display: grid; place-items: center; z-index: 20; }
#combat[hidden] { display: none; }
#arena { width: min(100vw, calc(100vh * 16 / 9)); height: auto; aspect-ratio: 16 / 9; display: block; touch-action: none; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud .tl { position: absolute; left: 12px; top: 10px; display: flex; gap: 10px; align-items: center; }
#hud .ring { position: relative; width: 74px; height: 74px; }
#hud .ring img { position: absolute; inset: 0; width: 100%; height: 100%; }
#hud .ring img.face { inset: 12px; width: 50px; height: 50px; border-radius: 50%; object-fit: cover; }
#hud .bars { display: flex; flex-direction: column; gap: 4px; }
#hud .tr { position: absolute; right: 70px; top: 14px; display: flex; gap: 16px; }
#hud .boss { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); width: min(520px, 46vw); text-align: center; }
#hud .boss .bar { width: 100%; height: 26px; }
#hud .boss .lbl { font-weight: bold; letter-spacing: 0.15em; text-transform: uppercase; color: #ffb3b3; font-size: 0.85rem; margin-bottom: 2px; text-shadow: 0 2px 4px #000; }
#hud .bl { position: absolute; left: 12px; bottom: 12px; right: 12px; display: flex; gap: 10px; align-items: flex-end; justify-content: space-between; }
#hud .actions { display: flex; gap: 10px; pointer-events: auto; }
#hud .act { position: relative; width: 74px; height: 74px; border: 0; background: url(../assets/pack/porthole.png) center / contain no-repeat; cursor: pointer; display: grid; place-items: center; color: #fff; font-weight: bold; font-size: 0.7rem; }
#hud .act img { width: 34px; height: 34px; object-fit: contain; }
#hud .act .cd { position: absolute; inset: 10px; border-radius: 50%; background: conic-gradient(rgba(7, 11, 24, 0.75) var(--p, 0%), transparent 0); }
#hud .act .n { position: absolute; bottom: 4px; right: 6px; font-size: 0.85rem; text-shadow: 0 1px 2px #000; }
#hud .act.on { filter: drop-shadow(0 0 10px var(--cyan)); }
#hud .act:disabled { filter: grayscale(1) brightness(0.6); }
#hud .keys { font-size: 0.75rem; color: rgba(219, 232, 240, 0.55); text-align: right; }
#hud .paused { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(3, 6, 14, 0.6); pointer-events: auto; }
#hud .paused .panel { text-align: center; display: flex; flex-direction: column; gap: 10px; }
#hud .pause-btn { position: absolute; right: 12px; top: 12px; width: 46px; height: 46px; background: none; border: 0; pointer-events: auto; cursor: pointer; }
#hud .pause-btn img { width: 100%; }
#banner { position: absolute; top: 28%; left: 0; right: 0; text-align: center; font-size: clamp(1.2rem, 3vw, 2.2rem); font-weight: 900; letter-spacing: 0.25em; text-transform: uppercase; color: #eafcff; text-shadow: 0 0 20px rgba(95, 242, 255, 0.8); pointer-events: none; opacity: 0; transition: opacity 0.4s; }
#banner.show { opacity: 1; }

#tip { position: fixed; z-index: 60; max-width: 260px; background: var(--panel); border: 2px solid var(--teal); border-radius: 10px; padding: 8px 10px; font-size: 0.82rem; pointer-events: none; }
#tip b { color: var(--orange); }

.loading { justify-content: center; gap: 16px; }
.loading .bar { width: 320px; }

@media (max-width: 900px) {
  .map-layout { grid-template-columns: 1fr; }
  .map { height: 420px; }
  .event { grid-template-columns: 1fr; }
  .event-art { min-height: 140px; }
  .event-art .main { max-height: 150px; }
  .node { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  .node.boss { width: 64px; height: 64px; margin: -32px 0 0 -32px; }
  #hud .keys { display: none; }
}

@keyframes hover { 0%, 100% { transform: translate(0, 0) rotate(0); } 25% { transform: translate(4px, -5px) rotate(1.5deg); } 75% { transform: translate(-3px, 4px) rotate(-1.5deg); } }
@keyframes thrust { from { filter: drop-shadow(-6px 0 6px rgba(95, 242, 255, 0.45)); } to { filter: drop-shadow(-14px 0 12px rgba(95, 242, 255, 0.85)); } }
@keyframes flyright { from { transform: translateX(-30vw); } to { transform: translateX(130vw); } }
@keyframes flyleft { from { transform: translateX(130vw); } to { transform: translateX(-30vw); } }
@keyframes bob { 50% { translate: 0 -4px; } }

.flyby { position: absolute; left: 0; width: 140px; pointer-events: none; opacity: 0.55; filter: drop-shadow(-12px 0 10px rgba(95, 242, 255, 0.5)); }
.flyby.right { scale: -1 1; animation: flyright 14s linear infinite; }
.flyby.left { animation: flyleft 18s linear infinite; filter: drop-shadow(12px 0 10px rgba(255, 61, 110, 0.5)); }
.flyby.small { width: 90px; animation-duration: 22s; }

.map-ship {
  position: absolute;
  width: 64px;
  margin: -52px 0 0 -32px;
  pointer-events: none;
  z-index: 2;
  scale: -1 1;
  rotate: var(--tilt, 0rad);
  transition: left 0.85s cubic-bezier(0.6, 0, 0.3, 1), top 0.85s cubic-bezier(0.6, 0, 0.3, 1);
  animation: bob 2s ease-in-out infinite, thrust 0.2s ease-in-out infinite alternate;
}
.map-ship.moving { animation: thrust 0.08s linear infinite alternate; filter: drop-shadow(-22px 0 14px rgba(95, 242, 255, 0.95)); }
.event-art .main { transform-origin: center; }
