:root {
  --ink: #08090c;
  --line: rgba(255, 255, 255, 0.08);
  --bone: #edeae3;
  --mute: #797a83;
  --gold: #d9ac55;

  /* Metal, set per skin by JS. Defaults to the sovereign. */
  --m-hi: #fbefcb;
  --m-a: #d9ac55;
  --m-b: #a97f33;
  --m-lo: #6e4c18;
  --m-deep: #3f2a0c;
  --m-aura: rgba(217, 172, 85, 0.16);

  /* Everything scales off the coin, and the coin scales off the viewport.
     No fixed pixel heights anywhere — the page must never scroll. */
  --coin-d: clamp(104px, min(23vh, 44vw), 210px);
  --coin-t: calc(var(--coin-d) * 0.082);
  --gap: clamp(0.4rem, 1.7vh, 1.6rem);
  --pad-y: clamp(0.9rem, 2.8vh, 3rem);
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;           /* one page, no scrolling, ever */
  overscroll-behavior: none;
}
body {
  margin: 0;
  background-color: var(--ink);
  background-image: radial-gradient(130% 90% at 50% -20%, #171a22 0%, #0c0e13 45%, var(--ink) 100%);
  color: var(--bone);
  font-family: "Inter Tight", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: 0.05; mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/></filter><rect width='220' height='220' filter='url(%23n)'/></svg>");
}
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; border-radius: 999px; }
::selection { background: var(--m-b); color: #0b0c10; }

/* ---------- layout: locked to one viewport ---------- */
main {
  position: relative; z-index: 1;
  margin: 0 auto; max-width: 36rem;
  height: 100vh; height: 100dvh;
  padding: calc(var(--pad-y) + env(safe-area-inset-top)) 1.5rem
           calc(var(--pad-y) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  gap: var(--gap);
}
header, footer, section {
  display: flex; flex-direction: column; align-items: center; width: 100%; min-height: 0;
}
.eyebrow {
  margin: 0; font-family: "JetBrains Mono", monospace; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.28em; color: var(--mute);
}
.hairline {
  height: 1px; width: 100%; max-width: 220px; margin-top: clamp(0.4rem, 1.4vh, 1rem);
  background: linear-gradient(90deg, transparent, var(--line) 22%, var(--line) 78%, transparent);
}

/* ---------- coin ---------- */
.stage {
  position: relative; perspective: 1500px; perspective-origin: 50% 42%;
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.aura {
  position: absolute; left: 50%; top: 50%;
  width: calc(var(--coin-d) * 2.1); height: calc(var(--coin-d) * 2.1);
  translate: -50% -50%; border-radius: 50%; pointer-events: none; opacity: 0.4;
  background: radial-gradient(50% 50% at 50% 50%, var(--m-aura), transparent 68%);
  transition: background 0.5s ease;
}
.coin-float { transform-style: preserve-3d; animation: coin-hover 7s ease-in-out infinite; }
@keyframes coin-hover { 0%,100% { transform: translate3d(0,0,0); } 50% { transform: translate3d(0,-5px,0); } }
.coin-lift, .coin-tilt { transform-style: preserve-3d; }
.coin-press {
  transform-style: preserve-3d;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.stage:active .coin-press { transform: scale(0.955); transition-duration: 0.09s; }
.coin {
  position: relative; width: var(--coin-d); height: var(--coin-d);
  transform-style: preserve-3d; will-change: transform;
}
.coin.restrike { animation: restrike 0.55s ease-out; }
@keyframes restrike {
  0% { filter: brightness(1.5) saturate(0.5); }
  100% { filter: brightness(1); }
}
.coin__face {
  position: absolute; inset: 0; border-radius: 50%;
  backface-visibility: hidden; overflow: hidden; display: grid; place-items: center;
  background-image:
    radial-gradient(110% 110% at 28% 20%, rgba(255,255,255,0.5), rgba(255,255,255,0) 46%),
    conic-gradient(from 205deg,
      var(--m-lo) 0%, var(--m-a) 11%, var(--m-hi) 21%, var(--m-b) 33%,
      var(--m-lo) 45%, var(--m-a) 59%, var(--m-hi) 69%, var(--m-b) 83%, var(--m-lo) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.3),
    inset 0 2px 3px rgba(255,255,255,0.32),
    inset 0 -3px 10px rgba(0,0,0,0.35),
    inset 0 0 26px rgba(0,0,0,0.22);
}
.coin__face--heads { transform: translateZ(calc(var(--coin-t) / 2)); }
.coin__face--tails { transform: rotateX(180deg) translateZ(calc(var(--coin-t) / 2)); }
.coin__field {
  position: absolute; inset: 8.5%; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4%;
  background-image: radial-gradient(100% 100% at 32% 24%,
    rgba(255,255,255,0.26), rgba(0,0,0,0.05) 55%, rgba(0,0,0,0.2) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.25),
    inset 0 1px 0 rgba(255,255,255,0.35),
    0 1px 0 rgba(255,255,255,0.22);
}
.coin__beads {
  position: absolute; inset: 3%; border-radius: 50%;
  border: 1px dashed rgba(0,0,0,0.28); opacity: 0.8;
}
.engrave {
  width: 44%; height: 44%; color: var(--m-deep); opacity: 0.82;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,0.4));
}
.coin__legend {
  font-family: "JetBrains Mono", monospace;
  font-size: calc(var(--coin-d) * 0.044); letter-spacing: 0.34em; text-indent: 0.34em;
  color: var(--m-deep); opacity: 0.72;
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
}
/* One specular sweep as the coin comes to rest, so the face it landed
   on announces itself instead of just stopping. */
.coin__gloss {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  opacity: 0; mix-blend-mode: screen;
  background: linear-gradient(112deg,
    transparent 32%, rgba(255,255,255,0.5) 47%, rgba(255,255,255,0.16) 56%, transparent 68%);
}
.coin.landed .coin__gloss { animation: sweep 0.85s cubic-bezier(0.25, 0.7, 0.25, 1) both; }
@keyframes sweep {
  0%   { opacity: 0; transform: translateX(-115%); }
  22%  { opacity: 1; }
  75%  { opacity: 0.85; }
  100% { opacity: 0; transform: translateX(115%); }
}

.coin__rim { position: absolute; inset: 0; transform-style: preserve-3d; }
.coin__rim span {
  position: absolute; left: 50%; top: 50%; height: var(--coin-t);
  background-image: linear-gradient(to bottom,
    var(--m-deep) 0%, var(--m-b) 18%, var(--m-hi) 48%, var(--m-a) 62%, var(--m-lo) 92%, var(--m-deep) 100%);
}
.shadow {
  width: calc(var(--coin-d) * 0.92); height: calc(var(--coin-d) * 0.13);
  margin-top: clamp(0.75rem, 2.3vh, 2rem);
  border-radius: 50%; opacity: 0.62; filter: blur(12px);
  background: radial-gradient(50% 50% at 50% 50%, rgba(0,0,0,0.92), rgba(0,0,0,0) 72%);
  will-change: transform, opacity, filter;
}

/* ---------- readout ---------- */
.readout {
  margin-top: clamp(0.85rem, 2.6vh, 2.25rem);
  height: clamp(76px, 14vh, 128px);
  display: flex; flex-direction: column; align-items: center;
}
.result {
  margin: 0; font-family: "Instrument Serif", Georgia, serif; font-style: italic;
  font-size: clamp(2rem, 8vh, 4.5rem); line-height: 1; letter-spacing: -0.02em;
}
.result.is-idle { color: rgba(121,122,131,0.7); }
.reveal { animation: reveal 0.7s cubic-bezier(0.16, 1.12, 0.28, 1) 0.06s both; }
@keyframes reveal {
  from { opacity: 0; transform: translateY(22px) scale(0.96); filter: blur(7px); }
  60%  { filter: blur(0); }
  to   { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}
.caption {
  margin: clamp(0.5rem, 1.6vh, 1.1rem) 0 0;
  font-family: "JetBrains Mono", monospace; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.28em; color: var(--mute);
  animation: fade 0.6s ease both;
}
.caption b { color: var(--m-a); font-weight: 500; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sound-toggle {
  position: absolute;
  top: calc(var(--pad-y) + env(safe-area-inset-top));
  right: 1.25rem;
  width: 30px; height: 30px; padding: 0;
  display: grid; place-items: center;
  border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--mute);
  transition: color 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}
.sound-toggle:hover { color: var(--m-a); border-color: rgba(255,255,255,0.18); }
.sound-toggle[aria-pressed="false"] { color: rgba(121,122,131,0.5); }
.sound-toggle svg { width: 15px; height: 15px; }

/* ---------- skins ---------- */
.skins {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 0.45rem 0.9rem; margin-bottom: clamp(0.7rem, 2.2vh, 1.5rem);
}
.swatches {
  display: flex; gap: 0.45rem; max-width: 100%;
  overflow-x: auto; scrollbar-width: none; padding: 2px 4px;
  scroll-snap-type: x proximity;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
          mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
}
.swatches::-webkit-scrollbar { display: none; }
.swatch { scroll-snap-align: center; flex: 0 0 auto; }
.swatch {
  width: 20px; height: 20px; padding: 0; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), inset 0 -2px 5px rgba(0,0,0,0.4);
  opacity: 0.55; transform: scale(0.92);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.2,0.8,0.2,1), box-shadow 0.3s ease;
}
.swatch:hover { opacity: 0.85; transform: scale(1); }
.swatch[aria-pressed="true"] {
  opacity: 1; transform: scale(1.06);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.45),
    inset 0 -2px 5px rgba(0,0,0,0.4),
    0 0 0 1px var(--ink),
    0 0 0 2px rgba(255,255,255,0.55);
}
.skin-name {
  font-family: "JetBrains Mono", monospace; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.22em; color: var(--mute);
  min-width: 9ch; text-align: center;
}

/* ---------- button ---------- */
.flip-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  padding: clamp(0.7rem, 1.8vh, 0.95rem) clamp(1.7rem, 6vw, 2.4rem);
  border-radius: 999px; border: 1px solid rgba(255,255,255,0.16);
  background: linear-gradient(180deg, rgba(255,255,255,0.09), rgba(255,255,255,0.02)), rgba(16,18,24,0.72);
  backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  color: var(--bone); font-family: inherit; font-size: 0.78rem; font-weight: 500;
  letter-spacing: 0.2em; text-transform: uppercase; cursor: pointer; white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.14), 0 18px 40px -20px rgba(0,0,0,0.9);
  transition: border-color 0.35s ease, box-shadow 0.35s ease, color 0.35s ease,
              transform 0.28s cubic-bezier(0.2,0.8,0.2,1);
}
.flip-btn::after {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px;
  background: linear-gradient(130deg, transparent 20%, var(--m-hi) 50%, transparent 80%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: 0; transition: opacity 0.4s ease; pointer-events: none;
}
.flip-btn:hover:not(:disabled) {
  transform: translateY(-2px); color: var(--m-hi); border-color: rgba(255,255,255,0.28);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.2), 0 22px 55px -22px var(--m-a);
}
.flip-btn:hover:not(:disabled)::after { opacity: 0.6; }
.flip-btn:active:not(:disabled) { transform: translateY(0) scale(0.965); transition-duration: 0.08s; }
.flip-btn:disabled { cursor: default; color: var(--mute); }

/* ---------- ledger ---------- */
.ledger-wrap {
  display: flex; flex-direction: column; align-items: center;
  gap: clamp(0.4rem, 1.2vh, 0.7rem); margin-top: clamp(0.8rem, 2.4vh, 1.6rem); width: 100%;
}
.ledger-wrap .hairline { max-width: 320px; margin-top: 0; }
.ledger {
  display: flex; align-items: center; flex-wrap: wrap; justify-content: center;
  gap: 0.35rem 1rem; font-family: "JetBrains Mono", monospace; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.22em; color: var(--mute);
}
.ledger .marks { display: flex; gap: 6px; }
.ledger .marks i { font-style: normal; color: rgba(121,122,131,0.6); }
.ledger .marks i.hot { color: var(--m-a); }
.ledger .dim { color: rgba(121,122,131,0.55); white-space: nowrap; }
.clear-btn {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit;
  color: rgba(121,122,131,0.45); text-transform: uppercase; letter-spacing: 0.22em;
  transition: color 0.3s ease;
}
.clear-btn:hover { color: var(--m-a); }
.clear-btn[hidden] { display: none; }

/* Short viewports: shed the non-essential labels, never the coin. */
@media (max-height: 660px) {
  .label, .ledger .dim.best { display: none; }
}
@media (max-height: 540px) {
  .eyebrow, header .hairline, .skin-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .coin-float { animation: none; }
  .reveal, .caption, .coin.restrike { animation-duration: 0.01ms; }
  .flip-btn, .coin-press, .swatch { transition-duration: 0.01ms; }
}
