/* Flash messages.

   These used to be a DaisyUI `.alert` row rendered inline at the top of
   `.content`, which pushed the whole page down by its own height the moment a
   view left a message behind - the reader's eye was already on the content, so
   the news arrived by shoving it. They are toasts now: they sit over the page
   under the navbar, say their piece, and time out on their own. */

.flash-stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  left: 50%;
  /* Below the sticky navbar (h-14). Pages without one - the exam shell - pass
     their own offset in. */
  max-height: calc(100vh - var(--flash-top, 4rem) - 1rem);
  max-width: min(30rem, calc(100vw - 1.5rem));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.25rem;
  pointer-events: none;
  position: fixed;
  top: var(--flash-top, 4rem);
  transform: translateX(-50%);
  width: 100%;
  /* Over the drawers (60) and their handles (70), under the confirm dialog,
     which is a top-layer <dialog> and so above all of this regardless. */
  z-index: 80;
}

.flash {
  align-items: flex-start;
  background-color: #fffdf7;
  border: 1px solid var(--flash-edge, #e3dac2);
  border-radius: 0.75rem;
  box-shadow: 0 10px 30px rgba(58, 52, 20, 0.18);
  color: #3a3428;
  display: flex;
  gap: 0.7rem;
  overflow: hidden;
  padding: 0.85rem 0.9rem;
  pointer-events: auto;
  position: relative;
}

/* Entrance. The stack is fixed at the top, so a toast comes down out of the
   bar rather than in from a corner nothing else on the page uses. */
.flash {
  animation: flash-in 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes flash-in {
  from {
    opacity: 0;
    transform: translateY(-0.7rem) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Leaving collapses the row as well as fading it, so the toasts below it walk
   up rather than jumping. */
.flash.is-leaving {
  margin-top: calc(-1 * var(--flash-height, 0px) - 0.6rem);
  opacity: 0;
  transform: translateY(-0.4rem);
  transition:
    opacity 0.14s ease,
    transform 0.14s ease,
    margin-top 0.18s ease 0.04s;
}

.flash__icon {
  align-items: center;
  background-color: var(--flash-tint, #f2ead6);
  border-radius: 999px;
  color: var(--flash-ink, #4e0d0d);
  display: flex;
  flex: 0 0 auto;
  font-size: 0.95rem;
  height: 1.85rem;
  justify-content: center;
  width: 1.85rem;
}

.flash__text {
  flex: 1 1 auto;
  font-size: 0.98rem;
  line-height: 1.5;
  /* A cleared-records message names a title that can run long and hold no
     spaces to break at. */
  overflow-wrap: anywhere;
  padding-top: 0.2rem;
}

.flash__close {
  background: none;
  border: none;
  border-radius: 0.5rem;
  color: #8a7a6a;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.4rem;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.flash__close:hover {
  background-color: rgba(78, 13, 13, 0.07);
  color: #4e0d0d;
}

.flash__close:focus-visible {
  outline: 2px solid var(--flash-ink, #4e0d0d);
  outline-offset: 1px;
}

/* How long is left, drawn rather than counted down in script: hovering the
   toast pauses the animation, and the same pause holds the dismissal, so the
   bar and the timer can never disagree. */
.flash__timer {
  animation: flash-timer var(--flash-life, 5s) linear forwards;
  background-color: var(--flash-ink, #4e0d0d);
  bottom: 0;
  height: 3px;
  left: 0;
  opacity: 0.45;
  position: absolute;
  transform-origin: left center;
  width: 100%;
}

@keyframes flash-timer {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

.flash:hover .flash__timer,
.flash:focus-within .flash__timer {
  animation-play-state: paused;
}

.flash--success {
  --flash-edge: #cfe1d3;
  --flash-ink: #35603f;
  --flash-tint: #e8f2ea;
}

.flash--error {
  --flash-edge: #e6c9c9;
  --flash-ink: #9b2c2c;
  --flash-tint: #fbeceb;
}

.flash--warning {
  --flash-edge: #e8d7a8;
  --flash-ink: #8a5a12;
  --flash-tint: #fbf1da;
}

.flash--info {
  --flash-edge: #dccfb0;
  --flash-ink: #4e0d0d;
  --flash-tint: #f4ecd9;
}

/* Share link: one focused decision, styled as a quiet paper card rather than
   another transient notification. The URL stays available to clipboard code
   without making a signed credential fill the reader's screen. */
.share-dialog {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(250, 246, 235, 0.98));
  border: 1px solid #ded3b9;
  border-radius: 1.25rem;
  box-shadow: 0 30px 80px rgba(35, 28, 15, 0.28);
  color: #302b22;
  margin: auto;
  max-width: min(28rem, calc(100vw - 2rem));
  overflow: hidden;
  padding: 2rem;
  pointer-events: auto;
  position: relative;
  text-align: center;
  width: 100%;
}

.share-dialog[open] {
  animation: share-dialog-in 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.share-dialog::backdrop {
  animation: share-backdrop-in 0.2s ease-out both;
  backdrop-filter: blur(5px);
  background: rgba(28, 23, 16, 0.55);
}

.share-dialog__glow {
  background: #d8bd65;
  border-radius: 999px;
  filter: blur(45px);
  height: 8rem;
  opacity: 0.2;
  position: absolute;
  right: -4rem;
  top: -5rem;
  width: 10rem;
}

.share-dialog__close {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: #837866;
  cursor: pointer;
  display: flex;
  height: 2.25rem;
  justify-content: center;
  position: absolute;
  right: 0.85rem;
  top: 0.85rem;
  transition: background-color 0.15s ease, color 0.15s ease;
  width: 2.25rem;
}

.share-dialog__close:hover {
  background: rgba(78, 13, 13, 0.07);
  color: #4e0d0d;
}

.share-dialog__close:focus-visible,
.share-dialog__copy:focus-visible {
  outline: 3px solid rgba(159, 126, 43, 0.35);
  outline-offset: 2px;
}

.share-dialog__mark {
  align-items: center;
  background: #4e0d0d;
  border: 5px solid #f0e7d2;
  border-radius: 999px;
  box-shadow: 0 7px 18px rgba(78, 13, 13, 0.2);
  color: #fff9e9;
  display: flex;
  font-size: 1.15rem;
  height: 3.75rem;
  justify-content: center;
  margin: 0 auto 1rem;
  transform: rotate(-8deg);
  width: 3.75rem;
}

.share-dialog__eyebrow {
  color: #8c7538;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  margin: 0 0 0.35rem;
  text-transform: uppercase;
}

.share-dialog__title {
  color: #3d1111;
  font-family: "Noto Serif CJK SC", "Songti SC", "Source Han Serif SC", serif;
  font-size: clamp(1.45rem, 5vw, 1.8rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.25;
  margin: 0;
}

.share-dialog__payload {
  margin: 1.35rem 0 0;
}

.share-dialog__filename {
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: #4a4438;
  display: -webkit-box;
  font-size: 0.94rem;
  line-height: 1.45;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.share-dialog__url {
  display: none;
  position: fixed;
  top: -10rem;
}

.share-dialog__expiry {
  align-items: center;
  background: #f2ecdc;
  border: 1px solid #e3d8bd;
  border-radius: 999px;
  color: #715d2c;
  display: inline-flex;
  font-size: 0.84rem;
  gap: 0.45rem;
  margin-top: 1rem;
  padding: 0.45rem 0.8rem;
}

.share-dialog__hint {
  color: #7d7464;
  font-size: 0.84rem;
  line-height: 1.5;
  margin: 0.9rem 0 1.25rem;
}

.share-dialog__copy {
  align-items: center;
  background: #4e0d0d;
  border: 1px solid #4e0d0d;
  border-radius: 0.75rem;
  box-shadow: 0 8px 20px rgba(78, 13, 13, 0.2);
  color: #fffaf0;
  cursor: pointer;
  display: flex;
  font-size: 1rem;
  font-weight: 650;
  gap: 0.6rem;
  justify-content: center;
  min-height: 3rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  width: 100%;
}

.share-dialog__copy:hover {
  background: #671616;
  box-shadow: 0 10px 24px rgba(78, 13, 13, 0.27);
  transform: translateY(-1px);
}

@keyframes share-dialog-in {
  from { opacity: 0; transform: translateY(1rem) scale(0.97); }
  to { opacity: 1; transform: none; }
}

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

@media (max-width: 640px) {
  .flash-stack {
    max-width: none;
    padding: 0.25rem 0.5rem;
  }

  .flash {
    padding: 0.75rem 0.8rem;
  }

  .share-dialog {
    border-radius: 1rem;
    padding: 1.65rem 1.25rem 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flash {
    animation-duration: 0.01ms;
  }

  .flash.is-leaving {
    transition-duration: 0.01ms;
  }

  .share-dialog[open],
  .share-dialog::backdrop {
    animation-duration: 0.01ms;
  }

  /* The bar still has to run - it is the timer, not decoration - but it moves
     as one step per second rather than continuously. */
  .flash__timer {
    animation-timing-function: steps(8, end);
  }
}
