/* Horcrux Hunt guest app. A hunter's ledger by candlelight (SPEC.md §10). */

@font-face {
  font-family: "IM Fell English";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/im-fell-english-regular.woff2") format("woff2");
}

@font-face {
  font-family: "IM Fell English";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/im-fell-english-italic.woff2") format("woff2");
}

:root {
  --soot: #1C1612;
  --parchment: #E9DFC7;
  --ash: #8B8072;          /* rules, dim emblems; not for text (4.6:1 on Soot) */
  --ash-text: #B3A994;     /* secondary text at 7.7:1 on Soot */
  --gold: #C9A24A;
  --curse: #5FBF5A;
  --wax: #8E2A2A;
  --rule: #3A3029;
  --display: "IM Fell English", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: 20px;
  --tabs-height: 64px;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--soot);
  color: var(--parchment);
  font: 17px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 34rem;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 24px) var(--gutter) calc(env(safe-area-inset-bottom) + var(--tabs-height) + 24px);
}

h1, h2, h3, p { margin: 0; }

.display {
  font-family: var(--display);
  font-weight: 400;
  line-height: 1.15;
}

h1.display { font-size: 2.1rem; }
h2.display { font-size: 1.6rem; }

.quiet { color: var(--ash-text); }
.gold { color: var(--gold); }

.screen { display: grid; gap: 20px; }
.screen--centred { min-height: 60vh; align-content: center; }

.rule { border: 0; border-top: 1px solid var(--rule); margin: 4px 0; width: 100%; }

/* Controls ---------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 12px 24px;
  border: 1px solid var(--gold);
  border-radius: 4px;
  background: var(--gold);
  color: var(--soot);
  font: 600 1.05rem/1.2 var(--sans);
  cursor: pointer;
  touch-action: manipulation;
}

.button:disabled { opacity: 0.5; cursor: default; }
.button:focus-visible, .link:focus-visible, .tab:focus-visible, input:focus-visible { outline: 2px solid var(--parchment); outline-offset: 3px; }

.button--quiet { background: transparent; color: var(--parchment); border-color: var(--ash); }

.link {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ash-text);
  font: inherit;
  font-size: 0.95rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  justify-self: start;
}

.field {
  width: 100%;
  min-height: 60px;
  padding: 8px 16px;
  border: 1px solid var(--ash);
  border-radius: 4px;
  background: #140F0C;
  color: var(--parchment);
  font: 2rem/1 var(--sans);
  letter-spacing: 0.5em;
  text-transform: uppercase;
  text-align: center;
}

.message { padding-left: 12px; border-left: 3px solid var(--wax); }

/* Connection indicator ----------------------------------------------------- */

.connection {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  right: 12px;
  z-index: 20;
  margin: 0;
  padding: 4px 10px;
  border: 1px solid var(--ash);
  border-radius: 999px;
  background: var(--soot);
  color: var(--ash-text);
  font-size: 0.85rem;
}

/* House header ------------------------------------------------------------- */

.house {
  display: grid;
  grid-template-columns: 6px 1fr auto;
  column-gap: 14px;
  row-gap: 2px;
  align-items: baseline;
}

.house__bar { grid-column: 1; grid-row: 1 / span 2; align-self: stretch; border-radius: 2px; background: var(--accent, var(--ash)); }
.house__name { font-family: var(--display); font-size: 1.9rem; line-height: 1.1; overflow-wrap: anywhere; }
.house__points { font-size: 1.1rem; white-space: nowrap; }
.house__meta { grid-column: 2; color: var(--ash-text); font-size: 0.95rem; }
.house__clock { grid-column: 3; font-variant-numeric: tabular-nums; white-space: nowrap; }

.banner { font-family: var(--display); font-size: 1.35rem; color: var(--gold); }

/* Emblems ------------------------------------------------------------------ */

.emblem { display: block; flex: none; color: var(--ash); --leaf: #6E5B34; --crack: 0; }
.emblem--found { color: var(--gold); --leaf: var(--gold); --crack: 1; }
.emblem--small { --stroke: 4; }

.emblem-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Ledger ------------------------------------------------------------------- */

.ledger { list-style: none; margin: 0; padding: 0; }

.entry {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  column-gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
  align-items: center;
}

.entry__name { font-family: var(--display); font-size: 1.3rem; line-height: 1.2; }
.entry__status { color: var(--ash-text); font-size: 0.9rem; text-align: right; white-space: nowrap; }
.entry__status .gold { display: block; }
.entry__clue { grid-column: 2 / span 2; margin-top: 4px; font-family: var(--display); font-style: italic; font-size: 1.1rem; color: var(--parchment); }
.entry--found .entry__name { color: var(--gold); }

/* Leaderboard -------------------------------------------------------------- */

.board { list-style: none; margin: 0; padding: 0; }

.standing {
  display: grid;
  grid-template-columns: 1.6rem 6px 1fr auto;
  column-gap: 12px;
  row-gap: 6px;
  padding: 14px 8px 14px 0;
  border-bottom: 1px solid var(--rule);
  align-items: center;
}

.standing__rank { grid-column: 1; color: var(--ash-text); text-align: right; font-variant-numeric: tabular-nums; }
.standing__bar { grid-column: 2; grid-row: 1 / span 2; align-self: stretch; border-radius: 2px; background: var(--accent, var(--ash)); }
.standing__house { grid-column: 3; font-family: var(--display); font-size: 1.3rem; line-height: 1.2; overflow-wrap: anywhere; }
.standing__points { grid-column: 4; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.standing__dots { grid-column: 3; display: flex; gap: 6px; align-items: center; }
.standing__time { grid-column: 4; text-align: right; color: var(--ash-text); font-size: 0.9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.standing--own { background: linear-gradient(90deg, rgba(201, 162, 74, 0.10), transparent 80%); }
.standing--winner .standing__house { color: var(--gold); }

.dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ash); }
.dot--found { background: var(--gold); border-color: var(--gold); }

/* Tabs --------------------------------------------------------------------- */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--rule);
  background: var(--soot);
}

.tab {
  flex: 1;
  max-width: 17rem;
  min-height: var(--tabs-height);
  border: 0;
  background: none;
  color: var(--ash-text);
  font: 1rem var(--sans);
  cursor: pointer;
}

.tab[aria-selected="true"] { color: var(--parchment); box-shadow: inset 0 2px 0 var(--gold); }

/* Sorting ------------------------------------------------------------------ */

.reveal { display: grid; gap: 12px; }
.reveal__house { font-family: var(--display); font-size: 2.6rem; line-height: 1.1; overflow-wrap: anywhere; }
.reveal__bar { height: 8px; border-radius: 4px; background: var(--accent, var(--gold)); }

/* Scan result modal -------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 18px;
  padding: calc(env(safe-area-inset-top) + 24px) var(--gutter) calc(env(safe-area-inset-bottom) + 24px);
  background: var(--soot);
  overflow-y: auto;
}

.modal > * { max-width: 34rem; width: 100%; margin: 0 auto; }
.modal__points { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 10px; border: 1px solid var(--gold); border-radius: 999px; color: var(--gold); font-size: 0.9rem; }

.noscript { padding: 24px; }

/* Motion arrives in Phase 3 (Sorting reveal, destruction, leaderboard FLIP), each
   inside @media (prefers-reduced-motion: no-preference). */

/* §10 numerals ------------------------------------------------------------- */
/* Every number a guest reads — points, ranks, clocks, countdowns, elapsed times —
   is set in the system sans with lining, tabular figures. The display face has
   oldstyle figures whose zero reads as a letter at a glance in a dim room. */

body { font-variant-numeric: lining-nums tabular-nums; }

.num,
.house__points,
.house__clock,
.house__meta,
.entry__status,
.standing__rank,
.standing__points,
.standing__time,
.modal__points {
  font-family: var(--sans);
  font-variant-numeric: lining-nums tabular-nums;
}

/* Motion (§10) -------------------------------------------------------------- */
/* Two moments and one transition, each keyed to a state change, never to a render,
   and each with a reduced-motion path that applies the end state at once. */

@property --crack {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

/* Destruction: the crack strokes draw in and the emblem flickers curse green,
   then the found state holds. Browsers without @property skip straight to the
   cracked end state, which is the same picture without the draw-in. */
.emblem--destroying { animation: destroy 1500ms ease-out both; }

@keyframes destroy {
  0%   { --crack: 0; transform: scale(1); filter: none; }
  12%  { transform: scale(1.05) rotate(-1.5deg); }
  30%  { --crack: 0.55; filter: drop-shadow(0 0 6px var(--curse)); }
  45%  { transform: scale(0.99) rotate(1deg); filter: none; }
  62%  { --crack: 1; filter: drop-shadow(0 0 12px var(--curse)); }
  74%  { filter: none; }
  86%  { filter: drop-shadow(0 0 5px var(--curse)); }
  100% { --crack: 1; transform: scale(1); filter: none; }
}

.badge--first { animation: gold-mark 900ms ease-out both; }

@keyframes gold-mark {
  0%   { opacity: 0; transform: scale(0.85); }
  45%  { opacity: 1; transform: scale(1.08); box-shadow: 0 0 20px rgba(201, 162, 74, 0.55); }
  100% { opacity: 1; transform: scale(1); box-shadow: none; }
}

.modal--enter { animation: fade-in 220ms ease-out both; }

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

/* Sorting reveal: names cycle in the display face, then the accent bar fills. */
.reveal__house--cycling { color: var(--ash-text); }
.reveal__bar { transform-origin: left center; }
.reveal__bar--fill { animation: fill-bar 700ms ease-out both; }

@keyframes fill-bar { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.standing--new { animation: fade-in 420ms ease-out both; }

@media (prefers-reduced-motion: reduce) {
  .emblem--destroying,
  .badge--first,
  .modal--enter,
  .reveal__bar--fill,
  .standing--new {
    animation: none;
  }
  .emblem--destroying { --crack: 1; }
}
