:root {
  --bg-night: #0a0e1a;
  --bg-night-deep: #05060c;
  --fog-color: rgba(180, 195, 220, 0.06);
  --ink: #d8dce6;
  --ink-dim: #8891a8;
  --accent: #7c9eff;
  --danger: #ff6b6b;
  --standard: #7d8494;
  --bronze: #a9682f;
  --silver: #c7cdd9;
  --gold: #e0b93a;
  --panel-bg: #12162a;
  --panel-border: #2a3050;
  --font-gothic: 'UnifrakturMaguntia', 'IM Fell English SC', serif;
  --font-serif: 'IM Fell English SC', Georgia, serif;
  --font-mono: 'Courier New', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-night);
  color: var(--ink);
  font-family: var(--font-mono);
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 40px;
}

a {
  color: var(--accent);
}

/* ---------- Header ---------- */

.site-header {
  text-align: center;
  padding: 28px 16px 8px;
}

.site-title {
  font-family: var(--font-gothic);
  font-weight: normal;
  font-size: 2.4rem;
  margin: 0 0 6px;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(124, 158, 255, 0.35);
  letter-spacing: 1px;
}

.tagline {
  color: var(--ink-dim);
  font-size: 0.85rem;
  max-width: 520px;
  margin: 0 auto;
}

/* ---------- Status bar ---------- */

.statusbar {
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 6px 18px;
  margin: 14px 0;
}

/* ---------- Ticker ---------- */

.ticker-wrap {
  width: min(1000px, 94vw);
  overflow: hidden;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 0;
  margin-bottom: 16px;
}

.ticker {
  white-space: nowrap;
  overflow: hidden;
}

.ticker-track {
  display: inline-block;
  padding-left: 100%;
  font-size: 0.8rem;
  color: var(--ink-dim);
  animation: ticker-scroll 30s linear infinite;
}

@keyframes ticker-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-100%); }
}

/* ---------- Monuments panel ---------- */

.monuments-panel {
  width: min(1000px, 94vw);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 16px;
}

.monuments-title {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: normal;
  margin: 0 0 10px;
  color: var(--ink);
}

.monuments-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.monuments-empty {
  color: var(--ink-dim);
  font-size: 0.8rem;
  margin: 0;
}

.monument-row {
  display: grid;
  grid-template-columns: 2em 1fr auto;
  align-items: baseline;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.monument-rank {
  color: var(--ink-dim);
  font-weight: bold;
}

.monument-name {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.monument-price {
  color: var(--ink-dim);
  font-weight: bold;
}

.monument-row.monument-first {
  border: 1px solid var(--gold);
  background: rgba(224, 185, 58, 0.1);
  font-size: 0.95rem;
  padding: 9px 12px;
}

.monument-row.monument-first .monument-rank,
.monument-row.monument-first .monument-price {
  color: var(--gold);
}

/* ---------- Canvas / grid ---------- */

.canvas-shell {
  position: relative; /* anchors .sky-moon, independent of canvas-scroll's own scroll */
  width: min(1800px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.canvas-scroll {
  position: relative;
  width: 100%;
  /* Static fallback; JS (sizeCanvasScroll) sets an explicit height fitted
     to the actual remaining viewport space below the ticker/counter/
     leaderboard, clamped to roughly this same 65-75vh range. */
  height: 70vh;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  box-shadow: inset 0 0 60px 20px rgba(0, 0, 0, 0.75);
  background: var(--bg-night-deep);
}

#fog-canvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  pointer-events: none;
}

#graveyard-canvas {
  position: relative;
  z-index: 1;
  display: block;
  cursor: pointer;
  background: transparent;
}

/* Moon: a viewport-fixed decoration, not a content-scrolled one. The grid
   can be many screens wide/tall, so a moon drawn at a fixed CONTENT
   coordinate only shows up when the user happens to scroll to that one
   spot — reading as a random pale blob with no "sky corner" context.
   Positioned relative to canvas-shell — a sibling of canvas-scroll, not a
   descendant — so it's immune by construction to canvas-scroll's own
   internal scroll (no sticky-positioning trickery needed). */
.sky-moon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 35% 35%,
    #f4f1e0,
    #f4f1e0 45%,
    rgba(244, 241, 224, 0.55) 62%,
    rgba(244, 241, 224, 0) 78%
  );
  box-shadow: 0 0 28px 12px rgba(255, 255, 240, 0.28);
  z-index: 2;
  pointer-events: none;
}

.canvas-hint {
  margin-top: 10px;
  color: var(--ink-dim);
  font-size: 0.78rem;
}

.tomb-tooltip {
  /* top/left are computed and set in JS (positionTooltip) to keep the
     tooltip fully inside canvas-scroll's visible viewport — no CSS
     transform here, since that would reintroduce a fixed offset the JS
     flip/clamp logic can't account for. */
  position: absolute;
  pointer-events: none;
  background: rgba(10, 14, 26, 0.95);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.75rem;
  color: var(--ink);
  max-width: 220px;
  z-index: 20;
}

.tomb-tooltip .tt-name {
  font-family: var(--font-serif);
  font-weight: bold;
  display: block;
  margin-bottom: 2px;
}

.tomb-tooltip .tt-founding {
  display: block;
  font-size: 0.68rem;
  color: #9dc9b8;
  margin-bottom: 3px;
}

.graveyard-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: rgba(10, 14, 26, 0.95);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.graveyard-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Footer ---------- */

.site-footer {
  margin-top: 24px;
  color: var(--ink-dim);
  font-size: 0.75rem;
  text-align: center;
}

/* ---------- Modal ---------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 24px;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 1.1rem;
  cursor: pointer;
}

.modal-title {
  font-family: var(--font-serif);
  margin-top: 0;
}

.modal-body {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.bury-form {
  flex: 1 1 280px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bury-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.bury-form input[type="text"],
.bury-form input[type="number"],
.bury-form textarea {
  background: var(--bg-night-deep);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--ink);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  resize: vertical;
}

.optional {
  color: var(--ink-dim);
  font-weight: normal;
}

.char-counter {
  font-size: 0.7rem;
  color: var(--ink-dim);
  text-align: right;
  margin-top: -6px;
}

.btn-secondary {
  background: transparent;
  border: 1px dashed var(--panel-border);
  color: var(--ink-dim);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  cursor: pointer;
  align-self: flex-start;
}

.btn-secondary:hover {
  color: var(--ink);
  border-color: var(--accent);
}

.skin-picker {
  margin-top: 4px;
}

.skin-picker-label {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-dim);
  margin-bottom: 6px;
}

.skin-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.skin-btn {
  background: var(--bg-night-deep);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  text-align: center;
}

.skin-btn small {
  color: var(--ink-dim);
}

.skin-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

#tribute-quick-amounts {
  grid-template-columns: repeat(3, 1fr);
}

.tribute-modal-body {
  color: var(--ink-dim);
  font-size: 0.85rem;
  margin: 0 0 14px;
}

.hidden {
  display: none;
}

.form-error {
  color: var(--danger);
  font-size: 0.8rem;
  min-height: 1em;
}

.price-line {
  font-size: 1rem;
  font-weight: bold;
}

.btn-primary {
  background: var(--accent);
  color: #0a0e1a;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-family: var(--font-mono);
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.preview-pane {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.preview-label {
  font-size: 0.72rem;
  color: var(--ink-dim);
}

#preview-canvas {
  background: var(--bg-night-deep);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
}

/* ---------- Success page ---------- */

.success-body {
  justify-content: center;
  min-height: 100vh;
}

.success-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 16px;
  width: min(480px, 100%);
  text-align: center;
}

.burial-stage {
  position: relative;
  width: 260px;
  height: 320px;
  overflow: hidden;
}

#burial-canvas {
  position: relative;
  top: 320px;
  animation: rise-up 2.4s ease-out forwards;
}

@keyframes rise-up {
  0% { top: 320px; }
  70% { top: -10px; }
  85% { top: 6px; }
  100% { top: 0; }
}

.dirt-particles {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 60px;
  pointer-events: none;
}

.dirt-speck {
  position: absolute;
  bottom: 10px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #4a3b2a;
  animation: dirt-fly 0.9s ease-out forwards;
  opacity: 0;
}

@keyframes dirt-fly {
  0% { opacity: 1; transform: translate(0, 0); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)); }
}

.success-content {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.success-content.hidden,
.form-error.hidden {
  display: none;
}

.success-content h1 {
  font-family: var(--font-gothic);
  font-weight: normal;
  margin: 0;
}

.success-project-name {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  margin: 0;
}

.success-epitaph {
  color: var(--ink-dim);
  font-style: italic;
  margin: 0;
  max-width: 400px;
}

.success-price {
  font-size: 0.85rem;
  color: var(--ink-dim);
  margin: 0;
}

.sound-toggle {
  background: none;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--ink);
}

.share-btn {
  margin-top: 8px;
}

.see-graveyard-link {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--ink-dim);
  text-decoration: none;
}

.see-graveyard-link:hover {
  color: var(--accent);
}

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

@media (max-width: 600px) {
  .site-title {
    font-size: 1.8rem;
  }

  .modal-body {
    flex-direction: column;
  }

  .preview-pane {
    flex: none;
    align-self: center;
  }
}
