/* Main page: the chance dial, the knife and the result effects. The Mystery forge is in forge-mystery.css. */

/* Forge: two item slots with the chance dial between them */
.forge {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: var(--gutter);
}

.slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-height: 300px;
  padding: 24px;
  background: var(--plate);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--plate-edge);
  text-align: center;
}

.slot p {
  margin: 0;
  color: var(--ash);
  font-size: var(--text-sm);
}

/* Both slots start with their title at the same height; what goes in them is centred below */
.slot-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  /* Room for the hint even when it hides, so the slot's content never jumps up */
  min-height: 44px;
}

.slot-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}


/* Registered as angles, so the browser can smoothly animate the zone when the chance changes */
@property --zone {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

@property --zone-start {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

/* The dial's own light is a layer behind it (::before), so a flare changes only its opacity and size, never a
   shadow that the browser would have to repaint. The push-in uses the separate scale property, so it adds up
   with the shake and flare keyframes, which use transform. */
.dial {
  --dial-push: 1.1;
  --dial-move-ms: 600ms;
  /* The arc's colours; data-level (set by forge.js) heats them from dull red to gold */
  --zone-colour: #ffb347;
  --zone-edge: #fff1c2;
  --zone-glow: rgba(255, 150, 40, 0.8);
  position: relative;
  isolation: isolate;
  align-self: center;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  transition: scale var(--dial-move-ms) cubic-bezier(0.22, 1, 0.36, 1);
}

.dial::before {
  content: "";
  position: absolute;
  inset: -22%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 107, 26, 0.34), rgba(255, 107, 26, 0.1) 55%, transparent 75%);
  opacity: 0.75;
  pointer-events: none;
  transition: opacity var(--dial-move-ms) ease-out;
}

.dial[data-level="low"] {
  --zone-colour: #d2452c;
  --zone-edge: #ff9a7a;
  --zone-glow: rgba(210, 69, 44, 0.75);
}

.dial[data-level="medium"] {
  --zone-colour: #ff7a1f;
  --zone-edge: #ffc27a;
  --zone-glow: rgba(255, 122, 31, 0.8);
}

.dial[data-level="high"] {
  --zone-colour: #ffc94d;
  --zone-edge: #fff4cf;
  --zone-glow: rgba(255, 201, 77, 0.8);
}

/* The camera moves in while the knife runs: the dial comes closer, its light grows, the slots step back */
.forge.is-focused .dial {
  scale: var(--dial-push);
}

.forge.is-focused .dial::before {
  opacity: 1;
}

.forge .slot {
  transition: opacity var(--dial-move-ms, 600ms) ease-out, filter var(--dial-move-ms, 600ms) ease-out;
}

.forge.is-focused .slot {
  opacity: 0.55;
  filter: saturate(0.6);
}

/* The result slot comes back to full light as soon as it shows the result */
.forge.is-focused .slot-won,
.forge.is-focused .slot-burned {
  opacity: 1;
  filter: none;
}

/* The wheel is made of layers: a dark face, a groove, the winning zone in the groove, a steel rim with marks */
.dial-wheel {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, #2e2928 40%, #171414 74%);
  border-radius: 50%;
}

.dial-wheel > *,
.dial-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.dial-track,
.dial-ring {
  -webkit-mask: radial-gradient(closest-side, transparent 74.5%, #000 75%, #000 88.5%, transparent 89%);
  mask: radial-gradient(closest-side, transparent 74.5%, #000 75%, #000 88.5%, transparent 89%);
}

.dial-track {
  background: #0c0a0a;
}

/* A filter runs before a mask, so the glow sits on a wrapper or the mask would cut it off */
.dial-zone {
  filter: drop-shadow(0 0 3px var(--zone-edge)) drop-shadow(0 0 10px var(--zone-glow));
  transition: filter 0.4s ease;
}

/* The bright lines mark the zone's edges, and they never make it wider than the real chance */
.dial-ring {
  --edge: min(1.5deg, calc(var(--zone) / 2));
  background: conic-gradient(
    from var(--zone-start),
    var(--zone-edge) 0deg,
    var(--zone-colour) var(--edge),
    var(--zone-colour) calc(var(--zone) - var(--edge)),
    var(--zone-edge) var(--zone),
    transparent var(--zone),
    transparent 360deg
  );
  transition: --zone 0.3s ease, --zone-start 0.3s ease;
}

.dial-bezel {
  background: conic-gradient(
    #6f6865, #38322f 12%, #8b8480 25%, #38322f 38%, #5d5653 50%, #2f2a28 63%, #86807b 76%, #38322f 88%, #6f6865
  );
  -webkit-mask: radial-gradient(closest-side, transparent 88%, #000 88.5%);
  mask: radial-gradient(closest-side, transparent 88%, #000 88.5%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* Small marks every 6 degrees and longer ones every 30, like on a gauge */
.dial-ticks {
  background:
    repeating-conic-gradient(from -0.5deg, rgba(0, 0, 0, 0.7) 0 1deg, transparent 1deg 30deg),
    repeating-conic-gradient(from -0.25deg, rgba(0, 0, 0, 0.42) 0 0.5deg, transparent 0.5deg 6deg);
  -webkit-mask: radial-gradient(closest-side, transparent 90.5%, #000 91%, #000 97.5%, transparent 98%);
  mask: radial-gradient(closest-side, transparent 90.5%, #000 91%, #000 97.5%, transparent 98%);
}

/* The arm covers the whole dial and turns around its centre, carrying the knife along the ring.
   The knife picture is drawn upright with its blade on the picture's centre line (images/m9.png),
   so centring the box centres the blade on the dial's axis. */
.dial-arm {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.dial-knife {
  position: absolute;
  top: 22px;
  left: 50%;
  height: 66px;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.7));
  transition: filter 0.3s ease;
}

/* While it runs the knife is hot: an ember edge on it (the owner asked for no trail behind it) */
.dial.is-spinning .dial-knife {
  filter: drop-shadow(0 0 2px #ffe08a) drop-shadow(0 0 8px rgba(255, 120, 30, 0.9));
}

/* The strike: a flash right where the knife stopped (the arm still holds the knife's angle).
   White-hot on a win, a dull red scorch on a loss. */
.dial-arm::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  width: 96px;
  height: 96px;
  margin-left: -48px;
  border-radius: 50%;
  background: radial-gradient(closest-side, #fff8ec, rgba(255, 190, 90, 0.75) 30%, rgba(255, 107, 26, 0.25) 60%, transparent);
  opacity: 0;
  transform: scale(0.3);
}

.dial-won .dial-arm::after {
  animation: knife-strike 0.9s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.dial-lost .dial-arm::after {
  background: radial-gradient(closest-side, rgba(255, 122, 107, 0.7), rgba(179, 54, 43, 0.35) 45%, transparent);
  animation: knife-strike 0.7s ease-out;
}

@keyframes knife-strike {
  0% { opacity: 0; transform: scale(0.3); }
  15% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.6); }
}

.dial-core {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 132px;
  height: 132px;
  background: radial-gradient(circle at 50% 35%, var(--iron-lighter), var(--iron));
  border: 1px solid var(--steel);
  border-radius: 50%;
  box-shadow: 0 0 0 5px var(--surface-control), 0 0 0 6px var(--steel);
  transform: translate(-50%, -50%);
}

.dial-value {
  color: var(--ember-light);
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.dial-label {
  color: var(--ash);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

[data-level="low"] .dial-label {
  color: var(--danger-text);
}

[data-level="medium"] .dial-label {
  color: var(--ember-light);
}

[data-level="high"] .dial-label {
  color: var(--gold);
}

.dial-effects {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  pointer-events: none;
}

/* The lightning button sits in the free corner beside the round dial */
.dial-fast-button {
  position: absolute;
  right: -2px;
  bottom: -2px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  background: var(--surface-control);
  border: var(--border);
  border-radius: 50%;
  cursor: pointer;
}

.dial-fast-button svg {
  width: 22px;
  height: 22px;
  fill: var(--ash);
}

.dial-fast-button:hover {
  border-color: var(--line-ember);
}

/* On: tinted like a chosen chip, never filled (the Forge button is the one filled control) */
.dial-fast-button[aria-pressed="true"] {
  background: var(--tint-ember);
  border-color: var(--ember);
}

.dial-fast-button[aria-pressed="true"] svg {
  fill: var(--ember-light);
}

/* Fast mode: the result effects finish as quickly as the shorter spin */
.forge-fast .dial-won,
.forge-fast .dial-won::before,
.forge-fast .dial-won .dial-zone,
.forge-fast .slot-won::after,
.forge-fast .slot-burned::after {
  animation-duration: 1.2s;
}

.forge-fast .slot-won .target-image {
  animation-duration: 0.6s;
}

.forge-fast .slot-burned .stake-tile {
  animation-duration: 0.85s;
}

/* The result is told in the middle of the dial: one big word that pops in where the chance was read.
   Win: the forge flares (its light layer swells), the arc burns white-hot, the target slot lights up.
   (The sparks are in forge-fx.css.) */
.dial-won {
  animation: forge-flare 1.9s ease-out;
}

.dial-won::before {
  animation: forge-light-flare 1.9s ease-out;
}

.dial-won .dial-zone {
  animation: zone-flare 1.9s ease-out;
}

.dial-won .dial-value,
.dial-won .dial-label {
  color: var(--gold);
}

.dial-won .dial-label,
.dial-lost .dial-label {
  font-weight: 800;
  transform-origin: 50% 0;
  animation: result-word 0.45s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

/* A flash of the slot's edge, drawn on its own layer so only its opacity changes */
.slot::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid var(--slot-flash-edge, var(--ember-light));
  border-radius: inherit;
  box-shadow: var(--slot-flash-shadow, 0 0 44px 6px rgba(255, 179, 71, 0.55));
  opacity: 0;
  pointer-events: none;
}

.slot-won::after,
.slot-burned::after {
  animation: slot-flash 1.9s ease-out;
}

.slot-won .target-image {
  animation: target-pop 0.9s ease-out;
}

@keyframes forge-flare {
  0% { transform: scale(1); }
  18% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes forge-light-flare {
  0% { opacity: 1; transform: scale(1); filter: none; }
  18% { opacity: 1; transform: scale(1.3); filter: brightness(2.2) saturate(1.2); }
  100% { opacity: 1; transform: scale(1); filter: none; }
}

@keyframes zone-flare {
  0%, 100% { filter: drop-shadow(0 0 3px var(--zone-edge)) drop-shadow(0 0 10px var(--zone-glow)); }
  15% { filter: brightness(1.7) drop-shadow(0 0 4px #fff8ec) drop-shadow(0 0 18px var(--zone-glow)); }
}

@keyframes result-word {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1.7); }
}

@keyframes slot-flash {
  0%, 100% { opacity: 0; }
  20%, 60% { opacity: 1; }
}

@keyframes target-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.12) rotate(-2deg); }
  100% { transform: scale(1); }
}

/* Loss: the dial gives a short shudder and goes cold (its light dies, the arc greys), the word is a dull red,
   the stake burns to ash, the target fades */
.dial-lost {
  animation: forge-shake 0.5s ease-in-out;
}

.dial-lost::before {
  opacity: 0.15;
}

.dial-lost .dial-zone {
  filter: grayscale(1) brightness(0.55);
}

.dial-lost .dial-value {
  color: var(--ash);
}

.dial-lost .dial-label {
  color: var(--danger-text);
}

.slot-burned {
  --slot-flash-edge: var(--danger);
  --slot-flash-shadow: inset 0 0 50px rgba(179, 54, 43, 0.55);
}

.smoke {
  position: absolute;
  bottom: 30%;
  width: 44px;
  height: 44px;
  background: radial-gradient(circle, rgba(170, 165, 160, 0.75), rgba(170, 165, 160, 0));
  border-radius: 50%;
  pointer-events: none;
}

.slot-burned .stake-tile {
  animation: stake-burn 1.3s ease-in forwards;
}

.slot-missed .target-image {
  filter: grayscale(1) brightness(0.55);
  transition: filter 0.3s ease;
}

@keyframes forge-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-1deg); }
  45% { transform: translateX(5px) rotate(0.8deg); }
  70% { transform: translateX(-3px); }
}

@keyframes stake-burn {
  0% { filter: none; opacity: 1; }
  45% { filter: brightness(1.7) sepia(1) saturate(4) hue-rotate(-25deg); opacity: 1; }
  100% { filter: grayscale(1) brightness(0.3); opacity: 0.15; }
}

.forge-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 24px 0 32px;
}

.forge-hint {
  min-height: 1.2em;
  margin: 0;
  color: var(--ash);
  font-size: 0.9rem;
}

