:root {
  --void: #070a14;
  --deep: #0b1020;
  --panel: rgba(12, 18, 36, 0.72);
  --panel-edge: rgba(148, 180, 210, 0.14);
  --ink: #e8eef8;
  --muted: #8b9bb8;
  --dim: #5a6a88;
  --phosphor: #5eead4;
  --phosphor-dim: rgba(94, 234, 212, 0.35);
  --sodium: #e8a46a;
  --sodium-glow: rgba(232, 164, 106, 0.45);
  --danger: #ff8a8a;
  --grid: rgba(120, 150, 190, 0.08);
  --font-display: "Instrument Serif", Georgia, serif;
  --font-body: "Outfit", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--void);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 400;
  letter-spacing: 0.01em;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(94, 234, 212, 0.07), transparent 55%),
    radial-gradient(900px 500px at 90% 10%, rgba(232, 164, 106, 0.06), transparent 50%),
    radial-gradient(800px 700px at 50% 100%, rgba(70, 100, 180, 0.12), transparent 60%),
    var(--void);
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.scan {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 39;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  opacity: 0.5;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.4rem 0.6rem;
  z-index: 5;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ffd2a8 0%, var(--sodium) 35%, transparent 36%),
    radial-gradient(circle at 50% 50%, transparent 48%, var(--phosphor-dim) 49%, transparent 60%);
  box-shadow:
    0 0 0 1px rgba(94, 234, 212, 0.25),
    0 0 24px var(--sodium-glow);
  animation: pulse-mark 3.6s ease-in-out infinite;
}

@keyframes pulse-mark {
  0%,
  100% {
    box-shadow:
      0 0 0 1px rgba(94, 234, 212, 0.25),
      0 0 18px var(--sodium-glow);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(94, 234, 212, 0.45),
      0 0 32px var(--sodium-glow);
  }
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.85rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.tag {
  margin: 0.2rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(10px);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink);
}

.pill.muted {
  color: var(--muted);
}

.dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--dim);
}

.dot.live {
  background: var(--phosphor);
  box-shadow: 0 0 8px var(--phosphor);
  animation: blink 1.8s ease-in-out infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.stage {
  position: relative;
  min-height: 0;
  margin: 0.4rem 0.8rem 0.6rem;
  border-radius: calc(var(--radius) + 4px);
  border: 1px solid var(--panel-edge);
  background:
    linear-gradient(180deg, rgba(20, 30, 55, 0.55), rgba(8, 12, 24, 0.85)),
    var(--deep);
  overflow: hidden;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 20px 60px rgba(0, 0, 0, 0.35);
}

#map {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 52dvh;
  cursor: crosshair;
  touch-action: none;
}

.tooltip {
  position: absolute;
  z-index: 6;
  max-width: min(280px, 70vw);
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  background: rgba(8, 12, 24, 0.92);
  border: 1px solid rgba(94, 234, 212, 0.25);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
}

.tooltip .t-body {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.35;
}

.tooltip .t-meta {
  margin: 0.35rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--phosphor);
  letter-spacing: 0.04em;
}

.pulse-panel,
.log-panel {
  position: absolute;
  z-index: 4;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(14px);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  max-width: min(340px, calc(100% - 1.6rem));
}

.pulse-panel {
  top: 1rem;
  left: 1rem;
}

.log-panel {
  top: 1rem;
  right: 1rem;
  width: min(300px, calc(100% - 1.6rem));
  max-height: min(42vh, 360px);
  display: flex;
  flex-direction: column;
}

.panel-label {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
}

.freq {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--sodium);
  text-transform: uppercase;
}

.panel-title {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
}

#pulse-text {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  line-height: 1.35;
  font-style: italic;
  color: var(--ink);
}

.pulse-meta {
  margin: 0.55rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--dim);
  letter-spacing: 0.06em;
}

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  scrollbar-width: thin;
  scrollbar-color: var(--dim) transparent;
}

.log li {
  padding-bottom: 0.55rem;
  border-bottom: 1px solid rgba(148, 180, 210, 0.08);
}

.log li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.log .l-body {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.35;
  color: var(--ink);
}

.log .l-meta {
  margin: 0.25rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--dim);
  letter-spacing: 0.04em;
}

.log li.fresh .l-body {
  color: var(--phosphor);
}

.tx {
  position: relative;
  z-index: 5;
  padding: 0.65rem 1rem calc(0.9rem + var(--safe-b));
}

#tx-form {
  max-width: 920px;
  margin: 0 auto;
}

.tx-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.55rem 0.55rem 0.95rem;
  border-radius: 999px;
  background: rgba(12, 18, 36, 0.9);
  border: 1px solid var(--panel-edge);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.25),
    0 12px 40px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.tx-prefix {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--sodium);
  letter-spacing: 0.08em;
  user-select: none;
}

#body {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.55rem 0;
}

#body::placeholder {
  color: var(--dim);
}

#tx-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.9rem;
  color: #1a1208;
  background: linear-gradient(180deg, #f0c08a, var(--sodium));
  box-shadow:
    0 0 0 1px rgba(255, 210, 160, 0.25),
    0 8px 24px var(--sodium-glow);
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}

#tx-btn:hover:not(:disabled) {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

#tx-btn:active:not(:disabled) {
  transform: translateY(0);
}

#tx-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tx-foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 1.1rem 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--dim);
}

#status.error {
  color: var(--danger);
}

#status.ok {
  color: var(--phosphor);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  .log-panel {
    display: none;
  }

  .pulse-panel {
    max-width: calc(100% - 1.6rem);
  }

  #pulse-text {
    font-size: 1.02rem;
  }

  .brand h1 {
    font-size: 1.55rem;
  }

  .tx-row {
    grid-template-columns: 1fr auto;
    border-radius: 18px;
    padding: 0.5rem;
  }

  .tx-prefix {
    display: none;
  }

  #body {
    grid-column: 1 / -1;
    padding: 0.55rem 0.7rem 0.25rem;
  }

  #tx-btn {
    grid-column: 2;
  }
}

@media (max-width: 520px) {
  .top {
    flex-direction: column;
    align-items: flex-start;
  }

  .meta {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand-mark,
  .dot.live {
    animation: none;
  }
}

:focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 2px;
}

/* —— Arrival —— */
.arrival {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background:
    radial-gradient(800px 500px at 50% 40%, rgba(94, 234, 212, 0.08), transparent 60%),
    rgba(5, 8, 16, 0.94);
  backdrop-filter: blur(12px);
  animation: arrival-in 0.5s ease;
}

/* `.arrival { display:grid }` would otherwise override the HTML hidden attribute */
.arrival[hidden],
.arrival.is-done {
  display: none !important;
  pointer-events: none !important;
}

.arrival.is-leaving {
  animation: arrival-out 0.45s ease forwards;
  pointer-events: none;
}

@keyframes arrival-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes arrival-out {
  to { opacity: 0; visibility: hidden; }
}

.arrival-inner {
  text-align: center;
  max-width: 28rem;
  padding: 2rem;
}

.arrival-freq {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  color: var(--sodium);
  margin: 0 0 1rem;
}

.arrival-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-style: italic;
  margin: 0 0 0.75rem;
  line-height: 1.15;
}

.arrival-sub {
  color: var(--muted);
  margin: 0 0 1.75rem;
  font-size: 0.95rem;
  line-height: 1.45;
}

.arrival-btn,
.primary-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.75rem 1.4rem;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.95rem;
  color: #1a1208;
  background: linear-gradient(180deg, #f0c08a, var(--sodium));
  box-shadow: 0 0 0 1px rgba(255, 210, 160, 0.25), 0 8px 24px var(--sodium-glow);
}

.arrival-btn:hover,
.primary-btn:hover {
  filter: brightness(1.05);
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--panel-edge);
  background: rgba(12, 18, 36, 0.7);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.ghost-btn:hover {
  border-color: rgba(94, 234, 212, 0.35);
  color: var(--phosphor);
}

.brand {
  text-decoration: none;
  color: inherit;
}

.link-pill {
  text-decoration: none;
  color: inherit;
}

.dot.sky {
  background: #9bb7ff;
  box-shadow: 0 0 8px rgba(155, 183, 255, 0.7);
  animation: none;
}

/* —— Sky ritual —— */
.sky-view {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(700px 400px at 50% 20%, rgba(155, 183, 255, 0.1), transparent 55%),
    rgba(4, 6, 12, 0.92);
  backdrop-filter: blur(16px);
  overflow-y: auto;
}

.sky-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
}

.sky-card {
  max-width: 38rem;
  width: 100%;
  padding: 2rem 1.75rem;
}

.sky-freq {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  color: #9bb7ff;
  margin: 0 0 0.75rem;
}

.sky-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2rem, 5vw, 2.8rem);
  margin: 0 0 1.25rem;
  font-style: italic;
}

.sky-text {
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  line-height: 1.45;
  font-style: italic;
  margin: 0 0 1.25rem;
  white-space: pre-wrap;
}

.sky-meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--dim);
  letter-spacing: 0.06em;
  margin: 0 0 1.5rem;
}

.sky-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

/* —— Place drawer —— */
.place-view {
  position: fixed;
  z-index: 30;
  top: 4.5rem;
  right: 1rem;
  width: min(360px, calc(100vw - 2rem));
  max-height: min(60vh, 480px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(16px);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.place-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.place-freq {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--sodium);
  margin: 0 0 0.25rem;
}

.place-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.5rem;
  margin: 0;
  font-style: italic;
}

.place-pulse {
  margin: 0.4rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.35;
  font-style: italic;
  font-family: var(--font-display);
}

.place-log {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

body.place-mode .log-panel {
  display: none;
}

/* —— Signal sheet —— */
.signal-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: end center;
  padding: 1rem;
  padding-bottom: calc(5.5rem + var(--safe-b));
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
}

.sheet-card {
  position: relative;
  width: min(440px, 100%);
  background: rgba(10, 14, 28, 0.95);
  border: 1px solid rgba(94, 234, 212, 0.2);
  border-radius: 18px;
  padding: 1.25rem 1.25rem 1.1rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: sheet-up 0.28s ease;
}

@keyframes sheet-up {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-x {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font-size: 1rem;
}

.sheet-body {
  margin: 0 1.5rem 0.5rem 0;
  font-size: 1.15rem;
  line-height: 1.4;
  font-family: var(--font-display);
  font-style: italic;
}

.sheet-meta {
  margin: 0 0 1rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--phosphor);
  letter-spacing: 0.04em;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sheet-status {
  margin: 0.65rem 0 0;
  min-height: 1.1em;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--dim);
}

.sheet-status.error { color: var(--danger); }
.sheet-status.ok { color: var(--phosphor); }

.hot-places {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.hot-places a {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
}

.hot-places a:hover {
  color: var(--phosphor);
  border-color: rgba(94, 234, 212, 0.3);
}

.log button.wave-inline {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  cursor: pointer;
  padding: 0;
  margin-left: 0.35rem;
}

.log button.wave-inline:hover {
  color: var(--sodium);
}

.log .l-actions {
  margin-top: 0.2rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.log a.place-link {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--dim);
  text-decoration: none;
}

.log a.place-link:hover {
  color: var(--phosphor);
}

body.arrival-open {
  overflow: hidden;
}

@media (max-width: 820px) {
  .place-view {
    top: auto;
    bottom: calc(5.5rem + var(--safe-b));
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
    max-height: 40vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .arrival,
  .arrival.is-leaving,
  .sheet-card {
    animation: none;
  }
}
