/* The crystal: one SVG ice cube, eight states switched by data-anim on .crystal.
   Every loop animates transform or opacity only; colours cross-fade through registered properties. */
@property --c-top { syntax: "<color>"; inherits: true; initial-value: #dff6fb; }
@property --c-left { syntax: "<color>"; inherits: true; initial-value: #9fdcec; }
@property --c-right { syntax: "<color>"; inherits: true; initial-value: #5fb9d3; }
@property --c-glow { syntax: "<color>"; inherits: true; initial-value: #8fe0f0; }

.crystal {
  --c-top: #e3f7fb; --c-left: #a6deed; --c-right: #63bad3; --c-glow: #8fe0f0;
  --c-edge: rgb(255 255 255 / .85);
  --breath: 4.8s;
  display: block; width: 100%; height: 100%; overflow: visible;
  transition: --c-top .9s var(--ease), --c-left .9s var(--ease), --c-right .9s var(--ease), --c-glow .9s var(--ease), opacity .6s, filter .6s;
}
[data-theme="dark"] .crystal:not([data-anim="error"], [data-anim="offline"]) { --c-left: #8fd2e6; --c-right: #3f97b4; }
.crystal .f-top { fill: var(--c-top); }
.crystal .f-left { fill: var(--c-left); }
.crystal .f-right { fill: var(--c-right); }
.crystal .edge { fill: none; stroke: var(--c-edge); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.crystal .inner { fill: none; stroke: rgb(255 255 255 / .55); stroke-width: 1.4; stroke-linejoin: round; }
.crystal .glow { fill: var(--c-glow); }
.crystal .shadow { fill: var(--ink); opacity: .12; }
.cr-waves ellipse { fill: none; stroke: var(--c-glow); stroke-width: 2; }
.orbit-path { fill: none; stroke: var(--c-glow); stroke-width: 2.5; stroke-dasharray: 3 9; opacity: .7; }
.chip-ice { fill: var(--c-top); stroke: var(--c-right); stroke-width: 2; stroke-linejoin: round; }
.frost-line { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-dasharray: 2 6; }

/* layers: hidden unless their state is on; they fade so a change of state never pops */
.cr-scan, .cr-refract, .cr-waves, .cr-orbit, .cr-shard, .cr-crack, .cr-frost { opacity: 0; transition: opacity .5s var(--ease); }
.cr-body, .cr-glow, .cr-refract-spin, .cr-scan-band, .cr-waves ellipse, .cr-orbit-spin, .cr-shard-fly, .cr-shadow {
  transform-box: view-box; transform-origin: 0 0;
}
.cr-shadow { transform-origin: 0 84px; }

/* idle: breathes, nothing else moves */
.cr-body { animation: breathe var(--breath) ease-in-out infinite; }
.cr-glow { opacity: .22; animation: glow var(--breath) ease-in-out infinite; }
.cr-shadow { animation: shadow var(--breath) ease-in-out infinite; }
@keyframes breathe { 50% { transform: translateY(-3px) scale(1.012); } }
@keyframes glow { 50% { opacity: .34; transform: scale(1.04); } }
@keyframes shadow { 50% { transform: scale(.94); opacity: .09; } }

/* reading the chats: a band of light passes through the ice, top to bottom */
[data-anim="read"] .cr-scan { opacity: 1; }
.cr-scan-band { animation: scan 2.2s var(--ease) infinite; }
@keyframes scan { from { transform: translateY(-78px); } to { transform: translateY(78px); } }

/* thinking and answering: light refracts inside, the core turns, the glow quickens */
[data-anim="think"] { --breath: 2.4s; --c-glow: #a8ecff; }
[data-anim="think"] .cr-refract { opacity: 1; }
.cr-refract-spin { animation: spin 7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* listening to a voice message: sound rings leave the cube */
[data-anim="voice"] .cr-waves { opacity: 1; }
.cr-waves ellipse { animation: ring 2.4s cubic-bezier(.3, .5, .4, 1) infinite; opacity: 0; }
.cr-waves ellipse:nth-child(2) { animation-delay: .8s; }
.cr-waves ellipse:nth-child(3) { animation-delay: 1.6s; }
@keyframes ring { from { transform: scale(.72); opacity: .55; } to { transform: scale(1.45); opacity: 0; } }

/* working with TIM: a chip of ice circles the cube like a record being fetched */
[data-anim="tim"] .cr-orbit { opacity: 1; }
.cr-orbit-spin { animation: spin 2.6s linear infinite; }

/* sending: a shard breaks off the top edge and leaves to the upper right */
[data-anim="send"] .cr-shard { opacity: 1; }
.cr-shard-fly { animation: fly 1.5s var(--ease) infinite; }
@keyframes fly { 0% { transform: translate(0, 0) scale(.6); opacity: 0; } 20% { opacity: 1; }
  100% { transform: translate(46px, -52px) scale(1); opacity: 0; } }

/* error: the ice warms to red, a crack draws once, the glow pulses slowly */
[data-anim="error"] { --c-top: #fbe3e6; --c-left: #f0a9b3; --c-right: #d66a7b; --c-glow: #ff8a98; --breath: 3.2s; }
[data-anim="error"] .cr-crack { opacity: 1; }
.cr-crack path { stroke-dasharray: 120; stroke-dashoffset: 120; }
[data-anim="error"] .cr-crack path { animation: crack .7s .2s var(--ease) forwards; }
@keyframes crack { to { stroke-dashoffset: 0; } }

/* no connection: frozen grey, no motion at all */
[data-anim="offline"] { --c-top: #e7ecee; --c-left: #c3ccd0; --c-right: #9aa6ac; --c-glow: #c3ccd0; opacity: .7; }
[data-anim="offline"] .cr-frost { opacity: 1; }
[data-anim="offline"] :is(.cr-body, .cr-glow, .cr-shadow) { animation: none; }
[data-theme="dark"] [data-anim="offline"] { --c-top: #607079; --c-left: #48565e; --c-right: #36434a; }

/* paused when the window is hidden (set by app.js) or the user asked for less motion */
.paused .crystal *, .paused .crystal { animation-play-state: paused !important; }
@media (prefers-reduced-motion: reduce) {
  .crystal *, .crystal { animation: none !important; transition-duration: .01s !important; }
  /* states stay readable without motion: the band, rings and chip sit still in their middle position */
  .cr-waves ellipse:first-child { opacity: .4; transform: scale(1.1); }
  .cr-crack path { stroke-dashoffset: 0; }
}
