#result-dialog {
  inline-size: min(48rem, calc(100% - 28px));
}

.result-panels {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 14px;
}

.result-score-panel,
.result-streak-panel {
  min-inline-size: 0;
  padding: clamp(12px, 3vw, 20px);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
}

.result-score-panel {
  border: none;
  background: rgb(255, 255, 255, 0);
}

.result-context {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: .9rem;
}

#result-dialog h2 {
  font-size: 1.9rem;
}

.result-scale {
  --result-position: 0%;
  position: relative;
  margin: 18px 20px 8px;
  padding-block-start: 0;
}

.result-track {
  position: relative;
  block-size: 13px;
}

/* Mask the paint, leaving the score marker and its label free to extend above it. */
.result-track::before,
.result-fill {
  position: absolute;
  inset: 0;
  border-radius: 5px;
}

.result-art-ready :is(.result-track::before, .result-fill) {
  mask: url("../assets/ui/brush-line.svg") center / 100% 100% no-repeat;
}

.result-track::before {
  background: #c9cbb9;
  content: "";
}

.result-ticks {
  position: absolute;
  inset: -3px 0;
  background: repeating-linear-gradient(to right, var(--ink) 0 2px, transparent 2px 20%);
  border-inline-end: 2px solid var(--ink);
  opacity: .38;
  pointer-events: none;
}

.result-fill {
  /* Clip one full-size stroke so its bristles stay aligned with the grey paint. */
  clip-path: inset(0 calc(100% - var(--result-position)) 0 0);
  background: var(--accent);
}

.result-marker {
  position: absolute;
  inset-inline-start: var(--result-position);
  inset-block-start: 50%;
  inline-size: 19px;
  block-size: 19px;
  translate: -50% -50%;
  border: 3px solid var(--white);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 3px 6px #263b2e33;
}

.result-marker-label {
  position: absolute;
  inset-inline-start: 50%;
  inset-block-start: 23px;
  translate: -50% 0;
  display: grid;
  justify-items: center;
  color: var(--accent-strong);
  white-space: nowrap;
}

.result-marker-label span {
  font-size: .9rem;
}

.result-marker-label strong {
  font-size: 2rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.result-endpoints {
  display: flex;
  justify-content: space-between;
  margin-block-start: 66px;
  color: var(--muted);
  font-size: .9rem;
}

.result-endpoints > span:last-child {
  display: grid;
  justify-items: end;
}

.result-endpoints strong {
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
}

.is-perfect .result-marker {
  background: #bb8126;
  box-shadow: 0 0 0 2px #bb8126, 0 0 18px #ffc83699;
}

.is-perfect .result-marker-label {
  color: #91601a;
}

.is-perfect .result-fill {
  background: #bb8126;
}

.result-share {
  border: none !important;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding-block-start: 12px;
  border-block-start: 1px solid var(--border);
}

.result-share a {
  display: inline-grid;
  place-items: center;
  color: inherit;
  text-decoration: none;
}

.result-share a:hover > .paper-skin {
  filter: brightness(.96) saturate(1.08);
}

.result-share a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.share-status {
  flex: 1 0 100%;
  min-block-size: 1.35em;
  margin: 0;
  color: var(--muted);
  font-size: .9rem;
}

.result-streak-panel {
  --streak-light: #e9e6df;
  --streak-paper: #f6f4ee;
  --surface-paint: radial-gradient(ellipse at var(--streak-light-position, 50% 25%), var(--streak-light), transparent 65%), var(--streak-paper);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  color: #5e5b54;
  text-align: center;
}

.result-streak-panel.is-streak-complete {
  --ui-paper-texture: url('../assets/ui/paper-fire.png');
  --streak-light: #ffe6bc;
  --streak-paper: #fff3df;
  color: #733d22;
}

.result-streak-panel > .paper-skin::before {
  mix-blend-mode: multiply;
}

.streak-details h3,
.streak-total,
.streak-message {
  margin: 0;
}

.streak-details h3 {
  font-size: 1.15rem;
}

.streak-total {
  margin-block: 3px 7px;
  font-size: 1.15rem;
  line-height: 1;
}

.streak-total strong {
  font-size: 2.8rem;
  font-variant-numeric: tabular-nums;
}

.streak-message {
  max-inline-size: 22ch;
  font-size: .95rem;
}

.streak-fire {
  position: relative;
  inline-size: 92px;
  block-size: 104px;
  filter: grayscale(1);
}

.is-streak-complete .streak-fire {
  filter: none;
}

.streak-fire::before {
  position: absolute;
  inset: 14% -12% -6%;
  background: radial-gradient(ellipse 46% 39% at 50% 59%, #ffad4a77, transparent);
  content: '';
}

.streak-particle {
  --drift: -7px;
  --rise: -18px;
  --duration: 1.85s;
  --paint-opacity: .92;
  position: absolute;
  top: var(--y);
  left: var(--x);
  inline-size: 34px;
  block-size: 22px;
  translate: -50% -50%;
  transform: rotate(var(--angle));
  border-radius: 55% 23% 56% 42%;
  background: linear-gradient(90deg, #ab3823, #e75527 52%, #ffb751);
  mask: url('../assets/ui/brush-line.svg') center / 100% 100% no-repeat;
  opacity: var(--paint-opacity);
}

.streak-particle:nth-child(even) {
  --drift: 8px;
  --duration: 1.55s;
}

.streak-particle-base {
  --rise: -11px;
  inline-size: 37px;
  block-size: 27px;
}

.streak-particle-core {
  --rise: -12px;
  inline-size: 25px;
  block-size: 15px;
  background: linear-gradient(90deg, #ff8732, #ffc851 55%, #fff4a3);
}

.streak-particle-ember {
  --rise: -27px;
  --duration: 2.4s;
  --paint-opacity: .75;
  inline-size: 9px;
  block-size: 5px;
  background: linear-gradient(90deg, #d75b2f, #ffbc57);
}

.streak-particle-ember:nth-child(even) {
  --duration: 2.05s;
}

@media (max-width: 740px) {
  #result-dialog {
    inline-size: min(31rem, calc(100% - 28px));
  }

  .result-panels {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .result-streak-panel {
    --streak-light-position: 12% 50%;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    justify-items: start;
    text-align: start;
  }

  .result-share .button {
    padding-inline: 10px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  #result-dialog[open].result-reveal-ready .result-fill {
    animation: result-fill-in 600ms cubic-bezier(.2, .8, .3, 1) both;
  }

  #result-dialog[open].result-reveal-ready .result-marker-label {
    animation: result-marker-in 420ms 160ms cubic-bezier(.2, 1.5, .5, 1) both;
  }

  #result-dialog[open] .streak-particle {
    animation: streak-rise var(--duration) var(--phase) ease-out infinite;
  }
}

@keyframes result-fill-in {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 calc(100% - var(--result-position)) 0 0); }
}

@keyframes result-marker-in {
  from { opacity: 0; transform: translateY(8px) scale(.85); }
  to { opacity: 1; transform: none; }
}

@keyframes streak-rise {
  0% {
    opacity: 0;
    transform: translateY(8px) rotate(calc(var(--angle) - 12deg)) scale(.7, .8);
  }

  24%, 56% { opacity: var(--paint-opacity); }

  50% { transform: translateY(-3px) rotate(var(--angle)); }

  100% {
    opacity: 0;
    transform: translate(var(--drift), var(--rise)) rotate(calc(var(--angle) + 14deg)) scale(.65, .38);
  }
}
