/* Local scenes styling: ship assembly (ch. 4) and star chart (ch. 6).
   Reuses the book palette from index.html; safe to load after the main styles. */

.scene {
  margin: 26px 0;
  padding: 20px;
  border-radius: 20px;
  background: #ffffff;
  border: 2px solid rgba(19, 122, 149, 0.25);
  box-shadow: 0 10px 26px rgba(14, 77, 100, 0.08);
  color: var(--ink, #2c241d);
}

.scene *,
.scene *::before,
.scene *::after {
  box-sizing: border-box;
}

.scene [hidden] {
  display: none !important;
}

.scene h3 {
  margin: 0 0 6px;
  font-size: 1.18rem;
  line-height: 1.3;
  color: var(--sea-dark, #0e4d64);
  display: flex;
  align-items: center;
  gap: 8px;
}

.scene-lead {
  margin: 0 0 14px;
  max-width: 62ch;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--ink-muted, #5d5044);
}

.scene-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.scene-btn {
  appearance: none;
  -webkit-appearance: none;
  min-height: 50px;
  padding: 11px 18px;
  border-radius: 14px;
  border: 2px solid transparent;
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.scene-btn:hover {
  transform: translateY(-1px);
}

.scene-btn:active {
  transform: translateY(1px);
}

.scene-btn:focus-visible {
  outline: 3px solid var(--gold, #e9a93a);
  outline-offset: 3px;
}

.scene-btn-primary {
  color: #ffffff;
  background: linear-gradient(135deg, var(--sea, #137a95) 0%, #1b9bb8 100%);
  border-color: rgba(14, 77, 100, 0.3);
  box-shadow: 0 7px 16px rgba(19, 122, 149, 0.24);
}

.scene-btn-primary:hover {
  background: linear-gradient(135deg, var(--sea-dark, #0e4d64) 0%, var(--sea, #137a95) 100%);
}

.scene-btn-secondary {
  color: #6b4a12;
  background: var(--gold-soft, #fff5d9);
  border-color: rgba(233, 169, 58, 0.6);
  box-shadow: 0 5px 12px rgba(233, 169, 58, 0.16);
}

.scene-btn-secondary:hover {
  border-color: var(--gold, #e9a93a);
}

.scene-status {
  margin: 12px 0 0;
  min-height: 46px;
  padding: 10px 13px;
  border-radius: 10px;
  border-left: 4px solid var(--gold, #e9a93a);
  background: var(--parchment, #fdf3df);
  color: var(--ink, #2c241d);
  font-size: 0.95rem;
  line-height: 1.45;
}

/* ------------------------------ Ship scene ------------------------------ */

.ship-stage {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(180deg, #70c9dd, #c7eede 46%, #ffe5a4 78%, #fbe3a5);
  border: 2px solid rgba(19, 122, 149, 0.16);
}

.ship-svg {
  display: block;
  width: 100%;
  height: auto;
}

.ship-handle {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 46%;
  padding: 9px 13px;
  border-radius: 14px;
  border: 2px solid #b9834a;
  background: linear-gradient(135deg, #fdf3df 0%, #e9c98e 100%);
  color: #5a3a1c;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.2;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  box-shadow: 0 5px 12px rgba(90, 58, 28, 0.2);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  /* Exclusive to the optional handle: the rest of the scene keeps native touch. */
  touch-action: none;
}

.ship-handle:hover {
  box-shadow: 0 7px 16px rgba(90, 58, 28, 0.26);
}

.ship-handle.is-dragging {
  z-index: 5;
  cursor: grabbing;
  transition: none;
  box-shadow: 0 12px 22px rgba(90, 58, 28, 0.3);
}

.ship-handle-piece {
  display: block;
  flex: none;
  width: clamp(44px, 12vw, 76px);
  height: 34px;
  pointer-events: none;
}

.ship-handle-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.ship-drop {
  position: absolute;
  left: 19%;
  top: 8%;
  width: 62%;
  height: 82%;
  z-index: 1;
  border: 2px dashed transparent;
  border-radius: 22px;
  pointer-events: none;
  transition: background-color 0.18s ease, border-color 0.18s ease;
}

.ship-stage.is-dragging .ship-drop {
  border-color: rgba(200, 90, 50, 0.65);
  background: rgba(233, 169, 58, 0.11);
}

.ship-ghost {
  transition: opacity 0.3s ease;
}

.scene-ship.is-complete .ship-ghost {
  opacity: 0;
}

.ship-part {
  opacity: 0;
  transform: translateY(10px);
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transition: opacity 0.38s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.ship-part.is-on {
  opacity: 1;
  transform: translateY(0);
}

/* Each part moves in its own way: the keel slides in, the hull drops in
   with a small bounce, the deck widens out, the mast swings up on its foot,
   and the sails unfurl from the top of the yard. Keyframes hold their last
   frame (fill both) and disappear on reset, when .is-on is removed. */
.ship-part-1.is-on {
  animation: shipKeelSlide 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ship-part-2.is-on {
  animation: shipHullDrop 0.85s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

.ship-part-3.is-on {
  transform-origin: 50% 50%;
  animation: shipDeckWiden 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ship-part-4 {
  transform-origin: 50% 100%;
}

.ship-part-4.is-on {
  animation: shipMastPivot 1s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

.ship-part-5.is-on .ship-sail-jib {
  transform-box: fill-box;
  transform-origin: 50% 0%;
  animation: shipSailUnfurl 1s cubic-bezier(0.22, 1, 0.36, 1) 0.25s both;
}

.ship-part-5.is-on .ship-sail-main {
  transform-box: fill-box;
  transform-origin: 50% 0%;
  animation: shipSailUnfurl 1.1s cubic-bezier(0.22, 1, 0.36, 1) 0.05s both;
}

.ship-part-5.is-on .ship-flag {
  transform-box: fill-box;
  transform-origin: 0% 50%;
  animation: shipFlagFlutter 1.4s ease-in-out 0.9s infinite alternate;
}

@keyframes shipKeelSlide {
  0% { opacity: 0; transform: translateX(-70px); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: translateX(0); }
}

@keyframes shipHullDrop {
  0% { opacity: 0; transform: translateY(-46px) rotate(-3deg); }
  55% { opacity: 1; transform: translateY(6px) rotate(1.5deg); }
  80% { transform: translateY(-3px) rotate(-0.5deg); }
  100% { opacity: 1; transform: translateY(0) rotate(0); }
}

@keyframes shipDeckWiden {
  0% { opacity: 0; transform: scaleX(0.2); }
  100% { opacity: 1; transform: scaleX(1); }
}

@keyframes shipMastPivot {
  0% { opacity: 0; transform: rotate(-22deg); }
  45% { opacity: 1; }
  75% { transform: rotate(4deg); }
  100% { opacity: 1; transform: rotate(0); }
}

@keyframes shipSailUnfurl {
  0% { opacity: 0; transform: scaleY(0.04); }
  30% { opacity: 1; }
  100% { opacity: 1; transform: scaleY(1); }
}

@keyframes shipFlagFlutter {
  0% { transform: skewY(-6deg) scaleX(1); }
  100% { transform: skewY(6deg) scaleX(0.9); }
}

.scene-ship.is-launching .ship-sea path {
  animation: shipSeaDrift 1.2s ease-in-out 2 alternate;
}

.scene-ship.is-launching .ship-sea path:nth-child(2) {
  animation-direction: alternate-reverse;
}

@keyframes shipSeaDrift {
  0% { transform: translateX(-10px); }
  100% { transform: translateX(10px); }
}

.scene-ship.is-launching .ship-boat {
  transform-box: view-box;
  transform-origin: 211px 246px;
  animation: shipLaunch 2.4s ease-in-out both;
}

@keyframes shipLaunch {
  0% { transform: none; }
  28% { transform: translate(22px, 2px) rotate(-4deg) scale(.95); }
  64% { transform: translate(72px, 5px) rotate(3deg) scale(.8); }
  100% { transform: translate(105px, 0) scale(.73); }
}

.ship-wake {
  opacity: 0;
  transition: opacity 0.8s ease;
}

.scene-ship.is-launching .ship-wake,
.scene-ship.is-launched .ship-wake {
  opacity: 0.85;
}

.scene-ship.is-launching .ship-wake path {
  animation: shipWake 2s ease-in-out infinite alternate;
}

.scene-ship.is-launching .ship-wake path:nth-child(2) { animation-delay: -0.7s; }
.scene-ship.is-launching .ship-wake path:nth-child(3) { animation-delay: -1.3s; }

@keyframes shipWake {
  from { opacity: 0.4; transform: translateX(0); }
  to { opacity: 1; transform: translateX(-12px); }
}

.ship-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.ship-progress li {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid #d7e7ec;
  background: #f2f7f9;
  color: #56707a;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

.ship-progress li.is-done {
  color: #7a5612;
  background: var(--gold-soft, #fff5d9);
  border-color: var(--gold, #e9a93a);
}

.ship-progress li.is-current {
  color: var(--sea-dark, #0e4d64);
  border-color: var(--sea, #137a95);
  box-shadow: 0 0 0 2px rgba(19, 122, 149, 0.12);
}

/* ------------------------------ Star scene ------------------------------ */

.scene-stars {
  color: #eef5ff;
  background:
    radial-gradient(120% 130% at 18% 0%, #1d3560 0%, #12213b 58%, #0d1930 100%);
  border-color: rgba(255, 226, 138, 0.35);
  box-shadow: 0 14px 30px rgba(10, 20, 40, 0.24);
}

.scene-stars h3 {
  color: #ffe28a;
}

.scene-stars .scene-lead {
  color: #c9dbf7;
}

.star-chart {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(255, 226, 138, 0.22);
  background:
    radial-gradient(circle at 72% 18%, rgba(255, 226, 138, 0.07), transparent 55%),
    #0e1b33;
}

.star-chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* A second full-bleed SVG holds the ambient twinkles and shooting stars. */
.star-chart-twinkle {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.star-twinkle {
  fill: #dfe9ff;
  animation: star-twinkle 3.6s ease-in-out infinite;
}

@keyframes star-twinkle {
  0%, 100% { opacity: 0.16; }
  50% { opacity: 0.9; }
}

.star-shooting {
  fill: #fff8d0;
  stroke: #ffe498;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0;
  filter: drop-shadow(0 0 5px #ffe698);
}
.star-shooting path { opacity: .7; }

/* Polaris breathes while the whole chart glows. */
.polaris.is-found .polaris-halo {
  animation: scenePolarisBreath 3.4s ease-in-out infinite;
}

@keyframes scenePolarisBreath {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.95; }
}

.star-shooting {
  animation: star-shoot var(--shot-period) linear var(--shot-delay) infinite;
}

@keyframes star-shoot {
  0%, 81% { opacity: 0; transform: translate(-102px, 40px); }
  84% { opacity: 1; }
  92%, 100% { opacity: 0; transform: translate(16px, -6px); }
}

@media (prefers-reduced-motion: reduce) {
  .star-twinkle,
  .star-shooting,
  .polaris.is-found .polaris-halo {
    animation: none !important;
  }
  .star-twinkle { opacity: 0.55; }
  .star-shooting { opacity: 0; }
}

.constellation-line {
  fill: none;
  stroke: #a9c8f5;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition: stroke-dashoffset 1.5s ease, opacity 0.3s ease;
}

.constellation-star {
  fill: #7893b7;
  opacity: 0.5;
  transition: fill 0.4s ease, opacity 0.4s ease, filter 0.4s ease;
  transition-delay: 0s;
}

.constellation.is-found .constellation-line { stroke-dashoffset: 0; opacity: 0.85; }
.constellation.is-found .constellation-star {
  fill: #fff0b4;
  opacity: 1;
  filter: drop-shadow(0 0 4px #ffda78);
  transition-delay: calc(var(--star-order) * 0.13s);
}

.polaris { opacity: 0.45; transition: opacity 0.5s ease; }
.polaris path, .polaris-halo { fill: none; stroke: #ffe698; stroke-width: 1.5; }
.polaris-halo { opacity: 0; transition: opacity 0.5s ease; }
.polaris.is-found { opacity: 1; }
.polaris.is-found .polaris-halo { opacity: 0.8; }
.polaris.is-found .constellation-star { fill: #fff4bc; opacity: 1; filter: drop-shadow(0 0 7px #ffe28a); }

.north-route { opacity: 0; transition: opacity 0.6s ease; }
.north-route path { fill: none; stroke: #f5d17b; stroke-width: 1.5; stroke-dasharray: 5 6; }
.north-route text { fill: #ffe28a; font: 12px sans-serif; }
.has-north-route .north-route { opacity: 0.85; }

.scene-stars.all-found .star-chart {
  animation: sceneChartGlow 1.1s ease-out 1;
}

@keyframes sceneChartGlow {
  0% {
    box-shadow: 0 0 0 0 rgba(244, 196, 94, 0);
  }
  35% {
    box-shadow: 0 0 0 4px rgba(244, 196, 94, 0.32), 0 0 32px rgba(244, 196, 94, 0.32);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(244, 196, 94, 0);
  }
}

.star-hotspot {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 50%);
  transform: translate(-50%, -50%);
  z-index: 2;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #ffe28a;
  font: inherit;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.star-hotspot:focus-visible {
  outline: 3px solid #ffe28a;
  outline-offset: 3px;
}

.star-hotspot-dot {
  display: block;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(255, 226, 138, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(244, 196, 94, 0.35);
  transition: transform 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
}

.star-hotspot:hover .star-hotspot-dot,
.star-hotspot:focus-visible .star-hotspot-dot {
  transform: scale(1.18);
}

.star-hotspot.is-selected .star-hotspot-dot {
  color: #fffbe6;
  transform: scale(1.2);
  text-shadow: 0 0 8px #fff6cf, 0 0 20px #ffe28a, 0 0 32px rgba(233, 169, 58, 0.7);
}

.star-hotspot.is-found:not(.is-selected) .star-hotspot-dot {
  opacity: 0.82;
}

.star-hotspot-label {
  position: absolute;
  top: calc(50% + 19px);
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 7px;
  border: 1px solid rgba(255, 226, 138, 0.14);
  border-radius: 999px;
  background: rgba(10, 22, 43, 0.74);
  color: #cfe0ff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.star-hotspot.is-selected .star-hotspot-label {
  color: #fff3c4;
  background: rgba(244, 196, 94, 0.2);
  border-color: rgba(255, 226, 138, 0.68);
}

.star-scene-detail {
  margin-top: 14px;
  min-height: 68px;
  padding: 12px 14px;
  border-radius: 12px;
  border-left: 4px solid #f4c45e;
  background: rgba(255, 255, 255, 0.08);
  color: #e9f2ff;
  line-height: 1.45;
}

.star-detail-name {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.star-detail-name-text {
  color: #ffe28a;
  font-weight: 800;
}

.star-detail-tr {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 7px;
  background: rgba(255, 226, 138, 0.14);
  color: #ffe28a;
  font-size: 0.78rem;
  font-weight: 700;
}

.star-detail-text {
  margin: 6px 0 0;
  font-size: 0.95rem;
  color: #e9f2ff;
}

.scene-stars .scene-btn-secondary {
  color: #fff3c4;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 226, 138, 0.38);
  box-shadow: none;
}

.scene-stars .scene-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 226, 138, 0.7);
}

.star-count {
  margin-left: auto;
  color: #a9c2e8;
  font-size: 0.8rem;
  font-weight: 700;
}

/* ------------------------------ Responsive ------------------------------ */

@media (max-width: 560px) {
  .scene {
    padding: 16px;
    border-radius: 16px;
  }

  .scene h3 {
    font-size: 1.05rem;
  }

  .scene-lead {
    font-size: 0.9rem;
  }

  .ship-handle {
    left: 8px;
    bottom: 8px;
    padding: 8px 10px;
    font-size: 0.75rem;
  }

  .star-hotspot {
    width: 44px;
    height: 44px;
  }

  .star-hotspot-dot {
    font-size: 1.35rem;
  }

  .star-hotspot-label {
    top: calc(50% + 18px);
    padding: 1px 5px;
    font-size: 0.6rem;
  }

  .star-count {
    margin-left: 0;
  }
}

/* ------------------------------ Print & motion ------------------------------ */

@media print {
  .scene,
  #scene-ship,
  #scene-stars {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scene *,
  .scene *::before,
  .scene *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
  }

  .ship-part {
    transform: none !important;
  }

  .ship-handle {
    transition: none !important;
  }

  .scene-stars.all-found .star-chart {
    animation: none;
  }
}
