:root {
  --cream: #fbf7ef;
  --cream-deep: #f3ecde;
  --ink: #2b211b;
  --ink-soft: #7a6a5e;
  --line: #e4d9c6;
  --accent: #b9542e;
  --ease: cubic-bezier(.22, .8, .24, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #fffdf8 0%, transparent 60%),
    radial-gradient(900px 600px at 50% 120%, #f1e8d6 0%, transparent 55%),
    var(--cream);
  color: var(--ink);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  display: grid;
  place-items: center;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: relative;
  width: min(560px, calc(100vw - 48px));
  min-height: 300px;
  display: grid;
  place-items: center;
}

/* ---------- form ---------- */
#form {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  transition: opacity .5s var(--ease), transform .6s var(--ease), filter .5s var(--ease);
}

#title {
  margin: 0 0 14px;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: clamp(30px, 6vw, 42px);
  font-weight: 500;
  letter-spacing: -.01em;
  text-align: center;
  color: var(--ink);
}

#query {
  width: 100%;
  height: 58px;
  padding: 0 24px;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
  box-shadow: 0 1px 0 #fff inset, 0 10px 30px -18px rgba(70, 45, 25, .35);
  transition: border-color .25s, box-shadow .25s;
}
#query::placeholder { color: #b3a595; }
#query:focus {
  border-color: #d7b79f;
  box-shadow: 0 0 0 5px rgba(185, 84, 46, .09), 0 12px 34px -16px rgba(70, 45, 25, .4);
}

#seek {
  height: 52px;
  min-width: 148px;
  padding: 0 40px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--cream);
  background: var(--ink);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 14px 28px -16px rgba(43, 33, 27, .8);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), background .2s;
}
#seek:hover { background: #3a2c24; transform: translateY(-1px); }
#seek:active { transform: translateY(1px) scale(.985); box-shadow: 0 8px 18px -14px rgba(43, 33, 27, .8); }
#seek:focus-visible { outline: 3px solid rgba(185, 84, 46, .35); outline-offset: 3px; }

#error {
  min-height: 20px;
  margin: 0;
  font-size: 14px;
  color: #a4432b;
  text-align: center;
}

/* ---------- working ---------- */
#working {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  opacity: 0;
  pointer-events: none;
  transform: scale(.86);
  transition: opacity .6s var(--ease), transform .8s var(--ease);
}

.orbit { width: 172px; height: 172px; filter: drop-shadow(0 14px 22px rgba(185, 84, 46, .18)); }
.orbit svg { width: 100%; height: 100%; overflow: visible; }

.track { fill: none; stroke: #eadfcb; stroke-width: 1.2; }
.arc { fill: none; stroke-width: 3.4; stroke-linecap: round; transform-origin: 60px 60px; }
.a1 { stroke-dasharray: 120 207; animation: spin 2.4s cubic-bezier(.45, .05, .55, .95) infinite; }
.a2 { stroke-dasharray: 90 149;  animation: spin-rev 1.9s cubic-bezier(.45, .05, .55, .95) infinite; }
.a3 { stroke-dasharray: 50 101;  animation: spin 1.3s linear infinite; }
.satellite { transform-origin: 60px 60px; animation: spin 3.2s linear infinite; }
.satellite circle { fill: var(--accent); }
.core { fill: var(--ink); transform-origin: 60px 60px; animation: breathe 1.8s ease-in-out infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spin-rev { to { transform: rotate(-360deg); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.35); } }

#phase {
  margin: 0;
  min-height: 24px;
  font-size: 16px;
  color: var(--ink);
  text-align: center;
  transition: opacity .35s var(--ease), transform .35s var(--ease);
}
#phase.swap { opacity: 0; transform: translateY(5px); }

#count {
  margin: 0;
  min-height: 22px;
  font-size: 14px;
  letter-spacing: .06em;
  color: var(--ink-soft);
  transition: opacity .4s;
}

/* ---------- result ---------- */
#result {
  display: none;
  width: 100%;
  flex-direction: column;
  gap: 22px;
}

.r-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.r-title {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: clamp(26px, 5vw, 34px);
  font-weight: 500;
  letter-spacing: -.01em;
}
.r-sub { margin: 4px 0 0; font-size: 14px; color: var(--ink-soft); }
.r-cost { margin: 6px 0 0; font-size: 13px; color: var(--ink-soft); }
.r-cost b { color: var(--ink); font-weight: 600; }
#again {
  padding: 8px 16px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
#again:hover { background: #fffdf8; border-color: #d7b79f; }

.stats { display: grid; gap: 12px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; align-items: stretch; }
.stat-label { grid-column: 1 / -1; margin: 2px 0 -2px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.stat {
  padding: 12px 14px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.stat b { display: block; font-size: 24px; font-weight: 600; letter-spacing: -.01em; }
.stat span { font-size: 12.5px; color: var(--ink-soft); }
.stat.strong { background: var(--ink); border-color: var(--ink); }
.stat.strong b { color: var(--cream); }
.stat.strong span { color: #d9cdbd; }

.panel {
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 18px 40px -28px rgba(70, 45, 25, .5);
  overflow: hidden;
}
.filters { display: grid; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.fgroup { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.flabel { min-width: 104px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}
.chip i { font-style: normal; font-size: 12px; opacity: .75; }
.chip.on { color: var(--cream); background: var(--ink); border-color: var(--ink); }
.chip:not(.on):hover { border-color: #d7b79f; color: var(--ink); }
.chip:focus-visible { outline: 3px solid rgba(185, 84, 46, .35); outline-offset: 2px; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; background: var(--cream-deep); border-bottom: 1px solid var(--line); }
.selected { font-size: 14px; color: var(--ink-soft); }
.selected b { color: var(--ink); }
#file {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--cream);
  text-decoration: none;
  font-size: 14.5px;
  font-weight: 600;
  background: var(--ink);
  border-radius: 999px;
  box-shadow: 0 12px 24px -16px rgba(43, 33, 27, .8);
  transition: transform .2s var(--ease), background .2s, opacity .2s;
}
#file:hover { background: #3a2c24; transform: translateY(-1px); }
#file svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#file[aria-disabled="true"] { opacity: .35; pointer-events: none; }

.list { list-style: none; margin: 0; padding: 0; max-height: min(62vh, 640px); overflow-y: auto; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.2fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid #efe6d5;
}
.row:last-child { border-bottom: 0; }
.who { min-width: 0; }
.name { color: var(--ink); font-weight: 600; text-decoration: none; }
.name:hover { text-decoration: underline; text-underline-offset: 3px; }
.meta, .why { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.why { font-style: italic; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.pill, .tag { padding: 3px 10px; font-size: 12px; border-radius: 999px; white-space: nowrap; }
.pill.confirmed { color: var(--cream); background: var(--ink); }
.pill.probable { color: #7d3a1d; background: #f6dfd1; }
.pill.unsure { color: var(--ink-soft); background: #efe6d5; }
.tag { color: var(--ink-soft); border: 1px solid var(--line); }
.post { font-size: 13px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.post:hover { text-decoration: underline; text-underline-offset: 3px; }
.empty { padding: 36px 18px; text-align: center; color: var(--ink-soft); font-size: 14px; }

/* ---------- states ---------- */
#stage[data-state="working"] #form { opacity: 0; transform: translateY(-18px) scale(.97); filter: blur(4px); pointer-events: none; }
#stage[data-state="working"] #working { opacity: 1; transform: none; pointer-events: auto; }

/* done: the form and orbit leave, the results page takes the whole width */
body:has(#stage[data-state="done"]) { place-items: start center; height: auto; min-height: 100%; padding: 44px 0 56px; }
#stage[data-state="done"] { width: min(1040px, calc(100% - 32px)); min-height: 0; display: block; }
#stage[data-state="done"] #form,
#stage[data-state="done"] #working { display: none; }
#stage[data-state="done"] #result { display: flex; animation: rise .8s var(--ease) backwards; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

@media (max-width: 760px) {
  body:has(#stage[data-state="done"]) { padding-top: 28px; }
  .flabel { min-width: 100%; }
  .row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 8px; }
  .tags { grid-column: 1 / -1; order: 3; }
  .bar { flex-direction: column; align-items: stretch; text-align: center; }
  #file { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .arc, .satellite, .core { animation-duration: 6s; }
  #stage * { transition-duration: .01ms !important; }
}
