:root {
  --navy: #0b1524;
  --navy-2: #101d33;
  --navy-3: #16273f;
  --paper: #f4efe4;
  --ink: #17202e;
  --gold: #d9a441;
  --mist: #93a4b8;
  --line: rgba(244, 239, 228, 0.14);
  --serif: Georgia, "Times New Roman", "Songti SC", "SimSun", serif;
  --sans: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: Consolas, "SF Mono", "Courier New", monospace;
}

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

html, body { height: 100%; }

body {
  background: var(--navy);
  color: var(--paper);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.mono { font-family: var(--mono); letter-spacing: 0.06em; }
.hidden { display: none !important; }

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Terminal ---------- */

#terminal {
  padding: 40px clamp(24px, 5vw, 72px) 24px;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(217, 164, 65, 0.07), transparent 60%),
    linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
  overflow: auto;
}

.term-meta {
  font-size: 11px;
  color: var(--gold);
  text-transform: uppercase;
}

.term-title {
  font-family: var(--serif);
  font-size: clamp(44px, 7vw, 72px);
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-top: 10px;
}

.term-sub {
  color: var(--mist);
  font-size: 15px;
  margin-top: 10px;
  max-width: 560px;
  line-height: 1.7;
}

.term-progress {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
  font-size: 12px;
  color: var(--mist);
}

.progress-track {
  width: min(280px, 34vw);
  height: 3px;
  background: rgba(244, 239, 228, 0.12);
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--gold);
  transition: width 0.5s ease;
}

.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  cursor: pointer;
  padding: 4px 0;
}

.link-btn:hover { text-decoration: underline; }

.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 36px;
  padding-bottom: 24px;
}

.card {
  position: relative;
  border: 1px solid var(--line);
  background: var(--navy-2);
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  color: var(--paper);
  font: inherit;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.35s;
}

.card:hover { transform: translateY(-6px); border-color: rgba(217, 164, 65, 0.55); }

.card-thumb {
  position: relative;
  height: 132px;
  overflow: hidden;
}

.card-thumb svg {
  position: absolute;
  left: 50%;
  bottom: -6px;
  height: 92%;
  transform: translateX(-50%);
  fill: rgba(11, 21, 36, 0.82);
}

.card-body {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px 16px;
}

.card-name {
  font-family: var(--serif);
  font-size: 24px;
  letter-spacing: 0.1em;
}

.card-site { font-size: 12px; color: var(--mist); margin-top: 4px; }

.card-code {
  font-size: 11px;
  color: var(--gold);
}

.card-status {
  position: absolute;
  top: 10px;
  right: 12px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: #7fd4a2;
  background: rgba(11, 21, 36, 0.72);
  border: 1px solid rgba(127, 212, 162, 0.4);
  padding: 3px 8px;
}

.card-stamped {
  position: absolute;
  top: 10px;
  left: 12px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--navy);
  background: var(--gold);
  padding: 3px 8px;
  letter-spacing: 0.08em;
}

.term-foot {
  margin-top: auto;
  padding-top: 8px;
  font-size: 11px;
  color: rgba(147, 164, 184, 0.6);
}

/* ---------- Boarding ---------- */

#boarding {
  align-items: center;
  justify-content: center;
  background: var(--navy);
}

.ticket {
  width: min(560px, 88vw);
  border: 1px solid var(--line);
  background: linear-gradient(160deg, var(--navy-3), var(--navy-2));
  padding: 28px 32px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: ticket-in 0.5s cubic-bezier(0.2, 0.9, 0.25, 1);
}

@keyframes ticket-in {
  from { opacity: 0; transform: translateY(26px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.ticket-top {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--gold);
}

.ticket-route {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 26px 0 20px;
}

.port-code { font-size: 26px; color: var(--paper); }
.port-name { font-size: 12px; color: var(--mist); margin-top: 4px; }
.port.right { text-align: right; }

.ticket-arc {
  position: relative;
  flex: 1;
  color: var(--gold);
}

.ticket-arc svg { display: block; width: 100%; height: 40px; }

.arc-dot {
  position: absolute;
  top: 4px;
  left: 0;
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  animation: arc-fly 1.4s ease-in-out forwards;
}

@keyframes arc-fly {
  0% { left: 0; top: 22px; }
  50% { left: calc(50% - 4px); top: -2px; }
  100% { left: calc(100% - 8px); top: 22px; }
}

.ticket-bottom {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--mist);
  border-top: 1px dashed var(--line);
  padding-top: 14px;
}

/* ---------- Stage ---------- */

#stage {
  background: #000;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

#stage.dragging { cursor: grabbing; }

.world {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--sky-1, #1b2a4a), var(--sky-2, #3d4f78) 55%, var(--sky-3, #c98a5b));
  transition: background 0.6s ease;
}

.sun {
  position: absolute;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--sun-color, rgba(255, 214, 140, 0.9)), transparent 70%);
  left: var(--sun-x, 70%);
  top: var(--sun-y, 22%);
  pointer-events: none;
}

.layer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 150vw;
  left: 0;
  will-change: transform;
  pointer-events: none;
}

.layer-far {
  opacity: 0.45;
}

.layer-far .ridge {
  position: absolute;
  bottom: 18%;
  width: 100%;
  height: 42%;
  fill: rgba(11, 21, 36, 0.55);
}

.layer-mid .landmark {
  position: absolute;
  bottom: 16%;
  left: 50%;
  height: 62%;
  transform: translateX(-50%);
  fill: rgba(8, 15, 26, 0.88);
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.35));
}

.layer-near .ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 18%;
  background: linear-gradient(180deg, var(--ground-1, #131c2c), var(--ground-2, #0a111d));
}

.layer-near .street {
  position: absolute;
  bottom: 6%;
  left: 10%;
  right: 10%;
  height: 2px;
  background: repeating-linear-gradient(90deg, rgba(244, 239, 228, 0.35) 0 36px, transparent 36px 72px);
}

.stage-scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 10, 18, 0.55), transparent 22%),
    linear-gradient(0deg, rgba(5, 10, 18, 0.6), transparent 30%);
}

.hud {
  position: absolute;
  left: clamp(16px, 3vw, 40px);
  right: clamp(16px, 3vw, 40px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.hud > * { pointer-events: auto; }

.hud-top { top: clamp(16px, 3vh, 32px); }

.ghost-btn {
  background: rgba(11, 21, 36, 0.55);
  border: 1px solid var(--line);
  color: var(--paper);
  font: inherit;
  font-size: 13px;
  padding: 9px 14px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: border-color 0.25s;
}

.ghost-btn:hover { border-color: var(--gold); }

.hud-dest { text-align: center; }

.hud-code { font-size: 11px; color: var(--gold); }

.hud-name {
  font-family: var(--serif);
  font-size: clamp(26px, 3.4vw, 40px);
  letter-spacing: 0.18em;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
}

.hud-right { text-align: right; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }

.hud-coords { font-size: 11px; color: var(--mist); }

.hud-bottom {
  bottom: clamp(16px, 3vh, 32px);
  align-items: flex-end;
}

.info-card {
  width: min(360px, 86vw);
  background: rgba(11, 21, 36, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  padding: 20px 22px;
}

.info-site {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: 0.12em;
  color: var(--gold);
}

.info-desc {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.8;
  color: rgba(244, 239, 228, 0.88);
}

.info-facts {
  list-style: none;
  margin-top: 12px;
  font-size: 11px;
  color: var(--mist);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.info-facts li::before { content: "· "; color: var(--gold); }

.stamp-btn {
  margin-top: 16px;
  width: 100%;
  padding: 11px 0;
  background: none;
  border: 1px dashed var(--gold);
  color: var(--gold);
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.24em;
  cursor: pointer;
  transition: background 0.25s, color 0.25s;
}

.stamp-btn:hover { background: rgba(217, 164, 65, 0.14); }

.stamp-btn.done {
  border-style: solid;
  background: var(--gold);
  color: var(--navy);
  cursor: default;
}

.stage-hint {
  font-size: 11px;
  color: rgba(244, 239, 228, 0.55);
  text-align: right;
  max-width: 40%;
}

/* ---------- Stamp FX ---------- */

.stamp-fx {
  position: absolute;
  right: clamp(24px, 8vw, 120px);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 5;
  display: none;
}

.stamp-ring {
  width: 170px;
  height: 170px;
  border: 4px double var(--gold);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--gold);
  background: rgba(11, 21, 36, 0.35);
  transform: rotate(-14deg);
  animation: stamp-hit 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes stamp-hit {
  0% { opacity: 0; transform: rotate(-40deg) scale(2.4); }
  60% { opacity: 1; transform: rotate(-14deg) scale(0.94); }
  100% { opacity: 1; transform: rotate(-14deg) scale(1); }
}

.stamp-fx.fade { opacity: 0; transition: opacity 0.5s ease 1.6s; }

.stamp-code { font-size: 30px; letter-spacing: 0.2em; }
.stamp-label { font-family: var(--serif); font-size: 18px; letter-spacing: 0.3em; }
.stamp-date { font-size: 10px; opacity: 0.8; }

/* ---------- Journal ---------- */

.journal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 92vw);
  background: var(--navy-2);
  border-left: 1px solid var(--line);
  padding: 28px;
  z-index: 20;
  overflow: auto;
  animation: journal-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes journal-in {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.journal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}

.journal-head h2 {
  font-family: var(--serif);
  font-size: 26px;
  letter-spacing: 0.16em;
}

.journal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.journal-item {
  border: 1px solid var(--line);
  padding: 16px 14px;
  text-align: center;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.journal-item.stamped { border-color: rgba(217, 164, 65, 0.55); }

.journal-item .j-code { font-family: var(--mono); font-size: 12px; color: var(--mist); }
.journal-item .j-name { font-family: var(--serif); font-size: 20px; letter-spacing: 0.14em; }
.journal-item .j-state { font-family: var(--mono); font-size: 10px; color: var(--mist); }
.journal-item.stamped .j-state { color: var(--gold); }

@media (max-width: 640px) {
  .hud-bottom { flex-direction: column; align-items: stretch; }
  .stage-hint { display: none; }
  .ticket-route { flex-direction: column; }
  .port.right { text-align: center; }
}
