:root {
  --night: #0b1220;
  --paper: #e8d2a0;
  --ink: #3a2412;
  --gold: #d8b56a;
  --foam: #f4efe4;
  --panel: rgba(12, 16, 28, 0.82);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  background: var(--night);
  color: var(--ink);
}

body {
  overflow-x: hidden;
}

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  z-index: 0;
}

.scene {
  position: relative;
  z-index: 1;
  width: min(42rem, 94vw);
  margin: 0 auto;
  min-height: 100vh;
  padding: 3.6rem 0 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.mast {
  text-align: center;
  color: var(--foam);
  text-shadow: 2px 2px 0 #0008;
}

.mast-year,
.mast-aka,
.gate-year,
.gate-sub,
.gate-cta {
  font-family: "Press Start 2P", monospace;
  letter-spacing: 0.14em;
}

.mast-year {
  font-size: 0.42rem;
  color: var(--gold);
  margin-bottom: 0.45rem;
}

.mast h2 {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.72rem, 2.8vw, 1.05rem);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.mast-bar,
.gate-bar {
  font-size: 0.7em;
  color: var(--gold);
}

.mast-aka {
  font-size: 0.38rem;
  color: #9aa8b8;
  margin-top: 0.4rem;
}

.stage {
  border: 3px solid var(--gold);
  background: rgba(8, 14, 24, 0.35);
  box-shadow: 6px 6px 0 #0007;
  padding: 0.7rem 0.5rem 0;
  overflow: hidden;
}

.waterline {
  height: 92px;
  position: relative;
  display: flex;
  justify-content: center;
}

.sea {
  height: 14px;
  background:
    repeating-linear-gradient(
      90deg,
      #123848 0 8px,
      #0e3040 8px 16px,
      #2a6a78 16px 18px,
      #0e3040 18px 26px
    );
  box-shadow: inset 0 2px 0 #3d8a8a;
}

.boat {
  position: relative;
  top: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

#ship,
#other {
  width: 108px;
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 0 #0006);
}

#ship {
  animation: bob 2.4s ease-in-out infinite;
}

#other {
  animation: bob-flip 2.6s ease-in-out infinite;
}

.nameplate {
  font-family: "Press Start 2P", monospace;
  font-size: 0.34rem;
  letter-spacing: 0.04em;
  border: 2px solid var(--gold);
  background: #12101c;
  color: var(--foam);
  padding: 0.3rem 0.38rem;
}

.nameplate:hover,
.names button:hover,
footer a:hover,
#music:hover {
  filter: brightness(1.12);
}

.panel {
  border: 3px solid #8a6a3a;
  background: var(--panel);
  box-shadow: 6px 6px 0 #0007;
  padding: 0.75rem 0.8rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.names {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.45rem;
  font-family: VT323, monospace;
  font-size: 1.15rem;
  color: var(--foam);
}

.names button {
  font-family: "Press Start 2P", monospace;
  font-size: 0.4rem;
  border: 2px solid var(--gold);
  background: transparent;
  color: var(--gold);
  padding: 0.42rem 0.5rem;
  cursor: pointer;
}

.names button.on {
  background: var(--gold);
  color: #1a1428;
}

.captain {
  display: flex;
  align-items: stretch;
  gap: 0.7rem;
}

#face {
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
  flex: none;
  border: 3px solid var(--gold);
  box-shadow: 4px 4px 0 #0008;
}

.bubble {
  flex: 1;
  background: var(--foam);
  border: 3px solid #1a1428;
  padding: 0.65rem 0.75rem;
  min-height: 4.4rem;
  position: relative;
  box-shadow: 4px 4px 0 #0005;
}

.bubble::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 22px;
  border: 7px solid transparent;
  border-right-color: #1a1428;
}

.bubble p {
  font-family: VT323, monospace;
  font-size: 1.4rem;
  line-height: 1.3;
  color: #1a1428;
}

.scroll {
  transform: scaleY(0.08);
  transform-origin: top;
  opacity: 0.35;
  transition: transform 1.1s ease, opacity 0.5s ease;
  filter: drop-shadow(6px 8px 0 #0005);
}

.scroll.open {
  transform: scaleY(1);
  opacity: 1;
}

.roll {
  height: 16px;
  background: repeating-linear-gradient(
    90deg,
    #6b3a18 0 10px,
    #8a4e22 10px 14px,
    #a8642c 14px 20px
  );
  border: 3px solid #2a160c;
}

.letter {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 18%),
    repeating-linear-gradient(
      180deg,
      var(--paper) 0 22px,
      #e2c894 22px 23px
    );
  border-left: 3px solid #2a160c;
  border-right: 3px solid #2a160c;
  padding: 1.15rem 1.25rem 1.45rem;
  font-family: VT323, monospace;
  font-size: 1.32rem;
  line-height: 1.38;
}

.seal {
  font-family: "Press Start 2P", monospace;
  font-size: 0.46rem;
  letter-spacing: 0.12em;
  margin-bottom: 0.7rem;
  color: #6b3a18;
}

h1 {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.82rem, 3vw, 1.1rem);
  line-height: 1.45;
  margin-bottom: 0.75rem;
}

.letter p + p {
  margin-top: 0.68rem;
}

.letter em {
  color: #6b3a18;
}

.sign {
  margin-top: 1rem;
  text-align: right;
}

.sources-title {
  margin-top: 1.25rem;
}

.chapter {
  margin-top: 1.15rem;
  margin-bottom: 0.45rem;
  font-size: 0.4rem;
}

.sources {
  list-style: none;
  margin-top: 0.4rem;
}

.sources li {
  margin-top: 0.32rem;
  padding-left: 0.85rem;
  position: relative;
}

.sources li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: #6b3a18;
}

.sources a {
  color: #5c3a18;
  text-decoration: underline;
  word-break: break-word;
}

body:has(#gate:not(.gone)) .scene,
body:has(#gate:not(.gone)) #music {
  visibility: hidden;
}

#gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  width: 100vw;
  height: 100%;
  margin: 0;
  padding: 1.5rem;
  border: 0;
  background: #070b16;
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.gate-card {
  width: min(28rem, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  padding: 1.4rem 1.1rem 1.3rem;
  border: 3px solid var(--gold);
  background: rgba(8, 12, 22, 0.88);
  box-shadow: 8px 8px 0 #0008;
  text-align: center;
}

.gate-year {
  font-size: 0.42rem;
  color: #9aa8b8;
}

.gate-name {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.78rem, 3.4vw, 1.15rem);
  line-height: 1.45;
  color: var(--foam);
  text-shadow: 3px 3px 0 #000;
}

.gate-sub {
  font-size: 0.4rem;
  color: var(--gold);
}

.gate-ships {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 1.4rem;
  margin: 0.2rem 0 0.15rem;
}

.gate-ships img {
  width: 96px;
  height: auto;
  image-rendering: pixelated;
}

#gate-ghost {
  transform: scaleX(-1);
}

.gate-cta {
  margin-top: 0.25rem;
  font-size: 0.52rem;
  border: 3px solid var(--gold);
  padding: 0.6rem 0.85rem;
  background: #12101c;
  animation: pulse 1.4s ease-in-out infinite;
}

#gate.gone {
  display: none;
}

#music,
footer a {
  font-family: "Press Start 2P", monospace;
  font-size: 0.4rem;
  color: var(--gold);
  border: 2px solid var(--gold);
  background: rgba(11, 18, 32, 0.9);
  padding: 0.45rem 0.55rem;
  text-decoration: none;
  cursor: pointer;
}

#music {
  position: fixed;
  top: max(1.15rem, calc(env(safe-area-inset-top) + 0.85rem));
  right: max(1.15rem, calc(env(safe-area-inset-right) + 0.85rem));
  z-index: 8;
}

#music.on {
  background: var(--gold);
  color: #1a1428;
}

.ca {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 3px solid var(--gold);
  background: var(--panel);
  box-shadow: 6px 6px 0 #0007;
  padding: 0.5rem 0.55rem;
}

.ca-label {
  font-family: "Press Start 2P", monospace;
  font-size: 0.38rem;
  color: var(--gold);
  flex: none;
}

#ca-addr {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: VT323, monospace;
  font-size: 1.15rem;
  color: var(--foam);
}

#ca-copy {
  flex: none;
  font-family: "Press Start 2P", monospace;
  font-size: 0.36rem;
  color: #1a1428;
  background: var(--gold);
  border: 2px solid var(--gold);
  padding: 0.38rem 0.45rem;
  cursor: pointer;
}

footer {
  display: flex;
  justify-content: center;
  padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
}

@keyframes bob {
  50% {
    transform: translateY(-5px);
  }
}

@keyframes bob-flip {
  0%,
  100% {
    transform: scaleX(-1) translateY(0);
  }
  50% {
    transform: scaleX(-1) translateY(-5px);
  }
}

@keyframes pulse {
  50% {
    background: var(--gold);
    color: #1a1428;
  }
}

@media (max-width: 700px) {
  .scene {
    padding-top: 3.2rem;
    gap: 0.7rem;
  }

  .captain {
    flex-direction: column;
    align-items: center;
  }

  .bubble {
    width: 100%;
  }

  .bubble::before {
    left: 28px;
    top: -14px;
    border-right-color: transparent;
    border-bottom-color: #1a1428;
  }

  .waterline {
    height: 108px;
  }

  #ship,
  #other {
    width: 78px;
  }

  .nameplate {
    max-width: 42vw;
    font-size: 0.28rem;
    line-height: 1.4;
    white-space: normal;
  }

  .meet .boat.us {
    left: 6%;
  }

  .meet .boat.them {
    right: 6%;
  }

  .one .boat.us {
    left: 30%;
  }

  .names {
    flex-direction: column;
  }

  .names button {
    width: 100%;
  }

  .letter {
    padding: 0.9rem 0.75rem 1.1rem;
    font-size: 1.18rem;
  }

  h1 {
    font-size: 0.7rem;
  }

  #music {
    font-size: 0.34rem;
    padding: 0.38rem 0.42rem;
    top: max(1.35rem, calc(env(safe-area-inset-top) + 1rem));
    right: max(1.35rem, calc(env(safe-area-inset-right) + 1rem));
  }

  .gate-cta {
    font-size: 0.42rem;
  }

  .gate-ships img {
    width: 72px;
  }

  .gate-card {
    gap: 0.55rem;
    padding: 1.1rem 0.8rem 1rem;
  }
}
