/* ============================================================
   Side-Project Cemetery — styles
   Dark, moonlit night. Loving humor. Passion doesn't die, it naps.
   ============================================================ */

:root {
  --page:        #0d0d12;
  --sky-top:     #0d0d12;
  --sky-bottom:  #1a1a24;
  --surface:     #1a1a19;
  --stone:       #26262e;
  --stone-top:   #2e2e37;
  --border:      rgba(255, 255, 255, 0.10);
  --border-soft: rgba(255, 255, 255, 0.06);

  --ink:      #ffffff;
  --ink-2:    #c3c2b7;
  --muted:    #898781;

  --flame:    #d95926;  /* warm accent — Rekindle */
  --ember:    #e66767;  /* candle flame highlight */

  --moon:     #e8e6d8;

  --radius:   14px;
  --radius-sm: 10px;
  --maxw:     1120px;

  --shadow:   0 18px 50px rgba(0, 0, 0, 0.55);

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--page);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.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;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--flame);
  color: #fff;
  padding: 10px 16px;
  z-index: 200;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

a { color: var(--ink-2); }

/* ============================================================
   The nighttime scene (fixed background)
   ============================================================ */

.scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top) 0%, #131320 55%, var(--sky-bottom) 100%);
}

.moon {
  position: absolute;
  top: 7vh;
  right: 12vw;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 38%, #fbfaf2 0%, var(--moon) 55%, #c9c7ba 100%);
  box-shadow:
    0 0 60px 18px rgba(232, 230, 216, 0.22),
    0 0 140px 60px rgba(232, 230, 216, 0.08);
}
/* faint craters */
.moon::before,
.moon::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(150, 148, 136, 0.30);
}
.moon::before { width: 20px; height: 20px; top: 30px; left: 34px; }
.moon::after  { width: 30px; height: 30px; top: 62px; left: 66px; box-shadow: -34px -8px 0 -8px rgba(150,148,136,0.28); }

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.4px 1.4px at 15% 22%, rgba(255,255,255,.85), transparent),
    radial-gradient(1.2px 1.2px at 42% 12%, rgba(255,255,255,.65), transparent),
    radial-gradient(1.5px 1.5px at 68% 28%, rgba(255,255,255,.75), transparent),
    radial-gradient(1.1px 1.1px at 82% 16%, rgba(255,255,255,.55), transparent),
    radial-gradient(1.3px 1.3px at 55% 8%,  rgba(255,255,255,.70), transparent),
    radial-gradient(1.1px 1.1px at 30% 34%, rgba(255,255,255,.50), transparent),
    radial-gradient(1.4px 1.4px at 90% 40%, rgba(255,255,255,.60), transparent),
    radial-gradient(1.2px 1.2px at 8%  46%, rgba(255,255,255,.45), transparent);
  animation: twinkle 6s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: 0.55; }
  to   { opacity: 1; }
}

.fog {
  position: absolute;
  left: -20%;
  width: 140%;
  height: 46vh;
  filter: blur(42px);
  opacity: 0.5;
  pointer-events: none;
}
.fog-a {
  bottom: 8vh;
  background: radial-gradient(60% 100% at 30% 60%, rgba(90, 96, 120, 0.42), transparent 70%);
  animation: driftA 46s ease-in-out infinite alternate;
}
.fog-b {
  bottom: 0;
  background: radial-gradient(55% 100% at 70% 70%, rgba(60, 66, 92, 0.45), transparent 70%);
  animation: driftB 62s ease-in-out infinite alternate;
}

@keyframes driftA {
  from { transform: translateX(-6%) translateY(0);    }
  to   { transform: translateX(10%) translateY(-14px); }
}
@keyframes driftB {
  from { transform: translateX(8%)  translateY(0);    }
  to   { transform: translateX(-9%) translateY(-10px); }
}

.fireflies { position: absolute; inset: 0; }
.fireflies span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffe6a0;
  box-shadow: 0 0 8px 2px rgba(255, 216, 120, 0.85);
  opacity: 0;
  animation: firefly var(--t, 7s) ease-in-out var(--d, 0s) infinite;
}

@keyframes firefly {
  0%   { opacity: 0;   transform: translate(0, 0) scale(0.6); }
  25%  { opacity: 0.9; }
  50%  { opacity: 0.2; transform: translate(14px, -18px) scale(1); }
  75%  { opacity: 0.8; }
  100% { opacity: 0;   transform: translate(-10px, -30px) scale(0.7); }
}

.ground {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 30vh;
  background: linear-gradient(180deg, transparent 0%, rgba(10, 12, 10, 0.55) 45%, #0a0d0b 100%);
}

/* ============================================================
   Hero
   ============================================================ */

.hero {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(48px, 9vh, 96px) 20px 10px;
  text-align: center;
}

.title {
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.6);
}

.tagline {
  color: var(--ink-2);
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  margin: 0 auto 30px;
  max-width: 34ch;
}

.visit-form {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0 auto;
  max-width: 560px;
}

.input-wrap {
  position: relative;
  flex: 1 1 260px;
  display: flex;
  align-items: center;
}
.input-wrap .at {
  position: absolute;
  left: 16px;
  color: var(--muted);
  font-size: 1.05rem;
  pointer-events: none;
}
#username {
  width: 100%;
  padding: 14px 16px 14px 34px;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}
#username::placeholder { color: var(--muted); }
#username:focus {
  outline: none;
  border-color: rgba(217, 89, 38, 0.6);
  box-shadow: 0 0 0 3px rgba(217, 89, 38, 0.18);
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s, border-color 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(217, 89, 38, 0.35);
}

.btn-primary {
  background: linear-gradient(180deg, #e2683a, var(--flame));
  color: #fff;
  box-shadow: 0 8px 26px rgba(217, 89, 38, 0.30);
}
.btn-primary:hover { box-shadow: 0 10px 32px rgba(217, 89, 38, 0.45); }

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--border);
}
.btn-ghost:hover {
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.03);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* ============================================================
   AI settings (bring your own keys)
   ============================================================ */

.ai-settings {
  max-width: 560px;
  margin: 18px auto 0;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.ai-settings summary {
  cursor: pointer;
  padding: 12px 16px;
  color: var(--ink-2);
  font-size: 0.95rem;
  list-style: none;
  user-select: none;
}
.ai-settings summary::-webkit-details-marker { display: none; }
.ai-hint { color: var(--muted); font-weight: 400; }
.ai-body { padding: 0 16px 16px; }
.ai-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 4px 0 14px;
}
.ai-note code { color: var(--ink-2); }
.ai-field { margin-bottom: 12px; }
.ai-field label {
  display: block;
  font-size: 0.9rem;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.ai-what { color: var(--muted); font-weight: 400; }
.ai-field input {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ai-field input:focus {
  outline: none;
  border-color: rgba(217, 89, 38, 0.5);
}
.ai-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.ai-actions .btn { padding: 9px 14px; font-size: 0.9rem; }
.keys-status { color: var(--muted); font-size: 0.85rem; }

/* ============================================================
   Notices / status
   ============================================================ */

.notice {
  max-width: 620px;
  margin: 20px auto 0;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(217, 89, 38, 0.10);
  border: 1px solid rgba(217, 89, 38, 0.28);
  color: var(--ink-2);
  font-size: 0.92rem;
}

.status {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 20px;
  text-align: center;
  color: var(--ink-2);
  min-height: 1px;
}

/* Big state cards (errors / empty / celebration) */
.state {
  max-width: 560px;
  margin: 40px auto;
  padding: 34px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow);
}
.state .emoji { font-size: 2.6rem; display: block; margin-bottom: 10px; }
.state h2 { margin: 0 0 8px; font-size: 1.4rem; }
.state p { color: var(--ink-2); margin: 6px 0; }
.state .sub { color: var(--muted); font-size: 0.9rem; }

.loading {
  color: var(--ink-2);
  font-size: 1.05rem;
  padding: 40px 0;
}
.loading .dots::after {
  content: "";
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
  100% { content: ""; }
}

/* display:flex/grid on a section would defeat the hidden attribute */
[hidden] { display: none !important; }

/* ============================================================
   Stats bar
   ============================================================ */

.stats-bar {
  max-width: var(--maxw);
  margin: 26px auto 8px;
  padding: 16px 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 26px;
  background: rgba(26, 26, 25, 0.72);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
.stat { text-align: center; min-width: 92px; }
.stat .val {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.1;
}
.stat .lbl {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ============================================================
   Cemetery + headstones
   ============================================================ */

.cemetery {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 26px 20px;
  align-items: end;
}

.grave { position: relative; }

.headstone {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 190px;
  padding: 20px 16px 18px;
  text-align: center;
  color: var(--ink-2);
  background: linear-gradient(180deg, var(--stone-top), var(--stone));
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 100px 100px var(--radius-sm) var(--radius-sm);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 0 0 1px rgba(0, 0, 0, 0.20),
    0 14px 26px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
}
/* rounded top border drawn separately so the arch reads cleanly */
.headstone::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--border);
  border-radius: 100px 100px var(--radius-sm) var(--radius-sm);
  pointer-events: none;
}

/* little grass mound under each stone */
.grave::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -8px;
  height: 16px;
  background: radial-gradient(60% 100% at 50% 0%, rgba(30, 40, 28, 0.9), transparent 72%);
  filter: blur(2px);
  z-index: -1;
}

.headstone:hover,
.headstone:focus-visible {
  transform: translateY(-6px);
  border-color: rgba(255, 255, 255, 0.20);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 20px 40px rgba(0, 0, 0, 0.55),
    0 0 34px rgba(217, 89, 38, 0.18);
  outline: none;
}

.hs-cross {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 6px;
  opacity: 0.75;
}

.hs-name {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.hs-lifespan {
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.hs-loved {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.hs-candles {
  margin: 8px 0 4px;
  font-size: 0.9rem;
  line-height: 1;
  min-height: 1em;
}
.hs-candles .candle {
  display: inline-block;
  animation: flicker 1.6s ease-in-out infinite;
  transform-origin: bottom center;
}
.hs-candles .candle:nth-child(2) { animation-delay: 0.3s; }
.hs-candles .candle:nth-child(3) { animation-delay: 0.6s; }
.hs-candles .candle:nth-child(4) { animation-delay: 0.15s; }
.hs-candles .candle:nth-child(5) { animation-delay: 0.45s; }

@keyframes flicker {
  0%, 100% { opacity: 1;    transform: scale(1)    rotate(-1deg); }
  50%      { opacity: 0.72; transform: scale(0.94) rotate(1.5deg); }
}

.hs-epitaph {
  margin-top: auto;
  padding-top: 10px;
  font-size: 0.86rem;
  font-style: italic;
  color: var(--ink-2);
  border-top: 1px solid var(--border-soft);
}
.hs-epitaph code {
  font-style: normal;
  font-size: 0.82em;
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--ink);
}

.hs-rekindle-hint {
  margin-top: 10px;
  font-size: 0.74rem;
  color: var(--flame);
  opacity: 0;
  transition: opacity 0.2s;
}
.headstone:hover .hs-rekindle-hint,
.headstone:focus-visible .hs-rekindle-hint { opacity: 1; }

/* rise-from-the-ground entrance */
@keyframes rise {
  from { opacity: 0; transform: translateY(26px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
.cemetery.animate .grave {
  opacity: 0;
  animation: rise 0.6s ease forwards;
  animation-delay: calc(var(--i, 0) * 55ms);
}

/* ============================================================
   Modal — Rekindle
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(6, 6, 10, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop 0.24s ease;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 8px;
}
.modal-head h2 { margin: 0; font-size: 1.3rem; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }

.modal-body { padding: 6px 22px 22px; }

.repo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 12px;
}
.repo-meta a { color: var(--ink-2); text-decoration: underline; }
.repo-desc {
  color: var(--ink-2);
  font-size: 0.95rem;
  margin: 0 0 14px;
}

.readme-box {
  background: var(--page);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  max-height: 150px;
  overflow-y: auto;
  color: var(--ink-2);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 16px;
}
.readme-box.empty { color: var(--muted); font-style: italic; }

.pitch {
  background: linear-gradient(180deg, rgba(217, 89, 38, 0.08), rgba(217, 89, 38, 0.03));
  border: 1px solid rgba(217, 89, 38, 0.25);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 4px 0 16px;
  animation: fade 0.3s ease;
}
.pitch p { margin: 0 0 12px; color: var(--ink); font-size: 0.98rem; }
.pitch .first-step {
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid rgba(217, 89, 38, 0.22);
  color: var(--ink-2);
  font-size: 0.92rem;
}
.pitch .first-step strong { color: var(--ink); }

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}
.modal-actions .btn { padding: 11px 16px; font-size: 0.92rem; }

.modal-sub-notice {
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 1em;
}

audio { width: 100%; margin-top: 12px; }

/* ============================================================
   Footer
   ============================================================ */

.footer {
  max-width: var(--maxw);
  margin: 20px auto 0;
  padding: 30px 20px 46px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}
.footer em { color: var(--ink-2); }
.footer-sub { font-size: 0.8rem; margin-top: 6px; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 600px) {
  .cemetery {
    grid-template-columns: repeat(2, 1fr);
    gap: 18px 12px;
    padding: 20px 14px 30px;
  }
  .headstone { min-height: 172px; padding: 16px 10px 14px; }
  .hs-name { font-size: 0.92rem; }

  .modal-backdrop { padding: 0; }
  .modal {
    max-width: none;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: none;
  }
  .stat .val { font-size: 1.25rem; }
}

@media (max-width: 380px) {
  .cemetery { grid-template-columns: 1fr; }
}

/* ============================================================
   Reduced motion — respect it fully
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .stars, .fog-a, .fog-b, .fireflies span,
  .hs-candles .candle, .loading .dots::after {
    animation: none !important;
  }
  .fireflies span { opacity: 0.6; }
  .cemetery.animate .grave {
    opacity: 1;
    animation: none;
  }
  .headstone { transition: box-shadow 0.2s ease, border-color 0.2s ease; }
  .headstone:hover, .headstone:focus-visible { transform: none; }
  .modal, .modal-backdrop, .pitch { animation: none; }
  * { scroll-behavior: auto; }
}

/* "Walk deeper" gate for prolific abandoners */
.walk-deeper {
  display: block;
  margin: 22px auto 8px;
  padding: 12px 22px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink-2, #c3c2b7);
  background: rgba(26, 26, 25, 0.72);
  border: 1px solid var(--border-soft, rgba(255, 255, 255, 0.1));
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.walk-deeper:hover {
  color: var(--ink, #fff);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}
