/* 준환 OS 2004 — extras: boot animation, messenger toast, screensaver (js/extras.js).
   The boot screen's base look lives in desktop.css; this file animates it. */

/* ---------- boot ---------- */
#boot {
  overflow: hidden;
  transition: opacity 400ms ease;
}
/* faint CRT scanlines and a soft vignette */
#boot::before,
#boot::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#boot::before {
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.028) 0 1px, rgba(255, 255, 255, 0) 1px 3px);
}
#boot::after {
  background: radial-gradient(120% 90% at 50% 45%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.45) 100%);
}
#boot .boot-inner { position: relative; z-index: 1; }
#boot.is-leaving { opacity: 0; pointer-events: none; }

#boot.is-running .boot-logo {
  animation:
    boot-logo-in 720ms cubic-bezier(0.2, 1.5, 0.35, 1) both,
    boot-glow 2.2s ease-in-out 720ms infinite;
}
#boot.is-running .boot-name { animation: boot-rise 520ms var(--ease-out) 160ms both; }
#boot.is-running .boot-bar { animation: boot-rise 520ms var(--ease-out) 300ms both; }
#boot.is-running .boot-msg { animation: boot-rise 520ms var(--ease-out) 400ms both; }

@keyframes boot-logo-in {
  0% { opacity: 0; transform: scale(0.4) rotate(-20deg); }
  100% { opacity: 1; transform: none; }
}
@keyframes boot-glow {
  0%, 100% { filter: drop-shadow(0 8px 18px rgba(255, 138, 43, 0.35)); }
  50% { filter: drop-shadow(0 6px 26px rgba(255, 168, 80, 0.7)); }
}
@keyframes boot-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* progress trough: blocks light up one by one, with a sweeping shine */
#boot.is-running .boot-bar {
  position: relative;
  overflow: hidden;
  gap: 5px;
  padding: 5px;
  border-color: #6d8fbb;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.22));
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.08);
}
#boot.is-running .boot-bar::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -40%;
  width: 40%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0));
  animation: boot-sweep 1.3s ease-in-out infinite;
}
@keyframes boot-sweep { to { transform: translateX(350%); } }
#boot.is-running .boot-bar i {
  width: 18px;
  height: 12px;
  animation: none;
  opacity: 1;
  background: rgba(143, 243, 255, 0.1);
  transition: background-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}
#boot.is-running .boot-bar i.is-on {
  background: linear-gradient(180deg, #d4fbff 0%, var(--c-led-on) 45%, #3fc6dc 100%);
  box-shadow: 0 0 8px rgba(143, 243, 255, 0.7);
  animation: boot-block 260ms var(--ease-out);
}
@keyframes boot-block { 0% { transform: scaleY(0.4); } 60% { transform: scaleY(1.15); } }
#boot.is-done .boot-bar::after { animation: none; opacity: 0; }

#boot .boot-msg { min-height: 1.5em; letter-spacing: 0.01em; }

.boot-foot {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
  animation: boot-rise 600ms var(--ease-out) 700ms both;
}
.boot-skip {
  padding: 3px 12px;
  border: 1px solid rgba(195, 210, 230, 0.35);
  border-radius: var(--r-pill);
  color: var(--c-bar-ink);
  font-size: 12.5px;
  font-weight: 700;
}
.boot-note { color: var(--c-bar-ink-2); font-size: 12px; }
#boot.is-done .boot-skip { visibility: hidden; }

/* a repeat visit: only the quiet loading screen, no animation */
#boot.is-quick .boot-bar i { animation-duration: 0.9s; }

/* ---------- messenger toast ---------- */
#toast {
  position: fixed;
  /* clear the two desktop icon columns so no icon is hidden while the toast is up */
  right: calc(var(--icon-w) * 2 + 34px);
  bottom: calc(var(--taskbar-h) + 14px);
  z-index: 58;
  width: 340px;
  max-width: calc(100vw - 24px);
}
#toast.is-in { animation: toast-in 420ms cubic-bezier(0.2, 1.25, 0.35, 1) both; }
#toast.is-out { animation: toast-out 220ms ease-in forwards; pointer-events: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(26px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(16px); }
}
@keyframes toast-in-top {
  from { opacity: 0; transform: translateY(-26px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out-top {
  to { opacity: 0; transform: translateY(-16px); }
}

.toast-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--c-win-line);
  border-radius: 12px;
  background: var(--c-paper);
  box-shadow: var(--sh-3), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.toast-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 5px 0 10px;
  border-bottom: 1px solid #8fb6d8;
  background: linear-gradient(180deg, var(--c-title-1) 0%, var(--c-title-2) 48%, var(--c-title-3) 52%, var(--c-title-4) 100%);
  color: var(--c-title-ink);
}
.toast-head::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, #5fd3c4, #6db7f2 60%, #b7a6f5);
}
.toast-app { flex: none; width: 16px; height: 16px; }
.toast-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
}
.toast-when { flex: none; color: var(--c-ink-2); font-size: 12px; font-weight: 700; }
.toast-x {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 22px;
  border: 1px solid #7f9fbf;
  border-radius: 7px;
  background: var(--gloss), linear-gradient(180deg, #ffffff, #d5e5f3);
  color: var(--c-navy);
  box-shadow: var(--sh-inset), 0 1px 1px rgba(12, 34, 64, 0.16);
  transition: filter var(--t-fast);
}
.toast-x svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.toast-x:hover {
  border-color: #b3261e;
  background: var(--gloss-soft), linear-gradient(180deg, #ef6a5b, #c9372a);
  color: #fff;
}

.toast-body {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px 14px 15px;
  background:
    radial-gradient(90% 120% at 0% 0%, rgba(200, 245, 230, 0.75), rgba(200, 245, 230, 0) 60%),
    linear-gradient(180deg, #ffffff, #f2f8fd);
}
.toast-avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 2px solid #fff;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff3e2, #ffd9ae);
  box-shadow: 0 0 0 1px #c9a27a, 0 3px 6px rgba(12, 34, 64, 0.18);
}
.toast-avatar img { width: 38px; height: 38px; }
.toast-dot {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 16px;
  height: 16px;
  border: 2.5px solid #fff;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #a6f0a0, #2fb34a 60%, #1d8a4a);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.toast-text { display: grid; gap: 3px; min-width: 0; line-height: 1.4; }
.toast-head-line { color: var(--c-ink); font-size: 14.5px; font-weight: 800; }
.toast-sub { color: var(--c-ink-2); font-size: 13px; font-weight: 700; }
.toast-em { color: var(--c-teal-d); font-weight: 800; }

/* time left: a thin bar that empties; hovering the card pauses it */
.toast-timer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, #5fd3c4, #6db7f2);
  transform-origin: 0 50%;
  animation: toast-time var(--toast-ms, 7000ms) linear both;
}
#toast.is-paused .toast-timer { animation-play-state: paused; }
@keyframes toast-time { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- screensaver ---------- */
#screensaver {
  position: fixed;
  inset: 0;
  z-index: 90;
  overflow: hidden;
  background:
    radial-gradient(70% 60% at 30% 20%, rgba(42, 127, 212, 0.28), rgba(42, 127, 212, 0) 70%),
    radial-gradient(60% 50% at 80% 90%, rgba(19, 168, 158, 0.2), rgba(19, 168, 158, 0) 70%),
    linear-gradient(180deg, #0b1a30 0%, #060e1c 100%);
  cursor: none;
  user-select: none;
}
#screensaver.is-on { animation: ss-in 700ms ease both; }
@keyframes ss-in { from { opacity: 0; } to { opacity: 1; } }

/* two star layers; the whole field drifts by exactly one tile per loop, so it never jumps */
.ss-stars,
.ss-stars::after {
  position: absolute;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 27% 64%, #cfe6ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 41% 32%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 58% 78%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 66% 22%, #ffe9b8 50%, transparent 51%),
    radial-gradient(1px 1px at 79% 51%, #cfe6ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 88% 12%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 93% 84%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 6% 88%, #cfe6ff 50%, transparent 51%),
    radial-gradient(1px 1px at 50% 6%, #fff 50%, transparent 51%);
  background-size: 520px 420px;
}
.ss-stars {
  top: -420px;
  left: 0;
  right: -520px;
  bottom: 0;
  opacity: 0.8;
  animation: ss-drift 150s linear infinite;
  will-change: transform;
}
@keyframes ss-drift { to { transform: translate(-520px, 420px); } }
.ss-stars::after {
  content: "";
  inset: 0;
  background-size: 260px 210px;
  background-position: 90px 50px;
  animation: ss-twinkle 3.2s ease-in-out infinite alternate;
}
@keyframes ss-twinkle { from { opacity: 0.15; } to { opacity: 0.9; } }

.ss-logo {
  --ss-accent: #ff9d42;
  --ss-hue: 0deg;
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 10px 14px;
  will-change: transform;
}
.ss-orb {
  width: 88px;
  height: 88px;
  filter: hue-rotate(var(--ss-hue)) drop-shadow(0 0 22px var(--ss-accent));
  transition: filter 400ms ease;
}
.ss-word {
  display: flex;
  align-items: baseline;
  gap: 0.3em;
  color: #fff;
  font-family: var(--font-display);
  font-size: 40px;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 3px 0 rgba(10, 30, 60, 0.6), 0 0 24px rgba(143, 243, 255, 0.25);
}
.ss-year {
  color: var(--ss-accent);
  font-weight: 400;
  transition: color 400ms ease;
}
.ss-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 12px;
  border: 1px solid rgba(195, 210, 230, 0.3);
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.06);
  color: var(--c-bar-ink-2);
  font-size: 13px;
  font-weight: 700;
}
.ss-time {
  color: var(--c-led-on);
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 0 8px rgba(143, 243, 255, 0.55);
}
.ss-time:empty { display: none; }
.ss-hint {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: max(24px, env(safe-area-inset-bottom));
  color: var(--c-bar-ink-2);
  font-size: 13px;
  text-align: center;
  animation: ss-hint 2.6s ease-in-out infinite alternate;
}
@keyframes ss-hint { from { opacity: 0.55; } to { opacity: 1; } }

/* reduced motion: the logo sits still in the middle */
#screensaver.is-still .ss-logo {
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
}

/* ---------- phones ---------- */
@media (max-width: 767.98px) {
  /* phones: drop in from the top like a phone banner, over the decorative wordmark, not the icons */
  #toast {
    top: max(10px, env(safe-area-inset-top));
    bottom: auto;
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
  }
  #toast.is-in { animation-name: toast-in-top; }
  #toast.is-out { animation-name: toast-out-top; }
  /* a full-screen panel is open: keep its back button free, sit above the taskbar instead */
  #desktop:has(.win:not([hidden]):not(.is-closing)) ~ #toast {
    top: auto;
    bottom: calc(var(--taskbar-h) + 10px);
  }
  #desktop:has(.win:not([hidden]):not(.is-closing)) ~ #toast.is-in { animation-name: toast-in; }
  #desktop:has(.win:not([hidden]):not(.is-closing)) ~ #toast.is-out { animation-name: toast-out; }
  .toast-body { grid-template-columns: 46px minmax(0, 1fr); gap: 11px; padding: 11px 12px 14px; }
  .toast-avatar { width: 46px; height: 46px; }
  .toast-avatar img { width: 34px; height: 34px; }
  .toast-head-line { font-size: 14px; }
  .ss-orb { width: 68px; height: 68px; }
  .ss-word { font-size: 30px; }
  .ss-tag { font-size: 12.5px; }
  #boot .boot-name { font-size: 34px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .toast-timer { display: none; }
  #boot.is-running .boot-bar::after { display: none; }
}
