/* Possession Detector — Victorian séance: a cabinet card on velvet, the photo in an oval spirit frame. */

:root {
  --velvet: #24141a;      /* séance-room drape */
  --velvet-deep: #120a0d;
  --paper: #e9dcbf;       /* aged cabinet-card stock */
  --paper-edge: #c9b48a;
  --ink: #2b1d16;         /* iron-gall ink */
  --ink-soft: #57412f;
  --candle: #e3a447;      /* only on dark surfaces */
  --ecto: #2e6142;        /* ectoplasm, deep enough to read on paper */
  --ecto-glow: #b4e3bf;
  --blood: #7a2a1d;

  --display: 'IM Fell English', 'Iowan Old Style', Georgia, serif;
  --body: 'Spectral', Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 3rem 1rem;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(227, 164, 71, 0.16), transparent 55%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.18) 0 2px, transparent 2px 9px),
    radial-gradient(ellipse at center, var(--velvet), var(--velvet-deep));
  color: var(--ink);
  font: 1.0625rem/1.65 var(--body);
}

.card {
  position: relative;
  width: min(100%, 34rem);
  padding: 2.75rem clamp(1.25rem, 5vw, 3rem) 2rem;
  text-align: center;
  background-color: var(--paper);
  /* aged paper: fractal noise + foxed edges, no image assets */
  background-image:
    radial-gradient(ellipse at center, transparent 55%, rgba(120, 80, 30, 0.28)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .1 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--paper-edge), 0 30px 80px rgba(0, 0, 0, 0.6);
}
/* gilt inner border of a cabinet card */
.card::before {
  content: '';
  position: absolute;
  inset: 0.6rem;
  border: 1px solid rgba(87, 65, 47, 0.45);
  border-radius: 3px;
  pointer-events: none;
}

h1 {
  margin: 0;
  font: italic 400 clamp(2.2rem, 7vw, 3.1rem)/1.05 var(--display);
  letter-spacing: 0.01em;
}

.lede {
  max-width: 28em;
  margin: 0.75rem auto 1.75rem;
  color: var(--ink-soft);
}

/* ---- The spirit frame: the one memorable thing ---- */
.frame-wrap {
  position: relative;
  width: min(72vw, 16rem);
  margin: 0 auto;
}
.frame-wrap::before { /* candle glow behind the frame */
  content: '';
  position: absolute;
  inset: -18%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(227, 164, 71, 0.35), transparent);
  animation: flicker 4s ease-in-out infinite;
  pointer-events: none;
}
.frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 3 / 4;
  padding: 0;
  overflow: hidden;
  border-radius: 50%;
  border: 0.55rem solid #3a2415;
  box-shadow:
    0 0 0 2px #b8893f,
    0 0 0 5px #3a2415,
    inset 0 0 40px rgba(0, 0, 0, 0.85);
  background: radial-gradient(ellipse at 50% 40%, #3b2a22, #140c0a);
  color: var(--paper);
  font: italic 1.05rem/1.4 var(--display);
  cursor: pointer;
  transition: box-shadow 0.25s;
}
.frame:disabled { cursor: progress; }
.frame:focus-visible { outline: 3px solid var(--candle); outline-offset: 8px; }
.frame.drag-over,
.frame:not(:disabled):hover {
  box-shadow: 0 0 0 2px #e3c27a, 0 0 0 5px #3a2415, 0 0 32px 6px rgba(180, 227, 191, 0.55), inset 0 0 40px rgba(0, 0, 0, 0.85);
}
.frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: sepia(0.35) contrast(1.05);
}
.frame-hint {
  position: relative;
  max-width: 9em;
  padding: 0.3em 0.6em;
}
.frame img:not([hidden]) + .frame-hint {
  align-self: end;
  margin-bottom: 14%;
  max-width: none;
  font-size: 0.9rem;
  background: rgba(20, 12, 10, 0.78);
  border-radius: 1em;
}
.frame.summoning img { animation: ecto 1.6s ease-in-out infinite alternate; }

/* ---- Loader: real progress, a burning wick ---- */
.loader { margin-top: 1.75rem; }
.loader[hidden] { display: none; }
.loader-title { margin: 0; font: italic 1.25rem var(--display); }
.wick {
  height: 6px;
  margin: 0.6rem auto;
  max-width: 18rem;
  background: rgba(43, 29, 22, 0.18);
  border-radius: 3px;
  overflow: hidden;
}
.wick-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #8a5a22, var(--candle));
  transition: width 0.3s;
}
.loader-text { margin: 0; font-size: 0.92rem; color: var(--ink-soft); }

/* ---- Verdict ---- */
.result { min-height: 1rem; margin-top: 1.5rem; }
.result p { margin: 0; }
.verdict {
  font: 400 clamp(1.9rem, 6.5vw, 2.6rem)/1.1 var(--display);
  letter-spacing: 0.04em;
  animation: manifest 0.9s ease-out;
}
.verdict.possessed { color: var(--ecto); }
.verdict.mortal { color: var(--blood); }
.verdict.unsure { color: var(--ink-soft); font-size: clamp(1.4rem, 4.6vw, 1.85rem); }
.confidence { margin-top: 0.35rem !important; font-size: 1.15rem; font-weight: 600; }
.limits-link { margin-top: 0.4rem !important; font-size: 0.95rem; }
.message { font-style: italic; color: var(--ink-soft); }
.message.error { color: var(--blood); font-style: normal; }

a { color: var(--blood); text-underline-offset: 0.18em; }
a:focus-visible, summary:focus-visible { outline: 2px solid var(--blood); outline-offset: 3px; }

/* ---- About ---- */
.about {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(87, 65, 47, 0.35);
  text-align: left;
}
.about summary {
  cursor: pointer;
  text-align: center;
  font: italic 1.1rem var(--display);
}
.about p { font-size: 0.95rem; }
.about table { margin: 0.5rem auto 1rem; border-collapse: collapse; font-size: 0.95rem; }
.about caption { font-style: italic; color: var(--ink-soft); padding-bottom: 0.3rem; }
.about th { text-align: left; font-weight: 400; padding: 0.15rem 1.5rem 0.15rem 0; }
.about td { text-align: right; font-variant-numeric: tabular-nums; }
.about tr:first-child { font-weight: 600; }
.about tr:first-child th { font-weight: 600; }

.privacy {
  margin: 1.5rem 0 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

@keyframes flicker {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  45% { opacity: 1; transform: scale(1.03); }
  55% { opacity: 0.7; transform: scale(0.99); }
}
@keyframes ecto {
  from { filter: sepia(0.35) blur(0); }
  to { filter: sepia(0.2) hue-rotate(70deg) saturate(1.4) blur(1.5px); }
}
@keyframes manifest {
  from { opacity: 0; filter: blur(6px); letter-spacing: 0.25em; }
  to { opacity: 1; filter: blur(0); letter-spacing: 0.04em; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
